feat: allow custom address on claims
This commit is contained in:
@@ -154,6 +154,91 @@ describe("/admin/orders", () => {
|
||||
);
|
||||
expect(response.status).toEqual(200);
|
||||
|
||||
expect(response.data.order.claims[0].shipping_address_id).toEqual(
|
||||
"test-shipping-address"
|
||||
);
|
||||
expect(response.data.order.claims[0].shipping_address).toEqual(
|
||||
expect.objectContaining({
|
||||
first_name: "lebron",
|
||||
country_code: "us",
|
||||
})
|
||||
);
|
||||
|
||||
expect(response.data.order.claims[0].claim_items).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
item_id: "test-item",
|
||||
quantity: 1,
|
||||
reason: "production_failure",
|
||||
images: expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
url: "https://test.image.com",
|
||||
}),
|
||||
]),
|
||||
}),
|
||||
])
|
||||
);
|
||||
|
||||
expect(response.data.order.claims[0].additional_items).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
variant_id: "test-variant",
|
||||
quantity: 1,
|
||||
}),
|
||||
])
|
||||
);
|
||||
});
|
||||
|
||||
it("creates a claim with a shipping address", async () => {
|
||||
const api = useApi();
|
||||
|
||||
const response = await api.post(
|
||||
"/admin/orders/test-order/claims",
|
||||
{
|
||||
type: "replace",
|
||||
shipping_address: {
|
||||
first_name: "test",
|
||||
last_name: "testson",
|
||||
address_1: "Test",
|
||||
city: "testvill",
|
||||
postal_code: "12345",
|
||||
country_code: "us",
|
||||
},
|
||||
claim_items: [
|
||||
{
|
||||
item_id: "test-item",
|
||||
quantity: 1,
|
||||
reason: "production_failure",
|
||||
tags: ["fluff"],
|
||||
images: ["https://test.image.com"],
|
||||
},
|
||||
],
|
||||
additional_items: [
|
||||
{
|
||||
variant_id: "test-variant",
|
||||
quantity: 1,
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
authorization: "Bearer test_token",
|
||||
},
|
||||
}
|
||||
);
|
||||
expect(response.status).toEqual(200);
|
||||
|
||||
expect(response.data.order.claims[0].shipping_address).toEqual(
|
||||
expect.objectContaining({
|
||||
first_name: "test",
|
||||
last_name: "testson",
|
||||
address_1: "Test",
|
||||
city: "testvill",
|
||||
postal_code: "12345",
|
||||
country_code: "us",
|
||||
})
|
||||
);
|
||||
|
||||
expect(response.data.order.claims[0].claim_items).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
|
||||
@@ -8,15 +8,15 @@
|
||||
"build": "babel src -d dist --extensions \".ts,.js\""
|
||||
},
|
||||
"dependencies": {
|
||||
"@medusajs/medusa": "1.1.19-dev-1618904018564",
|
||||
"medusa-interfaces": "1.1.7-dev-1618904018564",
|
||||
"@medusajs/medusa": "1.1.23-dev-1622110840148",
|
||||
"medusa-interfaces": "1.1.10-dev-1622110840148",
|
||||
"typeorm": "^0.2.31"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/cli": "^7.12.10",
|
||||
"@babel/core": "^7.12.10",
|
||||
"@babel/node": "^7.12.10",
|
||||
"babel-preset-medusa-package": "1.1.0-dev-1618904018564",
|
||||
"babel-preset-medusa-package": "1.1.3-dev-1622110840148",
|
||||
"jest": "^26.6.3"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1179,10 +1179,10 @@
|
||||
"@types/yargs" "^15.0.0"
|
||||
chalk "^4.0.0"
|
||||
|
||||
"@medusajs/medusa@1.1.19-dev-1618904018564":
|
||||
version "1.1.19-dev-1618904018564"
|
||||
resolved "http://localhost:4873/@medusajs%2fmedusa/-/medusa-1.1.19-dev-1618904018564.tgz#12589458950310185217184f4b65f6a8783d30ff"
|
||||
integrity sha512-LY1zXuIibEPjzmbkjnCxTU4rd2z6tBSabopu4oeVvHcMuMxUFs7mcdgzU2rvyLRjkcK9+X8aTjPYkjf42o1pfg==
|
||||
"@medusajs/medusa@1.1.23-dev-1622110840148":
|
||||
version "1.1.23-dev-1622110840148"
|
||||
resolved "http://localhost:4873/@medusajs%2fmedusa/-/medusa-1.1.23-dev-1622110840148.tgz#bae9d7130967750733aae58241be3a4796cb35eb"
|
||||
integrity sha512-mPTGyAId1vKUpnnGTSo1cmjSP0fonER2lFVTmWM711oN49PVQ+5UdcyfsnIaj2vLLTskuVgsO3oI7vTuZEj3rg==
|
||||
dependencies:
|
||||
"@hapi/joi" "^16.1.8"
|
||||
"@types/lodash" "^4.14.168"
|
||||
@@ -1203,8 +1203,8 @@
|
||||
joi "^17.3.0"
|
||||
joi-objectid "^3.0.1"
|
||||
jsonwebtoken "^8.5.1"
|
||||
medusa-core-utils "1.1.6-dev-1618904018564"
|
||||
medusa-test-utils "1.1.9-dev-1618904018564"
|
||||
medusa-core-utils "1.1.9-dev-1622110840148"
|
||||
medusa-test-utils "1.1.12-dev-1622110840148"
|
||||
morgan "^1.9.1"
|
||||
multer "^1.4.2"
|
||||
passport "^0.4.0"
|
||||
@@ -1727,10 +1727,10 @@ babel-preset-jest@^26.6.2:
|
||||
babel-plugin-jest-hoist "^26.6.2"
|
||||
babel-preset-current-node-syntax "^1.0.0"
|
||||
|
||||
babel-preset-medusa-package@1.1.0-dev-1618904018564:
|
||||
version "1.1.0-dev-1618904018564"
|
||||
resolved "http://localhost:4873/babel-preset-medusa-package/-/babel-preset-medusa-package-1.1.0-dev-1618904018564.tgz#c300c97715e3fb454f9f5a104ee332ee0861dc20"
|
||||
integrity sha512-9SceZbdOXyW90EFDXwbC3q33hG7iDw9qCj8amvB4fasYQAMHyLyI0vXh03r4NQe42mmEBswwVTOqEl0Nm30ELQ==
|
||||
babel-preset-medusa-package@1.1.3-dev-1622110840148:
|
||||
version "1.1.3-dev-1622110840148"
|
||||
resolved "http://localhost:4873/babel-preset-medusa-package/-/babel-preset-medusa-package-1.1.3-dev-1622110840148.tgz#18c91e24362345dee7944a4e4cb81d659a235de0"
|
||||
integrity sha512-jw8bVkwIDU2WvyJy6cLA1Gh9FQCWiTH/jdFIXza4StijEMHcCQQtucwnQJzj4yNd1z9WSpi22iy/hqtaoaeDbA==
|
||||
dependencies:
|
||||
"@babel/plugin-proposal-class-properties" "^7.12.1"
|
||||
"@babel/plugin-proposal-decorators" "^7.12.1"
|
||||
@@ -4331,28 +4331,28 @@ media-typer@0.3.0:
|
||||
resolved "https://registry.yarnpkg.com/media-typer/-/media-typer-0.3.0.tgz#8710d7af0aa626f8fffa1ce00168545263255748"
|
||||
integrity sha1-hxDXrwqmJvj/+hzgAWhUUmMlV0g=
|
||||
|
||||
medusa-core-utils@1.1.6-dev-1618904018564:
|
||||
version "1.1.6-dev-1618904018564"
|
||||
resolved "http://localhost:4873/medusa-core-utils/-/medusa-core-utils-1.1.6-dev-1618904018564.tgz#d6c86a5b628a3a6993578aa8bfb262f69cf8212d"
|
||||
integrity sha512-SQKuPLu6AcNK+X5PD85YC9aBcLznHFs+63wQ+992eFv5AsEkJUdjthf6PEgYjWQLrAs7IVR2ogZhCZoZ6sZ0NA==
|
||||
medusa-core-utils@1.1.9-dev-1622110840148:
|
||||
version "1.1.9-dev-1622110840148"
|
||||
resolved "http://localhost:4873/medusa-core-utils/-/medusa-core-utils-1.1.9-dev-1622110840148.tgz#7ab198b2159e1e7d9980c917359a682099815c60"
|
||||
integrity sha512-clMs7NNiDOhQc5mdTblzoWLsdWl8aywRJsbxNszq2wri05QaZEhjHuCq9mvcaQ1aoPg7qiR9ZY3Szw08llgnDQ==
|
||||
dependencies:
|
||||
joi "^17.3.0"
|
||||
joi-objectid "^3.0.1"
|
||||
|
||||
medusa-interfaces@1.1.7-dev-1618904018564:
|
||||
version "1.1.7-dev-1618904018564"
|
||||
resolved "http://localhost:4873/medusa-interfaces/-/medusa-interfaces-1.1.7-dev-1618904018564.tgz#44ebc208e45629842069b83376f3c70ce655d87c"
|
||||
integrity sha512-m/39l1fuQvDWlaqvqfbTsd+wZFkDBJjQJkuKEbWJrFtqYOfAy/4cWy+XgJ9BzJmQDI/mLydVPESzC0+97RvaOA==
|
||||
medusa-interfaces@1.1.10-dev-1622110840148:
|
||||
version "1.1.10-dev-1622110840148"
|
||||
resolved "http://localhost:4873/medusa-interfaces/-/medusa-interfaces-1.1.10-dev-1622110840148.tgz#072e4b97e16dbe50b34e5e5860a3de04796f437b"
|
||||
integrity sha512-LKx5q/mdhv3h690aZnkSGK+G62sSjIx+wnsa1ZvrH4z6d/LA3J+sIVs9/uu5Bh62/QYxPRpxd1PCK95Hk2/TxQ==
|
||||
dependencies:
|
||||
medusa-core-utils "1.1.6-dev-1618904018564"
|
||||
medusa-core-utils "1.1.9-dev-1622110840148"
|
||||
|
||||
medusa-test-utils@1.1.9-dev-1618904018564:
|
||||
version "1.1.9-dev-1618904018564"
|
||||
resolved "http://localhost:4873/medusa-test-utils/-/medusa-test-utils-1.1.9-dev-1618904018564.tgz#9dd28c9b8b0108f5cf8d9ff330a89deb95c6e0dc"
|
||||
integrity sha512-F+boaq7iRLGcPmDUFei4CzIL05dBmGByIkFNugvMaVqe01WOWfZPM29SyeuSSavvtqE8AslOTrtmCkUQHBSdaA==
|
||||
medusa-test-utils@1.1.12-dev-1622110840148:
|
||||
version "1.1.12-dev-1622110840148"
|
||||
resolved "http://localhost:4873/medusa-test-utils/-/medusa-test-utils-1.1.12-dev-1622110840148.tgz#919490912847ab292e115b058fff90d131adf889"
|
||||
integrity sha512-uDtOeLKQU3Xz+YuOYOvgwv0bbsuI09RSlJV5cRtQfFWi4uVWButyJR+Ho2KFKqq4M/vu+2hFmob2YGOcpRvOsQ==
|
||||
dependencies:
|
||||
"@babel/plugin-transform-classes" "^7.9.5"
|
||||
medusa-core-utils "1.1.6-dev-1618904018564"
|
||||
medusa-core-utils "1.1.9-dev-1622110840148"
|
||||
randomatic "^3.1.1"
|
||||
|
||||
merge-descriptors@1.0.1:
|
||||
|
||||
@@ -85,6 +85,9 @@ import { defaultRelations, defaultFields } from "./"
|
||||
* price:
|
||||
* description: The price to charge for the Shipping Method
|
||||
* type: integer
|
||||
* shipping_address:
|
||||
* type: object
|
||||
* description: "An optional shipping address to send the claim to. Defaults to the parent order's shipping address"
|
||||
* refund_amount:
|
||||
* description: The amount to refund the Customer when the Claim type is `refund`.
|
||||
* type: integer
|
||||
@@ -151,6 +154,7 @@ export default async (req, res) => {
|
||||
refund_amount: Validator.number()
|
||||
.integer()
|
||||
.optional(),
|
||||
shipping_address: Validator.object().optional(),
|
||||
metadata: Validator.object().optional(),
|
||||
})
|
||||
|
||||
@@ -203,6 +207,7 @@ export default async (req, res) => {
|
||||
idempotency_key: idempotencyKey.idempotency_key,
|
||||
order,
|
||||
type: value.type,
|
||||
shipping_address: value.shipping_address,
|
||||
claim_items: value.claim_items,
|
||||
return_shipping: value.return_shipping,
|
||||
additional_items: value.additional_items,
|
||||
|
||||
@@ -16,6 +16,7 @@ class ClaimService extends BaseService {
|
||||
constructor({
|
||||
manager,
|
||||
claimRepository,
|
||||
addressRepository,
|
||||
fulfillmentProviderService,
|
||||
fulfillmentService,
|
||||
lineItemService,
|
||||
@@ -35,6 +36,9 @@ class ClaimService extends BaseService {
|
||||
/** @private @constant {ClaimRepository} */
|
||||
this.claimRepository_ = claimRepository
|
||||
|
||||
/** @private @constant {AddressRepository} */
|
||||
this.addressRepo_ = addressRepository
|
||||
|
||||
/** @private @constant {FulfillmentProviderService} */
|
||||
this.fulfillmentProviderService_ = fulfillmentProviderService
|
||||
|
||||
@@ -74,6 +78,7 @@ class ClaimService extends BaseService {
|
||||
const cloned = new ClaimService({
|
||||
manager,
|
||||
claimRepository: this.claimRepository_,
|
||||
addressRepository: this.addressRepo_,
|
||||
fulfillmentProviderService: this.fulfillmentProviderService_,
|
||||
fulfillmentService: this.fulfillmentService_,
|
||||
paymentProviderService: this.paymentProviderService_,
|
||||
@@ -150,6 +155,11 @@ class ClaimService extends BaseService {
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a Claim on an Order. Claims consists of items that are claimed and
|
||||
* optionally items to be sent as replacement for the claimed items. The
|
||||
* shipping address that the new items will be shipped to
|
||||
*/
|
||||
create(data) {
|
||||
return this.atomicPhase_(async manager => {
|
||||
const claimRepo = manager.getCustomRepository(this.claimRepository_)
|
||||
@@ -162,9 +172,19 @@ class ClaimService extends BaseService {
|
||||
additional_items,
|
||||
shipping_methods,
|
||||
refund_amount,
|
||||
shipping_address,
|
||||
shipping_address_id,
|
||||
...rest
|
||||
} = data
|
||||
|
||||
let addressId = shipping_address_id || order.shipping_address_id
|
||||
if (shipping_address) {
|
||||
const addressRepo = manager.getCustomRepository(this.addressRepo_)
|
||||
const created = addressRepo.create(shipping_address)
|
||||
const saved = await addressRepo.save(created)
|
||||
addressId = saved.id
|
||||
}
|
||||
|
||||
if (type !== "refund" && type !== "replace") {
|
||||
throw new MedusaError(
|
||||
MedusaError.Types.INVALID_DATA,
|
||||
@@ -214,7 +234,7 @@ class ClaimService extends BaseService {
|
||||
)
|
||||
|
||||
const created = claimRepo.create({
|
||||
shipping_address_id: order.shipping_address_id,
|
||||
shipping_address_id: addressId,
|
||||
payment_status: type === "refund" ? "not_refunded" : "na",
|
||||
...rest,
|
||||
refund_amount: toRefund,
|
||||
|
||||
Reference in New Issue
Block a user