feat: creates support for swaps on the storefront (#355)
This commit is contained in:
@@ -0,0 +1,365 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`/store/carts /store/swaps simple swap 1`] = `
|
||||
Object {
|
||||
"swap": Object {
|
||||
"additional_items": Array [
|
||||
Object {
|
||||
"allow_discounts": true,
|
||||
"cart_id": StringMatching /\\^cart_\\*/,
|
||||
"claim_order_id": null,
|
||||
"created_at": Any<String>,
|
||||
"description": "Swap product",
|
||||
"fulfilled_quantity": null,
|
||||
"has_shipping": null,
|
||||
"id": StringMatching /\\^item_\\*/,
|
||||
"is_giftcard": false,
|
||||
"metadata": Object {},
|
||||
"order_id": null,
|
||||
"quantity": 1,
|
||||
"returned_quantity": null,
|
||||
"shipped_quantity": null,
|
||||
"should_merge": true,
|
||||
"swap_id": StringMatching /\\^swap_\\*/,
|
||||
"thumbnail": null,
|
||||
"title": "test product",
|
||||
"unit_price": 8000,
|
||||
"updated_at": Any<String>,
|
||||
"variant": Object {
|
||||
"allow_backorder": false,
|
||||
"barcode": null,
|
||||
"created_at": Any<String>,
|
||||
"deleted_at": null,
|
||||
"ean": null,
|
||||
"height": null,
|
||||
"hs_code": null,
|
||||
"id": "test-variant-2",
|
||||
"inventory_quantity": 1,
|
||||
"length": null,
|
||||
"manage_inventory": true,
|
||||
"material": null,
|
||||
"metadata": null,
|
||||
"mid_code": null,
|
||||
"origin_country": null,
|
||||
"product": Object {
|
||||
"collection_id": null,
|
||||
"created_at": Any<String>,
|
||||
"deleted_at": null,
|
||||
"description": null,
|
||||
"discountable": true,
|
||||
"handle": null,
|
||||
"height": null,
|
||||
"hs_code": null,
|
||||
"id": "test-product",
|
||||
"is_giftcard": false,
|
||||
"length": null,
|
||||
"material": null,
|
||||
"metadata": null,
|
||||
"mid_code": null,
|
||||
"origin_country": null,
|
||||
"profile_id": StringMatching /\\^sp_\\*/,
|
||||
"subtitle": null,
|
||||
"thumbnail": null,
|
||||
"title": "test product",
|
||||
"type_id": null,
|
||||
"updated_at": Any<String>,
|
||||
"weight": null,
|
||||
"width": null,
|
||||
},
|
||||
"product_id": "test-product",
|
||||
"sku": null,
|
||||
"title": "Swap product",
|
||||
"upc": null,
|
||||
"updated_at": Any<String>,
|
||||
"weight": null,
|
||||
"width": null,
|
||||
},
|
||||
"variant_id": "test-variant-2",
|
||||
},
|
||||
],
|
||||
"cart": Object {
|
||||
"billing_address_id": "test-billing-address",
|
||||
"completed_at": null,
|
||||
"context": null,
|
||||
"created_at": Any<String>,
|
||||
"customer_id": "test-customer",
|
||||
"deleted_at": null,
|
||||
"email": "test@email.com",
|
||||
"id": StringMatching /\\^cart_\\*/,
|
||||
"idempotency_key": null,
|
||||
"metadata": Object {
|
||||
"parent_order_id": "test-order",
|
||||
"swap_id": StringMatching /\\^swap_\\*/,
|
||||
},
|
||||
"payment_id": null,
|
||||
"region_id": "test-region",
|
||||
"shipping_address_id": "test-shipping-address",
|
||||
"type": "swap",
|
||||
"updated_at": Any<String>,
|
||||
},
|
||||
"cart_id": StringMatching /\\^cart_\\*/,
|
||||
"confirmed_at": null,
|
||||
"created_at": Any<String>,
|
||||
"deleted_at": null,
|
||||
"difference_due": null,
|
||||
"fulfillment_status": "not_fulfilled",
|
||||
"fulfillments": Array [],
|
||||
"id": StringMatching /\\^swap_\\*/,
|
||||
"idempotency_key": Any<String>,
|
||||
"metadata": null,
|
||||
"order": Object {
|
||||
"billing_address_id": "test-billing-address",
|
||||
"canceled_at": null,
|
||||
"cart_id": null,
|
||||
"created_at": Any<String>,
|
||||
"currency_code": "usd",
|
||||
"customer_id": "test-customer",
|
||||
"display_id": 1,
|
||||
"draft_order_id": null,
|
||||
"email": "test@email.com",
|
||||
"fulfillment_status": "fulfilled",
|
||||
"id": "test-order",
|
||||
"idempotency_key": null,
|
||||
"metadata": null,
|
||||
"no_notification": null,
|
||||
"payment_status": "captured",
|
||||
"region_id": "test-region",
|
||||
"shipping_address_id": "test-shipping-address",
|
||||
"status": "pending",
|
||||
"tax_rate": 0,
|
||||
"updated_at": Any<String>,
|
||||
},
|
||||
"order_id": "test-order",
|
||||
"payment": null,
|
||||
"payment_status": "not_paid",
|
||||
"return_order": Object {
|
||||
"claim_order_id": null,
|
||||
"created_at": Any<String>,
|
||||
"id": StringMatching /\\^ret_\\*/,
|
||||
"idempotency_key": null,
|
||||
"items": Array [
|
||||
Object {
|
||||
"is_requested": true,
|
||||
"item_id": "test-item",
|
||||
"metadata": null,
|
||||
"note": null,
|
||||
"quantity": 1,
|
||||
"reason_id": null,
|
||||
"received_quantity": null,
|
||||
"requested_quantity": 1,
|
||||
"return_id": StringMatching /\\^ret_\\*/,
|
||||
},
|
||||
],
|
||||
"metadata": null,
|
||||
"no_notification": true,
|
||||
"order_id": null,
|
||||
"received_at": null,
|
||||
"refund_amount": 7200,
|
||||
"shipping_data": null,
|
||||
"shipping_method": null,
|
||||
"status": "requested",
|
||||
"swap_id": StringMatching /\\^swap_\\*/,
|
||||
"updated_at": Any<String>,
|
||||
},
|
||||
"shipping_address": null,
|
||||
"shipping_address_id": null,
|
||||
"shipping_methods": Array [],
|
||||
"updated_at": Any<String>,
|
||||
},
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`/store/carts /store/swaps swap with return shipping 1`] = `
|
||||
Object {
|
||||
"swap": Object {
|
||||
"additional_items": Array [
|
||||
Object {
|
||||
"allow_discounts": true,
|
||||
"cart_id": StringMatching /\\^cart_\\*/,
|
||||
"claim_order_id": null,
|
||||
"created_at": Any<String>,
|
||||
"description": "Swap product",
|
||||
"fulfilled_quantity": null,
|
||||
"has_shipping": null,
|
||||
"id": StringMatching /\\^item_\\*/,
|
||||
"is_giftcard": false,
|
||||
"metadata": Object {},
|
||||
"order_id": null,
|
||||
"quantity": 1,
|
||||
"returned_quantity": null,
|
||||
"shipped_quantity": null,
|
||||
"should_merge": true,
|
||||
"swap_id": StringMatching /\\^swap_\\*/,
|
||||
"thumbnail": null,
|
||||
"title": "test product",
|
||||
"unit_price": 8000,
|
||||
"updated_at": Any<String>,
|
||||
"variant": Object {
|
||||
"allow_backorder": false,
|
||||
"barcode": null,
|
||||
"created_at": Any<String>,
|
||||
"deleted_at": null,
|
||||
"ean": null,
|
||||
"height": null,
|
||||
"hs_code": null,
|
||||
"id": "test-variant-2",
|
||||
"inventory_quantity": 1,
|
||||
"length": null,
|
||||
"manage_inventory": true,
|
||||
"material": null,
|
||||
"metadata": null,
|
||||
"mid_code": null,
|
||||
"origin_country": null,
|
||||
"product": Object {
|
||||
"collection_id": null,
|
||||
"created_at": Any<String>,
|
||||
"deleted_at": null,
|
||||
"description": null,
|
||||
"discountable": true,
|
||||
"handle": null,
|
||||
"height": null,
|
||||
"hs_code": null,
|
||||
"id": "test-product",
|
||||
"is_giftcard": false,
|
||||
"length": null,
|
||||
"material": null,
|
||||
"metadata": null,
|
||||
"mid_code": null,
|
||||
"origin_country": null,
|
||||
"profile_id": StringMatching /\\^sp_\\*/,
|
||||
"subtitle": null,
|
||||
"thumbnail": null,
|
||||
"title": "test product",
|
||||
"type_id": null,
|
||||
"updated_at": Any<String>,
|
||||
"weight": null,
|
||||
"width": null,
|
||||
},
|
||||
"product_id": "test-product",
|
||||
"sku": null,
|
||||
"title": "Swap product",
|
||||
"upc": null,
|
||||
"updated_at": Any<String>,
|
||||
"weight": null,
|
||||
"width": null,
|
||||
},
|
||||
"variant_id": "test-variant-2",
|
||||
},
|
||||
],
|
||||
"cart": Object {
|
||||
"billing_address_id": "test-billing-address",
|
||||
"completed_at": null,
|
||||
"context": null,
|
||||
"created_at": Any<String>,
|
||||
"customer_id": "test-customer",
|
||||
"deleted_at": null,
|
||||
"email": "test@email.com",
|
||||
"id": StringMatching /\\^cart_\\*/,
|
||||
"idempotency_key": null,
|
||||
"metadata": Object {
|
||||
"parent_order_id": "test-order",
|
||||
"swap_id": StringMatching /\\^swap_\\*/,
|
||||
},
|
||||
"payment_id": null,
|
||||
"region_id": "test-region",
|
||||
"shipping_address_id": "test-shipping-address",
|
||||
"type": "swap",
|
||||
"updated_at": Any<String>,
|
||||
},
|
||||
"cart_id": StringMatching /\\^cart_\\*/,
|
||||
"confirmed_at": null,
|
||||
"created_at": Any<String>,
|
||||
"deleted_at": null,
|
||||
"difference_due": null,
|
||||
"fulfillment_status": "not_fulfilled",
|
||||
"fulfillments": Array [],
|
||||
"id": StringMatching /\\^swap_\\*/,
|
||||
"idempotency_key": Any<String>,
|
||||
"metadata": null,
|
||||
"order": Object {
|
||||
"billing_address_id": "test-billing-address",
|
||||
"canceled_at": null,
|
||||
"cart_id": null,
|
||||
"created_at": Any<String>,
|
||||
"currency_code": "usd",
|
||||
"customer_id": "test-customer",
|
||||
"display_id": 2,
|
||||
"draft_order_id": null,
|
||||
"email": "test@email.com",
|
||||
"fulfillment_status": "fulfilled",
|
||||
"id": "test-order",
|
||||
"idempotency_key": null,
|
||||
"metadata": null,
|
||||
"no_notification": null,
|
||||
"payment_status": "captured",
|
||||
"region_id": "test-region",
|
||||
"shipping_address_id": "test-shipping-address",
|
||||
"status": "pending",
|
||||
"tax_rate": 0,
|
||||
"updated_at": Any<String>,
|
||||
},
|
||||
"order_id": "test-order",
|
||||
"payment": null,
|
||||
"payment_status": "not_paid",
|
||||
"return_order": Object {
|
||||
"claim_order_id": null,
|
||||
"created_at": Any<String>,
|
||||
"id": StringMatching /\\^ret_\\*/,
|
||||
"idempotency_key": null,
|
||||
"items": Array [
|
||||
Object {
|
||||
"is_requested": true,
|
||||
"item_id": "test-item",
|
||||
"metadata": null,
|
||||
"note": null,
|
||||
"quantity": 1,
|
||||
"reason_id": null,
|
||||
"received_quantity": null,
|
||||
"requested_quantity": 1,
|
||||
"return_id": StringMatching /\\^ret_\\*/,
|
||||
},
|
||||
],
|
||||
"metadata": null,
|
||||
"no_notification": true,
|
||||
"order_id": null,
|
||||
"received_at": null,
|
||||
"refund_amount": 6200,
|
||||
"shipping_data": Object {},
|
||||
"shipping_method": Object {
|
||||
"cart_id": null,
|
||||
"claim_order_id": null,
|
||||
"data": Object {},
|
||||
"id": StringMatching /\\^sm_\\*/,
|
||||
"order_id": null,
|
||||
"price": 1000,
|
||||
"return_id": StringMatching /\\^ret_\\*/,
|
||||
"shipping_option": Object {
|
||||
"admin_only": false,
|
||||
"amount": 1000,
|
||||
"created_at": Any<String>,
|
||||
"data": Object {},
|
||||
"deleted_at": null,
|
||||
"id": "return-option",
|
||||
"is_return": true,
|
||||
"metadata": null,
|
||||
"name": "Test ret",
|
||||
"price_type": "flat_rate",
|
||||
"profile_id": StringMatching /\\^sp_\\*/,
|
||||
"provider_id": "test-ful",
|
||||
"region_id": "test-region",
|
||||
"updated_at": Any<String>,
|
||||
},
|
||||
"shipping_option_id": "return-option",
|
||||
"swap_id": null,
|
||||
},
|
||||
"status": "requested",
|
||||
"swap_id": StringMatching /\\^swap_\\*/,
|
||||
"updated_at": Any<String>,
|
||||
},
|
||||
"shipping_address": null,
|
||||
"shipping_address_id": null,
|
||||
"shipping_methods": Array [],
|
||||
"updated_at": Any<String>,
|
||||
},
|
||||
}
|
||||
`;
|
||||
@@ -1,4 +1,4 @@
|
||||
const path = require("path");
|
||||
const path = require("path")
|
||||
const {
|
||||
Region,
|
||||
Order,
|
||||
@@ -12,110 +12,49 @@ const {
|
||||
Cart,
|
||||
ShippingMethod,
|
||||
Swap,
|
||||
} = require("@medusajs/medusa");
|
||||
} = require("@medusajs/medusa")
|
||||
|
||||
const setupServer = require("../../../helpers/setup-server");
|
||||
const { useApi } = require("../../../helpers/use-api");
|
||||
const { initDb, useDb } = require("../../../helpers/use-db");
|
||||
const setupServer = require("../../../helpers/setup-server")
|
||||
const { useApi } = require("../../../helpers/use-api")
|
||||
const { initDb, useDb } = require("../../../helpers/use-db")
|
||||
|
||||
const swapSeeder = require("../../helpers/swap-seeder");
|
||||
const cartSeeder = require("../../helpers/cart-seeder");
|
||||
const swapSeeder = require("../../helpers/swap-seeder")
|
||||
const cartSeeder = require("../../helpers/cart-seeder")
|
||||
|
||||
jest.setTimeout(30000);
|
||||
jest.setTimeout(30000)
|
||||
|
||||
describe("/store/carts", () => {
|
||||
let medusaProcess;
|
||||
let dbConnection;
|
||||
let medusaProcess
|
||||
let dbConnection
|
||||
|
||||
beforeAll(async () => {
|
||||
const cwd = path.resolve(path.join(__dirname, "..", ".."));
|
||||
dbConnection = await initDb({ cwd });
|
||||
medusaProcess = await setupServer({ cwd });
|
||||
});
|
||||
const cwd = path.resolve(path.join(__dirname, "..", ".."))
|
||||
dbConnection = await initDb({ cwd })
|
||||
medusaProcess = await setupServer({ cwd })
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
const db = useDb();
|
||||
await db.shutdown();
|
||||
medusaProcess.kill();
|
||||
});
|
||||
|
||||
describe("/store/swaps", () => {
|
||||
beforeEach(async () => {
|
||||
try {
|
||||
await cartSeeder(dbConnection);
|
||||
await swapSeeder(dbConnection);
|
||||
|
||||
const manager = dbConnection.manager;
|
||||
await manager.query(
|
||||
`UPDATE "swap" SET cart_id='test-cart-2' WHERE id = 'test-swap'`
|
||||
);
|
||||
await manager.query(
|
||||
`UPDATE "payment" SET swap_id=NULL WHERE id = 'test-payment-swap'`
|
||||
);
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
throw err;
|
||||
}
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
const db = useDb();
|
||||
await db.teardown();
|
||||
});
|
||||
|
||||
it("creates a swap from a cart id", async () => {
|
||||
const api = useApi();
|
||||
|
||||
const getRes = await api.post("/store/swaps", {
|
||||
cart_id: "test-cart-2",
|
||||
});
|
||||
expect(getRes.status).toEqual(200);
|
||||
});
|
||||
|
||||
it("fails due to partial inventory", async () => {
|
||||
const api = useApi();
|
||||
const manager = dbConnection.manager;
|
||||
|
||||
const li = manager.create(LineItem, {
|
||||
id: "test-item-with-no-stock",
|
||||
title: "No Stock Item",
|
||||
description: "Line Item Desc",
|
||||
thumbnail: "https://test.js/1234",
|
||||
unit_price: 8000,
|
||||
quantity: 1,
|
||||
variant_id: "test-variant-2",
|
||||
cart_id: "test-cart-2",
|
||||
});
|
||||
await manager.save(li);
|
||||
|
||||
try {
|
||||
await api.post("/store/swaps", {
|
||||
cart_id: "test-cart-2",
|
||||
});
|
||||
} catch (e) {
|
||||
expect(e.response.data.message).toEqual(
|
||||
"Variant with id: test-variant-2 does not have the required inventory"
|
||||
);
|
||||
}
|
||||
});
|
||||
});
|
||||
const db = useDb()
|
||||
await db.shutdown()
|
||||
medusaProcess.kill()
|
||||
})
|
||||
|
||||
describe("GET /store/orders", () => {
|
||||
beforeEach(async () => {
|
||||
const manager = dbConnection.manager;
|
||||
const manager = dbConnection.manager
|
||||
await manager.query(
|
||||
`ALTER SEQUENCE order_display_id_seq RESTART WITH 111`
|
||||
);
|
||||
)
|
||||
await manager.insert(Region, {
|
||||
id: "region",
|
||||
name: "Test Region",
|
||||
currency_code: "usd",
|
||||
tax_rate: 0,
|
||||
});
|
||||
})
|
||||
await manager.insert(Customer, {
|
||||
id: "cus_1234",
|
||||
email: "test@email.com",
|
||||
});
|
||||
})
|
||||
await manager.insert(Order, {
|
||||
id: "order_test",
|
||||
email: "test@email.com",
|
||||
@@ -124,17 +63,17 @@ describe("/store/carts", () => {
|
||||
region_id: "region",
|
||||
tax_rate: 0,
|
||||
currency_code: "usd",
|
||||
});
|
||||
})
|
||||
|
||||
const defaultProfile = await manager.findOne(ShippingProfile, {
|
||||
type: "default",
|
||||
});
|
||||
})
|
||||
await manager.insert(Product, {
|
||||
id: "test-product",
|
||||
title: "test product",
|
||||
profile_id: defaultProfile.id,
|
||||
options: [{ id: "test-option", title: "Size" }],
|
||||
});
|
||||
})
|
||||
|
||||
await manager.insert(ProductVariant, {
|
||||
id: "test-variant",
|
||||
@@ -147,7 +86,7 @@ describe("/store/carts", () => {
|
||||
value: "Size",
|
||||
},
|
||||
],
|
||||
});
|
||||
})
|
||||
|
||||
await manager.insert(LineItem, {
|
||||
id: "test-item",
|
||||
@@ -158,59 +97,59 @@ describe("/store/carts", () => {
|
||||
unit_price: 8000,
|
||||
quantity: 1,
|
||||
variant_id: "test-variant",
|
||||
});
|
||||
});
|
||||
})
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
const db = useDb();
|
||||
await db.teardown();
|
||||
});
|
||||
const db = useDb()
|
||||
await db.teardown()
|
||||
})
|
||||
|
||||
it("looks up order", async () => {
|
||||
const api = useApi();
|
||||
const api = useApi()
|
||||
|
||||
const response = await api
|
||||
.get("/store/orders?display_id=111&email=test@email.com")
|
||||
.catch((err) => {
|
||||
return err.response;
|
||||
});
|
||||
expect(response.status).toEqual(200);
|
||||
expect(response.data.order.display_id).toEqual(111);
|
||||
expect(response.data.order.email).toEqual("test@email.com");
|
||||
});
|
||||
return err.response
|
||||
})
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data.order.display_id).toEqual(111)
|
||||
expect(response.data.order.email).toEqual("test@email.com")
|
||||
})
|
||||
|
||||
it("fails if display_id + email not provided", async () => {
|
||||
const api = useApi();
|
||||
const api = useApi()
|
||||
|
||||
const response = await api
|
||||
.get("/store/orders?display_id=111")
|
||||
.catch((err) => {
|
||||
return err.response;
|
||||
});
|
||||
expect(response.status).toEqual(400);
|
||||
});
|
||||
return err.response
|
||||
})
|
||||
expect(response.status).toEqual(400)
|
||||
})
|
||||
|
||||
it("fails if display_id + email not provided", async () => {
|
||||
const api = useApi();
|
||||
const api = useApi()
|
||||
|
||||
const response = await api
|
||||
.get("/store/orders?email=test@email.com")
|
||||
.catch((err) => {
|
||||
return err.response;
|
||||
});
|
||||
expect(response.status).toEqual(400);
|
||||
});
|
||||
return err.response
|
||||
})
|
||||
expect(response.status).toEqual(400)
|
||||
})
|
||||
|
||||
it("fails if email not correct", async () => {
|
||||
const api = useApi();
|
||||
const api = useApi()
|
||||
|
||||
const response = await api
|
||||
.get("/store/orders?display_id=111&email=test1@email.com")
|
||||
.catch((err) => {
|
||||
return err.response;
|
||||
});
|
||||
return err.response
|
||||
})
|
||||
|
||||
expect(response.status).toEqual(404);
|
||||
});
|
||||
});
|
||||
});
|
||||
expect(response.status).toEqual(404)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -0,0 +1,258 @@
|
||||
const path = require("path")
|
||||
const {
|
||||
Region,
|
||||
Order,
|
||||
Customer,
|
||||
ShippingProfile,
|
||||
Product,
|
||||
ProductVariant,
|
||||
MoneyAmount,
|
||||
LineItem,
|
||||
Payment,
|
||||
Cart,
|
||||
ShippingMethod,
|
||||
ShippingOption,
|
||||
Swap,
|
||||
} = require("@medusajs/medusa")
|
||||
|
||||
const setupServer = require("../../../helpers/setup-server")
|
||||
const { useApi } = require("../../../helpers/use-api")
|
||||
const { initDb, useDb } = require("../../../helpers/use-db")
|
||||
|
||||
const orderSeeder = require("../../helpers/order-seeder")
|
||||
|
||||
jest.setTimeout(30000)
|
||||
|
||||
describe("/store/carts", () => {
|
||||
let medusaProcess
|
||||
let dbConnection
|
||||
|
||||
beforeAll(async () => {
|
||||
const cwd = path.resolve(path.join(__dirname, "..", ".."))
|
||||
dbConnection = await initDb({ cwd })
|
||||
medusaProcess = await setupServer({ cwd })
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
const db = useDb()
|
||||
await db.shutdown()
|
||||
medusaProcess.kill()
|
||||
})
|
||||
|
||||
describe("/store/swaps", () => {
|
||||
beforeEach(async () => {
|
||||
try {
|
||||
await orderSeeder(dbConnection)
|
||||
|
||||
const manager = dbConnection.manager
|
||||
await manager.query(
|
||||
`UPDATE "swap" SET cart_id='test-cart-2' WHERE id = 'test-swap'`
|
||||
)
|
||||
await manager.query(
|
||||
`UPDATE "payment" SET swap_id=NULL WHERE id = 'test-payment-swap'`
|
||||
)
|
||||
|
||||
const defaultProfile = await manager.findOne(ShippingProfile, {
|
||||
type: "default",
|
||||
})
|
||||
await manager.insert(ShippingOption, {
|
||||
id: "return-option",
|
||||
name: "Test ret",
|
||||
profile_id: defaultProfile.id,
|
||||
region_id: "test-region",
|
||||
provider_id: "test-ful",
|
||||
data: {},
|
||||
price_type: "flat_rate",
|
||||
amount: 1000,
|
||||
is_return: true,
|
||||
})
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
throw err
|
||||
}
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
const db = useDb()
|
||||
await db.teardown()
|
||||
})
|
||||
|
||||
it("simple swap", async () => {
|
||||
const api = useApi()
|
||||
|
||||
const response = await api
|
||||
.post("/store/swaps", {
|
||||
order_id: "test-order",
|
||||
return_items: [
|
||||
{
|
||||
item_id: "test-item",
|
||||
quantity: 1,
|
||||
},
|
||||
],
|
||||
additional_items: [
|
||||
{
|
||||
variant_id: "test-variant-2",
|
||||
quantity: 1,
|
||||
},
|
||||
],
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log(err.response.data.message)
|
||||
})
|
||||
|
||||
expect(response.data).toMatchSnapshot({
|
||||
swap: {
|
||||
id: expect.stringMatching(/^swap_*/),
|
||||
idempotency_key: expect.any(String),
|
||||
additional_items: [
|
||||
{
|
||||
id: expect.stringMatching(/^item_*/),
|
||||
cart_id: expect.stringMatching(/^cart_*/),
|
||||
swap_id: expect.stringMatching(/^swap_*/),
|
||||
variant: {
|
||||
id: "test-variant-2",
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
product: {
|
||||
profile_id: expect.stringMatching(/^sp_*/),
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
},
|
||||
},
|
||||
quantity: 1,
|
||||
variant_id: "test-variant-2",
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
},
|
||||
],
|
||||
order: {
|
||||
id: "test-order",
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
},
|
||||
cart_id: expect.stringMatching(/^cart_*/),
|
||||
cart: {
|
||||
id: expect.stringMatching(/^cart_*/),
|
||||
billing_address_id: "test-billing-address",
|
||||
type: "swap",
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
metadata: {
|
||||
swap_id: expect.stringMatching(/^swap_*/),
|
||||
},
|
||||
},
|
||||
return_order: {
|
||||
id: expect.stringMatching(/^ret_*/),
|
||||
swap_id: expect.stringMatching(/^swap_*/),
|
||||
refund_amount: 7200,
|
||||
items: [
|
||||
{
|
||||
item_id: "test-item",
|
||||
quantity: 1,
|
||||
return_id: expect.stringMatching(/^ret_*/),
|
||||
},
|
||||
],
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
},
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
it("swap with return shipping", async () => {
|
||||
const api = useApi()
|
||||
|
||||
const response = await api
|
||||
.post("/store/swaps", {
|
||||
order_id: "test-order",
|
||||
return_items: [
|
||||
{
|
||||
item_id: "test-item",
|
||||
quantity: 1,
|
||||
},
|
||||
],
|
||||
return_shipping_option: "return-option",
|
||||
additional_items: [
|
||||
{
|
||||
variant_id: "test-variant-2",
|
||||
quantity: 1,
|
||||
},
|
||||
],
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log(err.response.data.message)
|
||||
})
|
||||
|
||||
expect(response.data).toMatchSnapshot({
|
||||
swap: {
|
||||
id: expect.stringMatching(/^swap_*/),
|
||||
idempotency_key: expect.any(String),
|
||||
additional_items: [
|
||||
{
|
||||
id: expect.stringMatching(/^item_*/),
|
||||
cart_id: expect.stringMatching(/^cart_*/),
|
||||
swap_id: expect.stringMatching(/^swap_*/),
|
||||
variant: {
|
||||
id: "test-variant-2",
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
product: {
|
||||
profile_id: expect.stringMatching(/^sp_*/),
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
},
|
||||
},
|
||||
quantity: 1,
|
||||
variant_id: "test-variant-2",
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
},
|
||||
],
|
||||
order: {
|
||||
id: "test-order",
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
},
|
||||
cart_id: expect.stringMatching(/^cart_*/),
|
||||
cart: {
|
||||
id: expect.stringMatching(/^cart_*/),
|
||||
billing_address_id: "test-billing-address",
|
||||
type: "swap",
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
metadata: {
|
||||
swap_id: expect.stringMatching(/^swap_*/),
|
||||
},
|
||||
},
|
||||
return_order: {
|
||||
id: expect.stringMatching(/^ret_*/),
|
||||
swap_id: expect.stringMatching(/^swap_*/),
|
||||
refund_amount: 6200,
|
||||
shipping_method: {
|
||||
id: expect.stringMatching(/^sm_*/),
|
||||
return_id: expect.stringMatching(/^ret_*/),
|
||||
shipping_option: {
|
||||
profile_id: expect.stringMatching(/^sp_*/),
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
},
|
||||
},
|
||||
items: [
|
||||
{
|
||||
item_id: "test-item",
|
||||
quantity: 1,
|
||||
return_id: expect.stringMatching(/^ret_*/),
|
||||
},
|
||||
],
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
},
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
},
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -8,15 +8,15 @@
|
||||
"build": "babel src -d dist --extensions \".ts,.js\""
|
||||
},
|
||||
"dependencies": {
|
||||
"@medusajs/medusa": "1.1.36-dev-1629109473927",
|
||||
"medusa-interfaces": "1.1.21-dev-1629109473927",
|
||||
"@medusajs/medusa": "1.1.38-dev-1630001256218",
|
||||
"medusa-interfaces": "1.1.21-dev-1630001256218",
|
||||
"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.13-dev-1629109473927",
|
||||
"babel-preset-medusa-package": "1.1.13-dev-1630001256218",
|
||||
"jest": "^26.6.3"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
const { dropDatabase } = require("pg-god");
|
||||
|
||||
afterAll(() => {
|
||||
dropDatabase({ databaseName: "medusa-integration" });
|
||||
});
|
||||
@@ -1230,10 +1230,10 @@
|
||||
"@types/yargs" "^15.0.0"
|
||||
chalk "^4.0.0"
|
||||
|
||||
"@medusajs/medusa-cli@1.1.15-dev-1629109473927":
|
||||
version "1.1.15-dev-1629109473927"
|
||||
resolved "http://localhost:4873/@medusajs%2fmedusa-cli/-/medusa-cli-1.1.15-dev-1629109473927.tgz#d7d170daab4fc471f78841d55799f8d0c426c3a9"
|
||||
integrity sha512-VOaMDt1vkB/13dXqr9eeW6fKspI5sOzh1hAMZvJZ8Y3k0+2/eHr7imzxwBwOHW9qbgzCASq31hNGRl5SG+GigQ==
|
||||
"@medusajs/medusa-cli@1.1.16-dev-1630001256218":
|
||||
version "1.1.16-dev-1630001256218"
|
||||
resolved "http://localhost:4873/@medusajs%2fmedusa-cli/-/medusa-cli-1.1.16-dev-1630001256218.tgz#f1df1f0cb89e56261690640e7743c5cfa34b70d9"
|
||||
integrity sha512-02owiukP3bsGSo5yhuVUpNEB++CpkaJVDAxR7n8XxkIj+Jh4lBnTrO1m4JU4IddZZzHvm/ikpw/hDSgUuWia+g==
|
||||
dependencies:
|
||||
"@babel/polyfill" "^7.8.7"
|
||||
"@babel/runtime" "^7.9.6"
|
||||
@@ -1251,8 +1251,8 @@
|
||||
is-valid-path "^0.1.1"
|
||||
joi-objectid "^3.0.1"
|
||||
meant "^1.0.1"
|
||||
medusa-core-utils "1.1.20-dev-1629109473927"
|
||||
medusa-telemetry "0.0.2-dev-1629109473927"
|
||||
medusa-core-utils "1.1.20-dev-1630001256218"
|
||||
medusa-telemetry "0.0.3-dev-1630001256218"
|
||||
netrc-parser "^3.1.6"
|
||||
open "^8.0.6"
|
||||
ora "^5.4.1"
|
||||
@@ -1266,13 +1266,13 @@
|
||||
winston "^3.3.3"
|
||||
yargs "^15.3.1"
|
||||
|
||||
"@medusajs/medusa@1.1.36-dev-1629109473927":
|
||||
version "1.1.36-dev-1629109473927"
|
||||
resolved "http://localhost:4873/@medusajs%2fmedusa/-/medusa-1.1.36-dev-1629109473927.tgz#198c64c177aa5d39785fbada7f97bfc54d41737b"
|
||||
integrity sha512-4URRvrzBFqU72xGy0jZw3puLknNlZLQ2qCSopMF36qqPa0EFfZhC/fu2x7DIqAdbR8+WxPV/IV8nJQZwlbcOAA==
|
||||
"@medusajs/medusa@1.1.38-dev-1630001256218":
|
||||
version "1.1.38-dev-1630001256218"
|
||||
resolved "http://localhost:4873/@medusajs%2fmedusa/-/medusa-1.1.38-dev-1630001256218.tgz#f01c1644c4f9ee741d1effbbc9458c9bdcc75a10"
|
||||
integrity sha512-WdJDV3GP642uUaoxg+65zUXmc3LMKqzctSjNX3iegpjfcB4fat9TXXiO00+YEV95nyRfxrhixMzmH7If7XY1jA==
|
||||
dependencies:
|
||||
"@hapi/joi" "^16.1.8"
|
||||
"@medusajs/medusa-cli" "1.1.15-dev-1629109473927"
|
||||
"@medusajs/medusa-cli" "1.1.16-dev-1630001256218"
|
||||
"@types/lodash" "^4.14.168"
|
||||
awilix "^4.2.3"
|
||||
body-parser "^1.19.0"
|
||||
@@ -1282,6 +1282,7 @@
|
||||
cookie-parser "^1.4.4"
|
||||
core-js "^3.6.5"
|
||||
cors "^2.8.5"
|
||||
cross-spawn "^7.0.3"
|
||||
dotenv "^8.2.0"
|
||||
express "^4.17.1"
|
||||
express-session "^1.17.1"
|
||||
@@ -1292,8 +1293,8 @@
|
||||
joi "^17.3.0"
|
||||
joi-objectid "^3.0.1"
|
||||
jsonwebtoken "^8.5.1"
|
||||
medusa-core-utils "1.1.20-dev-1629109473927"
|
||||
medusa-test-utils "1.1.23-dev-1629109473927"
|
||||
medusa-core-utils "1.1.20-dev-1630001256218"
|
||||
medusa-test-utils "1.1.23-dev-1630001256218"
|
||||
morgan "^1.9.1"
|
||||
multer "^1.4.2"
|
||||
passport "^0.4.0"
|
||||
@@ -1938,10 +1939,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.13-dev-1629109473927:
|
||||
version "1.1.13-dev-1629109473927"
|
||||
resolved "http://localhost:4873/babel-preset-medusa-package/-/babel-preset-medusa-package-1.1.13-dev-1629109473927.tgz#1ec273faf2a64f1a02a23106de19d2babc9223bc"
|
||||
integrity sha512-Im7BInUm9S0OTb04CLiWRUNpVdNciJ7xVwFicNvCettujV5DvJWpMK/pYhYj+5HCyvYkZcgR2X3KZTpOtIt+uA==
|
||||
babel-preset-medusa-package@1.1.13-dev-1630001256218:
|
||||
version "1.1.13-dev-1630001256218"
|
||||
resolved "http://localhost:4873/babel-preset-medusa-package/-/babel-preset-medusa-package-1.1.13-dev-1630001256218.tgz#6a040844854c36aa054c63192dfff3eb96ea1175"
|
||||
integrity sha512-9MhOVXbNcMnHKg7FxMaQ81dswTS9eP8ow44OC4RoMa8xKxV9DCTcD3H8asJSYhP7k5EqkCP9EvT+6CUspAt6wQ==
|
||||
dependencies:
|
||||
"@babel/plugin-proposal-class-properties" "^7.12.1"
|
||||
"@babel/plugin-proposal-decorators" "^7.12.1"
|
||||
@@ -5073,25 +5074,25 @@ 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.20-dev-1629109473927:
|
||||
version "1.1.20-dev-1629109473927"
|
||||
resolved "http://localhost:4873/medusa-core-utils/-/medusa-core-utils-1.1.20-dev-1629109473927.tgz#fec5497a8d06cc4c264755fc691dcc89c285d041"
|
||||
integrity sha512-qAdf4KZRDtB4hPI5TYTCTlGXP+0WAbNOm5BX77aiLBGhDqjcYTH6zE2E1KWnMcpeydtqoVQ5Cpnt52tPX/HAFw==
|
||||
medusa-core-utils@1.1.20-dev-1630001256218:
|
||||
version "1.1.20-dev-1630001256218"
|
||||
resolved "http://localhost:4873/medusa-core-utils/-/medusa-core-utils-1.1.20-dev-1630001256218.tgz#0a87f9580ed5afec881eca71b31c47233bdbd527"
|
||||
integrity sha512-tOblNeS7/ko3Q6cKwqwe0hAj/QL9cu8568Cx4dArQv4in1MIqSfnP3qZ6lwH/gvYLGhEJi4F70A2bYOoAqxNIw==
|
||||
dependencies:
|
||||
joi "^17.3.0"
|
||||
joi-objectid "^3.0.1"
|
||||
|
||||
medusa-interfaces@1.1.21-dev-1629109473927:
|
||||
version "1.1.21-dev-1629109473927"
|
||||
resolved "http://localhost:4873/medusa-interfaces/-/medusa-interfaces-1.1.21-dev-1629109473927.tgz#b53f49b31a6ff34de09a4b2a71e10966aff4210d"
|
||||
integrity sha512-gtxUAcWD5yyWTMnHm7egamyVKtgc2bbaHfF/ezK7y+dqUPwHI9nry4Kpuy7YboF5XX4X/FHVajkRfGSJVPun7Q==
|
||||
medusa-interfaces@1.1.21-dev-1630001256218:
|
||||
version "1.1.21-dev-1630001256218"
|
||||
resolved "http://localhost:4873/medusa-interfaces/-/medusa-interfaces-1.1.21-dev-1630001256218.tgz#0b1b509e0db91b0299cf9f2cc8034aaeeb5bb2b6"
|
||||
integrity sha512-tmTTagdicUxImDR4V2fvU5j2johMvVdL71ptFcJJFxYUSZarRz6KcfPaQZzjVK+eJwIVG9qFjNVVoR/xk7sb4Q==
|
||||
dependencies:
|
||||
medusa-core-utils "1.1.20-dev-1629109473927"
|
||||
medusa-core-utils "1.1.20-dev-1630001256218"
|
||||
|
||||
medusa-telemetry@0.0.2-dev-1629109473927:
|
||||
version "0.0.2-dev-1629109473927"
|
||||
resolved "http://localhost:4873/medusa-telemetry/-/medusa-telemetry-0.0.2-dev-1629109473927.tgz#4ac0eb3ef4d1d0dea112a841023c2415b09fd5df"
|
||||
integrity sha512-a+k7QtRx9o3AFHsp7i9hijSTT5KWeDPKNFkRIcB3gEMaS+CkcCZ3CA3563yoeRJmGKpAcSxrRtbFDz8v757dLA==
|
||||
medusa-telemetry@0.0.3-dev-1630001256218:
|
||||
version "0.0.3-dev-1630001256218"
|
||||
resolved "http://localhost:4873/medusa-telemetry/-/medusa-telemetry-0.0.3-dev-1630001256218.tgz#d3a43c9d10ee32a189f236cd9082aee62606948b"
|
||||
integrity sha512-8RhUNhTvu6NsqBZZuoWeNQE5bPVgoMeBdzOlr9RnY4vfxjUlzLM7mNanRIol06Zmhz9sRd8/8Tqe2HfcfrSd6A==
|
||||
dependencies:
|
||||
axios "^0.21.1"
|
||||
axios-retry "^3.1.9"
|
||||
@@ -5102,13 +5103,13 @@ medusa-telemetry@0.0.2-dev-1629109473927:
|
||||
remove-trailing-slash "^0.1.1"
|
||||
uuid "^8.3.2"
|
||||
|
||||
medusa-test-utils@1.1.23-dev-1629109473927:
|
||||
version "1.1.23-dev-1629109473927"
|
||||
resolved "http://localhost:4873/medusa-test-utils/-/medusa-test-utils-1.1.23-dev-1629109473927.tgz#b7e47941f48b0a0b8be8d11b4e1dac75a1ada71e"
|
||||
integrity sha512-6NE+XQXBc6Qo8hFxCpY+mTzjOdymKlzdIokG8C+FihK9vLx79xI2iCKD9vv7ERmUA6j5ebNohS3GfRyPwfdMaQ==
|
||||
medusa-test-utils@1.1.23-dev-1630001256218:
|
||||
version "1.1.23-dev-1630001256218"
|
||||
resolved "http://localhost:4873/medusa-test-utils/-/medusa-test-utils-1.1.23-dev-1630001256218.tgz#8c0f4db11ee345b40ea51120e26df64f59b0ce9c"
|
||||
integrity sha512-jZH8wfxKtgJDJ7psdJ9ADmhbvtHTFKgrTohDrJ3HHu7NpUMAstA7NXc9v2kKCbznpQae81BI3lW/12nCfqel8Q==
|
||||
dependencies:
|
||||
"@babel/plugin-transform-classes" "^7.9.5"
|
||||
medusa-core-utils "1.1.20-dev-1629109473927"
|
||||
medusa-core-utils "1.1.20-dev-1630001256218"
|
||||
randomatic "^3.1.1"
|
||||
|
||||
merge-descriptors@1.0.1:
|
||||
|
||||
Reference in New Issue
Block a user