From bfc2f45499c07698135542006cb3930f901bc2e8 Mon Sep 17 00:00:00 2001 From: Alexey Afanasev Date: Thu, 1 Jun 2017 18:03:45 +0300 Subject: [PATCH 1/6] PUT for shipping addresses --- .../models/cord/OrderShippingAddress.scala | 16 ++++- .../phoenix/app/phoenix/routes/Customer.scala | 5 ++ .../app/phoenix/routes/admin/CartRoutes.scala | 7 ++ .../carts/CartShippingAddressUpdater.scala | 33 ++++++++++ .../AddressesIntegrationTest.scala | 66 +++++++++++-------- .../integration/testutils/HttpSupport.scala | 14 ++++ .../testutils/apis/PhoenixStorefrontApi.scala | 8 +++ 7 files changed, 122 insertions(+), 27 deletions(-) diff --git a/phoenix-scala/phoenix/app/phoenix/models/cord/OrderShippingAddress.scala b/phoenix-scala/phoenix/app/phoenix/models/cord/OrderShippingAddress.scala index a157195a95..206ed22899 100644 --- a/phoenix-scala/phoenix/app/phoenix/models/cord/OrderShippingAddress.scala +++ b/phoenix-scala/phoenix/app/phoenix/models/cord/OrderShippingAddress.scala @@ -5,7 +5,7 @@ import java.time.Instant import core.db._ import phoenix.models.location.{Address, Addresses, Region, Regions} import phoenix.models.traits.Addressable -import phoenix.payloads.AddressPayloads.UpdateAddressPayload +import phoenix.payloads.AddressPayloads.{CreateAddressPayload, UpdateAddressPayload} import shapeless._ import slick.jdbc.PostgresProfile.api._ @@ -53,6 +53,20 @@ object OrderShippingAddress { phoneNumber = p.phoneNumber.fold(a.phoneNumber)(Some(_)) ) } + + def fromCreatePatchPayload(a: OrderShippingAddress, p: CreateAddressPayload) = { + OrderShippingAddress( + id = a.id, + cordRef = a.cordRef, + regionId = p.regionId, + name = p.name, + address1 = p.address1, + address2 = p.address2.fold(a.address2)(Some(_)), + city = p.city, + zip = p.zip, + phoneNumber = p.phoneNumber.fold(a.phoneNumber)(Some(_)) + ) + } } class OrderShippingAddresses(tag: Tag) diff --git a/phoenix-scala/phoenix/app/phoenix/routes/Customer.scala b/phoenix-scala/phoenix/app/phoenix/routes/Customer.scala index a5b8520a9c..c1ce48f3d7 100644 --- a/phoenix-scala/phoenix/app/phoenix/routes/Customer.scala +++ b/phoenix-scala/phoenix/app/phoenix/routes/Customer.scala @@ -143,6 +143,11 @@ object Customer { payload) } } ~ + (put & pathEnd & entity(as[CreateAddressPayload])) { payload ⇒ + mutateOrFailures { + CartShippingAddressUpdater.createOrUpdateShippingAddress(auth.model, payload) + } + } ~ (delete & pathEnd) { deleteOrFailures { CartShippingAddressUpdater.removeShippingAddress(auth.model) diff --git a/phoenix-scala/phoenix/app/phoenix/routes/admin/CartRoutes.scala b/phoenix-scala/phoenix/app/phoenix/routes/admin/CartRoutes.scala index 8c6e85e3e4..56ee3ddb2a 100644 --- a/phoenix-scala/phoenix/app/phoenix/routes/admin/CartRoutes.scala +++ b/phoenix-scala/phoenix/app/phoenix/routes/admin/CartRoutes.scala @@ -145,6 +145,13 @@ object CartRoutes { Some(refNum)) } } ~ + (put & pathEnd & entity(as[CreateAddressPayload])) { payload ⇒ + mutateOrFailures { + CartShippingAddressUpdater.createOrUpdateShippingAddress(auth.model, + payload, + Some(refNum)) + } + } ~ (delete & pathEnd) { mutateOrFailures { CartShippingAddressUpdater.removeShippingAddress(auth.model, Some(refNum)) diff --git a/phoenix-scala/phoenix/app/phoenix/services/carts/CartShippingAddressUpdater.scala b/phoenix-scala/phoenix/app/phoenix/services/carts/CartShippingAddressUpdater.scala index 6014083cc5..70ec4449ea 100644 --- a/phoenix-scala/phoenix/app/phoenix/services/carts/CartShippingAddressUpdater.scala +++ b/phoenix-scala/phoenix/app/phoenix/services/carts/CartShippingAddressUpdater.scala @@ -14,6 +14,7 @@ import phoenix.services.{CartValidator, LogActivity} import slick.jdbc.PostgresProfile.api._ import phoenix.utils.aliases._ import core.db._ +import cats.implicits._ object CartShippingAddressUpdater { @@ -23,6 +24,13 @@ object CartShippingAddressUpdater { def mustFindShipAddressForCart(cart: Cart)(implicit ec: EC): DbResultT[OrderShippingAddress] = OrderShippingAddresses.findByOrderRef(cart.refNum).mustFindOneOr(NoShipAddress(cart.refNum)) + private def createShippingAddress(cart: Cart, payload: CreateAddressPayload)( + implicit ec: EC): DbResultT[OrderShippingAddress] = + for { + newAddress ← * <~ Addresses.create(Address.fromPayload(payload, cart.accountId)) + shippingAddress ← * <~ OrderShippingAddresses.copyFromAddress(newAddress, cart.refNum) + } yield shippingAddress + def createShippingAddressFromAddressId(originator: User, addressId: Int, refNum: Option[String] = None)( @@ -83,6 +91,31 @@ object CartShippingAddressUpdater { buildOneShipping(shipAddress, region)) } yield TheResponse.validated(response, validated) + def createOrUpdateShippingAddress(originator: User, + payload: CreateAddressPayload, + refNum: Option[String] = None)( + implicit ec: EC, + db: DB, + ac: AC, + ctx: OC): DbResultT[TheResponse[CartResponse]] = + for { + cart ← * <~ getCartByOriginator(originator, refNum) + shippingAddress ← * <~ OrderShippingAddresses + .findByOrderRef(cart.refNum) + .one + .findOrCreate(createShippingAddress(cart, payload)) + + region ← * <~ Regions.mustFindById404(shippingAddress.regionId) + + patch = OrderShippingAddress.fromCreatePatchPayload(shippingAddress, payload) + _ ← * <~ OrderShippingAddresses.update(shippingAddress, patch) + validated ← * <~ CartValidator(cart).validate() + response ← * <~ CartResponse.buildRefreshed(cart) + _ ← * <~ LogActivity().orderShippingAddressUpdated(originator, + response, + buildOneShipping(shippingAddress, region)) + } yield TheResponse.validated(response, validated) + def removeShippingAddress(originator: User, refNum: Option[String] = None)( implicit ec: EC, db: DB, diff --git a/phoenix-scala/phoenix/test/integration/AddressesIntegrationTest.scala b/phoenix-scala/phoenix/test/integration/AddressesIntegrationTest.scala index eb785dbfdd..a9fcafb9c3 100644 --- a/phoenix-scala/phoenix/test/integration/AddressesIntegrationTest.scala +++ b/phoenix-scala/phoenix/test/integration/AddressesIntegrationTest.scala @@ -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.payloads.CartPayloads.CreateCart import phoenix.responses.AddressResponse 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,10 +20,12 @@ class AddressesIntegrationTest with DefaultJwtAdminAuth with ApiFixtureHelpers with PhoenixAdminApi + with PhoenixStorefrontApi with PhoenixPublicApi with BakedFixtures { "GET /v1/customers/:customerId/addresses" - { + pending "lists addresses" in new CustomerAddress_Baked { val addresses = customersApi(customer.accountId).addresses.get().as[Seq[AddressResponse]] @@ -31,20 +35,17 @@ 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") + pending + "creates an address" in new Customer_Seed with AddressFixtures { 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)) } } "POST /v1/customers/:customerId/addresses/:addressId/default" - { + pending "sets the isDefaultShippingAddress flag on an address" in new NoDefaultAddressFixture { customersApi(customer.accountId).address(address.id).setDefault().mustBeOk() Addresses.findOneById(address.id).gimme.value.isDefaultShipping mustBe true @@ -60,6 +61,7 @@ class AddressesIntegrationTest } "DELETE /v1/customers/:customerId/addresses/default" - { + pending "removes an existing default from a shipping address" in new CustomerAddress_Baked { customersApi(customer.accountId).addresses.unsetDefault().mustBeEmpty() @@ -74,31 +76,25 @@ 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)) + pending + "can be edited" in new CustomerAddress_Baked with AddressFixtures { + (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 { + pending + "can be deleted" in new CustomerAddress_Baked with AddressFixtures { //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 +140,15 @@ class AddressesIntegrationTest } } + "PUT /v1/my/addresses" - { + "put shipping addresses in" in new AddressFixtures { + withNewCustomerAuth(TestLoginData.random) { implicit auth ⇒ + cartsApi.create(CreateCart(customerId = auth.customerId.some)).as[CartResponse] + storefrontCartsApi.shippingAddress.createOrUpdate(addressPayload).mustBeOk() + } + } + } + "GET /v1/my/addresses" - { "retrieves a customer's addresses" in { val (customer, loginData) = api_newCustomerWithLogin() @@ -211,4 +216,13 @@ class AddressesIntegrationTest trait NoDefaultAddressFixture extends CustomerAddress_Baked with EmptyCustomerCart_Baked { val shippingAddress = OrderShippingAddresses.copyFromAddress(address, cart.refNum).gimme } + + trait AddressFixtures { + val addressPayload = CreateAddressPayload(name = "Home Office", + regionId = 1, + address1 = "3000 Coolio Dr", + city = "Seattle", + zip = "55555") + } + } diff --git a/phoenix-scala/phoenix/test/integration/testutils/HttpSupport.scala b/phoenix-scala/phoenix/test/integration/testutils/HttpSupport.scala index 8481596bbe..e92f014255 100644 --- a/phoenix-scala/phoenix/test/integration/testutils/HttpSupport.scala +++ b/phoenix-scala/phoenix/test/integration/testutils/HttpSupport.scala @@ -117,6 +117,17 @@ trait HttpSupport dispatchRequest(request, jwtCookie) } + def PUT(path: String, rawBody: String, jwtCookie: Option[Cookie]): HttpResponse = { + val request = HttpRequest(method = HttpMethods.PUT, + uri = pathToAbsoluteUrl(path), + entity = HttpEntity.Strict( + ContentTypes.`application/json`, + ByteString(rawBody) + )) + + dispatchRequest(request, jwtCookie) + } + def POST(path: String, jwtCookie: Option[Cookie]): HttpResponse = dispatchRequest(HttpRequest(method = HttpMethods.POST, uri = pathToAbsoluteUrl(path)), jwtCookie) @@ -143,6 +154,9 @@ trait HttpSupport def POST[T <: AnyRef](path: String, payload: T, jwtCookie: Option[Cookie]): HttpResponse = POST(path, writeJson(payload), jwtCookie) + def PUT[T <: AnyRef](path: String, payload: T, jwtCookie: Option[Cookie]): HttpResponse = + PUT(path, writeJson(payload), jwtCookie) + def PATCH[T <: AnyRef](path: String, payload: T, jwtCookie: Option[Cookie]): HttpResponse = PATCH(path, writeJson(payload), jwtCookie) diff --git a/phoenix-scala/phoenix/test/integration/testutils/apis/PhoenixStorefrontApi.scala b/phoenix-scala/phoenix/test/integration/testutils/apis/PhoenixStorefrontApi.scala index 33a4dc0e9b..82405c5d66 100644 --- a/phoenix-scala/phoenix/test/integration/testutils/apis/PhoenixStorefrontApi.scala +++ b/phoenix-scala/phoenix/test/integration/testutils/apis/PhoenixStorefrontApi.scala @@ -2,6 +2,7 @@ package testutils.apis import akka.http.scaladsl.model.HttpResponse import cats.implicits._ +import phoenix.payloads.AddressPayloads.CreateAddressPayload import phoenix.payloads.CartPayloads.CheckoutCart import phoenix.payloads.LineItemPayloads.UpdateLineItemsPayload import phoenix.payloads.PaymentPayloads.{CreateApplePayPayment, CreateCreditCardFromTokenPayload} @@ -43,7 +44,14 @@ trait PhoenixStorefrontApi extends HttpSupport { self: FoxSuite ⇒ def searchByRegion(countryCode: String)(implicit aa: TestCustomerAuth): HttpResponse = GET(s"$shippingMethods/$countryCode", aa.jwtCookie.some) + } + + object shippingAddress { + val shippingAddress = s"$cartPath/shipping-address" + def createOrUpdate(payload: CreateAddressPayload)( + implicit ca: TestCustomerAuth): HttpResponse = + PUT(shippingAddress, payload, ca.jwtCookie.some) } } From 08191424fb76ef8e69733cbd6fe0e2bae25bb9a7 Mon Sep 17 00:00:00 2001 From: Alexey Afanasev Date: Fri, 2 Jun 2017 03:03:52 +0300 Subject: [PATCH 2/6] Append tests --- .../AddressesIntegrationTest.scala | 47 ++++++++++++++----- .../testutils/apis/PhoenixStorefrontApi.scala | 10 ++++ 2 files changed, 44 insertions(+), 13 deletions(-) diff --git a/phoenix-scala/phoenix/test/integration/AddressesIntegrationTest.scala b/phoenix-scala/phoenix/test/integration/AddressesIntegrationTest.scala index a9fcafb9c3..7e135c8a43 100644 --- a/phoenix-scala/phoenix/test/integration/AddressesIntegrationTest.scala +++ b/phoenix-scala/phoenix/test/integration/AddressesIntegrationTest.scala @@ -6,7 +6,7 @@ import phoenix.models.cord.OrderShippingAddresses import phoenix.models.location.{Address, Addresses, Country, Region} import phoenix.payloads.AddressPayloads.CreateAddressPayload import phoenix.payloads.CartPayloads.CreateCart -import phoenix.responses.AddressResponse +import phoenix.responses.{AddressResponse, CustomerResponse, TheResponse} import phoenix.responses.PublicResponses.CountryWithRegions import phoenix.responses.cord.CartResponse import testutils._ @@ -25,7 +25,6 @@ class AddressesIntegrationTest with BakedFixtures { "GET /v1/customers/:customerId/addresses" - { - pending "lists addresses" in new CustomerAddress_Baked { val addresses = customersApi(customer.accountId).addresses.get().as[Seq[AddressResponse]] @@ -35,8 +34,7 @@ class AddressesIntegrationTest } "POST /v1/customers/:customerId/addresses" - { - pending - "creates an address" in new Customer_Seed with AddressFixtures { + "creates an address" in new Customer_Seed with AddressFixture { val newAddress = customersApi(customer.accountId).addresses.create(addressPayload).as[AddressResponse] newAddress.name must === (addressPayload.name) @@ -45,7 +43,6 @@ class AddressesIntegrationTest } "POST /v1/customers/:customerId/addresses/:addressId/default" - { - pending "sets the isDefaultShippingAddress flag on an address" in new NoDefaultAddressFixture { customersApi(customer.accountId).address(address.id).setDefault().mustBeOk() Addresses.findOneById(address.id).gimme.value.isDefaultShipping mustBe true @@ -61,7 +58,6 @@ class AddressesIntegrationTest } "DELETE /v1/customers/:customerId/addresses/default" - { - pending "removes an existing default from a shipping address" in new CustomerAddress_Baked { customersApi(customer.accountId).addresses.unsetDefault().mustBeEmpty() @@ -76,8 +72,7 @@ class AddressesIntegrationTest } "PATCH /v1/customers/:customerId/addresses/:addressId" - { - pending - "can be edited" in new CustomerAddress_Baked with AddressFixtures { + "can be edited" in new CustomerAddress_Baked with AddressFixture { (addressPayload.name, addressPayload.address1) must !==((address.name, address.address1)) val updated = customersApi(customer.accountId) @@ -90,8 +85,7 @@ class AddressesIntegrationTest } "DELETE /v1/customers/:customerId/addresses/:addressId" - { - pending - "can be deleted" in new CustomerAddress_Baked with AddressFixtures { + "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 = addressPayload.copy(isDefault = true) @@ -140,11 +134,38 @@ class AddressesIntegrationTest } } - "PUT /v1/my/addresses" - { - "put shipping addresses in" in new AddressFixtures { + "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 + .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) } } } @@ -217,7 +238,7 @@ class AddressesIntegrationTest val shippingAddress = OrderShippingAddresses.copyFromAddress(address, cart.refNum).gimme } - trait AddressFixtures { + trait AddressFixture { val addressPayload = CreateAddressPayload(name = "Home Office", regionId = 1, address1 = "3000 Coolio Dr", diff --git a/phoenix-scala/phoenix/test/integration/testutils/apis/PhoenixStorefrontApi.scala b/phoenix-scala/phoenix/test/integration/testutils/apis/PhoenixStorefrontApi.scala index 82405c5d66..c544274ae9 100644 --- a/phoenix-scala/phoenix/test/integration/testutils/apis/PhoenixStorefrontApi.scala +++ b/phoenix-scala/phoenix/test/integration/testutils/apis/PhoenixStorefrontApi.scala @@ -12,6 +12,13 @@ trait PhoenixStorefrontApi extends HttpSupport { self: FoxSuite ⇒ val rootPrefix: String = "v1/my" + object accountApi { + val accountPath = s"$rootPrefix/account" + + def getAccount()(implicit ca: TestCustomerAuth): HttpResponse = + GET(accountPath, ca.jwtCookie.some) + } + case class storefrontProductsApi(reference: String) { val productPath = s"$rootPrefix/products/$reference/baked" @@ -49,6 +56,9 @@ trait PhoenixStorefrontApi extends HttpSupport { self: FoxSuite ⇒ object shippingAddress { val shippingAddress = s"$cartPath/shipping-address" + def create(payload: CreateAddressPayload)(implicit ca: TestCustomerAuth): HttpResponse = + POST(shippingAddress, payload, ca.jwtCookie.some) + def createOrUpdate(payload: CreateAddressPayload)( implicit ca: TestCustomerAuth): HttpResponse = PUT(shippingAddress, payload, ca.jwtCookie.some) From 2e89bbdb2bf3fce7146cd13eb27453af8822dde0 Mon Sep 17 00:00:00 2001 From: Alexey Afanasev Date: Fri, 2 Jun 2017 03:21:54 +0300 Subject: [PATCH 3/6] Update api docs --- .../content/reference/resources/customer_cart.apib | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/developer-portal/content/reference/resources/customer_cart.apib b/developer-portal/content/reference/resources/customer_cart.apib index 863c1bd217..2fd04f9859 100644 --- a/developer-portal/content/reference/resources/customer_cart.apib +++ b/developer-portal/content/reference/resources/customer_cart.apib @@ -151,6 +151,14 @@ Removes the shipping method from the cart. + Attributes (UpdateAddressPayload) + Response 200 (application/json) + Attributes (FullOrder) + + +### Create or update [PUT /v1/my/cart/shipping-address] + ++ Request (application/json) + + Attributes(CreateAddressPayload) ++ Response 200 (application/json) + + Attributes (Address) ### Delete [DELETE] From 93786772a3f411e7e834cc929677364862ad570d Mon Sep 17 00:00:00 2001 From: Alexey Afanasev Date: Fri, 2 Jun 2017 11:17:20 +0300 Subject: [PATCH 4/6] Meaningful param names --- .../models/cord/OrderShippingAddress.scala | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/phoenix-scala/phoenix/app/phoenix/models/cord/OrderShippingAddress.scala b/phoenix-scala/phoenix/app/phoenix/models/cord/OrderShippingAddress.scala index 206ed22899..7cb62f7874 100644 --- a/phoenix-scala/phoenix/app/phoenix/models/cord/OrderShippingAddress.scala +++ b/phoenix-scala/phoenix/app/phoenix/models/cord/OrderShippingAddress.scala @@ -54,17 +54,17 @@ object OrderShippingAddress { ) } - def fromCreatePatchPayload(a: OrderShippingAddress, p: CreateAddressPayload) = { + def fromCreatePatchPayload(existingAddress: OrderShippingAddress, incomingPayload: CreateAddressPayload) = { OrderShippingAddress( - id = a.id, - cordRef = a.cordRef, - regionId = p.regionId, - name = p.name, - address1 = p.address1, - address2 = p.address2.fold(a.address2)(Some(_)), - city = p.city, - zip = p.zip, - phoneNumber = p.phoneNumber.fold(a.phoneNumber)(Some(_)) + id = existingAddress.id, + cordRef = existingAddress.cordRef, + regionId = incomingPayload.regionId, + name = incomingPayload.name, + address1 = incomingPayload.address1, + address2 = incomingPayload.address2.fold(existingAddress.address2)(Some(_)), + city = incomingPayload.city, + zip = incomingPayload.zip, + phoneNumber = incomingPayload.phoneNumber.fold(existingAddress.phoneNumber)(Some(_)) ) } } From 6d4f4c4e9303d77605b6b337e59e3537e1e32b81 Mon Sep 17 00:00:00 2001 From: Alexey Afanasev Date: Mon, 5 Jun 2017 13:45:15 +0300 Subject: [PATCH 5/6] Update customer address on PUT --- phoenix-scala/core/app/core/db/package.scala | 9 ++-- .../models/cord/OrderShippingAddress.scala | 14 ++++- .../carts/CartShippingAddressUpdater.scala | 35 ++++++++----- .../AddressesIntegrationTest.scala | 27 +++++++--- .../CartValidatorIntegrationTest.scala | 2 +- .../ShippingMethodsIntegrationTest.scala | 4 +- .../integration/services/CheckoutTest.scala | 6 +-- .../services/ShippingManagerTest.scala | 51 ++++++++++--------- 8 files changed, 93 insertions(+), 55 deletions(-) diff --git a/phoenix-scala/core/app/core/db/package.scala b/phoenix-scala/core/app/core/db/package.scala index 0129374b27..4489001db4 100644 --- a/phoenix-scala/core/app/core/db/package.scala +++ b/phoenix-scala/core/app/core/db/package.scala @@ -342,18 +342,19 @@ package object db { implicit class EnrichedDBIOpt[R](val dbio: DBIO[Option[R]]) extends AnyVal { - def findOrCreate(r: DbResultT[R])(implicit ec: EC): DbResultT[R] = { + def findOrCreate(createAction: ⇒ DbResultT[R])(implicit ec: EC): DbResultT[R] = { dbio.dbresult.flatMap { case Some(model) ⇒ DbResultT.good(model) - case None ⇒ r + case None ⇒ createAction } } // Last item in tuple determines if cart was created or not - def findOrCreateExtended(r: DbResultT[R])(implicit ec: EC): DbResultT[(R, FoundOrCreated)] = { + def findOrCreateExtended(createAction: ⇒ DbResultT[R])( + implicit ec: EC): DbResultT[(R, FoundOrCreated)] = { dbio.dbresult.flatMap { case Some(model) ⇒ DbResultT.good((model, Found)) - case _ ⇒ r.map(result ⇒ (result, Created)) + case _ ⇒ createAction.map(result ⇒ (result, Created)) } } diff --git a/phoenix-scala/phoenix/app/phoenix/models/cord/OrderShippingAddress.scala b/phoenix-scala/phoenix/app/phoenix/models/cord/OrderShippingAddress.scala index 7cb62f7874..78fb9ab209 100644 --- a/phoenix-scala/phoenix/app/phoenix/models/cord/OrderShippingAddress.scala +++ b/phoenix-scala/phoenix/app/phoenix/models/cord/OrderShippingAddress.scala @@ -54,7 +54,8 @@ object OrderShippingAddress { ) } - def fromCreatePatchPayload(existingAddress: OrderShippingAddress, incomingPayload: CreateAddressPayload) = { + def fromCreatePatchPayload(existingAddress: OrderShippingAddress, + incomingPayload: CreateAddressPayload) = { OrderShippingAddress( id = existingAddress.id, cordRef = existingAddress.cordRef, @@ -86,6 +87,7 @@ class OrderShippingAddresses(tag: Tag) def * = (id, cordRef, regionId, name, address1, address2, city, zip, phoneNumber, createdAt, updatedAt) <> ((OrderShippingAddress.apply _).tupled, OrderShippingAddress.unapply) + // FIXME this fk is not reflected in db schema @aafa def address = foreignKey(Addresses.tableName, id, Addresses)(_.id) def order = foreignKey(Carts.tableName, cordRef, Carts)(_.referenceNumber) def region = foreignKey(Regions.tableName, regionId, Regions)(_.id) @@ -100,7 +102,7 @@ object OrderShippingAddresses import scope._ - def copyFromAddress(address: Address, cordRef: String)( + def createFromAddress(address: Address, cordRef: String)( implicit ec: EC): DbResultT[OrderShippingAddress] = create(OrderShippingAddress.buildFromAddress(address).copy(cordRef = cordRef)) @@ -120,6 +122,14 @@ object OrderShippingAddresses shippingAddresses ← q regions ← Regions if regions.id === shippingAddresses.regionId } yield (shippingAddresses, regions) + + def withCustomerAddress(accountId: Int) + : Query[(OrderShippingAddresses, Addresses), (OrderShippingAddress, Address), Seq] = + for { + shippingAddresses ← q + adr ← Addresses + if adr.accountId === accountId && adr.address1 === shippingAddresses.address1 && adr.name === shippingAddresses.name + } yield (shippingAddresses, adr) // FIXME when we have fk to Address @aafa } } } diff --git a/phoenix-scala/phoenix/app/phoenix/services/carts/CartShippingAddressUpdater.scala b/phoenix-scala/phoenix/app/phoenix/services/carts/CartShippingAddressUpdater.scala index 70ec4449ea..839663ee4d 100644 --- a/phoenix-scala/phoenix/app/phoenix/services/carts/CartShippingAddressUpdater.scala +++ b/phoenix-scala/phoenix/app/phoenix/services/carts/CartShippingAddressUpdater.scala @@ -10,11 +10,12 @@ import phoenix.payloads.AddressPayloads._ import phoenix.responses.AddressResponse.buildOneShipping import phoenix.responses.TheResponse import phoenix.responses.cord.CartResponse -import phoenix.services.{CartValidator, LogActivity} +import phoenix.services.{CartValidator, LineItemUpdater, LogActivity} import slick.jdbc.PostgresProfile.api._ import phoenix.utils.aliases._ import core.db._ import cats.implicits._ +import OrderShippingAddresses.scope._ object CartShippingAddressUpdater { @@ -25,11 +26,11 @@ object CartShippingAddressUpdater { OrderShippingAddresses.findByOrderRef(cart.refNum).mustFindOneOr(NoShipAddress(cart.refNum)) private def createShippingAddress(cart: Cart, payload: CreateAddressPayload)( - implicit ec: EC): DbResultT[OrderShippingAddress] = + implicit ec: EC): DbResultT[(OrderShippingAddress, Address)] = for { newAddress ← * <~ Addresses.create(Address.fromPayload(payload, cart.accountId)) - shippingAddress ← * <~ OrderShippingAddresses.copyFromAddress(newAddress, cart.refNum) - } yield shippingAddress + shippingAddress ← * <~ OrderShippingAddresses.createFromAddress(newAddress, cart.refNum) + } yield (shippingAddress, newAddress) def createShippingAddressFromAddressId(originator: User, addressId: Int, @@ -44,7 +45,7 @@ object CartShippingAddressUpdater { _ ← * <~ OrderShippingAddresses.findByOrderRef(cart.refNum).delete (address, _) = addAndReg _ ← * <~ address.mustBelongToAccount(cart.accountId) - shipAddress ← * <~ OrderShippingAddresses.copyFromAddress(address, cart.refNum) + shipAddress ← * <~ OrderShippingAddresses.createFromAddress(address, cart.refNum) region ← * <~ Regions.mustFindById404(shipAddress.regionId) validated ← * <~ CartValidator(cart).validate() response ← * <~ CartResponse.buildRefreshed(cart) @@ -63,7 +64,7 @@ object CartShippingAddressUpdater { cart ← * <~ getCartByOriginator(originator, refNum) newAddress ← * <~ Addresses.create(Address.fromPayload(payload, cart.accountId)) _ ← * <~ OrderShippingAddresses.findByOrderRef(cart.refNum).delete - shipAddress ← * <~ OrderShippingAddresses.copyFromAddress(newAddress, cart.refNum) + shipAddress ← * <~ OrderShippingAddresses.createFromAddress(newAddress, cart.refNum) region ← * <~ Regions.mustFindById404(shipAddress.regionId) validated ← * <~ CartValidator(cart).validate() response ← * <~ CartResponse.buildRefreshed(cart) @@ -100,15 +101,23 @@ object CartShippingAddressUpdater { ctx: OC): DbResultT[TheResponse[CartResponse]] = for { cart ← * <~ getCartByOriginator(originator, refNum) - shippingAddress ← * <~ OrderShippingAddresses - .findByOrderRef(cart.refNum) - .one - .findOrCreate(createShippingAddress(cart, payload)) - region ← * <~ Regions.mustFindById404(shippingAddress.regionId) + shippingTuple ← * <~ OrderShippingAddresses + .findByOrderRef(cart.refNum) + .withCustomerAddress(cart.accountId) + .one + .findOrCreateExtended(createShippingAddress(cart, payload)) - patch = OrderShippingAddress.fromCreatePatchPayload(shippingAddress, payload) - _ ← * <~ OrderShippingAddresses.update(shippingAddress, patch) + ((shippingAddress, address), foundOrCreated) = shippingTuple + + _ ← * <~ doOrMeh(foundOrCreated == Found, for { + _ ← * <~ Addresses.update(address, Address.fromPayload(payload, cart.accountId)) + _ ← * <~ OrderShippingAddresses.update( + shippingAddress, + OrderShippingAddress.fromCreatePatchPayload(shippingAddress, payload)) + } yield DbResultT.unit) + + region ← * <~ Regions.mustFindById404(shippingAddress.regionId) validated ← * <~ CartValidator(cart).validate() response ← * <~ CartResponse.buildRefreshed(cart) _ ← * <~ LogActivity().orderShippingAddressUpdated(originator, diff --git a/phoenix-scala/phoenix/test/integration/AddressesIntegrationTest.scala b/phoenix-scala/phoenix/test/integration/AddressesIntegrationTest.scala index 7e135c8a43..442a44dd4a 100644 --- a/phoenix-scala/phoenix/test/integration/AddressesIntegrationTest.scala +++ b/phoenix-scala/phoenix/test/integration/AddressesIntegrationTest.scala @@ -157,15 +157,28 @@ class AddressesIntegrationTest "PUT shipping addresses must be idempotent" in new AddressFixture { withNewCustomerAuth(TestLoginData.random) { implicit auth ⇒ - cartsApi.create(CreateCart(customerId = auth.customerId.some)).as[CartResponse] + val cart = cartsApi.create(CreateCart(customerId = auth.customerId.some)).as[CartResponse] storefrontCartsApi.shippingAddress.createOrUpdate(addressPayload).mustBeOk() - storefrontCartsApi.shippingAddress.createOrUpdate(addressPayload).mustBeOk() + storefrontCartsApi.shippingAddress + .createOrUpdate(addressPayload.copy(address1 = "My New address")) + .mustBeOk() - customersApi(auth.customerId).addresses.get - .as[Seq[AddressResponse]] - .onlyElement - .address1 must === (addressPayload.address1) + val shippingAddress = cartsApi(cart.referenceNumber) + .get() + .asTheResult[CartResponse] + .shippingAddress + .value match { + case adr ⇒ (adr.address1, adr.city, adr.zip) + } + + val customerAddress = + customersApi(auth.customerId).addresses.get.as[Seq[AddressResponse]].onlyElement match { + case adr ⇒ (adr.address1, adr.city, adr.zip) + } + + shippingAddress must === (("My New address", addressPayload.city, addressPayload.zip)) + customerAddress must === (("My New address", addressPayload.city, addressPayload.zip)) } } } @@ -235,7 +248,7 @@ class AddressesIntegrationTest trait ShippingAddressFixture extends EmptyCartWithShipAddress_Baked trait NoDefaultAddressFixture extends CustomerAddress_Baked with EmptyCustomerCart_Baked { - val shippingAddress = OrderShippingAddresses.copyFromAddress(address, cart.refNum).gimme + val shippingAddress = OrderShippingAddresses.createFromAddress(address, cart.refNum).gimme } trait AddressFixture { diff --git a/phoenix-scala/phoenix/test/integration/CartValidatorIntegrationTest.scala b/phoenix-scala/phoenix/test/integration/CartValidatorIntegrationTest.scala index 6a8fcfb243..3e0fc02bbc 100644 --- a/phoenix-scala/phoenix/test/integration/CartValidatorIntegrationTest.scala +++ b/phoenix-scala/phoenix/test/integration/CartValidatorIntegrationTest.scala @@ -149,7 +149,7 @@ class CartValidatorIntegrationTest val (shipMethod) = (for { address ← * <~ Addresses.create( Factories.address.copy(accountId = customer.accountId, regionId = 4129)) - _ ← * <~ OrderShippingAddresses.copyFromAddress(address = address, cordRef = cart.refNum) + _ ← * <~ OrderShippingAddresses.createFromAddress(address = address, cordRef = cart.refNum) shipMethod ← * <~ ShippingMethods.create(Factories.shippingMethods.head) } yield shipMethod).gimme val refNum = cart.refNum diff --git a/phoenix-scala/phoenix/test/integration/ShippingMethodsIntegrationTest.scala b/phoenix-scala/phoenix/test/integration/ShippingMethodsIntegrationTest.scala index 889b35d130..c0300f4028 100644 --- a/phoenix-scala/phoenix/test/integration/ShippingMethodsIntegrationTest.scala +++ b/phoenix-scala/phoenix/test/integration/ShippingMethodsIntegrationTest.scala @@ -174,8 +174,8 @@ class ShippingMethodsIntegrationTest productContext ← * <~ ObjectContexts.mustFindById404(SimpleContext.id) address ← * <~ Addresses.create( Factories.address.copy(accountId = customer.accountId, regionId = californiaId)) - shipAddress ← * <~ OrderShippingAddresses.copyFromAddress(address = address, - cordRef = cart.refNum) + shipAddress ← * <~ OrderShippingAddresses.createFromAddress(address = address, + cordRef = cart.refNum) product ← * <~ Mvp.insertProduct(productContext.id, Factories.products.head.copy(title = "Donkey", price = 27)) _ ← * <~ CartLineItems.create(CartLineItem(cordRef = cart.refNum, skuId = product.skuId)) diff --git a/phoenix-scala/phoenix/test/integration/services/CheckoutTest.scala b/phoenix-scala/phoenix/test/integration/services/CheckoutTest.scala index b0e7193312..6dc99d1735 100644 --- a/phoenix-scala/phoenix/test/integration/services/CheckoutTest.scala +++ b/phoenix-scala/phoenix/test/integration/services/CheckoutTest.scala @@ -182,8 +182,8 @@ class CheckoutTest _ ← * <~ OrderShippingMethods.create( OrderShippingMethod.build(cart.refNum, shipMethod)) - _ ← * <~ OrderShippingAddresses.copyFromAddress(address = address, - cordRef = cart.refNum) + _ ← * <~ OrderShippingAddresses.createFromAddress(address = address, + cordRef = cart.refNum) gcIds ← * <~ generateGiftCards(gcData.map(_.cardAmount)) scIds ← * <~ generateStoreCredits(scData.map(_.cardAmount)) @@ -257,7 +257,7 @@ class CheckoutTest override val cart = super.cart.copy(grandTotal = 1000) (for { _ ← * <~ OrderShippingMethods.create(OrderShippingMethod.build(cart.refNum, shipMethod)) - _ ← * <~ OrderShippingAddresses.copyFromAddress(address = address, cordRef = cart.refNum) + _ ← * <~ OrderShippingAddresses.createFromAddress(address = address, cordRef = cart.refNum) } yield {}).gimme } } diff --git a/phoenix-scala/phoenix/test/integration/services/ShippingManagerTest.scala b/phoenix-scala/phoenix/test/integration/services/ShippingManagerTest.scala index dfc389e507..8657e839e0 100644 --- a/phoenix-scala/phoenix/test/integration/services/ShippingManagerTest.scala +++ b/phoenix-scala/phoenix/test/integration/services/ShippingManagerTest.scala @@ -46,7 +46,7 @@ class ShippingManagerTest extends IntegrationTestBase with TestObjectContext wit isDefaultShipping = false)) .gimme OrderShippingAddresses.filter(_.id === shippingAddress.id).delete.run().futureValue - OrderShippingAddresses.copyFromAddress(address = canada, cordRef = cart.refNum).gimme + OrderShippingAddresses.createFromAddress(address = canada, cordRef = cart.refNum).gimme val matchingMethods = getShippingMethodsForCart(cart.refNum).gimme matchingMethods.headOption.value.name must === (shippingMethod.adminDisplayName) @@ -77,8 +77,9 @@ class ShippingManagerTest extends IntegrationTestBase with TestObjectContext wit val (address, orderShippingAddress) = (for { address ← * <~ Addresses.create(Factories.address.copy(accountId = customer.accountId, regionId = washingtonId)) - orderShippingAddress ← * <~ OrderShippingAddresses.copyFromAddress(address = address, - cordRef = cart.refNum) + orderShippingAddress ← * <~ OrderShippingAddresses.createFromAddress(address = address, + cordRef = + cart.refNum) } yield (address, orderShippingAddress)).gimme val matchingMethods = getShippingMethodsForCart(cart.refNum).gimme @@ -89,8 +90,9 @@ class ShippingManagerTest extends IntegrationTestBase with TestObjectContext wit val (address, orderShippingAddress) = (for { address ← * <~ Addresses.create(Factories.address.copy(accountId = customer.accountId, regionId = michiganId)) - orderShippingAddress ← * <~ OrderShippingAddresses.copyFromAddress(address = address, - cordRef = cart.refNum) + orderShippingAddress ← * <~ OrderShippingAddresses.createFromAddress(address = address, + cordRef = + cart.refNum) } yield (address, orderShippingAddress)).gimme val matchingMethods = getShippingMethodsForCart(cart.refNum).gimme @@ -104,8 +106,9 @@ class ShippingManagerTest extends IntegrationTestBase with TestObjectContext wit val (address, orderShippingAddress) = (for { address ← * <~ Addresses.create(Factories.address.copy(accountId = customer.accountId, regionId = washingtonId)) - orderShippingAddress ← * <~ OrderShippingAddresses.copyFromAddress(address = address, - cordRef = cart.refNum) + orderShippingAddress ← * <~ OrderShippingAddresses.createFromAddress(address = address, + cordRef = + cart.refNum) } yield (address, orderShippingAddress)).gimme val matchingMethods = getShippingMethodsForCart(cart.refNum).gimme @@ -118,8 +121,9 @@ class ShippingManagerTest extends IntegrationTestBase with TestObjectContext wit Factories.address.copy(accountId = customer.accountId, regionId = washingtonId, address1 = "P.O. Box 1234")) - orderShippingAddress ← * <~ OrderShippingAddresses.copyFromAddress(address = address, - cordRef = cart.refNum) + orderShippingAddress ← * <~ OrderShippingAddresses.createFromAddress(address = address, + cordRef = + cart.refNum) } yield (address, orderShippingAddress)).gimme val matchingMethods = getShippingMethodsForCart(cart.refNum).gimme @@ -132,8 +136,9 @@ class ShippingManagerTest extends IntegrationTestBase with TestObjectContext wit Factories.address.copy(accountId = customer.accountId, regionId = washingtonId, address2 = Some("P.O. Box 1234"))) - orderShippingAddress ← * <~ OrderShippingAddresses.copyFromAddress(address = address, - cordRef = cart.refNum) + orderShippingAddress ← * <~ OrderShippingAddresses.createFromAddress(address = address, + cordRef = + cart.refNum) } yield (address, orderShippingAddress)).gimme val matchingMethods = getShippingMethodsForCart(cart.refNum).gimme @@ -163,8 +168,8 @@ class ShippingManagerTest extends IntegrationTestBase with TestObjectContext wit val (address, shippingAddress) = (for { address ← * <~ Addresses.create( Factories.address.copy(accountId = customer.accountId, regionId = californiaId)) - shippingAddress ← * <~ OrderShippingAddresses.copyFromAddress(address = address, - cordRef = cart.refNum) + shippingAddress ← * <~ OrderShippingAddresses.createFromAddress(address = address, + cordRef = cart.refNum) } yield (address, shippingAddress)).gimme } @@ -202,8 +207,8 @@ class ShippingManagerTest extends IntegrationTestBase with TestObjectContext wit val (address, orderShippingAddress) = (for { address ← * <~ Addresses.create( Factories.address.copy(accountId = customer.accountId, regionId = californiaId)) - orderShippingAddress ← * <~ OrderShippingAddresses.copyFromAddress(address = address, - cordRef = cart.refNum) + orderShippingAddress ← * <~ OrderShippingAddresses.createFromAddress(address = address, + cordRef = cart.refNum) } yield (address, orderShippingAddress)).gimme } @@ -211,8 +216,8 @@ class ShippingManagerTest extends IntegrationTestBase with TestObjectContext wit val (address, orderShippingAddress) = (for { address ← * <~ Addresses.create( Factories.address.copy(accountId = customer.accountId, regionId = washingtonId)) - orderShippingAddress ← * <~ OrderShippingAddresses.copyFromAddress(address = address, - cordRef = cart.refNum) + orderShippingAddress ← * <~ OrderShippingAddresses.createFromAddress(address = address, + cordRef = cart.refNum) } yield (address, orderShippingAddress)).gimme } @@ -220,8 +225,8 @@ class ShippingManagerTest extends IntegrationTestBase with TestObjectContext wit val (address, orderShippingAddress) = (for { address ← * <~ Addresses.create( Factories.address.copy(accountId = customer.accountId, regionId = michiganId)) - orderShippingAddress ← * <~ OrderShippingAddresses.copyFromAddress(address = address, - cordRef = cart.refNum) + orderShippingAddress ← * <~ OrderShippingAddresses.createFromAddress(address = address, + cordRef = cart.refNum) } yield (address, orderShippingAddress)).gimme } @@ -284,8 +289,8 @@ class ShippingManagerTest extends IntegrationTestBase with TestObjectContext wit cheapAddress ← * <~ Addresses.create( Factories.address.copy(accountId = customer.accountId, isDefaultShipping = false)) - _ ← * <~ OrderShippingAddresses.copyFromAddress(address = cheapAddress, - cordRef = cheapCart.refNum) + _ ← * <~ OrderShippingAddresses.createFromAddress(address = cheapAddress, + cordRef = cheapCart.refNum) account2 ← * <~ Accounts.create(Account()) customer2 ← * <~ Users.create( Factories.customer.copy(accountId = account2.id, email = "foo@bar.baz".some)) @@ -305,8 +310,8 @@ class ShippingManagerTest extends IntegrationTestBase with TestObjectContext wit expensiveAddress ← * <~ Addresses.create( Factories.address.copy(accountId = customer.accountId, isDefaultShipping = false)) - _ ← * <~ OrderShippingAddresses.copyFromAddress(address = expensiveAddress, - cordRef = expensiveCart.refNum) + _ ← * <~ OrderShippingAddresses.createFromAddress(address = expensiveAddress, + cordRef = expensiveCart.refNum) cheapCart ← * <~ CartTotaler.saveTotals(cheapCart) expensiveCart ← * <~ CartTotaler.saveTotals(expensiveCart) From 503cf7d44fac5a46f4206a3e14a16b33f4b8b100 Mon Sep 17 00:00:00 2001 From: Alexey Afanasev Date: Wed, 21 Jun 2017 19:16:33 +0300 Subject: [PATCH 6/6] post merge fixes --- .../phoenix/models/cord/OrderShippingAddress.scala | 10 +++++++++- .../services/carts/CartShippingAddressUpdater.scala | 8 +++----- .../test/integration/AddressesIntegrationTest.scala | 3 ++- .../test/integration/testutils/HttpSupport.scala | 11 ----------- 4 files changed, 14 insertions(+), 18 deletions(-) diff --git a/phoenix-scala/phoenix/app/phoenix/models/cord/OrderShippingAddress.scala b/phoenix-scala/phoenix/app/phoenix/models/cord/OrderShippingAddress.scala index 7866ee50ea..08b897e1d7 100644 --- a/phoenix-scala/phoenix/app/phoenix/models/cord/OrderShippingAddress.scala +++ b/phoenix-scala/phoenix/app/phoenix/models/cord/OrderShippingAddress.scala @@ -87,7 +87,7 @@ object OrderShippingAddresses import scope._ - def copyFromAddress(address: Address, cordRef: String)(implicit ec: EC): DbResultT[OrderShippingAddress] = + def createFromAddress(address: Address, cordRef: String)(implicit ec: EC): DbResultT[OrderShippingAddress] = create(OrderShippingAddress.buildFromAddress(address).copy(cordRef = cordRef)) def findByOrderRef(cordRef: String): QuerySeq = @@ -106,6 +106,14 @@ object OrderShippingAddresses shippingAddresses ← q regions ← Regions if regions.id === shippingAddresses.regionId } yield (shippingAddresses, regions) + + def withCustomerAddress( + accountId: Int): Query[(OrderShippingAddresses, Addresses), (OrderShippingAddress, Address), Seq] = + for { + shippingAddresses ← q + adr ← Addresses + if adr.accountId === accountId && adr.address1 === shippingAddresses.address1 && adr.name === shippingAddresses.name + } yield (shippingAddresses, adr) // FIXME when we have fk to Address @aafa } } } diff --git a/phoenix-scala/phoenix/app/phoenix/services/carts/CartShippingAddressUpdater.scala b/phoenix-scala/phoenix/app/phoenix/services/carts/CartShippingAddressUpdater.scala index 18bcdc986d..bcc9da22b8 100644 --- a/phoenix-scala/phoenix/app/phoenix/services/carts/CartShippingAddressUpdater.scala +++ b/phoenix-scala/phoenix/app/phoenix/services/carts/CartShippingAddressUpdater.scala @@ -10,7 +10,7 @@ import phoenix.payloads.AddressPayloads._ import phoenix.responses.AddressResponse.buildFromOrder import phoenix.responses.TheResponse import phoenix.responses.cord.CartResponse -import phoenix.services.{CartValidator, LineItemUpdater, LogActivity} +import phoenix.services.{CartValidator, LogActivity} import slick.jdbc.PostgresProfile.api._ import phoenix.utils.aliases._ import core.db._ @@ -89,6 +89,7 @@ object CartShippingAddressUpdater { .orderShippingAddressUpdated(originator, response, buildFromOrder(shipAddress, region)) } yield TheResponse.validated(response, validated) + // FIXME !!! @aafa def createOrUpdateShippingAddress(originator: User, payload: CreateAddressPayload, refNum: Option[String] = None)( @@ -111,9 +112,6 @@ object CartShippingAddressUpdater { foundOrCreated == Found, for { _ ← * <~ Addresses.update(address, Address.fromPayload(payload, cart.accountId)) - _ ← * <~ OrderShippingAddresses.update( - shippingAddress, - OrderShippingAddress.fromCreatePatchPayload(shippingAddress, payload)) } yield DbResultT.unit ) @@ -122,7 +120,7 @@ object CartShippingAddressUpdater { response ← * <~ CartResponse.buildRefreshed(cart) _ ← * <~ LogActivity().orderShippingAddressUpdated(originator, response, - buildOneShipping(shippingAddress, region)) + buildFromOrder(shippingAddress, region)) } yield TheResponse.validated(response, validated) def removeShippingAddress(originator: User, refNum: Option[String] = None)( diff --git a/phoenix-scala/phoenix/test/integration/AddressesIntegrationTest.scala b/phoenix-scala/phoenix/test/integration/AddressesIntegrationTest.scala index bd31cf8111..ad680bbb0f 100644 --- a/phoenix-scala/phoenix/test/integration/AddressesIntegrationTest.scala +++ b/phoenix-scala/phoenix/test/integration/AddressesIntegrationTest.scala @@ -5,7 +5,8 @@ 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, TheResponse} import phoenix.responses.PublicResponses.CountryWithRegions import phoenix.responses.cord.CartResponse import testutils._ diff --git a/phoenix-scala/phoenix/test/integration/testutils/HttpSupport.scala b/phoenix-scala/phoenix/test/integration/testutils/HttpSupport.scala index 775c373035..660dd68867 100644 --- a/phoenix-scala/phoenix/test/integration/testutils/HttpSupport.scala +++ b/phoenix-scala/phoenix/test/integration/testutils/HttpSupport.scala @@ -125,17 +125,6 @@ trait HttpSupport dispatchRequest(request, jwtCookie) } - def PUT(path: String, rawBody: String, jwtCookie: Option[Cookie]): HttpResponse = { - val request = HttpRequest(method = HttpMethods.PUT, - uri = pathToAbsoluteUrl(path), - entity = HttpEntity.Strict( - ContentTypes.`application/json`, - ByteString(rawBody) - )) - - dispatchRequest(request, jwtCookie) - } - def POST(path: String, jwtCookie: Option[Cookie]): HttpResponse = dispatchRequest(HttpRequest(method = HttpMethods.POST, uri = pathToAbsoluteUrl(path)), jwtCookie)