chore(feature-flags): Sales Channels enabled by default (#2966)
This commit is contained in:
@@ -47,7 +47,7 @@ Object {
|
||||
"status": "draft",
|
||||
"subtitle": null,
|
||||
"thumbnail": null,
|
||||
"title": "Practical Frozen Fish",
|
||||
"title": "Handmade Frozen Chair",
|
||||
"type_id": Any<String>,
|
||||
"updated_at": Any<String>,
|
||||
"weight": null,
|
||||
|
||||
@@ -33,6 +33,7 @@ Array [
|
||||
],
|
||||
"origin_country": null,
|
||||
"profile_id": StringMatching /\\^sp_\\*/,
|
||||
"sales_channels": Array [],
|
||||
"status": "draft",
|
||||
"subtitle": null,
|
||||
"tags": Array [],
|
||||
@@ -174,6 +175,7 @@ Object {
|
||||
],
|
||||
"origin_country": null,
|
||||
"profile_id": StringMatching /\\^sp_\\*/,
|
||||
"sales_channels": Array [],
|
||||
"status": "draft",
|
||||
"subtitle": null,
|
||||
"tags": Array [
|
||||
@@ -351,6 +353,7 @@ Object {
|
||||
],
|
||||
"origin_country": null,
|
||||
"profile_id": StringMatching /\\^sp_\\*/,
|
||||
"sales_channels": Array [],
|
||||
"status": "published",
|
||||
"subtitle": null,
|
||||
"tags": Array [
|
||||
|
||||
@@ -32,34 +32,6 @@ Object {
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`sales channels GET /admin/sales-channels should list the sales channel 1`] = `
|
||||
Object {
|
||||
"count": 2,
|
||||
"limit": 20,
|
||||
"offset": 0,
|
||||
"sales_channels": ArrayContaining [
|
||||
Object {
|
||||
"created_at": Any<String>,
|
||||
"deleted_at": null,
|
||||
"description": "test description",
|
||||
"id": Any<String>,
|
||||
"is_disabled": false,
|
||||
"name": "test name",
|
||||
"updated_at": Any<String>,
|
||||
},
|
||||
Object {
|
||||
"created_at": Any<String>,
|
||||
"deleted_at": null,
|
||||
"description": "test description 2",
|
||||
"id": Any<String>,
|
||||
"is_disabled": false,
|
||||
"name": "test name 2",
|
||||
"updated_at": Any<String>,
|
||||
},
|
||||
],
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`sales channels GET /admin/sales-channels should list the sales channel using free text search 1`] = `
|
||||
Object {
|
||||
"count": 1,
|
||||
|
||||
@@ -6,145 +6,3 @@ Object {
|
||||
"type": "invalid_data",
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`/admin/store POST /admin/store successfully updates and store currencies 1`] = `
|
||||
Object {
|
||||
"created_at": Any<String>,
|
||||
"currencies": Array [
|
||||
Object {
|
||||
"code": "jpy",
|
||||
"name": "Japanese Yen",
|
||||
"symbol": "¥",
|
||||
"symbol_native": "¥",
|
||||
},
|
||||
Object {
|
||||
"code": "usd",
|
||||
"name": "US Dollar",
|
||||
"symbol": "$",
|
||||
"symbol_native": "$",
|
||||
},
|
||||
],
|
||||
"default_currency_code": "usd",
|
||||
"default_location_id": null,
|
||||
"id": Any<String>,
|
||||
"invite_link_template": null,
|
||||
"metadata": null,
|
||||
"name": "Medusa Store",
|
||||
"payment_link_template": null,
|
||||
"swap_link_template": null,
|
||||
"updated_at": Any<String>,
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`/admin/store POST /admin/store successfully updates default currency and store currencies 1`] = `
|
||||
Object {
|
||||
"created_at": Any<String>,
|
||||
"currencies": Array [
|
||||
Object {
|
||||
"code": "jpy",
|
||||
"name": "Japanese Yen",
|
||||
"symbol": "¥",
|
||||
"symbol_native": "¥",
|
||||
},
|
||||
Object {
|
||||
"code": "usd",
|
||||
"name": "US Dollar",
|
||||
"symbol": "$",
|
||||
"symbol_native": "$",
|
||||
},
|
||||
],
|
||||
"default_currency": Object {
|
||||
"code": "jpy",
|
||||
"name": "Japanese Yen",
|
||||
"symbol": "¥",
|
||||
"symbol_native": "¥",
|
||||
},
|
||||
"default_currency_code": "jpy",
|
||||
"default_location_id": null,
|
||||
"id": Any<String>,
|
||||
"invite_link_template": null,
|
||||
"metadata": null,
|
||||
"name": "Medusa Store",
|
||||
"payment_link_template": null,
|
||||
"swap_link_template": null,
|
||||
"updated_at": Any<String>,
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`/admin/store POST /admin/store successfully updates default currency code 1`] = `
|
||||
Object {
|
||||
"created_at": Any<String>,
|
||||
"currencies": Array [
|
||||
Object {
|
||||
"code": "usd",
|
||||
"name": "US Dollar",
|
||||
"symbol": "$",
|
||||
"symbol_native": "$",
|
||||
},
|
||||
Object {
|
||||
"code": "dkk",
|
||||
"name": "Danish Krone",
|
||||
"symbol": "Dkr",
|
||||
"symbol_native": "kr",
|
||||
},
|
||||
],
|
||||
"default_currency": Object {
|
||||
"code": "dkk",
|
||||
"name": "Danish Krone",
|
||||
"symbol": "Dkr",
|
||||
"symbol_native": "kr",
|
||||
},
|
||||
"default_currency_code": "dkk",
|
||||
"default_location_id": null,
|
||||
"id": Any<String>,
|
||||
"invite_link_template": null,
|
||||
"metadata": null,
|
||||
"name": "Medusa Store",
|
||||
"payment_link_template": null,
|
||||
"swap_link_template": null,
|
||||
"updated_at": Any<String>,
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`/admin/store Store creation has created store with default currency 1`] = `
|
||||
Object {
|
||||
"created_at": Any<String>,
|
||||
"currencies": Array [
|
||||
Object {
|
||||
"code": "usd",
|
||||
"name": "US Dollar",
|
||||
"symbol": "$",
|
||||
"symbol_native": "$",
|
||||
},
|
||||
],
|
||||
"default_currency": Object {
|
||||
"code": "usd",
|
||||
"name": "US Dollar",
|
||||
"symbol": "$",
|
||||
"symbol_native": "$",
|
||||
},
|
||||
"default_currency_code": "usd",
|
||||
"default_location_id": null,
|
||||
"feature_flags": Any<Array>,
|
||||
"fulfillment_providers": Array [
|
||||
Object {
|
||||
"id": "test-ful",
|
||||
"is_installed": true,
|
||||
},
|
||||
],
|
||||
"id": Any<String>,
|
||||
"invite_link_template": null,
|
||||
"metadata": null,
|
||||
"modules": Any<Array>,
|
||||
"name": "Medusa Store",
|
||||
"payment_link_template": null,
|
||||
"payment_providers": Array [
|
||||
Object {
|
||||
"id": "test-pay",
|
||||
"is_installed": true,
|
||||
},
|
||||
],
|
||||
"swap_link_template": null,
|
||||
"updated_at": Any<String>,
|
||||
}
|
||||
`;
|
||||
|
||||
@@ -12,7 +12,10 @@ const {
|
||||
DiscountConditionOperator,
|
||||
} = require("@medusajs/medusa")
|
||||
const { IdMap } = require("medusa-test-utils")
|
||||
const { simpleDiscountFactory } = require("../../factories")
|
||||
const {
|
||||
simpleDiscountFactory,
|
||||
simpleSalesChannelFactory,
|
||||
} = require("../../factories")
|
||||
|
||||
jest.setTimeout(30000)
|
||||
|
||||
|
||||
@@ -109,31 +109,20 @@ describe("sales channels", () => {
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data.sales_channels).toBeTruthy()
|
||||
expect(response.data.sales_channels.length).toBe(2)
|
||||
expect(response.data).toMatchSnapshot({
|
||||
count: 2,
|
||||
limit: 20,
|
||||
offset: 0,
|
||||
sales_channels: expect.arrayContaining([
|
||||
{
|
||||
id: expect.any(String),
|
||||
name: salesChannel1.name,
|
||||
description: salesChannel1.description,
|
||||
is_disabled: false,
|
||||
deleted_at: null,
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
},
|
||||
{
|
||||
id: expect.any(String),
|
||||
name: salesChannel2.name,
|
||||
description: salesChannel2.description,
|
||||
is_disabled: false,
|
||||
deleted_at: null,
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
},
|
||||
]),
|
||||
})
|
||||
expect(response.data).toEqual(
|
||||
expect.objectContaining({
|
||||
sales_channels: expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
name: salesChannel1.name,
|
||||
description: salesChannel1.description,
|
||||
}),
|
||||
expect.objectContaining({
|
||||
name: salesChannel2.name,
|
||||
description: salesChannel2.description,
|
||||
}),
|
||||
]),
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
it("should list the sales channel using free text search", async () => {
|
||||
@@ -632,7 +621,7 @@ describe("sales channels", () => {
|
||||
relations: ["sales_channels"],
|
||||
})
|
||||
|
||||
expect(attachedProduct.sales_channels.length).toBe(1)
|
||||
expect(attachedProduct.sales_channels.length).toBe(2)
|
||||
expect(attachedProduct.sales_channels).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
@@ -641,6 +630,10 @@ describe("sales channels", () => {
|
||||
description: "test description",
|
||||
is_disabled: false,
|
||||
}),
|
||||
expect.objectContaining({
|
||||
id: expect.any(String),
|
||||
is_disabled: false,
|
||||
}),
|
||||
])
|
||||
)
|
||||
|
||||
@@ -679,7 +672,8 @@ describe("sales channels", () => {
|
||||
relations: ["sales_channels"],
|
||||
})
|
||||
|
||||
expect(attachedProduct.sales_channels.length).toBe(0)
|
||||
// default sales channel
|
||||
expect(attachedProduct.sales_channels.length).toBe(1)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -733,7 +727,8 @@ describe("sales channels", () => {
|
||||
relations: ["sales_channels"],
|
||||
})
|
||||
|
||||
expect(attachedProduct.sales_channels.length).toBe(1)
|
||||
// + default sales channel
|
||||
expect(attachedProduct.sales_channels.length).toBe(2)
|
||||
expect(attachedProduct.sales_channels).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
@@ -742,6 +737,10 @@ describe("sales channels", () => {
|
||||
description: "test description",
|
||||
is_disabled: false,
|
||||
}),
|
||||
expect.objectContaining({
|
||||
id: expect.any(String),
|
||||
is_disabled: false,
|
||||
}),
|
||||
])
|
||||
)
|
||||
})
|
||||
|
||||
@@ -44,20 +44,26 @@ describe("/admin/store", () => {
|
||||
})
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data.store).toMatchSnapshot({
|
||||
id: expect.any(String),
|
||||
name: "Medusa Store",
|
||||
currencies: [
|
||||
{
|
||||
code: "usd",
|
||||
},
|
||||
],
|
||||
modules: expect.any(Array),
|
||||
feature_flags: expect.any(Array),
|
||||
default_currency_code: "usd",
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
})
|
||||
expect(response.data.store).toEqual(
|
||||
expect.objectContaining({
|
||||
id: expect.any(String),
|
||||
default_sales_channel_id: expect.any(String),
|
||||
default_sales_channel: expect.objectContaining({
|
||||
id: expect.any(String),
|
||||
}),
|
||||
name: "Medusa Store",
|
||||
currencies: expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
code: "usd",
|
||||
}),
|
||||
]),
|
||||
modules: expect.any(Array),
|
||||
feature_flags: expect.any(Array),
|
||||
default_currency_code: "usd",
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
})
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -142,21 +148,24 @@ describe("/admin/store", () => {
|
||||
.catch((err) => console.log(err))
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data.store).toMatchSnapshot({
|
||||
id: expect.any(String),
|
||||
name: "Medusa Store",
|
||||
currencies: [
|
||||
{
|
||||
code: "usd",
|
||||
},
|
||||
{
|
||||
code: "dkk",
|
||||
},
|
||||
],
|
||||
default_currency_code: "dkk",
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
})
|
||||
expect(response.data.store).toEqual(
|
||||
expect.objectContaining({
|
||||
id: expect.any(String),
|
||||
name: "Medusa Store",
|
||||
default_sales_channel_id: expect.any(String),
|
||||
currencies: expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
code: "usd",
|
||||
}),
|
||||
expect.objectContaining({
|
||||
code: "dkk",
|
||||
}),
|
||||
]),
|
||||
default_currency_code: "dkk",
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
it("successfully updates default currency and store currencies", async () => {
|
||||
@@ -174,21 +183,24 @@ describe("/admin/store", () => {
|
||||
)
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data.store).toMatchSnapshot({
|
||||
id: expect.any(String),
|
||||
name: "Medusa Store",
|
||||
currencies: [
|
||||
{
|
||||
code: "jpy",
|
||||
},
|
||||
{
|
||||
code: "usd",
|
||||
},
|
||||
],
|
||||
default_currency_code: "jpy",
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
})
|
||||
expect(response.data.store).toEqual(
|
||||
expect.objectContaining({
|
||||
id: expect.any(String),
|
||||
name: "Medusa Store",
|
||||
default_sales_channel_id: expect.any(String),
|
||||
currencies: expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
code: "jpy",
|
||||
}),
|
||||
expect.objectContaining({
|
||||
code: "usd",
|
||||
}),
|
||||
]),
|
||||
default_currency_code: "jpy",
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
it("successfully updates and store currencies", async () => {
|
||||
@@ -205,21 +217,24 @@ describe("/admin/store", () => {
|
||||
)
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data.store).toMatchSnapshot({
|
||||
id: expect.any(String),
|
||||
name: "Medusa Store",
|
||||
currencies: [
|
||||
{
|
||||
code: "jpy",
|
||||
},
|
||||
{
|
||||
code: "usd",
|
||||
},
|
||||
],
|
||||
default_currency_code: "usd",
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
})
|
||||
expect(response.data.store).toEqual(
|
||||
expect.objectContaining({
|
||||
id: expect.any(String),
|
||||
default_sales_channel_id: expect.any(String),
|
||||
name: "Medusa Store",
|
||||
currencies: expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
code: "jpy",
|
||||
}),
|
||||
expect.objectContaining({
|
||||
code: "usd",
|
||||
}),
|
||||
]),
|
||||
default_currency_code: "usd",
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
})
|
||||
)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -81,128 +81,3 @@ Object {
|
||||
"offset": 0,
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`/admin/batch-jobs GET /admin/batch-jobs lists batch jobs created by the user and where completed_at is null 1`] = `
|
||||
Object {
|
||||
"batch_jobs": Array [
|
||||
Object {
|
||||
"canceled_at": null,
|
||||
"completed_at": null,
|
||||
"confirmed_at": null,
|
||||
"context": Object {},
|
||||
"created_at": Any<String>,
|
||||
"created_by": "admin_user",
|
||||
"deleted_at": null,
|
||||
"dry_run": false,
|
||||
"failed_at": null,
|
||||
"id": "job_3",
|
||||
"pre_processed_at": null,
|
||||
"processing_at": null,
|
||||
"result": null,
|
||||
"status": "created",
|
||||
"type": "product-export",
|
||||
"updated_at": Any<String>,
|
||||
},
|
||||
Object {
|
||||
"canceled_at": null,
|
||||
"completed_at": null,
|
||||
"confirmed_at": null,
|
||||
"context": Object {},
|
||||
"created_at": Any<String>,
|
||||
"created_by": "admin_user",
|
||||
"deleted_at": null,
|
||||
"dry_run": false,
|
||||
"failed_at": null,
|
||||
"id": "job_2",
|
||||
"pre_processed_at": null,
|
||||
"processing_at": null,
|
||||
"result": null,
|
||||
"status": "created",
|
||||
"type": "product-export",
|
||||
"updated_at": Any<String>,
|
||||
},
|
||||
Object {
|
||||
"canceled_at": null,
|
||||
"completed_at": null,
|
||||
"confirmed_at": null,
|
||||
"context": Object {},
|
||||
"created_at": Any<String>,
|
||||
"created_by": "admin_user",
|
||||
"deleted_at": null,
|
||||
"dry_run": false,
|
||||
"failed_at": null,
|
||||
"id": "job_1",
|
||||
"pre_processed_at": null,
|
||||
"processing_at": null,
|
||||
"result": null,
|
||||
"status": "created",
|
||||
"type": "product-export",
|
||||
"updated_at": Any<String>,
|
||||
},
|
||||
],
|
||||
"count": 3,
|
||||
"limit": 10,
|
||||
"offset": 0,
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`/admin/batch-jobs POST /admin/batch-jobs/ Creates a batch job 1`] = `
|
||||
Object {
|
||||
"canceled_at": null,
|
||||
"completed_at": null,
|
||||
"confirmed_at": null,
|
||||
"context": Object {
|
||||
"list_config": Object {
|
||||
"order": Object {
|
||||
"created_at": "DESC",
|
||||
},
|
||||
"relations": Array [
|
||||
"variants",
|
||||
"variants.prices",
|
||||
"variants.options",
|
||||
"images",
|
||||
"options",
|
||||
"tags",
|
||||
"type",
|
||||
"collection",
|
||||
"variants.prices.region",
|
||||
],
|
||||
"skip": 0,
|
||||
"take": 50,
|
||||
},
|
||||
},
|
||||
"created_at": Any<String>,
|
||||
"created_by": "admin_user",
|
||||
"deleted_at": null,
|
||||
"dry_run": false,
|
||||
"failed_at": null,
|
||||
"id": Any<String>,
|
||||
"pre_processed_at": null,
|
||||
"processing_at": null,
|
||||
"result": null,
|
||||
"status": "created",
|
||||
"type": "product-export",
|
||||
"updated_at": Any<String>,
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`/admin/batch-jobs POST /admin/batch-jobs/:id/cancel Cancels batch job created by the user 1`] = `
|
||||
Object {
|
||||
"canceled_at": Any<String>,
|
||||
"completed_at": null,
|
||||
"confirmed_at": null,
|
||||
"context": Object {},
|
||||
"created_at": Any<String>,
|
||||
"created_by": "admin_user",
|
||||
"deleted_at": null,
|
||||
"dry_run": false,
|
||||
"failed_at": null,
|
||||
"id": "job_1",
|
||||
"pre_processed_at": null,
|
||||
"processing_at": null,
|
||||
"result": null,
|
||||
"status": "canceled",
|
||||
"type": "product-export",
|
||||
"updated_at": Any<String>,
|
||||
}
|
||||
`;
|
||||
|
||||
@@ -123,28 +123,30 @@ describe("/admin/batch-jobs", () => {
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data.batch_jobs.length).toEqual(3)
|
||||
expect(response.data).toMatchSnapshot({
|
||||
batch_jobs: [
|
||||
{
|
||||
id: "job_3",
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
created_by: "admin_user",
|
||||
},
|
||||
{
|
||||
id: "job_2",
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
created_by: "admin_user",
|
||||
},
|
||||
{
|
||||
id: "job_1",
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
created_by: "admin_user",
|
||||
},
|
||||
],
|
||||
})
|
||||
expect(response.data).toEqual(
|
||||
expect.objectContaining({
|
||||
batch_jobs: expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
id: "job_3",
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
created_by: "admin_user",
|
||||
}),
|
||||
expect.objectContaining({
|
||||
id: "job_2",
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
created_by: "admin_user",
|
||||
}),
|
||||
expect.objectContaining({
|
||||
id: "job_1",
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
created_by: "admin_user",
|
||||
}),
|
||||
]),
|
||||
})
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -207,13 +209,15 @@ describe("/admin/batch-jobs", () => {
|
||||
)
|
||||
|
||||
expect(response.status).toEqual(201)
|
||||
expect(response.data.batch_job).toMatchSnapshot({
|
||||
created_by: "admin_user",
|
||||
status: "created",
|
||||
id: expect.any(String),
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
})
|
||||
expect(response.data.batch_job).toEqual(
|
||||
expect.objectContaining({
|
||||
created_by: "admin_user",
|
||||
status: "created",
|
||||
id: expect.any(String),
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
})
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -272,12 +276,14 @@ describe("/admin/batch-jobs", () => {
|
||||
)
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data.batch_job).toMatchSnapshot({
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
canceled_at: expect.any(String),
|
||||
status: "canceled",
|
||||
})
|
||||
expect(response.data.batch_job).toEqual(
|
||||
expect.objectContaining({
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
canceled_at: expect.any(String),
|
||||
status: "canceled",
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
it("Fails to cancel a batch job created by a different user", async () => {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
const path = require("path")
|
||||
const fs = require("fs/promises")
|
||||
import { resolve, sep } from "path"
|
||||
import { simpleSalesChannelFactory } from "../../../factories"
|
||||
|
||||
const setupServer = require("../../../../helpers/setup-server")
|
||||
const { useApi } = require("../../../../helpers/use-api")
|
||||
@@ -49,6 +50,11 @@ describe("Batch job of product-export type", () => {
|
||||
await productSeeder(dbConnection)
|
||||
await adminSeeder(dbConnection)
|
||||
await userSeeder(dbConnection)
|
||||
|
||||
await simpleSalesChannelFactory(dbConnection, {
|
||||
id: "test-channel",
|
||||
is_default: true,
|
||||
})
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
|
||||
@@ -40,7 +40,7 @@ Object {
|
||||
"cart_id": null,
|
||||
"claim_order_id": StringMatching /\\^claim_\\*/,
|
||||
"created_at": Any<String>,
|
||||
"description": "Practical Granite Pizza",
|
||||
"description": "Refined Wooden Chair",
|
||||
"fulfilled_quantity": null,
|
||||
"has_shipping": null,
|
||||
"id": StringMatching /\\^item_\\*/,
|
||||
@@ -67,7 +67,7 @@ Object {
|
||||
},
|
||||
],
|
||||
"thumbnail": null,
|
||||
"title": "Awesome Metal Ball",
|
||||
"title": "Gorgeous Cotton Table",
|
||||
"unit_price": 100,
|
||||
"updated_at": Any<String>,
|
||||
"variant": Object {
|
||||
@@ -107,7 +107,7 @@ Object {
|
||||
"status": "draft",
|
||||
"subtitle": null,
|
||||
"thumbnail": null,
|
||||
"title": "Awesome Metal Ball",
|
||||
"title": "Gorgeous Cotton Table",
|
||||
"type_id": null,
|
||||
"updated_at": Any<String>,
|
||||
"weight": null,
|
||||
@@ -115,7 +115,7 @@ Object {
|
||||
},
|
||||
"product_id": "test-product",
|
||||
"sku": null,
|
||||
"title": "Practical Granite Pizza",
|
||||
"title": "Refined Wooden Chair",
|
||||
"upc": null,
|
||||
"updated_at": Any<String>,
|
||||
"weight": null,
|
||||
|
||||
@@ -185,7 +185,7 @@ Object {
|
||||
"metadata": null,
|
||||
"option_id": Any<String>,
|
||||
"updated_at": Any<String>,
|
||||
"value": "Handcrafted",
|
||||
"value": "Practical",
|
||||
"variant_id": Any<String>,
|
||||
},
|
||||
],
|
||||
|
||||
@@ -98,6 +98,7 @@ Object {
|
||||
"payment_authorized_at": null,
|
||||
"payment_id": null,
|
||||
"region_id": "test-region",
|
||||
"sales_channel_id": Any<String>,
|
||||
"shipping_address_id": "test-shipping-address",
|
||||
"type": "swap",
|
||||
"updated_at": Any<String>,
|
||||
@@ -131,6 +132,7 @@ Object {
|
||||
"object": "order",
|
||||
"payment_status": "captured",
|
||||
"region_id": "test-region",
|
||||
"sales_channel_id": null,
|
||||
"shipping_address_id": "test-shipping-address",
|
||||
"status": "pending",
|
||||
"tax_rate": 0,
|
||||
@@ -275,6 +277,7 @@ Object {
|
||||
"payment_authorized_at": null,
|
||||
"payment_id": null,
|
||||
"region_id": "test-region",
|
||||
"sales_channel_id": Any<String>,
|
||||
"shipping_address_id": "test-shipping-address",
|
||||
"type": "swap",
|
||||
"updated_at": Any<String>,
|
||||
@@ -308,6 +311,7 @@ Object {
|
||||
"object": "order",
|
||||
"payment_status": "captured",
|
||||
"region_id": "test-region",
|
||||
"sales_channel_id": null,
|
||||
"shipping_address_id": "test-shipping-address",
|
||||
"status": "pending",
|
||||
"tax_rate": 0,
|
||||
|
||||
@@ -22,6 +22,7 @@ const {
|
||||
simpleProductFactory,
|
||||
simpleShippingOptionFactory,
|
||||
simpleLineItemFactory,
|
||||
simpleSalesChannelFactory,
|
||||
} = require("../../../factories")
|
||||
const {
|
||||
simpleDiscountFactory,
|
||||
@@ -57,6 +58,9 @@ describe("/store/carts", () => {
|
||||
})
|
||||
|
||||
describe("POST /store/carts", () => {
|
||||
let prod1
|
||||
let prodSale
|
||||
|
||||
beforeEach(async () => {
|
||||
const manager = dbConnection.manager
|
||||
await manager.insert(Region, {
|
||||
@@ -70,6 +74,21 @@ describe("/store/carts", () => {
|
||||
SET region_id='region'
|
||||
WHERE iso_2 = 'us'`
|
||||
)
|
||||
|
||||
prod1 = await simpleProductFactory(dbConnection, {
|
||||
id: "test-product",
|
||||
variants: [{ id: "test-variant_1" }],
|
||||
})
|
||||
|
||||
prodSale = await simpleProductFactory(dbConnection, {
|
||||
id: "test-product-sale",
|
||||
variants: [
|
||||
{
|
||||
id: "test-variant-sale",
|
||||
prices: [{ amount: 1000, currency: "usd" }],
|
||||
},
|
||||
],
|
||||
})
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
@@ -108,8 +127,6 @@ describe("/store/carts", () => {
|
||||
})
|
||||
|
||||
it("creates a cart with items", async () => {
|
||||
await productSeeder(dbConnection)
|
||||
|
||||
const yesterday = ((today) =>
|
||||
new Date(today.setDate(today.getDate() - 1)))(new Date())
|
||||
const tomorrow = ((today) =>
|
||||
@@ -128,7 +145,7 @@ describe("/store/carts", () => {
|
||||
await dbConnection.manager.save(priceList1)
|
||||
|
||||
const ma_sale_1 = dbConnection.manager.create(MoneyAmount, {
|
||||
variant_id: "test-variant-sale",
|
||||
variant_id: prodSale.variants[0].id,
|
||||
currency_code: "usd",
|
||||
amount: 800,
|
||||
price_list_id: "pl_current",
|
||||
@@ -142,11 +159,11 @@ describe("/store/carts", () => {
|
||||
.post("/store/carts", {
|
||||
items: [
|
||||
{
|
||||
variant_id: "test-variant_1",
|
||||
variant_id: prod1.variants[0].id,
|
||||
quantity: 1,
|
||||
},
|
||||
{
|
||||
variant_id: "test-variant-sale",
|
||||
variant_id: prodSale.variants[0].id,
|
||||
quantity: 2,
|
||||
},
|
||||
],
|
||||
@@ -160,11 +177,11 @@ describe("/store/carts", () => {
|
||||
expect(response.data.cart.items).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
variant_id: "test-variant_1",
|
||||
variant_id: prod1.variants[0].id,
|
||||
quantity: 1,
|
||||
}),
|
||||
expect.objectContaining({
|
||||
variant_id: "test-variant-sale",
|
||||
variant_id: prodSale.variants[0].id,
|
||||
quantity: 2,
|
||||
unit_price: 800,
|
||||
}),
|
||||
@@ -931,6 +948,11 @@ describe("/store/carts", () => {
|
||||
beforeEach(async () => {
|
||||
await cartSeeder(dbConnection)
|
||||
await swapSeeder(dbConnection)
|
||||
|
||||
await simpleSalesChannelFactory(dbConnection, {
|
||||
id: "test-channel",
|
||||
is_default: true,
|
||||
})
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
@@ -2263,6 +2285,10 @@ describe("/store/carts", () => {
|
||||
describe("get-cart with session customer", () => {
|
||||
beforeEach(async () => {
|
||||
await cartSeeder(dbConnection)
|
||||
await simpleSalesChannelFactory(dbConnection, {
|
||||
id: "test-channel",
|
||||
is_default: true,
|
||||
})
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
|
||||
@@ -13,6 +13,7 @@ const {
|
||||
simpleProductFactory,
|
||||
simplePriceListFactory,
|
||||
simpleDiscountFactory,
|
||||
simpleSalesChannelFactory,
|
||||
} = require("../../../factories")
|
||||
const { IdMap } = require("medusa-test-utils")
|
||||
|
||||
@@ -155,9 +156,11 @@ describe("[MEDUSA_FF_TAX_INCLUSIVE_PRICING] /store/carts", () => {
|
||||
tax_rate: 20,
|
||||
name: "region test",
|
||||
}
|
||||
const buildProductData = (productId, variantId) => {
|
||||
|
||||
const buildProductData = (productId, variantId, salesChannelId) => {
|
||||
return {
|
||||
id: productId,
|
||||
sales_channels: [{ id: salesChannelId }],
|
||||
variants: [
|
||||
{
|
||||
id: variantId,
|
||||
@@ -203,10 +206,14 @@ describe("[MEDUSA_FF_TAX_INCLUSIVE_PRICING] /store/carts", () => {
|
||||
|
||||
describe("with a cart with full tax exclusive variant pricing", () => {
|
||||
beforeEach(async () => {
|
||||
const salesChannel = await simpleSalesChannelFactory(dbConnection, {
|
||||
id: "test-channel",
|
||||
is_default: true,
|
||||
})
|
||||
await simpleRegionFactory(dbConnection, regionData)
|
||||
await simpleProductFactory(
|
||||
dbConnection,
|
||||
buildProductData(productId1, variantId1)
|
||||
buildProductData(productId1, variantId1, salesChannel.id)
|
||||
)
|
||||
await simplePriceListFactory(
|
||||
dbConnection,
|
||||
@@ -214,7 +221,7 @@ describe("[MEDUSA_FF_TAX_INCLUSIVE_PRICING] /store/carts", () => {
|
||||
)
|
||||
await simpleProductFactory(
|
||||
dbConnection,
|
||||
buildProductData(productId2, variantId2)
|
||||
buildProductData(productId2, variantId2, salesChannel.id)
|
||||
)
|
||||
await simplePriceListFactory(
|
||||
dbConnection,
|
||||
@@ -280,10 +287,15 @@ describe("[MEDUSA_FF_TAX_INCLUSIVE_PRICING] /store/carts", () => {
|
||||
}
|
||||
|
||||
beforeEach(async () => {
|
||||
const salesChannel = await simpleSalesChannelFactory(dbConnection, {
|
||||
id: "test-channel",
|
||||
is_default: true,
|
||||
})
|
||||
|
||||
await simpleRegionFactory(dbConnection, regionData)
|
||||
await simpleProductFactory(
|
||||
dbConnection,
|
||||
buildProductData(productId1, variantId1)
|
||||
buildProductData(productId1, variantId1, salesChannel.id)
|
||||
)
|
||||
await simplePriceListFactory(
|
||||
dbConnection,
|
||||
@@ -291,7 +303,7 @@ describe("[MEDUSA_FF_TAX_INCLUSIVE_PRICING] /store/carts", () => {
|
||||
)
|
||||
await simpleProductFactory(
|
||||
dbConnection,
|
||||
buildProductData(productId2, variantId2)
|
||||
buildProductData(productId2, variantId2, salesChannel.id)
|
||||
)
|
||||
await simplePriceListFactory(
|
||||
dbConnection,
|
||||
@@ -357,10 +369,15 @@ describe("[MEDUSA_FF_TAX_INCLUSIVE_PRICING] /store/carts", () => {
|
||||
}
|
||||
|
||||
beforeEach(async () => {
|
||||
const salesChannel = await simpleSalesChannelFactory(dbConnection, {
|
||||
id: "test-channel",
|
||||
is_default: true,
|
||||
})
|
||||
|
||||
await simpleRegionFactory(dbConnection, regionData)
|
||||
await simpleProductFactory(
|
||||
dbConnection,
|
||||
buildProductData(productId1, variantId1)
|
||||
buildProductData(productId1, variantId1, salesChannel.id)
|
||||
)
|
||||
await simplePriceListFactory(
|
||||
dbConnection,
|
||||
@@ -368,7 +385,7 @@ describe("[MEDUSA_FF_TAX_INCLUSIVE_PRICING] /store/carts", () => {
|
||||
)
|
||||
await simpleProductFactory(
|
||||
dbConnection,
|
||||
buildProductData(productId2, variantId2)
|
||||
buildProductData(productId2, variantId2, salesChannel.id)
|
||||
)
|
||||
await simplePriceListFactory(
|
||||
dbConnection,
|
||||
|
||||
@@ -24,7 +24,7 @@ describe("Gift Card - Tax calculations", () => {
|
||||
const cwd = path.resolve(path.join(__dirname, "..", "..", "..", ".."))
|
||||
const [process, connection] = await startServerWithEnvironment({
|
||||
cwd,
|
||||
env: {}
|
||||
env: {},
|
||||
})
|
||||
dbConnection = connection
|
||||
medusaProcess = process
|
||||
@@ -51,7 +51,9 @@ describe("Gift Card - Tax calculations", () => {
|
||||
name: "region test",
|
||||
})
|
||||
|
||||
customer = await simpleCustomerFactory(dbConnection, { password: 'medusatest' })
|
||||
customer = await simpleCustomerFactory(dbConnection, {
|
||||
password: "medusatest",
|
||||
})
|
||||
|
||||
customerData = {
|
||||
email: customer.email,
|
||||
@@ -64,19 +66,25 @@ describe("Gift Card - Tax calculations", () => {
|
||||
is_giftcard: true,
|
||||
discountable: false,
|
||||
options: [{ id: "denom", title: "Denomination" }],
|
||||
variants: [{
|
||||
title: "Gift Card",
|
||||
prices: [{ currency: "usd", amount: 30000, region_id: region.id }],
|
||||
options: [{ option_id: "denom", value: "Denomination" }],
|
||||
}]
|
||||
variants: [
|
||||
{
|
||||
title: "Gift Card",
|
||||
prices: [{ currency: "usd", amount: 30000, region_id: region.id }],
|
||||
options: [{ option_id: "denom", value: "Denomination" }],
|
||||
},
|
||||
],
|
||||
})
|
||||
})
|
||||
|
||||
it("adding a gift card purchase to cart treats it like buying a product", async () => {
|
||||
const api = useApi()
|
||||
const customerResponse = await api.post("/store/customers", customerData, {
|
||||
withCredentials: true,
|
||||
})
|
||||
const customerResponse = await api.post(
|
||||
"/store/customers",
|
||||
customerData,
|
||||
{
|
||||
withCredentials: true,
|
||||
}
|
||||
)
|
||||
|
||||
const createCartResponse = await api.post("/store/carts", {
|
||||
region_id: region.id,
|
||||
@@ -110,8 +118,8 @@ describe("Gift Card - Tax calculations", () => {
|
||||
id: product.variants[0].id,
|
||||
product: expect.objectContaining({
|
||||
is_giftcard: true,
|
||||
})
|
||||
})
|
||||
}),
|
||||
}),
|
||||
}),
|
||||
])
|
||||
)
|
||||
@@ -119,11 +127,18 @@ describe("Gift Card - Tax calculations", () => {
|
||||
|
||||
it("purchasing a gift card via an order creates a gift card entity", async () => {
|
||||
const api = useApi()
|
||||
const customerResponse = await api.post("/store/customers", customerData, {
|
||||
withCredentials: true,
|
||||
})
|
||||
const customerResponse = await api.post(
|
||||
"/store/customers",
|
||||
customerData,
|
||||
{
|
||||
withCredentials: true,
|
||||
}
|
||||
)
|
||||
|
||||
const cartFactory = await simpleCartFactory(dbConnection, { customer, region })
|
||||
const cartFactory = await simpleCartFactory(dbConnection, {
|
||||
customer,
|
||||
region,
|
||||
})
|
||||
|
||||
const response = await api.post(
|
||||
`/store/carts/${cartFactory.id}/line-items`,
|
||||
@@ -140,9 +155,11 @@ describe("Gift Card - Tax calculations", () => {
|
||||
|
||||
await api.post(`/store/carts/${cart.id}/payment-sessions`)
|
||||
|
||||
const createdOrderResponse = await api.post(`/store/carts/${cart.id}/complete-cart`)
|
||||
const createdOrderResponse = await api.post(
|
||||
`/store/carts/${cart.id}/complete-cart`
|
||||
)
|
||||
const createdGiftCards = await dbConnection.manager.find(GiftCard, {
|
||||
where: { order_id: createdOrderResponse.data.data.id }
|
||||
where: { order_id: createdOrderResponse.data.data.id },
|
||||
})
|
||||
const createdGiftCard = createdGiftCards[0]
|
||||
|
||||
@@ -163,14 +180,18 @@ describe("Gift Card - Tax calculations", () => {
|
||||
tax_rate: region.tax_rate,
|
||||
})
|
||||
const expensiveProduct = await simpleProductFactory(dbConnection, {
|
||||
variants: [{
|
||||
title: "Product cost higher than gift card balance",
|
||||
prices: [{
|
||||
amount: 50000,
|
||||
currency: "usd",
|
||||
region_id: region.id,
|
||||
}],
|
||||
}]
|
||||
variants: [
|
||||
{
|
||||
title: "Product cost higher than gift card balance",
|
||||
prices: [
|
||||
{
|
||||
amount: 50000,
|
||||
currency: "usd",
|
||||
region_id: region.id,
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
})
|
||||
|
||||
const customerRes = await api.post("/store/customers", customerData, {
|
||||
@@ -200,7 +221,9 @@ describe("Gift Card - Tax calculations", () => {
|
||||
const getCartResponse = await api.get(`/store/carts/${cartFactory.id}`)
|
||||
const cart = getCartResponse.data.cart
|
||||
await api.post(`/store/carts/${cart.id}/payment-sessions`)
|
||||
const createdOrder = await api.post(`/store/carts/${cart.id}/complete-cart`)
|
||||
const createdOrder = await api.post(
|
||||
`/store/carts/${cart.id}/complete-cart`
|
||||
)
|
||||
|
||||
expect(createdOrder.data.data).toEqual(
|
||||
expect.objectContaining({
|
||||
@@ -228,12 +251,12 @@ describe("Gift Card - Tax calculations", () => {
|
||||
refundable: 59500,
|
||||
tax_lines: expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
rate: 19
|
||||
})
|
||||
rate: 19,
|
||||
}),
|
||||
]),
|
||||
})
|
||||
}),
|
||||
]),
|
||||
}),
|
||||
})
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -114,6 +114,7 @@ describe("/store/carts", () => {
|
||||
cart_id: expect.stringMatching(/^cart_*/),
|
||||
cart: {
|
||||
id: expect.stringMatching(/^cart_*/),
|
||||
sales_channel_id: expect.any(String),
|
||||
billing_address_id: "test-billing-address",
|
||||
type: "swap",
|
||||
created_at: expect.any(String),
|
||||
@@ -201,6 +202,7 @@ describe("/store/carts", () => {
|
||||
cart_id: expect.stringMatching(/^cart_*/),
|
||||
cart: {
|
||||
id: expect.stringMatching(/^cart_*/),
|
||||
sales_channel_id: expect.any(String),
|
||||
billing_address_id: "test-billing-address",
|
||||
shipping_address_id: "test-shipping-address",
|
||||
type: "swap",
|
||||
|
||||
Reference in New Issue
Block a user