Skip to content

Commit a4880e6

Browse files
test: it - additional addresss and state
1 parent 0946c5a commit a4880e6

File tree

1 file changed

+111
-0
lines changed
  • src/integration-test/java/com/commercetools/sync/integration/externalsource/customers

1 file changed

+111
-0
lines changed

src/integration-test/java/com/commercetools/sync/integration/externalsource/customers/CustomerSyncIT.java

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,4 +344,115 @@ void sync_WithUpdatedAllFieldsOfCustomer_ShouldUpdateCustomerWithAllExpectedActi
344344
.isEqualTo(
345345
"Summary: 1 customers were processed in total (0 created, 1 updated and 0 failed to sync).");
346346
}
347+
348+
@Test
349+
void sync_WithUpdatedAddressStateAndAdditionalStreetInfo_ShouldUpdateCustomer() {
350+
// Create a customer with addresses containing state and additionalStreetInfo
351+
final CustomerDraft customerDraftWithAddressFields =
352+
CustomerDraftBuilder.of()
353+
354+
.password("12345")
355+
.key("customer-key-address-test")
356+
.addresses(
357+
asList(
358+
AddressBuilder.of()
359+
.country(CountryCode.US.name())
360+
.city("San Francisco")
361+
.key("address1")
362+
.state("California")
363+
.additionalStreetInfo("Suite 100")
364+
.build(),
365+
AddressBuilder.of()
366+
.country(CountryCode.DE.name())
367+
.city("Munich")
368+
.key("address2")
369+
.state("Bavaria")
370+
.additionalStreetInfo("Building A")
371+
.build()))
372+
.build();
373+
374+
// Create the customer
375+
final CustomerSyncStatistics createStatistics =
376+
customerSync
377+
.sync(singletonList(customerDraftWithAddressFields))
378+
.toCompletableFuture()
379+
.join();
380+
381+
assertThat(createStatistics.getCreated().get()).isEqualTo(1);
382+
assertThat(errorMessages).isEmpty();
383+
assertThat(warningMessages).isEmpty();
384+
385+
// Verify the created customer has the correct fields
386+
final Customer createdCustomer =
387+
TestClientUtils.CTP_TARGET_CLIENT
388+
.customers()
389+
.withKey("customer-key-address-test")
390+
.get()
391+
.executeBlocking()
392+
.getBody();
393+
394+
assertThat(createdCustomer.getAddresses()).hasSize(2);
395+
assertThat(createdCustomer.getAddresses().get(0).getState()).isEqualTo("California");
396+
assertThat(createdCustomer.getAddresses().get(0).getAdditionalStreetInfo())
397+
.isEqualTo("Suite 100");
398+
assertThat(createdCustomer.getAddresses().get(1).getState()).isEqualTo("Bavaria");
399+
assertThat(createdCustomer.getAddresses().get(1).getAdditionalStreetInfo())
400+
.isEqualTo("Building A");
401+
402+
// Update the customer with different state and additionalStreetInfo
403+
final CustomerDraft updatedCustomerDraft =
404+
CustomerDraftBuilder.of()
405+
406+
.password("12345")
407+
.key("customer-key-address-test")
408+
.addresses(
409+
asList(
410+
AddressBuilder.of()
411+
.country(CountryCode.US.name())
412+
.city("San Francisco")
413+
.key("address1")
414+
.state("Texas") // Changed from California
415+
.additionalStreetInfo("Suite 200") // Changed from Suite 100
416+
.build(),
417+
AddressBuilder.of()
418+
.country(CountryCode.DE.name())
419+
.city("Munich")
420+
.key("address2")
421+
.state("Berlin") // Changed from Bavaria
422+
.additionalStreetInfo("Building B") // Changed from Building A
423+
.build()))
424+
.build();
425+
426+
// Clear previous update actions
427+
updateActionList.clear();
428+
429+
// Sync the updated customer
430+
final CustomerSyncStatistics updateStatistics =
431+
customerSync.sync(singletonList(updatedCustomerDraft)).toCompletableFuture().join();
432+
433+
assertThat(updateStatistics.getUpdated().get()).isEqualTo(1);
434+
assertThat(errorMessages).isEmpty();
435+
assertThat(warningMessages).isEmpty();
436+
437+
// Verify update actions were generated for the changed fields
438+
assertThat(updateActionList).isNotEmpty();
439+
assertThat(updateActionList.toString()).contains("changeAddress");
440+
441+
// Verify the updated customer has the new values
442+
final Customer updatedCustomer =
443+
TestClientUtils.CTP_TARGET_CLIENT
444+
.customers()
445+
.withKey("customer-key-address-test")
446+
.get()
447+
.executeBlocking()
448+
.getBody();
449+
450+
assertThat(updatedCustomer.getAddresses()).hasSize(2);
451+
assertThat(updatedCustomer.getAddresses().get(0).getState()).isEqualTo("Texas");
452+
assertThat(updatedCustomer.getAddresses().get(0).getAdditionalStreetInfo())
453+
.isEqualTo("Suite 200");
454+
assertThat(updatedCustomer.getAddresses().get(1).getState()).isEqualTo("Berlin");
455+
assertThat(updatedCustomer.getAddresses().get(1).getAdditionalStreetInfo())
456+
.isEqualTo("Building B");
457+
}
347458
}

0 commit comments

Comments
 (0)