merge develop
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`/admin/auth creates admin session correctly 1`] = `
|
||||
Object {
|
||||
"api_token": "test_token",
|
||||
"created_at": Any<String>,
|
||||
"deleted_at": null,
|
||||
"email": "admin@medusa.js",
|
||||
"first_name": null,
|
||||
"id": "admin_user",
|
||||
"last_name": null,
|
||||
"metadata": null,
|
||||
"updated_at": Any<String>,
|
||||
}
|
||||
`;
|
||||
@@ -380,5 +380,198 @@ Array [
|
||||
"weight": null,
|
||||
"width": null,
|
||||
},
|
||||
Object {
|
||||
"collection": Any<Object>,
|
||||
"collection_id": "test-collection1",
|
||||
"created_at": Any<String>,
|
||||
"deleted_at": null,
|
||||
"description": "test-product-description",
|
||||
"discountable": true,
|
||||
"handle": "test-product_filtering_3",
|
||||
"height": null,
|
||||
"hs_code": null,
|
||||
"id": StringMatching /\\^test-\\*/,
|
||||
"images": Array [],
|
||||
"is_giftcard": false,
|
||||
"length": null,
|
||||
"material": null,
|
||||
"metadata": null,
|
||||
"mid_code": null,
|
||||
"options": Any<Array>,
|
||||
"origin_country": null,
|
||||
"profile_id": StringMatching /\\^sp_\\*/,
|
||||
"status": "draft",
|
||||
"subtitle": null,
|
||||
"tags": Any<Array>,
|
||||
"thumbnail": null,
|
||||
"title": "Test product filtering 3",
|
||||
"type": Any<Object>,
|
||||
"type_id": "test-type",
|
||||
"updated_at": Any<String>,
|
||||
"variants": Any<Array>,
|
||||
"weight": null,
|
||||
"width": null,
|
||||
},
|
||||
Object {
|
||||
"collection": Any<Object>,
|
||||
"collection_id": "test-collection1",
|
||||
"created_at": Any<String>,
|
||||
"deleted_at": null,
|
||||
"description": "test-product-description",
|
||||
"discountable": true,
|
||||
"handle": "test-product_filtering_1",
|
||||
"height": null,
|
||||
"hs_code": null,
|
||||
"id": StringMatching /\\^test-\\*/,
|
||||
"images": Array [],
|
||||
"is_giftcard": false,
|
||||
"length": null,
|
||||
"material": null,
|
||||
"metadata": null,
|
||||
"mid_code": null,
|
||||
"options": Any<Array>,
|
||||
"origin_country": null,
|
||||
"profile_id": StringMatching /\\^sp_\\*/,
|
||||
"status": "proposed",
|
||||
"subtitle": null,
|
||||
"tags": Any<Array>,
|
||||
"thumbnail": null,
|
||||
"title": "Test product filtering 1",
|
||||
"type": Any<Object>,
|
||||
"type_id": "test-type",
|
||||
"updated_at": Any<String>,
|
||||
"variants": Any<Array>,
|
||||
"weight": null,
|
||||
"width": null,
|
||||
},
|
||||
Object {
|
||||
"collection": Any<Object>,
|
||||
"collection_id": "test-collection2",
|
||||
"created_at": Any<String>,
|
||||
"deleted_at": null,
|
||||
"description": "test-product-description",
|
||||
"discountable": true,
|
||||
"handle": "test-product_filtering_2",
|
||||
"height": null,
|
||||
"hs_code": null,
|
||||
"id": StringMatching /\\^test-\\*/,
|
||||
"images": Array [],
|
||||
"is_giftcard": false,
|
||||
"length": null,
|
||||
"material": null,
|
||||
"metadata": null,
|
||||
"mid_code": null,
|
||||
"options": Any<Array>,
|
||||
"origin_country": null,
|
||||
"profile_id": StringMatching /\\^sp_\\*/,
|
||||
"status": "published",
|
||||
"subtitle": null,
|
||||
"tags": Any<Array>,
|
||||
"thumbnail": null,
|
||||
"title": "Test product filtering 2",
|
||||
"type": Any<Object>,
|
||||
"type_id": "test-type",
|
||||
"updated_at": Any<String>,
|
||||
"variants": Any<Array>,
|
||||
"weight": null,
|
||||
"width": null,
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`/admin/products GET /admin/products returns a list of products with giftcard in list 1`] = `
|
||||
Array [
|
||||
Object {
|
||||
"collection": null,
|
||||
"collection_id": null,
|
||||
"created_at": Any<String>,
|
||||
"deleted_at": null,
|
||||
"description": "test-giftcard-description",
|
||||
"discountable": false,
|
||||
"handle": "test-giftcard",
|
||||
"height": null,
|
||||
"hs_code": null,
|
||||
"id": StringMatching /\\^prod_\\*/,
|
||||
"images": Array [],
|
||||
"is_giftcard": true,
|
||||
"length": null,
|
||||
"material": null,
|
||||
"metadata": null,
|
||||
"mid_code": null,
|
||||
"options": Array [
|
||||
Object {
|
||||
"created_at": Any<String>,
|
||||
"deleted_at": null,
|
||||
"id": StringMatching /\\^opt_\\*/,
|
||||
"metadata": null,
|
||||
"product_id": StringMatching /\\^prod_\\*/,
|
||||
"title": "Denominations",
|
||||
"updated_at": Any<String>,
|
||||
},
|
||||
],
|
||||
"origin_country": null,
|
||||
"profile_id": StringMatching /\\^sp_\\*/,
|
||||
"status": "draft",
|
||||
"subtitle": null,
|
||||
"tags": Array [],
|
||||
"thumbnail": null,
|
||||
"title": "Test Giftcard",
|
||||
"type": null,
|
||||
"type_id": null,
|
||||
"updated_at": Any<String>,
|
||||
"variants": Array [
|
||||
Object {
|
||||
"allow_backorder": false,
|
||||
"barcode": null,
|
||||
"created_at": Any<String>,
|
||||
"deleted_at": null,
|
||||
"ean": null,
|
||||
"height": null,
|
||||
"hs_code": null,
|
||||
"id": StringMatching /\\^variant_\\*/,
|
||||
"inventory_quantity": 0,
|
||||
"length": null,
|
||||
"manage_inventory": true,
|
||||
"material": null,
|
||||
"metadata": null,
|
||||
"mid_code": null,
|
||||
"options": Array [
|
||||
Object {
|
||||
"created_at": Any<String>,
|
||||
"deleted_at": null,
|
||||
"id": StringMatching /\\^opt_\\*/,
|
||||
"metadata": null,
|
||||
"option_id": StringMatching /\\^opt_\\*/,
|
||||
"updated_at": Any<String>,
|
||||
"value": "100",
|
||||
"variant_id": StringMatching /\\^variant_\\*/,
|
||||
},
|
||||
],
|
||||
"origin_country": null,
|
||||
"prices": Array [
|
||||
Object {
|
||||
"amount": 100,
|
||||
"created_at": Any<String>,
|
||||
"currency_code": "usd",
|
||||
"deleted_at": null,
|
||||
"id": Any<String>,
|
||||
"region_id": null,
|
||||
"sale_amount": null,
|
||||
"updated_at": Any<String>,
|
||||
"variant_id": StringMatching /\\^variant_\\*/,
|
||||
},
|
||||
],
|
||||
"product_id": StringMatching /\\^prod_\\*/,
|
||||
"sku": null,
|
||||
"title": "Test variant",
|
||||
"upc": null,
|
||||
"updated_at": Any<String>,
|
||||
"weight": null,
|
||||
"width": null,
|
||||
},
|
||||
],
|
||||
"weight": null,
|
||||
"width": null,
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
54
integration-tests/api/__tests__/admin/auth.js
Normal file
54
integration-tests/api/__tests__/admin/auth.js
Normal file
@@ -0,0 +1,54 @@
|
||||
const path = require("path")
|
||||
const { Region, DiscountRule, Discount } = require("@medusajs/medusa")
|
||||
|
||||
const setupServer = require("../../../helpers/setup-server")
|
||||
const { useApi } = require("../../../helpers/use-api")
|
||||
const { initDb, useDb } = require("../../../helpers/use-db")
|
||||
const adminSeeder = require("../../helpers/admin-seeder")
|
||||
const { exportAllDeclaration } = require("@babel/types")
|
||||
|
||||
jest.setTimeout(30000)
|
||||
|
||||
describe("/admin/auth", () => {
|
||||
let medusaProcess
|
||||
let dbConnection
|
||||
|
||||
beforeAll(async () => {
|
||||
const cwd = path.resolve(path.join(__dirname, "..", ".."))
|
||||
dbConnection = await initDb({ cwd })
|
||||
medusaProcess = await setupServer({ cwd })
|
||||
|
||||
try {
|
||||
await adminSeeder(dbConnection)
|
||||
} catch (e) {
|
||||
throw e
|
||||
}
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
const db = useDb()
|
||||
await db.shutdown()
|
||||
medusaProcess.kill()
|
||||
})
|
||||
|
||||
it("creates admin session correctly", async () => {
|
||||
const api = useApi()
|
||||
|
||||
const response = await api
|
||||
.post("/admin/auth", {
|
||||
email: "admin@medusa.js",
|
||||
password: "secret_password",
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log(err)
|
||||
})
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data.user.password_hash).toEqual(undefined)
|
||||
expect(response.data.user).toMatchSnapshot({
|
||||
email: "admin@medusa.js",
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -158,6 +158,193 @@ describe("/admin/discounts", () => {
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
it("creates a discount with start and end dates", async () => {
|
||||
const api = useApi()
|
||||
|
||||
const response = await api
|
||||
.post(
|
||||
"/admin/discounts",
|
||||
{
|
||||
code: "HELLOWORLD",
|
||||
rule: {
|
||||
description: "test",
|
||||
type: "percentage",
|
||||
value: 10,
|
||||
allocation: "total",
|
||||
},
|
||||
usage_limit: 10,
|
||||
starts_at: new Date("09/15/2021 11:50"),
|
||||
ends_at: new Date("09/15/2021 17:50"),
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer test_token",
|
||||
},
|
||||
}
|
||||
)
|
||||
.catch((err) => {
|
||||
console.log(err)
|
||||
})
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data.discount).toEqual(
|
||||
expect.objectContaining({
|
||||
code: "HELLOWORLD",
|
||||
usage_limit: 10,
|
||||
starts_at: expect.any(String),
|
||||
ends_at: expect.any(String),
|
||||
})
|
||||
)
|
||||
|
||||
expect(new Date(response.data.discount.starts_at)).toEqual(
|
||||
new Date("09/15/2021 11:50")
|
||||
)
|
||||
|
||||
expect(new Date(response.data.discount.ends_at)).toEqual(
|
||||
new Date("09/15/2021 17:50")
|
||||
)
|
||||
|
||||
const updated = await api
|
||||
.post(
|
||||
`/admin/discounts/${response.data.discount.id}`,
|
||||
{
|
||||
usage_limit: 20,
|
||||
starts_at: new Date("09/14/2021 11:50"),
|
||||
ends_at: new Date("09/17/2021 17:50"),
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer test_token",
|
||||
},
|
||||
}
|
||||
)
|
||||
.catch((err) => {
|
||||
console.log(err)
|
||||
})
|
||||
|
||||
expect(updated.status).toEqual(200)
|
||||
expect(updated.data.discount).toEqual(
|
||||
expect.objectContaining({
|
||||
code: "HELLOWORLD",
|
||||
usage_limit: 20,
|
||||
starts_at: expect.any(String),
|
||||
ends_at: expect.any(String),
|
||||
})
|
||||
)
|
||||
|
||||
expect(new Date(updated.data.discount.starts_at)).toEqual(
|
||||
new Date("09/14/2021 11:50")
|
||||
)
|
||||
|
||||
expect(new Date(updated.data.discount.ends_at)).toEqual(
|
||||
new Date("09/17/2021 17:50")
|
||||
)
|
||||
})
|
||||
|
||||
it("fails to update end date to a date before start date", async () => {
|
||||
expect.assertions(6)
|
||||
|
||||
const api = useApi()
|
||||
|
||||
const response = await api
|
||||
.post(
|
||||
"/admin/discounts",
|
||||
{
|
||||
code: "HELLOWORLD",
|
||||
rule: {
|
||||
description: "test",
|
||||
type: "percentage",
|
||||
value: 10,
|
||||
allocation: "total",
|
||||
},
|
||||
usage_limit: 10,
|
||||
starts_at: new Date("09/15/2021 11:50"),
|
||||
ends_at: new Date("09/15/2021 17:50"),
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer test_token",
|
||||
},
|
||||
}
|
||||
)
|
||||
.catch((err) => {
|
||||
console.log(err)
|
||||
})
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data.discount).toEqual(
|
||||
expect.objectContaining({
|
||||
code: "HELLOWORLD",
|
||||
usage_limit: 10,
|
||||
starts_at: expect.any(String),
|
||||
ends_at: expect.any(String),
|
||||
})
|
||||
)
|
||||
|
||||
expect(new Date(response.data.discount.starts_at)).toEqual(
|
||||
new Date("09/15/2021 11:50")
|
||||
)
|
||||
|
||||
expect(new Date(response.data.discount.ends_at)).toEqual(
|
||||
new Date("09/15/2021 17:50")
|
||||
)
|
||||
|
||||
await api
|
||||
.post(
|
||||
`/admin/discounts/${response.data.discount.id}`,
|
||||
{
|
||||
usage_limit: 20,
|
||||
ends_at: new Date("09/11/2021 17:50"),
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer test_token",
|
||||
},
|
||||
}
|
||||
)
|
||||
.catch((err) => {
|
||||
expect(err.response.status).toEqual(400)
|
||||
expect(err.response.data.message).toEqual(
|
||||
`"ends_at" must be greater than "starts_at"`
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
it("fails to create discount with end date before start date", async () => {
|
||||
expect.assertions(2)
|
||||
const api = useApi()
|
||||
|
||||
const response = await api
|
||||
.post(
|
||||
"/admin/discounts",
|
||||
{
|
||||
code: "HELLOWORLD",
|
||||
rule: {
|
||||
description: "test",
|
||||
type: "percentage",
|
||||
value: 10,
|
||||
allocation: "total",
|
||||
},
|
||||
usage_limit: 10,
|
||||
starts_at: new Date("09/15/2021 11:50"),
|
||||
ends_at: new Date("09/14/2021 17:50"),
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer test_token",
|
||||
},
|
||||
}
|
||||
)
|
||||
.catch((err) => {
|
||||
expect(err.response.status).toEqual(400)
|
||||
expect(err.response.data.message).toEqual([
|
||||
expect.objectContaining({
|
||||
message: `"ends_at" must be greater than "ref:starts_at"`,
|
||||
}),
|
||||
])
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe("testing for soft-deletion + uniqueness on discount codes", () => {
|
||||
@@ -286,6 +473,21 @@ describe("/admin/discounts", () => {
|
||||
is_dynamic: true,
|
||||
is_disabled: false,
|
||||
rule_id: "test-discount-rule",
|
||||
valid_duration: "P2Y",
|
||||
})
|
||||
await manager.insert(DiscountRule, {
|
||||
id: "test-discount-rule1",
|
||||
description: "Dynamic rule",
|
||||
type: "percentage",
|
||||
value: 10,
|
||||
allocation: "total",
|
||||
})
|
||||
await manager.insert(Discount, {
|
||||
id: "test-discount1",
|
||||
code: "DYNAMICCode",
|
||||
is_dynamic: true,
|
||||
is_disabled: false,
|
||||
rule_id: "test-discount-rule1",
|
||||
})
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
@@ -298,7 +500,7 @@ describe("/admin/discounts", () => {
|
||||
await db.teardown()
|
||||
})
|
||||
|
||||
it("creates a dynamic discount", async () => {
|
||||
it("creates a dynamic discount with ends_at", async () => {
|
||||
const api = useApi()
|
||||
|
||||
const response = await api
|
||||
@@ -318,6 +520,40 @@ describe("/admin/discounts", () => {
|
||||
})
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data.discount).toEqual(
|
||||
expect.objectContaining({
|
||||
code: "HELLOWORLD",
|
||||
ends_at: expect.any(String),
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
it("creates a dynamic discount without ends_at", async () => {
|
||||
const api = useApi()
|
||||
|
||||
const response = await api
|
||||
.post(
|
||||
"/admin/discounts/test-discount1/dynamic-codes",
|
||||
{
|
||||
code: "HELLOWORLD",
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer test_token",
|
||||
},
|
||||
}
|
||||
)
|
||||
.catch((err) => {
|
||||
// console.log(err)
|
||||
})
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data.discount).toEqual(
|
||||
expect.objectContaining({
|
||||
code: "HELLOWORLD",
|
||||
ends_at: null,
|
||||
})
|
||||
)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -4,6 +4,7 @@ const {
|
||||
Order,
|
||||
LineItem,
|
||||
ProductVariant,
|
||||
CustomShippingOption,
|
||||
} = require("@medusajs/medusa")
|
||||
|
||||
const setupServer = require("../../../helpers/setup-server")
|
||||
@@ -79,7 +80,6 @@ describe("/admin/orders", () => {
|
||||
await adminSeeder(dbConnection)
|
||||
await orderSeeder(dbConnection)
|
||||
await swapSeeder(dbConnection)
|
||||
await claimSeeder(dbConnection)
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
throw err
|
||||
@@ -222,6 +222,48 @@ describe("/admin/orders", () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe("POST /admin/orders/:id/swaps", () => {
|
||||
beforeEach(async () => {
|
||||
try {
|
||||
await adminSeeder(dbConnection)
|
||||
await orderSeeder(dbConnection)
|
||||
await claimSeeder(dbConnection)
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
throw err
|
||||
}
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
const db = useDb()
|
||||
await db.teardown()
|
||||
})
|
||||
|
||||
it("creates a swap on a claim", async () => {
|
||||
const api = useApi()
|
||||
|
||||
const swapOnSwap = await api.post(
|
||||
"/admin/orders/order-with-claim/swaps",
|
||||
{
|
||||
return_items: [
|
||||
{
|
||||
item_id: "test-item-co-2",
|
||||
quantity: 1,
|
||||
},
|
||||
],
|
||||
additional_items: [{ variant_id: "test-variant", quantity: 1 }],
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
authorization: "Bearer test_token",
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
expect(swapOnSwap.status).toEqual(200)
|
||||
})
|
||||
})
|
||||
|
||||
describe("POST /admin/orders/:id/claims", () => {
|
||||
beforeEach(async () => {
|
||||
try {
|
||||
@@ -317,6 +359,43 @@ describe("/admin/orders", () => {
|
||||
)
|
||||
})
|
||||
|
||||
it("creates a claim on a claim", async () => {
|
||||
const api = useApi()
|
||||
|
||||
const claimOnClaim = await api
|
||||
.post(
|
||||
"/admin/orders/order-with-claim/claims",
|
||||
{
|
||||
type: "replace",
|
||||
claim_items: [
|
||||
{
|
||||
item_id: "test-item-co-2",
|
||||
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",
|
||||
},
|
||||
}
|
||||
)
|
||||
.catch((err) => {
|
||||
console.log(err)
|
||||
})
|
||||
|
||||
expect(claimOnClaim.status).toEqual(200)
|
||||
})
|
||||
|
||||
it("creates a claim with a shipping address", async () => {
|
||||
const api = useApi()
|
||||
|
||||
@@ -840,6 +919,61 @@ describe("/admin/orders", () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe("POST /admin/orders/:id/claims", () => {
|
||||
beforeEach(async () => {
|
||||
try {
|
||||
await adminSeeder(dbConnection)
|
||||
await orderSeeder(dbConnection)
|
||||
await swapSeeder(dbConnection)
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
throw err
|
||||
}
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
const db = useDb()
|
||||
await db.teardown()
|
||||
})
|
||||
|
||||
it("creates a claim on a swap", async () => {
|
||||
const api = useApi()
|
||||
|
||||
const claimOnClaim = await api
|
||||
.post(
|
||||
"/admin/orders/order-with-swap/claims",
|
||||
{
|
||||
type: "replace",
|
||||
claim_items: [
|
||||
{
|
||||
item_id: "return-item-1",
|
||||
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",
|
||||
},
|
||||
}
|
||||
)
|
||||
.catch((err) => {
|
||||
console.log(err)
|
||||
})
|
||||
|
||||
expect(claimOnClaim.status).toEqual(200)
|
||||
})
|
||||
})
|
||||
|
||||
describe("POST /admin/orders/:id/return", () => {
|
||||
let rrId
|
||||
beforeEach(async () => {
|
||||
@@ -1276,6 +1410,47 @@ describe("/admin/orders", () => {
|
||||
expect(response.status).toEqual(200)
|
||||
})
|
||||
|
||||
it("creates a swap with custom shipping options", async () => {
|
||||
const api = useApi()
|
||||
|
||||
const response = await api.post(
|
||||
"/admin/orders/test-order/swaps",
|
||||
{
|
||||
return_items: [
|
||||
{
|
||||
item_id: "test-item",
|
||||
quantity: 1,
|
||||
},
|
||||
],
|
||||
additional_items: [{ variant_id: "test-variant-2", quantity: 1 }],
|
||||
custom_shipping_options: [{ option_id: "test-option", price: 0 }],
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
authorization: "Bearer test_token",
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
const swap = response.data.order.swaps[0]
|
||||
|
||||
const manager = dbConnection.manager
|
||||
const customOptions = await manager.find(CustomShippingOption, {
|
||||
shipping_option_id: "test-option",
|
||||
})
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
expect(customOptions).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
shipping_option_id: "test-option",
|
||||
price: 0,
|
||||
cart_id: swap.cart_id,
|
||||
}),
|
||||
])
|
||||
)
|
||||
})
|
||||
|
||||
it("creates a swap and a return", async () => {
|
||||
const api = useApi()
|
||||
|
||||
|
||||
@@ -46,7 +46,35 @@ describe("/admin/products", () => {
|
||||
const api = useApi()
|
||||
|
||||
const res = await api
|
||||
.get("/admin/products?status%5B%5D=null", {
|
||||
.get("/admin/products", {
|
||||
headers: {
|
||||
Authorization: "Bearer test_token",
|
||||
},
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log(err)
|
||||
})
|
||||
|
||||
expect(res.status).toEqual(200)
|
||||
expect(res.data.products).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
id: "test-product",
|
||||
status: "draft",
|
||||
}),
|
||||
expect.objectContaining({
|
||||
id: "test-product1",
|
||||
status: "draft",
|
||||
}),
|
||||
])
|
||||
)
|
||||
})
|
||||
|
||||
it("returns a list of all products when no query is provided", async () => {
|
||||
const api = useApi()
|
||||
|
||||
const res = await api
|
||||
.get("/admin/products?q=", {
|
||||
headers: {
|
||||
Authorization: "Bearer test_token",
|
||||
},
|
||||
@@ -89,7 +117,7 @@ describe("/admin/products", () => {
|
||||
})
|
||||
|
||||
const response = await api
|
||||
.get("/admin/products?status%5B%5D=proposed", {
|
||||
.get("/admin/products?status[]=proposed", {
|
||||
headers: {
|
||||
Authorization: "Bearer test_token",
|
||||
},
|
||||
@@ -109,6 +137,258 @@ describe("/admin/products", () => {
|
||||
)
|
||||
})
|
||||
|
||||
it("returns a list of products where status is proposed or published", async () => {
|
||||
const api = useApi()
|
||||
|
||||
const notExpected = [
|
||||
expect.objectContaining({ status: "draft" }),
|
||||
expect.objectContaining({ status: "rejected" }),
|
||||
]
|
||||
|
||||
const response = await api
|
||||
.get("/admin/products?status[]=published,proposed", {
|
||||
headers: {
|
||||
Authorization: "Bearer test_token",
|
||||
},
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log(err)
|
||||
})
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data.products).toEqual([
|
||||
expect.objectContaining({
|
||||
id: "test-product_filtering_1",
|
||||
status: "proposed",
|
||||
}),
|
||||
expect.objectContaining({
|
||||
id: "test-product_filtering_2",
|
||||
status: "published",
|
||||
}),
|
||||
])
|
||||
|
||||
for (const notExpect of notExpected) {
|
||||
expect(response.data.products).toEqual(
|
||||
expect.not.arrayContaining([notExpect])
|
||||
)
|
||||
}
|
||||
})
|
||||
|
||||
it("returns a list of products in collection", async () => {
|
||||
const api = useApi()
|
||||
|
||||
const notExpected = [
|
||||
expect.objectContaining({ collection_id: "test-collection" }),
|
||||
expect.objectContaining({ collection_id: "test-collection2" }),
|
||||
]
|
||||
|
||||
const response = await api
|
||||
.get("/admin/products?collection_id[]=test-collection1", {
|
||||
headers: {
|
||||
Authorization: "Bearer test_token",
|
||||
},
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log(err)
|
||||
})
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data.products).toEqual([
|
||||
expect.objectContaining({
|
||||
id: "test-product_filtering_1",
|
||||
collection_id: "test-collection1",
|
||||
}),
|
||||
expect.objectContaining({
|
||||
id: "test-product_filtering_3",
|
||||
collection_id: "test-collection1",
|
||||
}),
|
||||
])
|
||||
|
||||
for (const notExpect of notExpected) {
|
||||
expect(response.data.products).toEqual(
|
||||
expect.not.arrayContaining([notExpect])
|
||||
)
|
||||
}
|
||||
})
|
||||
|
||||
it("returns a list of products with tags", async () => {
|
||||
const api = useApi()
|
||||
|
||||
const notExpected = [
|
||||
expect.objectContaining({ id: "tag1" }),
|
||||
expect.objectContaining({ id: "tag2" }),
|
||||
expect.objectContaining({ id: "tag4" }),
|
||||
]
|
||||
|
||||
const response = await api
|
||||
.get("/admin/products?tags[]=tag3", {
|
||||
headers: {
|
||||
Authorization: "Bearer test_token",
|
||||
},
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log(err)
|
||||
})
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data.products).toEqual([
|
||||
expect.objectContaining({
|
||||
id: "test-product_filtering_1",
|
||||
tags: [expect.objectContaining({ id: "tag3" })],
|
||||
}),
|
||||
expect.objectContaining({
|
||||
id: "test-product_filtering_2",
|
||||
tags: [expect.objectContaining({ id: "tag3" })],
|
||||
}),
|
||||
])
|
||||
for (const product of response.data.products) {
|
||||
for (const notExpect of notExpected) {
|
||||
expect(product.tags).toEqual(expect.not.arrayContaining([notExpect]))
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
it("returns a list of products with tags in a collection", async () => {
|
||||
const api = useApi()
|
||||
|
||||
const notExpectedTags = [
|
||||
expect.objectContaining({ id: "tag1" }),
|
||||
expect.objectContaining({ id: "tag2" }),
|
||||
expect.objectContaining({ id: "tag3" }),
|
||||
]
|
||||
|
||||
const notExpectedCollections = [
|
||||
expect.objectContaining({ collection_id: "test-collection" }),
|
||||
expect.objectContaining({ collection_id: "test-collection2" }),
|
||||
]
|
||||
|
||||
const response = await api
|
||||
.get("/admin/products?collection_id[]=test-collection1&tags[]=tag4", {
|
||||
headers: {
|
||||
Authorization: "Bearer test_token",
|
||||
},
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log(err)
|
||||
})
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data.products).toEqual([
|
||||
expect.objectContaining({
|
||||
id: "test-product_filtering_3",
|
||||
collection_id: "test-collection1",
|
||||
tags: [expect.objectContaining({ id: "tag4" })],
|
||||
}),
|
||||
])
|
||||
|
||||
for (const notExpect of notExpectedCollections) {
|
||||
expect(response.data.products).toEqual(
|
||||
expect.not.arrayContaining([notExpect])
|
||||
)
|
||||
}
|
||||
|
||||
for (const product of response.data.products) {
|
||||
for (const notExpect of notExpectedTags) {
|
||||
expect(product.tags).toEqual(expect.not.arrayContaining([notExpect]))
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
it("returns a list of products with giftcard in list", async () => {
|
||||
const api = useApi()
|
||||
|
||||
const payload = {
|
||||
title: "Test Giftcard",
|
||||
is_giftcard: true,
|
||||
description: "test-giftcard-description",
|
||||
options: [{ title: "Denominations" }],
|
||||
variants: [
|
||||
{
|
||||
title: "Test variant",
|
||||
prices: [{ currency_code: "usd", amount: 100 }],
|
||||
options: [{ value: "100" }],
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
await api
|
||||
.post("/admin/products", payload, {
|
||||
headers: {
|
||||
Authorization: "Bearer test_token",
|
||||
},
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log(err)
|
||||
})
|
||||
|
||||
const response = await api
|
||||
.get("/admin/products?is_giftcard=true", {
|
||||
headers: {
|
||||
Authorization: "Bearer test_token",
|
||||
},
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log(err)
|
||||
})
|
||||
|
||||
expect(response.data.products).toEqual(
|
||||
expect.not.arrayContaining([
|
||||
expect.objectContaining({ is_giftcard: false }),
|
||||
])
|
||||
)
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data.products).toMatchSnapshot([
|
||||
{
|
||||
title: "Test Giftcard",
|
||||
id: expect.stringMatching(/^prod_*/),
|
||||
is_giftcard: true,
|
||||
description: "test-giftcard-description",
|
||||
profile_id: expect.stringMatching(/^sp_*/),
|
||||
options: [
|
||||
{
|
||||
title: "Denominations",
|
||||
id: expect.stringMatching(/^opt_*/),
|
||||
product_id: expect.stringMatching(/^prod_*/),
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
},
|
||||
],
|
||||
|
||||
variants: [
|
||||
{
|
||||
title: "Test variant",
|
||||
id: expect.stringMatching(/^variant_*/),
|
||||
product_id: expect.stringMatching(/^prod_*/),
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
prices: [
|
||||
{
|
||||
id: expect.any(String),
|
||||
currency_code: "usd",
|
||||
amount: 100,
|
||||
variant_id: expect.stringMatching(/^variant_*/),
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
},
|
||||
],
|
||||
options: [
|
||||
{
|
||||
id: expect.stringMatching(/^opt_*/),
|
||||
option_id: expect.stringMatching(/^opt_*/),
|
||||
created_at: expect.any(String),
|
||||
variant_id: expect.stringMatching(/^variant_*/),
|
||||
updated_at: expect.any(String),
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
},
|
||||
])
|
||||
})
|
||||
|
||||
it("returns a list of products with child entities", async () => {
|
||||
const api = useApi()
|
||||
|
||||
@@ -306,6 +586,42 @@ describe("/admin/products", () => {
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
},
|
||||
{
|
||||
id: expect.stringMatching(/^test-*/),
|
||||
profile_id: expect.stringMatching(/^sp_*/),
|
||||
created_at: expect.any(String),
|
||||
type: expect.any(Object),
|
||||
collection: expect.any(Object),
|
||||
options: expect.any(Array),
|
||||
tags: expect.any(Array),
|
||||
variants: expect.any(Array),
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
},
|
||||
{
|
||||
id: expect.stringMatching(/^test-*/),
|
||||
profile_id: expect.stringMatching(/^sp_*/),
|
||||
created_at: expect.any(String),
|
||||
type: expect.any(Object),
|
||||
collection: expect.any(Object),
|
||||
options: expect.any(Array),
|
||||
tags: expect.any(Array),
|
||||
variants: expect.any(Array),
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
},
|
||||
{
|
||||
id: expect.stringMatching(/^test-*/),
|
||||
profile_id: expect.stringMatching(/^sp_*/),
|
||||
created_at: expect.any(String),
|
||||
type: expect.any(Object),
|
||||
collection: expect.any(Object),
|
||||
options: expect.any(Array),
|
||||
tags: expect.any(Array),
|
||||
variants: expect.any(Array),
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
},
|
||||
])
|
||||
})
|
||||
})
|
||||
@@ -592,6 +908,28 @@ describe("/admin/products", () => {
|
||||
)
|
||||
})
|
||||
|
||||
it("updates product (removes images when empty array included)", async () => {
|
||||
const api = useApi()
|
||||
|
||||
const payload = {
|
||||
images: [],
|
||||
}
|
||||
|
||||
const response = await api
|
||||
.post("/admin/products/test-product", payload, {
|
||||
headers: {
|
||||
Authorization: "Bearer test_token",
|
||||
},
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log(err)
|
||||
})
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
|
||||
expect(response.data.product.images.length).toEqual(0)
|
||||
})
|
||||
|
||||
it("fails to update product with invalid status", async () => {
|
||||
const api = useApi()
|
||||
|
||||
@@ -696,6 +1034,7 @@ describe("/admin/products", () => {
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe("testing for soft-deletion + uniqueness on handles, collection and variant properties", () => {
|
||||
beforeEach(async () => {
|
||||
try {
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`/admin/auth creates store session correctly 1`] = `
|
||||
Object {
|
||||
"billing_address_id": null,
|
||||
"created_at": Any<String>,
|
||||
"deleted_at": null,
|
||||
"email": "test@testesen.dk",
|
||||
"first_name": "test",
|
||||
"has_account": true,
|
||||
"id": Any<String>,
|
||||
"last_name": "testesen",
|
||||
"metadata": null,
|
||||
"orders": Array [],
|
||||
"phone": "12345678",
|
||||
"updated_at": Any<String>,
|
||||
}
|
||||
`;
|
||||
@@ -17,6 +17,18 @@ Object {
|
||||
"material": null,
|
||||
"metadata": null,
|
||||
"mid_code": null,
|
||||
"options": Array [
|
||||
Object {
|
||||
"created_at": Any<String>,
|
||||
"deleted_at": null,
|
||||
"id": "test-variant-option",
|
||||
"metadata": null,
|
||||
"option_id": "test-option",
|
||||
"updated_at": Any<String>,
|
||||
"value": "Default variant",
|
||||
"variant_id": "test-variant",
|
||||
},
|
||||
],
|
||||
"origin_country": null,
|
||||
"prices": Array [
|
||||
Object {
|
||||
@@ -61,6 +73,18 @@ Object {
|
||||
"material": null,
|
||||
"metadata": null,
|
||||
"mid_code": null,
|
||||
"options": Array [
|
||||
Object {
|
||||
"created_at": Any<String>,
|
||||
"deleted_at": null,
|
||||
"id": "test-variant-option",
|
||||
"metadata": null,
|
||||
"option_id": "test-option",
|
||||
"updated_at": Any<String>,
|
||||
"value": "Default variant",
|
||||
"variant_id": "test-variant",
|
||||
},
|
||||
],
|
||||
"origin_country": null,
|
||||
"prices": Array [
|
||||
Object {
|
||||
|
||||
64
integration-tests/api/__tests__/store/auth.js
Normal file
64
integration-tests/api/__tests__/store/auth.js
Normal file
@@ -0,0 +1,64 @@
|
||||
const path = require("path")
|
||||
const { Region, DiscountRule, Discount } = require("@medusajs/medusa")
|
||||
|
||||
const setupServer = require("../../../helpers/setup-server")
|
||||
const { useApi } = require("../../../helpers/use-api")
|
||||
const { initDb, useDb } = require("../../../helpers/use-db")
|
||||
const adminSeeder = require("../../helpers/admin-seeder")
|
||||
const { exportAllDeclaration } = require("@babel/types")
|
||||
|
||||
jest.setTimeout(30000)
|
||||
|
||||
describe("/admin/auth", () => {
|
||||
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()
|
||||
})
|
||||
|
||||
it("creates store session correctly", async () => {
|
||||
const api = useApi()
|
||||
|
||||
await api
|
||||
.post("/store/customers", {
|
||||
email: "test@testesen.dk",
|
||||
password: "secret_password",
|
||||
first_name: "test",
|
||||
last_name: "testesen",
|
||||
phone: "12345678",
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log(err)
|
||||
})
|
||||
|
||||
const response = await api
|
||||
.post("/store/auth", {
|
||||
email: "test@testesen.dk",
|
||||
password: "secret_password",
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log(err)
|
||||
})
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data.customer.password_hash).toEqual(undefined)
|
||||
expect(response.data.customer).toMatchSnapshot({
|
||||
id: expect.any(String),
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
first_name: "test",
|
||||
last_name: "testesen",
|
||||
phone: "12345678",
|
||||
email: "test@testesen.dk",
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -1,5 +1,12 @@
|
||||
const path = require("path")
|
||||
const { Region, LineItem, GiftCard } = require("@medusajs/medusa")
|
||||
const {
|
||||
Region,
|
||||
LineItem,
|
||||
GiftCard,
|
||||
Cart,
|
||||
CustomShippingOption,
|
||||
ShippingOption,
|
||||
} = require("@medusajs/medusa")
|
||||
|
||||
const setupServer = require("../../../helpers/setup-server")
|
||||
const { useApi } = require("../../../helpers/use-api")
|
||||
@@ -63,6 +70,24 @@ describe("/store/carts", () => {
|
||||
expect(getRes.status).toEqual(200)
|
||||
})
|
||||
|
||||
it("fails to create a cart when no region exist", async () => {
|
||||
const api = useApi()
|
||||
|
||||
await dbConnection.manager.query(
|
||||
`UPDATE "country" SET region_id=null WHERE iso_2 = 'us'`
|
||||
)
|
||||
await dbConnection.manager.query(`DELETE from region`)
|
||||
|
||||
try {
|
||||
await api.post("/store/carts")
|
||||
} catch (error) {
|
||||
expect(error.response.status).toEqual(400)
|
||||
expect(error.response.data.message).toEqual(
|
||||
"A region is required to create a cart"
|
||||
)
|
||||
}
|
||||
})
|
||||
|
||||
it("creates a cart with country", async () => {
|
||||
const api = useApi()
|
||||
|
||||
@@ -131,20 +156,77 @@ describe("/store/carts", () => {
|
||||
})
|
||||
|
||||
it("fails on apply discount if limit has been reached", async () => {
|
||||
expect.assertions(2)
|
||||
const api = useApi()
|
||||
|
||||
await api
|
||||
.post("/store/carts/test-cart", {
|
||||
discounts: [{ code: "SPENT" }],
|
||||
})
|
||||
.catch((error) => {
|
||||
expect(error.response.status).toEqual(400)
|
||||
expect(error.response.data.message).toEqual(
|
||||
"Discount has been used maximum allowed times"
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
it("fails to apply expired discount", async () => {
|
||||
expect.assertions(2)
|
||||
const api = useApi()
|
||||
|
||||
try {
|
||||
await api.post("/store/carts/test-cart", {
|
||||
discounts: [{ code: "CREATED" }],
|
||||
discounts: [{ code: "EXP_DISC" }],
|
||||
})
|
||||
} catch (error) {
|
||||
expect(error.response.status).toEqual(400)
|
||||
expect(error.response.data.message).toEqual(
|
||||
"Discount has been used maximum allowed times"
|
||||
)
|
||||
expect(error.response.data.message).toEqual("Discount is expired")
|
||||
}
|
||||
})
|
||||
|
||||
it("fails on discount before start day", async () => {
|
||||
expect.assertions(2)
|
||||
const api = useApi()
|
||||
|
||||
try {
|
||||
await api.post("/store/carts/test-cart", {
|
||||
discounts: [{ code: "PREM_DISC" }],
|
||||
})
|
||||
} catch (error) {
|
||||
expect(error.response.status).toEqual(400)
|
||||
expect(error.response.data.message).toEqual("Discount is not valid yet")
|
||||
}
|
||||
})
|
||||
|
||||
it("fails on apply invalid dynamic discount", async () => {
|
||||
const api = useApi()
|
||||
|
||||
try {
|
||||
await api.post("/store/carts/test-cart", {
|
||||
discounts: [{ code: "INV_DYN_DISC" }],
|
||||
})
|
||||
} catch (error) {
|
||||
expect(error.response.status).toEqual(400)
|
||||
expect(error.response.data.message).toEqual("Discount is expired")
|
||||
}
|
||||
})
|
||||
|
||||
it("Applies dynamic discount to cart correctly", async () => {
|
||||
const api = useApi()
|
||||
|
||||
const cart = await api.post(
|
||||
"/store/carts/test-cart",
|
||||
{
|
||||
discounts: [{ code: "DYN_DISC" }],
|
||||
},
|
||||
{ withCredentials: true }
|
||||
)
|
||||
|
||||
expect(cart.data.cart.shipping_total).toBe(1000)
|
||||
expect(cart.status).toEqual(200)
|
||||
})
|
||||
|
||||
it("updates cart customer id", async () => {
|
||||
const api = useApi()
|
||||
|
||||
@@ -377,14 +459,42 @@ describe("/store/carts", () => {
|
||||
|
||||
describe("POST /store/carts/:id/shipping-methods", () => {
|
||||
beforeEach(async () => {
|
||||
await cartSeeder(dbConnection)
|
||||
try {
|
||||
await cartSeeder(dbConnection)
|
||||
const manager = dbConnection.manager
|
||||
|
||||
const _cart = await manager.create(Cart, {
|
||||
id: "test-cart-with-cso",
|
||||
customer_id: "some-customer",
|
||||
email: "some-customer@email.com",
|
||||
shipping_address: {
|
||||
id: "test-shipping-address",
|
||||
first_name: "lebron",
|
||||
country_code: "us",
|
||||
},
|
||||
region_id: "test-region",
|
||||
currency_code: "usd",
|
||||
type: "swap",
|
||||
})
|
||||
|
||||
let cartWithCustomSo = await manager.save(_cart)
|
||||
|
||||
await manager.insert(CustomShippingOption, {
|
||||
id: "another-cso-test",
|
||||
cart_id: "test-cart-with-cso",
|
||||
shipping_option_id: "test-option",
|
||||
price: 5,
|
||||
})
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
}
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
await doAfterEach()
|
||||
})
|
||||
|
||||
it("adds a shipping method to cart", async () => {
|
||||
it("adds a normal shipping method to cart", async () => {
|
||||
const api = useApi()
|
||||
|
||||
const cartWithShippingMethod = await api.post(
|
||||
@@ -401,6 +511,49 @@ describe("/store/carts", () => {
|
||||
expect(cartWithShippingMethod.status).toEqual(200)
|
||||
})
|
||||
|
||||
it("given a cart with custom options and a shipping option already belonging to said cart, then it should add a shipping method based on the given custom shipping option", async () => {
|
||||
const shippingOptionId = "test-option"
|
||||
|
||||
const api = useApi()
|
||||
|
||||
const cartWithCustomShippingMethod = await api
|
||||
.post(
|
||||
"/store/carts/test-cart-with-cso/shipping-methods",
|
||||
{
|
||||
option_id: shippingOptionId,
|
||||
},
|
||||
{ withCredentials: true }
|
||||
)
|
||||
.catch((err) => err.response)
|
||||
|
||||
expect(
|
||||
cartWithCustomShippingMethod.data.cart.shipping_methods
|
||||
).toContainEqual(
|
||||
expect.objectContaining({
|
||||
shipping_option_id: shippingOptionId,
|
||||
price: 5,
|
||||
})
|
||||
)
|
||||
expect(cartWithCustomShippingMethod.status).toEqual(200)
|
||||
})
|
||||
|
||||
it("given a cart with custom options and an option id not corresponding to any custom shipping option, then it should throw an invalid error", async () => {
|
||||
const api = useApi()
|
||||
|
||||
try {
|
||||
await api.post(
|
||||
"/store/carts/test-cart-with-cso/shipping-methods",
|
||||
{
|
||||
option_id: "orphan-so",
|
||||
},
|
||||
{ withCredentials: true }
|
||||
)
|
||||
} catch (err) {
|
||||
expect(err.response.status).toEqual(400)
|
||||
expect(err.response.data.message).toEqual("Wrong shipping option")
|
||||
}
|
||||
})
|
||||
|
||||
it("adds a giftcard to cart, but ensures discount only applied to discountable items", async () => {
|
||||
const api = useApi()
|
||||
|
||||
@@ -425,13 +578,15 @@ describe("/store/carts", () => {
|
||||
)
|
||||
|
||||
// Add a 10% discount to the cart
|
||||
const cartWithGiftcard = await api.post(
|
||||
"/store/carts/test-cart",
|
||||
{
|
||||
discounts: [{ code: "10PERCENT" }],
|
||||
},
|
||||
{ withCredentials: true }
|
||||
)
|
||||
const cartWithGiftcard = await api
|
||||
.post(
|
||||
"/store/carts/test-cart",
|
||||
{
|
||||
discounts: [{ code: "10PERCENT" }],
|
||||
},
|
||||
{ withCredentials: true }
|
||||
)
|
||||
.catch((err) => console.log(err))
|
||||
|
||||
// Ensure that the discount is only applied to the standard item
|
||||
expect(cartWithGiftcard.data.cart.total).toBe(1900) // 1000 (giftcard) + 900 (standard item with 10% discount)
|
||||
|
||||
@@ -221,5 +221,47 @@ describe("/store/customers", () => {
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
it("unsets customer billing address", async () => {
|
||||
const api = useApi()
|
||||
|
||||
const authResponse = await api.post("/store/auth", {
|
||||
email: "john@deere.com",
|
||||
password: "test",
|
||||
})
|
||||
|
||||
const customerId = authResponse.data.customer.id
|
||||
const [authCookie] = authResponse.headers["set-cookie"][0].split(";")
|
||||
|
||||
const check = await api.post(
|
||||
`/store/customers/me`,
|
||||
{
|
||||
billing_address: "addr_test",
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Cookie: authCookie,
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
expect(check.status).toEqual(200)
|
||||
expect(check.data.customer.billing_address_id).toEqual("addr_test")
|
||||
|
||||
const response = await api.post(
|
||||
`/store/customers/me`,
|
||||
{
|
||||
billing_address: null,
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Cookie: authCookie,
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data.customer.billing_address_id).toEqual(null)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,63 +1,63 @@
|
||||
const path = require("path");
|
||||
const path = require("path")
|
||||
|
||||
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 draftOrderSeeder = require("../../helpers/draft-order-seeder");
|
||||
const draftOrderSeeder = require("../../helpers/draft-order-seeder")
|
||||
|
||||
jest.setTimeout(30000);
|
||||
jest.setTimeout(30000)
|
||||
|
||||
describe("/store/carts (draft-orders)", () => {
|
||||
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();
|
||||
const db = useDb()
|
||||
await db.shutdown()
|
||||
|
||||
medusaProcess.kill();
|
||||
});
|
||||
medusaProcess.kill()
|
||||
})
|
||||
|
||||
describe("POST /admin/draft-order", () => {
|
||||
beforeEach(async () => {
|
||||
try {
|
||||
await draftOrderSeeder(dbConnection);
|
||||
await draftOrderSeeder(dbConnection)
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
throw err;
|
||||
console.log(err)
|
||||
throw err
|
||||
}
|
||||
});
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
const db = useDb();
|
||||
await db.teardown();
|
||||
});
|
||||
const db = useDb()
|
||||
await db.teardown()
|
||||
})
|
||||
|
||||
it("completes a cart for a draft order thereby creating an order for the draft order", async () => {
|
||||
const api = useApi();
|
||||
const api = useApi()
|
||||
|
||||
const response = await api
|
||||
.post("/store/carts/test-cart/complete-cart", {})
|
||||
.catch((err) => {
|
||||
console.log(err);
|
||||
});
|
||||
console.log(err)
|
||||
})
|
||||
|
||||
expect(response.status).toEqual(200);
|
||||
expect(response.status).toEqual(200)
|
||||
|
||||
const createdOrder = await api
|
||||
.get(`/store/orders/${response.data.data.id}`, {})
|
||||
.catch((err) => {
|
||||
console.log(err);
|
||||
});
|
||||
console.log(err)
|
||||
})
|
||||
|
||||
expect(createdOrder.data.order.cart_id).toEqual("test-cart");
|
||||
});
|
||||
});
|
||||
});
|
||||
expect(createdOrder.data.order.cart_id).toEqual("test-cart")
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,63 +1,63 @@
|
||||
const path = require("path");
|
||||
const { Region, GiftCard } = require("@medusajs/medusa");
|
||||
const path = require("path")
|
||||
const { Region, GiftCard } = 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")
|
||||
|
||||
jest.setTimeout(30000);
|
||||
jest.setTimeout(30000)
|
||||
|
||||
describe("/store/gift-cards", () => {
|
||||
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();
|
||||
});
|
||||
const db = useDb()
|
||||
await db.shutdown()
|
||||
medusaProcess.kill()
|
||||
})
|
||||
|
||||
describe("GET /store/gift-cards/:code", () => {
|
||||
beforeEach(async () => {
|
||||
const manager = dbConnection.manager;
|
||||
const manager = dbConnection.manager
|
||||
await manager.insert(Region, {
|
||||
id: "region",
|
||||
name: "Test Region",
|
||||
currency_code: "usd",
|
||||
tax_rate: 0,
|
||||
});
|
||||
})
|
||||
await manager.insert(GiftCard, {
|
||||
id: "gift_test",
|
||||
code: "GC_TEST",
|
||||
value: 200,
|
||||
balance: 120,
|
||||
region_id: "region",
|
||||
});
|
||||
});
|
||||
})
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
const db = useDb();
|
||||
await db.teardown();
|
||||
});
|
||||
const db = useDb()
|
||||
await db.teardown()
|
||||
})
|
||||
|
||||
it("retrieves a gift card", async () => {
|
||||
const api = useApi();
|
||||
const api = useApi()
|
||||
|
||||
const response = await api.get("/store/gift-cards/GC_TEST");
|
||||
expect(response.status).toEqual(200);
|
||||
const response = await api.get("/store/gift-cards/GC_TEST")
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data.gift_card).toEqual({
|
||||
id: "gift_test",
|
||||
code: "GC_TEST",
|
||||
value: 200,
|
||||
balance: 120,
|
||||
region: expect.any(Object),
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -65,6 +65,12 @@ describe("/store/variants", () => {
|
||||
updated_at: expect.any(String),
|
||||
weight: null,
|
||||
width: null,
|
||||
options: [
|
||||
{
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
},
|
||||
],
|
||||
prices: [
|
||||
{
|
||||
created_at: expect.any(String),
|
||||
@@ -79,6 +85,9 @@ describe("/store/variants", () => {
|
||||
},
|
||||
],
|
||||
product: expect.any(Object),
|
||||
options: [
|
||||
{ created_at: expect.any(String), updated_at: expect.any(String) },
|
||||
],
|
||||
},
|
||||
],
|
||||
})
|
||||
@@ -113,6 +122,12 @@ describe("/store/variants", () => {
|
||||
updated_at: expect.any(String),
|
||||
weight: null,
|
||||
width: null,
|
||||
options: [
|
||||
{
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
},
|
||||
],
|
||||
prices: [
|
||||
{
|
||||
created_at: expect.any(String),
|
||||
@@ -127,6 +142,9 @@ describe("/store/variants", () => {
|
||||
},
|
||||
],
|
||||
product: expect.any(Object),
|
||||
options: [
|
||||
{ created_at: expect.any(String), updated_at: expect.any(String) },
|
||||
],
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,94 +1,96 @@
|
||||
const path = require("path");
|
||||
const path = require("path")
|
||||
|
||||
const { ReturnReason } = require("@medusajs/medusa");
|
||||
const { ReturnReason } = 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")
|
||||
|
||||
jest.setTimeout(30000);
|
||||
jest.setTimeout(30000)
|
||||
|
||||
describe("/store/return-reasons", () => {
|
||||
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();
|
||||
});
|
||||
const db = useDb()
|
||||
await db.shutdown()
|
||||
medusaProcess.kill()
|
||||
})
|
||||
|
||||
describe("GET /store/return-reasons", () => {
|
||||
let rrId;
|
||||
let rrId_1;
|
||||
let rrId_2;
|
||||
let rrId
|
||||
let rrId_1
|
||||
let rrId_2
|
||||
|
||||
beforeEach(async () => {
|
||||
try {
|
||||
const created = dbConnection.manager.create(ReturnReason, {
|
||||
value: "wrong_size",
|
||||
label: "Wrong size",
|
||||
});
|
||||
})
|
||||
|
||||
const result = await dbConnection.manager.save(created);
|
||||
rrId = result.id;
|
||||
const result = await dbConnection.manager.save(created)
|
||||
rrId = result.id
|
||||
|
||||
const created_child = dbConnection.manager.create(ReturnReason, {
|
||||
value: "too_big",
|
||||
label: "Too Big",
|
||||
parent_return_reason_id: rrId
|
||||
});
|
||||
parent_return_reason_id: rrId,
|
||||
})
|
||||
|
||||
const result_child = await dbConnection.manager.save(created_child);
|
||||
rrId_1 = result_child.id;
|
||||
const result_child = await dbConnection.manager.save(created_child)
|
||||
rrId_1 = result_child.id
|
||||
|
||||
const created_2 = dbConnection.manager.create(ReturnReason, {
|
||||
value: "too_big_1",
|
||||
label: "Too Big 1",
|
||||
});
|
||||
})
|
||||
|
||||
const result_2 = await dbConnection.manager.save(created_2);
|
||||
rrId_2 = result_2.id;
|
||||
const result_2 = await dbConnection.manager.save(created_2)
|
||||
rrId_2 = result_2.id
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
throw err;
|
||||
console.log(err)
|
||||
throw err
|
||||
}
|
||||
});
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
const db = useDb();
|
||||
await db.teardown();
|
||||
});
|
||||
const db = useDb()
|
||||
await db.teardown()
|
||||
})
|
||||
|
||||
it("list return reasons", async () => {
|
||||
const api = useApi();
|
||||
const api = useApi()
|
||||
|
||||
const response = await api.get("/store/return-reasons").catch((err) => {
|
||||
console.log(err);
|
||||
});
|
||||
console.log(err)
|
||||
})
|
||||
|
||||
expect(response.status).toEqual(200);
|
||||
expect(response.status).toEqual(200)
|
||||
|
||||
expect(response.data.return_reasons).toEqual([
|
||||
expect.objectContaining({
|
||||
id: rrId,
|
||||
value: "wrong_size",
|
||||
return_reason_children:[expect.objectContaining({
|
||||
id: rrId_1,
|
||||
value: "too_big",
|
||||
}),]
|
||||
return_reason_children: [
|
||||
expect.objectContaining({
|
||||
id: rrId_1,
|
||||
value: "too_big",
|
||||
}),
|
||||
],
|
||||
}),
|
||||
expect.objectContaining({
|
||||
id: rrId_2,
|
||||
value: "too_big_1",
|
||||
}),
|
||||
]);
|
||||
});
|
||||
});
|
||||
});
|
||||
])
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
const path = require("path");
|
||||
const path = require("path")
|
||||
const {
|
||||
Region,
|
||||
ReturnReason,
|
||||
@@ -12,56 +12,56 @@ const {
|
||||
LineItem,
|
||||
Discount,
|
||||
DiscountRule,
|
||||
} = 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")
|
||||
|
||||
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();
|
||||
});
|
||||
const db = useDb()
|
||||
await db.shutdown()
|
||||
medusaProcess.kill()
|
||||
})
|
||||
|
||||
describe("POST /store/returns", () => {
|
||||
let rrId;
|
||||
let rrId_child;
|
||||
let rrResult;
|
||||
let rrId
|
||||
let rrId_child
|
||||
let rrResult
|
||||
|
||||
beforeEach(async () => {
|
||||
const manager = dbConnection.manager;
|
||||
const manager = dbConnection.manager
|
||||
await manager.query(
|
||||
`ALTER SEQUENCE order_display_id_seq RESTART WITH 111`
|
||||
);
|
||||
)
|
||||
|
||||
const defaultProfile = await manager.findOne(ShippingProfile, {
|
||||
type: "default",
|
||||
});
|
||||
|
||||
})
|
||||
|
||||
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",
|
||||
@@ -71,7 +71,7 @@ describe("/store/carts", () => {
|
||||
region_id: "region",
|
||||
tax_rate: 0,
|
||||
currency_code: "usd",
|
||||
});
|
||||
})
|
||||
|
||||
await manager.insert(DiscountRule, {
|
||||
id: "discount_rule_id",
|
||||
@@ -79,7 +79,7 @@ describe("/store/carts", () => {
|
||||
value: 10,
|
||||
allocation: "total",
|
||||
type: "percentage",
|
||||
});
|
||||
})
|
||||
|
||||
const d = manager.create(Discount, {
|
||||
id: "test-discount",
|
||||
@@ -87,9 +87,9 @@ describe("/store/carts", () => {
|
||||
is_dynamic: false,
|
||||
is_disabled: false,
|
||||
rule_id: "discount_rule_id",
|
||||
});
|
||||
})
|
||||
|
||||
await manager.save(d);
|
||||
await manager.save(d)
|
||||
|
||||
const ord = manager.create(Order, {
|
||||
id: "order_with_discount",
|
||||
@@ -99,18 +99,18 @@ describe("/store/carts", () => {
|
||||
region_id: "region",
|
||||
tax_rate: 0,
|
||||
currency_code: "usd",
|
||||
});
|
||||
})
|
||||
|
||||
ord.discounts = [d];
|
||||
ord.discounts = [d]
|
||||
|
||||
await manager.save(ord);
|
||||
await manager.save(ord)
|
||||
|
||||
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",
|
||||
@@ -123,7 +123,7 @@ describe("/store/carts", () => {
|
||||
value: "Size",
|
||||
},
|
||||
],
|
||||
});
|
||||
})
|
||||
|
||||
await manager.insert(LineItem, {
|
||||
id: "test-item",
|
||||
@@ -135,7 +135,7 @@ describe("/store/carts", () => {
|
||||
unit_price: 8000,
|
||||
quantity: 1,
|
||||
variant_id: "test-variant",
|
||||
});
|
||||
})
|
||||
|
||||
await manager.insert(ShippingOption, {
|
||||
id: "test-option",
|
||||
@@ -147,35 +147,35 @@ describe("/store/carts", () => {
|
||||
price_type: "flat_rate",
|
||||
amount: 1000,
|
||||
is_return: true,
|
||||
});
|
||||
})
|
||||
|
||||
const created = dbConnection.manager.create(ReturnReason, {
|
||||
value: "wrong_size",
|
||||
label: "Wrong Size",
|
||||
});
|
||||
const result = await dbConnection.manager.save(created);
|
||||
})
|
||||
const result = await dbConnection.manager.save(created)
|
||||
|
||||
rrResult = result
|
||||
rrId = result.id;
|
||||
rrId = result.id
|
||||
|
||||
const created_1 = dbConnection.manager.create(ReturnReason, {
|
||||
value: "too_big",
|
||||
label: "Too Big",
|
||||
parent_return_reason_id: rrId,
|
||||
});
|
||||
})
|
||||
|
||||
const result_1 = await dbConnection.manager.save(created_1);
|
||||
const result_1 = await dbConnection.manager.save(created_1)
|
||||
|
||||
rrId_child = result_1.id;
|
||||
});
|
||||
rrId_child = result_1.id
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
const db = useDb();
|
||||
await db.teardown();
|
||||
});
|
||||
const db = useDb()
|
||||
await db.teardown()
|
||||
})
|
||||
|
||||
it("creates a return", async () => {
|
||||
const api = useApi();
|
||||
const api = useApi()
|
||||
|
||||
const response = await api
|
||||
.post("/store/returns", {
|
||||
@@ -188,16 +188,16 @@ describe("/store/carts", () => {
|
||||
],
|
||||
})
|
||||
.catch((err) => {
|
||||
return err.response;
|
||||
});
|
||||
expect(response.status).toEqual(200);
|
||||
return err.response
|
||||
})
|
||||
expect(response.status).toEqual(200)
|
||||
|
||||
expect(response.data.return.refund_amount).toEqual(8000);
|
||||
});
|
||||
expect(response.data.return.refund_amount).toEqual(8000)
|
||||
})
|
||||
|
||||
it("failes to create a return with a reason category", async () => {
|
||||
const api = useApi();
|
||||
|
||||
const api = useApi()
|
||||
|
||||
const response = await api
|
||||
.post("/store/returns", {
|
||||
order_id: "order_test",
|
||||
@@ -211,17 +211,18 @@ describe("/store/carts", () => {
|
||||
],
|
||||
})
|
||||
.catch((err) => {
|
||||
return err.response;
|
||||
});
|
||||
return err.response
|
||||
})
|
||||
|
||||
expect(response.status).toEqual(400);
|
||||
expect(response.data.message).toEqual('Cannot apply return reason category')
|
||||
|
||||
});
|
||||
expect(response.status).toEqual(400)
|
||||
expect(response.data.message).toEqual(
|
||||
"Cannot apply return reason category"
|
||||
)
|
||||
})
|
||||
|
||||
it("creates a return with reasons", async () => {
|
||||
const api = useApi();
|
||||
|
||||
const api = useApi()
|
||||
|
||||
const response = await api
|
||||
.post("/store/returns", {
|
||||
order_id: "order_test",
|
||||
@@ -236,28 +237,28 @@ describe("/store/carts", () => {
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log(err.response)
|
||||
return err.response;
|
||||
});
|
||||
expect(response.status).toEqual(200);
|
||||
return err.response
|
||||
})
|
||||
expect(response.status).toEqual(200)
|
||||
|
||||
expect(response.data.return.items).toEqual([
|
||||
expect.objectContaining({
|
||||
reason_id: rrId_child,
|
||||
note: "TOO small",
|
||||
}),
|
||||
]);
|
||||
});
|
||||
])
|
||||
})
|
||||
|
||||
it("creates a return with discount and non-discountable item", async () => {
|
||||
const api = useApi();
|
||||
const api = useApi()
|
||||
|
||||
await dbConnection.manager.query(
|
||||
`UPDATE line_item set allow_discounts=false where id='test-item'`
|
||||
);
|
||||
)
|
||||
|
||||
await dbConnection.manager.query(
|
||||
`UPDATE line_item set order_id='order_with_discount' where id='test-item'`
|
||||
);
|
||||
)
|
||||
|
||||
const response = await api
|
||||
.post("/store/returns", {
|
||||
@@ -270,15 +271,15 @@ describe("/store/carts", () => {
|
||||
],
|
||||
})
|
||||
.catch((err) => {
|
||||
return err.response;
|
||||
});
|
||||
return err.response
|
||||
})
|
||||
|
||||
expect(response.status).toEqual(200);
|
||||
expect(response.data.return.refund_amount).toEqual(8000);
|
||||
});
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data.return.refund_amount).toEqual(8000)
|
||||
})
|
||||
|
||||
it("creates a return with shipping method", async () => {
|
||||
const api = useApi();
|
||||
const api = useApi()
|
||||
|
||||
const response = await api
|
||||
.post("/store/returns", {
|
||||
@@ -294,12 +295,11 @@ describe("/store/carts", () => {
|
||||
],
|
||||
})
|
||||
.catch((err) => {
|
||||
return err.response;
|
||||
});
|
||||
expect(response.status).toEqual(200);
|
||||
return err.response
|
||||
})
|
||||
expect(response.status).toEqual(200)
|
||||
|
||||
expect(response.data.return.refund_amount).toEqual(7000);
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
expect(response.data.return.refund_amount).toEqual(7000)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,51 +1,53 @@
|
||||
const path = require("path");
|
||||
const { Region, ShippingProfile, ShippingOption } = require("@medusajs/medusa");
|
||||
const path = require("path")
|
||||
const { Region, ShippingProfile, ShippingOption } = 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 cartSeeder = require("../../helpers/cart-seeder")
|
||||
const swapSeeder = require("../../helpers/swap-seeder")
|
||||
|
||||
jest.setTimeout(30000);
|
||||
jest.setTimeout(30000)
|
||||
|
||||
describe("/store/shipping-options", () => {
|
||||
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();
|
||||
});
|
||||
const db = useDb()
|
||||
await db.shutdown()
|
||||
medusaProcess.kill()
|
||||
})
|
||||
|
||||
describe("POST /store/shipping-options", () => {
|
||||
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(Region, {
|
||||
id: "region2",
|
||||
name: "Test Region 2",
|
||||
currency_code: "usd",
|
||||
tax_rate: 0,
|
||||
});
|
||||
})
|
||||
|
||||
const defaultProfile = await manager.findOne(ShippingProfile, {
|
||||
type: "default",
|
||||
});
|
||||
})
|
||||
|
||||
await manager.insert(ShippingOption, {
|
||||
id: "test-out",
|
||||
@@ -57,7 +59,7 @@ describe("/store/shipping-options", () => {
|
||||
price_type: "flat_rate",
|
||||
amount: 2000,
|
||||
is_return: false,
|
||||
});
|
||||
})
|
||||
|
||||
await manager.insert(ShippingOption, {
|
||||
id: "test-return",
|
||||
@@ -69,7 +71,7 @@ describe("/store/shipping-options", () => {
|
||||
price_type: "flat_rate",
|
||||
amount: 1000,
|
||||
is_return: true,
|
||||
});
|
||||
})
|
||||
|
||||
await manager.insert(ShippingOption, {
|
||||
id: "test-region2",
|
||||
@@ -81,51 +83,102 @@ describe("/store/shipping-options", () => {
|
||||
price_type: "flat_rate",
|
||||
amount: 1000,
|
||||
is_return: false,
|
||||
});
|
||||
});
|
||||
})
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
const db = useDb();
|
||||
await db.teardown();
|
||||
});
|
||||
const db = useDb()
|
||||
await db.teardown()
|
||||
})
|
||||
|
||||
it("retrieves all shipping options", async () => {
|
||||
const api = useApi();
|
||||
const api = useApi()
|
||||
|
||||
const response = await api.get("/store/shipping-options").catch((err) => {
|
||||
return err.response;
|
||||
});
|
||||
return err.response
|
||||
})
|
||||
|
||||
expect(response.status).toEqual(200);
|
||||
expect(response.data.shipping_options.length).toEqual(3);
|
||||
});
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data.shipping_options.length).toEqual(3)
|
||||
})
|
||||
|
||||
it("creates a return with shipping method", async () => {
|
||||
const api = useApi();
|
||||
const api = useApi()
|
||||
|
||||
const response = await api
|
||||
.get("/store/shipping-options?is_return=true")
|
||||
.catch((err) => {
|
||||
return err.response;
|
||||
});
|
||||
return err.response
|
||||
})
|
||||
|
||||
expect(response.status).toEqual(200);
|
||||
expect(response.data.shipping_options.length).toEqual(1);
|
||||
expect(response.data.shipping_options[0].id).toEqual("test-return");
|
||||
});
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data.shipping_options.length).toEqual(1)
|
||||
expect(response.data.shipping_options[0].id).toEqual("test-return")
|
||||
})
|
||||
|
||||
it("creates a return with shipping method", async () => {
|
||||
const api = useApi();
|
||||
const api = useApi()
|
||||
|
||||
const response = await api
|
||||
.get("/store/shipping-options?region_id=region2")
|
||||
.catch((err) => {
|
||||
return err.response;
|
||||
});
|
||||
return err.response
|
||||
})
|
||||
|
||||
expect(response.status).toEqual(200);
|
||||
expect(response.data.shipping_options.length).toEqual(1);
|
||||
expect(response.data.shipping_options[0].id).toEqual("test-region2");
|
||||
});
|
||||
});
|
||||
});
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data.shipping_options.length).toEqual(1)
|
||||
expect(response.data.shipping_options[0].id).toEqual("test-region2")
|
||||
})
|
||||
})
|
||||
|
||||
describe("GET /store/shipping-options/:cart_id", () => {
|
||||
beforeEach(async () => {
|
||||
await cartSeeder(dbConnection)
|
||||
await swapSeeder(dbConnection)
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
const db = useDb()
|
||||
await db.teardown()
|
||||
})
|
||||
|
||||
it("given a default cart, when user retrieves its shipping options, then should return a list of shipping options", async () => {
|
||||
const api = useApi()
|
||||
|
||||
const response = await api
|
||||
.get("/store/shipping-options/test-cart-2")
|
||||
.catch((err) => {
|
||||
return err.response
|
||||
})
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data.shipping_options).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({ id: "test-option", amount: 1000 }),
|
||||
expect.objectContaining({ id: "test-option-2", amount: 500 }),
|
||||
])
|
||||
)
|
||||
})
|
||||
|
||||
it("given a cart with custom shipping options, when user retrieves its shipping options, then should return the list of custom shipping options", async () => {
|
||||
const api = useApi()
|
||||
|
||||
const response = await api
|
||||
.get("/store/shipping-options/test-cart-rma")
|
||||
.catch((err) => {
|
||||
return err.response
|
||||
})
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data.shipping_options).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
id: "test-option",
|
||||
amount: 0,
|
||||
name: "test-option",
|
||||
}),
|
||||
])
|
||||
)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user