import * as assert from "assert" ; import BatchTableDeleteEntityOptionalParams from "../../../src/table/batch/BatchTableDeleteEntityOptionalParams" ; import BatchTableInsertEntityOptionalParams from "../../../src/table/batch/BatchTableInsertEntityOptionalParams" ; import BatchTableQueryEntitiesWithPartitionAndRowKeyOptionalParams from "../../../src/table/batch/BatchTableQueryEntitiesWithPartitionAndRowKeyOptionalParams" ; import { TableBatchSerialization } from "../../../src/table/batch/TableBatchSerialization" ; import SerializationRequestMockStrings from "./mock.request.serialization.strings" ; import SerializationResponseMocks from "./mock.response.serialization.strings" ; import SerializationObjectForBatchRequestFactory from "./mock.serialization.batchrequest.factory" ; describe ( "batch serialization unit tests, these are not the API integration tests:" , ( ) => { it ( "serializes, mock table batch response to query with partition key and row key operation correctly" , async ( ) => { const expectedResponseString = SerializationResponseMocks . PartialBatchQueryWithPartitionKeyAndRowKeyResponse ; const serializer = new TableBatchSerialization ( ) ; serializer . deserializeBatchRequest ( SerializationRequestMockStrings . BatchQueryWithPartitionKeyAndRowKeyRequest ) ; const request = SerializationObjectForBatchRequestFactory . GetBatchRequestForQueryWithPartitionandRowKeyResponseMock ( ) ; request . ingestOptionalParams ( new BatchTableQueryEntitiesWithPartitionAndRowKeyOptionalParams ( ) ) ; const serializedBatchOperationResponse = await serializer . serializeTableQueryEntityWithPartitionAndRowKeyBatchResponse ( request , SerializationObjectForBatchRequestFactory . GetBatchTableQueryEntitiesWithPartitionAndRowKeyResponseMock ( ) ) ; const splitResponse = serializedBatchOperationResponse . split ( "\r\n" ) ; const splitExpected = expectedResponseString . split ( "\r\n" ) ; splitResponse . forEach ( ( value ) => { if ( value . length > 2 ) { assert . notEqual ( splitExpected . indexOf ( value ) , - 1 , "Could not find " + value ) ; } } ) ; } ) ; it ( "serializes, mock table batch response to single insert" , ( done ) => { const expectedResponseString = SerializationResponseMocks . PartialBatchSingleInsertOrReplaceResponseString ; const serializer = new TableBatchSerialization ( ) ; serializer . deserializeBatchRequest ( SerializationRequestMockStrings . BatchSingleInsertOrReplaceRequestString ) ; const request = SerializationObjectForBatchRequestFactory . GetBatchRequestForSingleInsertResponseMock ( ) ; request . ingestOptionalParams ( new BatchTableInsertEntityOptionalParams ( ) ) ; const serializedBatchOperationResponse = serializer . serializeTableInsertEntityBatchResponse ( request , SerializationObjectForBatchRequestFactory . GetBatchOperationMockForSingleInsert ( ) ) ; const splitResponse = serializedBatchOperationResponse . split ( "\r\n" ) ; const splitExpected = expectedResponseString . split ( "\r\n" ) ; splitExpected . forEach ( ( value ) => { if ( value . length > 2 ) { assert . notEqual ( splitResponse . indexOf ( value ) , - 1 , "Could not find " + value + " in serialized response." ) ; } } ) ; done ( ) ; } ) ; it ( "serializes, mock table batch response to single delete" , async ( ) => { const expectedResponseString = SerializationResponseMocks . PartialBatchSingleDeleteResponseString ; const serializer = new TableBatchSerialization ( ) ; serializer . deserializeBatchRequest ( SerializationRequestMockStrings . BatchSingleDeleteRequestString ) ; const request = SerializationObjectForBatchRequestFactory . GetBatchRequestForSingleDeletetResponseMock ( ) ; request . ingestOptionalParams ( new BatchTableDeleteEntityOptionalParams ( ) ) ; const serializedBatchOperationResponse = serializer . serializeTableDeleteEntityBatchResponse ( request , SerializationObjectForBatchRequestFactory . GetBatchOperationMockForSingleDelete ( ) ) ; const splitResponse = serializedBatchOperationResponse . split ( "\r\n" ) ; const splitExpected = expectedResponseString . split ( "\r\n" ) ; splitExpected . forEach ( ( value ) => { if ( value . length > 2 ) { assert . notEqual ( splitResponse . indexOf ( value ) , - 1 , "Could not find " + value + " in serialized response." ) ; } } ) ; } ) ; } ) ;