-
Notifications
You must be signed in to change notification settings - Fork 3
PUT method for shipping addresses #2036
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 3 commits
bfc2f45
0819142
2e89bbd
9378677
6d4f4c4
dbd204d
503cf7d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,10 +5,12 @@ import phoenix.models.account._ | |
| import phoenix.models.cord.OrderShippingAddresses | ||
| import phoenix.models.location.{Address, Addresses, Country, Region} | ||
| import phoenix.payloads.AddressPayloads.CreateAddressPayload | ||
| import phoenix.responses.AddressResponse | ||
| import phoenix.payloads.CartPayloads.CreateCart | ||
| import phoenix.responses.{AddressResponse, CustomerResponse, TheResponse} | ||
| import phoenix.responses.PublicResponses.CountryWithRegions | ||
| import phoenix.responses.cord.CartResponse | ||
| import testutils._ | ||
| import testutils.apis.{PhoenixAdminApi, PhoenixPublicApi} | ||
| import testutils.apis.{PhoenixAdminApi, PhoenixPublicApi, PhoenixStorefrontApi} | ||
| import testutils.fixtures.BakedFixtures | ||
| import testutils.fixtures.api.{ApiFixtureHelpers, randomAddress} | ||
|
|
||
|
|
@@ -18,6 +20,7 @@ class AddressesIntegrationTest | |
| with DefaultJwtAdminAuth | ||
| with ApiFixtureHelpers | ||
| with PhoenixAdminApi | ||
| with PhoenixStorefrontApi | ||
| with PhoenixPublicApi | ||
| with BakedFixtures { | ||
|
|
||
|
|
@@ -31,15 +34,10 @@ class AddressesIntegrationTest | |
| } | ||
|
|
||
| "POST /v1/customers/:customerId/addresses" - { | ||
| "creates an address" in new Customer_Seed { | ||
| val payload = CreateAddressPayload(name = "Home Office", | ||
| regionId = 1, | ||
| address1 = "3000 Coolio Dr", | ||
| city = "Seattle", | ||
| zip = "55555") | ||
| "creates an address" in new Customer_Seed with AddressFixture { | ||
| val newAddress = | ||
| customersApi(customer.accountId).addresses.create(payload).as[AddressResponse] | ||
| newAddress.name must === (payload.name) | ||
| customersApi(customer.accountId).addresses.create(addressPayload).as[AddressResponse] | ||
| newAddress.name must === (addressPayload.name) | ||
| newAddress.isDefault must === (Some(false)) | ||
| } | ||
| } | ||
|
|
@@ -74,31 +72,23 @@ class AddressesIntegrationTest | |
| } | ||
|
|
||
| "PATCH /v1/customers/:customerId/addresses/:addressId" - { | ||
| "can be edited" in new CustomerAddress_Baked { | ||
| val payload = CreateAddressPayload(name = "Home Office", | ||
| regionId = 1, | ||
| address1 = "3000 Coolio Dr", | ||
| city = "Seattle", | ||
| zip = "55555") | ||
| (payload.name, payload.address1) must !==((address.name, address.address1)) | ||
| "can be edited" in new CustomerAddress_Baked with AddressFixture { | ||
| (addressPayload.name, addressPayload.address1) must !==((address.name, address.address1)) | ||
|
|
||
| val updated = | ||
| customersApi(customer.accountId).address(address.id).edit(payload).as[AddressResponse] | ||
| val updated = customersApi(customer.accountId) | ||
| .address(address.id) | ||
| .edit(addressPayload) | ||
| .as[AddressResponse] | ||
|
|
||
| (updated.name, updated.address1) must === ((payload.name, payload.address1)) | ||
| (updated.name, updated.address1) must === ((addressPayload.name, addressPayload.address1)) | ||
| } | ||
| } | ||
|
|
||
| "DELETE /v1/customers/:customerId/addresses/:addressId" - { | ||
| "can be deleted" in new CustomerAddress_Baked { | ||
| "can be deleted" in new CustomerAddress_Baked with AddressFixture { | ||
|
|
||
| //notice the payload is a default shipping address. Delete should make it not default. | ||
| val payload = CreateAddressPayload(name = "Delete Me", | ||
| regionId = 1, | ||
| address1 = "5000 Delete Dr", | ||
| city = "Deattle", | ||
| zip = "666", | ||
| isDefault = true) | ||
| val payload = addressPayload.copy(isDefault = true) | ||
|
|
||
| val newAddress: AddressResponse = | ||
| customersApi(customer.accountId).addresses.create(payload).as[AddressResponse] | ||
|
|
@@ -144,6 +134,42 @@ class AddressesIntegrationTest | |
| } | ||
| } | ||
|
|
||
| "Create /v1/my/addresses" - { | ||
| "POST shipping addresses into a cart adds it to customer details as well" in new AddressFixture { | ||
| withNewCustomerAuth(TestLoginData.random) { implicit auth ⇒ | ||
| val cart = cartsApi.create(CreateCart(customerId = auth.customerId.some)).as[CartResponse] | ||
|
|
||
| storefrontCartsApi.shippingAddress.create(addressPayload).as[TheResponse[CartResponse]] | ||
|
|
||
| customersApi(auth.customerId).addresses.get | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Anna-ZZZ, I think that was my question befooore, hmm. Maybe in
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Request is sent with customer auth anyways because of implicits |
||
| .as[Seq[AddressResponse]] | ||
| .onlyElement | ||
| .address1 must === (addressPayload.address1) | ||
|
|
||
| cartsApi(cart.referenceNumber) | ||
| .get() | ||
| .asTheResult[CartResponse] | ||
| .shippingAddress | ||
| .value | ||
| .address1 must === (addressPayload.address1) | ||
| } | ||
| } | ||
|
|
||
| "PUT shipping addresses must be idempotent" in new AddressFixture { | ||
| withNewCustomerAuth(TestLoginData.random) { implicit auth ⇒ | ||
| cartsApi.create(CreateCart(customerId = auth.customerId.some)).as[CartResponse] | ||
|
|
||
| storefrontCartsApi.shippingAddress.createOrUpdate(addressPayload).mustBeOk() | ||
| storefrontCartsApi.shippingAddress.createOrUpdate(addressPayload).mustBeOk() | ||
|
|
||
| customersApi(auth.customerId).addresses.get | ||
| .as[Seq[AddressResponse]] | ||
| .onlyElement | ||
| .address1 must === (addressPayload.address1) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| "GET /v1/my/addresses" - { | ||
| "retrieves a customer's addresses" in { | ||
| val (customer, loginData) = api_newCustomerWithLogin() | ||
|
|
@@ -211,4 +237,13 @@ class AddressesIntegrationTest | |
| trait NoDefaultAddressFixture extends CustomerAddress_Baked with EmptyCustomerCart_Baked { | ||
| val shippingAddress = OrderShippingAddresses.copyFromAddress(address, cart.refNum).gimme | ||
| } | ||
|
|
||
| trait AddressFixture { | ||
| val addressPayload = CreateAddressPayload(name = "Home Office", | ||
| regionId = 1, | ||
| address1 = "3000 Coolio Dr", | ||
| city = "Seattle", | ||
| zip = "55555") | ||
| } | ||
|
|
||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Anna-ZZZ might not like the identifiers. I’m cool with them, but let’s wait before merge, maybe?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Um, you're right, will fix them.