public static CustomerDraftDsl newCustomerDraft() { return CustomerDraftDsl.of(CUSTOMER_NAME, randomEmail(CustomerFixtures.class), PASSWORD); } }
@Test public void getShippingAddressIdsInEmptyCase() { final CustomerDraft draft = CustomerDraftDsl.of(randomEmail(getClass()), "secret"); final CustomerSignInResult customerSignInResult = client().executeBlocking(CustomerCreateCommand.of(draft)); final Customer customer = customerSignInResult.getCustomer(); assertThat(customer.getBillingAddressIds()).isNotNull().isEmpty(); assertThat(customer.getShippingAddressIds()).isNotNull().isEmpty(); assertThat(customer.getAddresses()).isNotNull().isEmpty(); assertThat(customer.getShippingAddresses()).isNotNull().isEmpty(); assertThat(customer.getBillingAddresses()).isNotNull().isEmpty(); } }
@Test public void createCustomerWithCart() throws Exception { final Cart cart = client().executeBlocking(CartCreateCommand.of(CartDraft.of(EUR)));//could of course be filled with products final String email = randomEmail(CustomerCreateCommandIntegrationTest.class); final CustomerDraft draft = CustomerDraftDsl.of(CUSTOMER_NAME, email, PASSWORD).withCart(cart); final CustomerSignInResult result = client().executeBlocking(CustomerCreateCommand.of(draft)); assertThat(result.getCart()).isNotNull(); assertThat(result.getCart().getId()).isEqualTo(cart.getId()); }
@Test public void createCustomerWithCartWithCartExpansion() { final CustomerGroup customerGroup = CustomerGroupFixtures.b2cCustomerGroup(client()); final Cart cart = client().executeBlocking(CartCreateCommand.of(CartDraft.of(EUR))); final String email = randomEmail(CustomerCreateCommandIntegrationTest.class); final CustomerDraft draft = CustomerDraftDsl.of(CUSTOMER_NAME, email, PASSWORD).withCart(cart).withCustomerGroup(customerGroup); final CustomerCreateCommand customerCreateCommand = CustomerCreateCommand.of(draft) .withExpansionPaths(m -> m.cart().customerGroup()); final CustomerSignInResult result = client().executeBlocking(customerCreateCommand); assertThat(result.getCart()).isNotNull(); assertThat(result.getCart().getId()).isEqualTo(cart.getId()); assertThat(result.getCart().getCustomerGroup().getObj()).isEqualTo(customerGroup); }
final CustomerGroup customerGroup = CustomerGroupFixtures.b2cCustomerGroup(client()); final CustomerName name = CustomerName.ofFirstAndLastName("John", "Smith"); final String email = randomEmail(CustomerCreateCommandIntegrationTest.class); final String externalId = randomString(); final String password = "secret";
@Test public void anonymousId() { final String anonymousId = randomKey(); final CartDraft cartDraft = CartDraft.of(EUR).withCountry(DE).withAnonymousId(anonymousId); final Cart cart = client().executeBlocking(CartCreateCommand.of(cartDraft)); final String email = randomEmail(CustomerCreateCommandIntegrationTest.class); final CustomerDraft customerDraft = CustomerDraftBuilder .of(email, "secret") .anonymousId(anonymousId) .build(); final CustomerSignInResult customerSignInResult = client().executeBlocking(CustomerCreateCommand.of(customerDraft)); assertThat(customerSignInResult.getCustomer().getEmail()).isEqualTo(email); assertThat(customerSignInResult.getCart().getId()) .as("the customer gets the cart from the anonymous session assigned on sign-up") .isEqualTo(cart.getId()); }
@Test public void changeEmail() throws Exception { withCustomer(client(), customer -> { final String newEmail = randomEmail(CustomerUpdateCommandIntegrationTest.class); assertThat(customer.getEmail()).isNotEqualTo(newEmail); final Customer updatedCustomer = client().executeBlocking(CustomerUpdateCommand.of(customer, ChangeEmail.of(newEmail))); assertThat(updatedCustomer.getEmail()).isEqualTo(newEmail); Query<CustomerEmailChangedMessage> messageQuery = MessageQuery.of() .withPredicates(m -> m.resource().is(customer)) .withSort(m -> m.createdAt().sort().desc()) .withLimit(1L) .forMessageType(CustomerEmailChangedMessage.MESSAGE_HINT); assertEventually(() -> { final PagedQueryResult<CustomerEmailChangedMessage> queryResult = client().executeBlocking(messageQuery); assertThat(queryResult.head()).isPresent(); final CustomerEmailChangedMessage message = queryResult.head().get(); assertThat(message.getEmail()).isEqualTo(newEmail); }); }); }
private static Customer createCustomer(final String firstName, final String lastName,final String middleName, final String title) { final CustomerName customerName = CustomerName.ofFirstAndLastName(firstName, lastName); final CustomerDraft draft = CustomerDraftDsl.of(customerName, randomEmail(CustomerQueryIntegrationTest.class), "secret") .withLocale(Locale.GERMAN) .withMiddleName(middleName) .withTitle(title) .withExternalId(randomString()+firstName) .withCustomerNumber(randomKey()); final CustomerSignInResult signInResult = client().executeBlocking(CustomerCreateCommand.of(draft)); final Customer initialCustomer = signInResult.getCustomer(); final Customer updatedCustomer = client().executeBlocking(CustomerUpdateCommand.of(initialCustomer, asList(AddAddress.of(AddressBuilder.of(CountryCode.DE).city(randomString()).build()), SetCustomerGroup.of(b2cCustomerGroup(client()))))); final SetDefaultShippingAddress shippingAddressAction = SetDefaultShippingAddress.ofAddress(updatedCustomer.getAddresses().get(0)); final SetDefaultBillingAddress billingAddressAction = SetDefaultBillingAddress.ofAddress(updatedCustomer.getAddresses().get(0)); return client().executeBlocking(CustomerUpdateCommand.of(updatedCustomer, asList(shippingAddressAction, billingAddressAction))); } }