From 33087663890a7c17b98667be0fbabe215def13dd Mon Sep 17 00:00:00 2001 From: Oliver Windall Juhl <59018053+olivermrbl@users.noreply.github.com> Date: Tue, 10 Jan 2023 17:45:23 +0100 Subject: [PATCH] chore(feature-flags): Sales Channels enabled by default (#2966) --- .changeset/young-parents-pump.md | 4 + .../admin/__snapshots__/discount.js.snap | 2 +- .../admin/__snapshots__/product.js.snap | 3 + .../__snapshots__/sales-channels.js.snap | 28 ---- .../admin/__snapshots__/store.js.snap | 142 ------------------ .../api/__tests__/admin/colllections.js | 5 +- .../api/__tests__/admin/sales-channels.js | 55 ++++--- .../api/__tests__/admin/store.js | 133 ++++++++-------- .../batch-jobs/__snapshots__/api.js.snap | 125 --------------- .../api/__tests__/batch-jobs/api.js | 76 +++++----- .../__tests__/batch-jobs/product/export.js | 6 + .../claims/__snapshots__/index.js.snap | 8 +- .../__snapshots__/product-variants.js.snap | 2 +- .../store/__snapshots__/swaps.js.snap | 4 + .../api/__tests__/store/cart/cart.js | 40 ++++- .../store/cart/ff-tax-inclusive-pricing.js | 31 +++- .../store/cart/gift-cards/tax-calculation.js | 85 +++++++---- .../api/__tests__/store/swaps.js | 2 + .../api/factories/simple-product-factory.ts | 18 ++- integration-tests/api/helpers/admin-seeder.js | 1 + .../api/helpers/draft-order-seeder.js | 14 ++ integration-tests/api/helpers/order-seeder.js | 10 ++ .../api/helpers/product-seeder.js | 1 + .../__snapshots__/index.js.snap | 8 + .../__tests__/medusa-plugin-sendgrid/index.js | 4 +- .../plugins/factories/simple-store-factory.ts | 15 +- .../admin/orders/__tests__/get-order.js | 2 +- .../src/api/routes/admin/orders/index.ts | 12 +- .../admin/products/__tests__/get-product.js | 1 + .../routes/admin/store/__tests__/get-store.js | 5 +- .../loaders/feature-flags/sales-channels.ts | 2 +- .../medusa/src/services/__mocks__/order.js | 4 + packages/medusa/src/services/event-bus.ts | 2 - .../strategies/batch-jobs/product/import.ts | 20 +-- 34 files changed, 372 insertions(+), 498 deletions(-) create mode 100644 .changeset/young-parents-pump.md diff --git a/.changeset/young-parents-pump.md b/.changeset/young-parents-pump.md new file mode 100644 index 0000000000..8a5615707c --- /dev/null +++ b/.changeset/young-parents-pump.md @@ -0,0 +1,4 @@ +--- +--- + +chore(feature-flags): Sales Channels enabled by default diff --git a/integration-tests/api/__tests__/admin/__snapshots__/discount.js.snap b/integration-tests/api/__tests__/admin/__snapshots__/discount.js.snap index 2395a494df..054c0213c9 100644 --- a/integration-tests/api/__tests__/admin/__snapshots__/discount.js.snap +++ b/integration-tests/api/__tests__/admin/__snapshots__/discount.js.snap @@ -47,7 +47,7 @@ Object { "status": "draft", "subtitle": null, "thumbnail": null, - "title": "Practical Frozen Fish", + "title": "Handmade Frozen Chair", "type_id": Any, "updated_at": Any, "weight": null, diff --git a/integration-tests/api/__tests__/admin/__snapshots__/product.js.snap b/integration-tests/api/__tests__/admin/__snapshots__/product.js.snap index 44b21dd816..2eeafb5cde 100644 --- a/integration-tests/api/__tests__/admin/__snapshots__/product.js.snap +++ b/integration-tests/api/__tests__/admin/__snapshots__/product.js.snap @@ -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 [ diff --git a/integration-tests/api/__tests__/admin/__snapshots__/sales-channels.js.snap b/integration-tests/api/__tests__/admin/__snapshots__/sales-channels.js.snap index 415a89a331..14680a74e9 100644 --- a/integration-tests/api/__tests__/admin/__snapshots__/sales-channels.js.snap +++ b/integration-tests/api/__tests__/admin/__snapshots__/sales-channels.js.snap @@ -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, - "deleted_at": null, - "description": "test description", - "id": Any, - "is_disabled": false, - "name": "test name", - "updated_at": Any, - }, - Object { - "created_at": Any, - "deleted_at": null, - "description": "test description 2", - "id": Any, - "is_disabled": false, - "name": "test name 2", - "updated_at": Any, - }, - ], -} -`; - exports[`sales channels GET /admin/sales-channels should list the sales channel using free text search 1`] = ` Object { "count": 1, diff --git a/integration-tests/api/__tests__/admin/__snapshots__/store.js.snap b/integration-tests/api/__tests__/admin/__snapshots__/store.js.snap index 4e595002ff..0162ad57ef 100644 --- a/integration-tests/api/__tests__/admin/__snapshots__/store.js.snap +++ b/integration-tests/api/__tests__/admin/__snapshots__/store.js.snap @@ -6,145 +6,3 @@ Object { "type": "invalid_data", } `; - -exports[`/admin/store POST /admin/store successfully updates and store currencies 1`] = ` -Object { - "created_at": Any, - "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, - "invite_link_template": null, - "metadata": null, - "name": "Medusa Store", - "payment_link_template": null, - "swap_link_template": null, - "updated_at": Any, -} -`; - -exports[`/admin/store POST /admin/store successfully updates default currency and store currencies 1`] = ` -Object { - "created_at": Any, - "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, - "invite_link_template": null, - "metadata": null, - "name": "Medusa Store", - "payment_link_template": null, - "swap_link_template": null, - "updated_at": Any, -} -`; - -exports[`/admin/store POST /admin/store successfully updates default currency code 1`] = ` -Object { - "created_at": Any, - "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, - "invite_link_template": null, - "metadata": null, - "name": "Medusa Store", - "payment_link_template": null, - "swap_link_template": null, - "updated_at": Any, -} -`; - -exports[`/admin/store Store creation has created store with default currency 1`] = ` -Object { - "created_at": Any, - "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, - "fulfillment_providers": Array [ - Object { - "id": "test-ful", - "is_installed": true, - }, - ], - "id": Any, - "invite_link_template": null, - "metadata": null, - "modules": Any, - "name": "Medusa Store", - "payment_link_template": null, - "payment_providers": Array [ - Object { - "id": "test-pay", - "is_installed": true, - }, - ], - "swap_link_template": null, - "updated_at": Any, -} -`; diff --git a/integration-tests/api/__tests__/admin/colllections.js b/integration-tests/api/__tests__/admin/colllections.js index 149c6a0cd9..5244ecbe99 100644 --- a/integration-tests/api/__tests__/admin/colllections.js +++ b/integration-tests/api/__tests__/admin/colllections.js @@ -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) diff --git a/integration-tests/api/__tests__/admin/sales-channels.js b/integration-tests/api/__tests__/admin/sales-channels.js index e1d864fd22..6afa433219 100644 --- a/integration-tests/api/__tests__/admin/sales-channels.js +++ b/integration-tests/api/__tests__/admin/sales-channels.js @@ -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, + }), ]) ) }) diff --git a/integration-tests/api/__tests__/admin/store.js b/integration-tests/api/__tests__/admin/store.js index 3b346f127f..5f5e78d2d5 100644 --- a/integration-tests/api/__tests__/admin/store.js +++ b/integration-tests/api/__tests__/admin/store.js @@ -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), + }) + ) }) }) }) diff --git a/integration-tests/api/__tests__/batch-jobs/__snapshots__/api.js.snap b/integration-tests/api/__tests__/batch-jobs/__snapshots__/api.js.snap index 78911629c3..cbbfedf02c 100644 --- a/integration-tests/api/__tests__/batch-jobs/__snapshots__/api.js.snap +++ b/integration-tests/api/__tests__/batch-jobs/__snapshots__/api.js.snap @@ -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, - "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, - }, - Object { - "canceled_at": null, - "completed_at": null, - "confirmed_at": null, - "context": Object {}, - "created_at": Any, - "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, - }, - Object { - "canceled_at": null, - "completed_at": null, - "confirmed_at": null, - "context": Object {}, - "created_at": Any, - "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, - }, - ], - "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, - "created_by": "admin_user", - "deleted_at": null, - "dry_run": false, - "failed_at": null, - "id": Any, - "pre_processed_at": null, - "processing_at": null, - "result": null, - "status": "created", - "type": "product-export", - "updated_at": Any, -} -`; - -exports[`/admin/batch-jobs POST /admin/batch-jobs/:id/cancel Cancels batch job created by the user 1`] = ` -Object { - "canceled_at": Any, - "completed_at": null, - "confirmed_at": null, - "context": Object {}, - "created_at": Any, - "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, -} -`; diff --git a/integration-tests/api/__tests__/batch-jobs/api.js b/integration-tests/api/__tests__/batch-jobs/api.js index d9c247d686..a8eca5dc16 100644 --- a/integration-tests/api/__tests__/batch-jobs/api.js +++ b/integration-tests/api/__tests__/batch-jobs/api.js @@ -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 () => { diff --git a/integration-tests/api/__tests__/batch-jobs/product/export.js b/integration-tests/api/__tests__/batch-jobs/product/export.js index 87cf4bb776..e4bf6d34a1 100644 --- a/integration-tests/api/__tests__/batch-jobs/product/export.js +++ b/integration-tests/api/__tests__/batch-jobs/product/export.js @@ -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 () => { diff --git a/integration-tests/api/__tests__/claims/__snapshots__/index.js.snap b/integration-tests/api/__tests__/claims/__snapshots__/index.js.snap index 7860a7b7f5..523a20bda9 100644 --- a/integration-tests/api/__tests__/claims/__snapshots__/index.js.snap +++ b/integration-tests/api/__tests__/claims/__snapshots__/index.js.snap @@ -40,7 +40,7 @@ Object { "cart_id": null, "claim_order_id": StringMatching /\\^claim_\\*/, "created_at": Any, - "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, "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, "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, "weight": null, diff --git a/integration-tests/api/__tests__/store/__snapshots__/product-variants.js.snap b/integration-tests/api/__tests__/store/__snapshots__/product-variants.js.snap index 7086baa4dc..c1555f4c49 100644 --- a/integration-tests/api/__tests__/store/__snapshots__/product-variants.js.snap +++ b/integration-tests/api/__tests__/store/__snapshots__/product-variants.js.snap @@ -185,7 +185,7 @@ Object { "metadata": null, "option_id": Any, "updated_at": Any, - "value": "Handcrafted", + "value": "Practical", "variant_id": Any, }, ], diff --git a/integration-tests/api/__tests__/store/__snapshots__/swaps.js.snap b/integration-tests/api/__tests__/store/__snapshots__/swaps.js.snap index 6e256c0499..91d39bbcb0 100644 --- a/integration-tests/api/__tests__/store/__snapshots__/swaps.js.snap +++ b/integration-tests/api/__tests__/store/__snapshots__/swaps.js.snap @@ -98,6 +98,7 @@ Object { "payment_authorized_at": null, "payment_id": null, "region_id": "test-region", + "sales_channel_id": Any, "shipping_address_id": "test-shipping-address", "type": "swap", "updated_at": Any, @@ -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, "shipping_address_id": "test-shipping-address", "type": "swap", "updated_at": Any, @@ -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, diff --git a/integration-tests/api/__tests__/store/cart/cart.js b/integration-tests/api/__tests__/store/cart/cart.js index 9a6ac4f8c1..2d8e3be2f0 100644 --- a/integration-tests/api/__tests__/store/cart/cart.js +++ b/integration-tests/api/__tests__/store/cart/cart.js @@ -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 () => { diff --git a/integration-tests/api/__tests__/store/cart/ff-tax-inclusive-pricing.js b/integration-tests/api/__tests__/store/cart/ff-tax-inclusive-pricing.js index 9a8432a6c8..d53ed406ce 100644 --- a/integration-tests/api/__tests__/store/cart/ff-tax-inclusive-pricing.js +++ b/integration-tests/api/__tests__/store/cart/ff-tax-inclusive-pricing.js @@ -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, diff --git a/integration-tests/api/__tests__/store/cart/gift-cards/tax-calculation.js b/integration-tests/api/__tests__/store/cart/gift-cards/tax-calculation.js index 427cfd2d2b..cee5e8a0bb 100644 --- a/integration-tests/api/__tests__/store/cart/gift-cards/tax-calculation.js +++ b/integration-tests/api/__tests__/store/cart/gift-cards/tax-calculation.js @@ -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, + }), ]), - }) + }), ]), - }), + }) ) }) }) diff --git a/integration-tests/api/__tests__/store/swaps.js b/integration-tests/api/__tests__/store/swaps.js index 89b8a5d011..c8fd08ca78 100644 --- a/integration-tests/api/__tests__/store/swaps.js +++ b/integration-tests/api/__tests__/store/swaps.js @@ -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", diff --git a/integration-tests/api/factories/simple-product-factory.ts b/integration-tests/api/factories/simple-product-factory.ts index b972a94f95..39c6c1695b 100644 --- a/integration-tests/api/factories/simple-product-factory.ts +++ b/integration-tests/api/factories/simple-product-factory.ts @@ -4,7 +4,8 @@ import { ProductTag, ProductType, ShippingProfile, - ShippingProfileType + ShippingProfileType, + Store } from "@medusajs/medusa" import faker from "faker" import { Connection } from "typeorm" @@ -56,6 +57,21 @@ export const simpleProductFactory = async ( await simpleSalesChannelFactory(connection, salesChannel) ) ) + } else { + const store = await manager.findOne(Store, { + relations: ["default_sales_channel"], + }) + + if (store?.default_sales_channel) { + sales_channels = [store.default_sales_channel] + } else { + const salesChannel = await simpleSalesChannelFactory(connection, { + id: `default-${Math.random() * 1000}`, + is_default: true, + }) + + sales_channels = [salesChannel] + } } const prodId = data.id || `simple-product-${Math.random() * 1000}` diff --git a/integration-tests/api/helpers/admin-seeder.js b/integration-tests/api/helpers/admin-seeder.js index 660bad0470..1397533a88 100644 --- a/integration-tests/api/helpers/admin-seeder.js +++ b/integration-tests/api/helpers/admin-seeder.js @@ -1,5 +1,6 @@ const Scrypt = require("scrypt-kdf") const { User } = require("@medusajs/medusa") +const { simpleSalesChannelFactory } = require("../factories") module.exports = async (connection, data = {}) => { const manager = connection.manager diff --git a/integration-tests/api/helpers/draft-order-seeder.js b/integration-tests/api/helpers/draft-order-seeder.js index 4f4c9dcc1e..83c9a45647 100644 --- a/integration-tests/api/helpers/draft-order-seeder.js +++ b/integration-tests/api/helpers/draft-order-seeder.js @@ -15,6 +15,7 @@ const { DiscountRule, Payment, } = require("@medusajs/medusa") +const { simpleSalesChannelFactory } = require("../factories") module.exports = async (connection, data = {}) => { const manager = connection.manager @@ -23,6 +24,11 @@ module.exports = async (connection, data = {}) => { type: "default", }) + const salesChannel = await simpleSalesChannelFactory(connection, { + id: "sales-channel", + is_default: true, + }) + await manager.insert(Product, { id: "test-product", title: "test product", @@ -30,6 +36,10 @@ module.exports = async (connection, data = {}) => { options: [{ id: "test-option", title: "Size" }], }) + await manager.query( + `insert into product_sales_channel values ('test-product', '${salesChannel.id}');` + ) + await manager.insert(Address, { id: "oli-shipping", first_name: "oli", @@ -44,6 +54,10 @@ module.exports = async (connection, data = {}) => { options: [{ id: "test-option-color", title: "Color" }], }) + await manager.query( + `insert into product_sales_channel values ('test-product-2', '${salesChannel.id}');` + ) + await manager.insert(ProductVariant, { id: "test-variant", title: "test variant", diff --git a/integration-tests/api/helpers/order-seeder.js b/integration-tests/api/helpers/order-seeder.js index d46bf341d7..f3e5d5d9b5 100644 --- a/integration-tests/api/helpers/order-seeder.js +++ b/integration-tests/api/helpers/order-seeder.js @@ -14,6 +14,7 @@ const { ShippingProfile, Swap, } = require("@medusajs/medusa") +const { simpleSalesChannelFactory } = require("../factories") module.exports = async (connection, data = {}) => { const manager = connection.manager @@ -22,6 +23,11 @@ module.exports = async (connection, data = {}) => { type: "default", }) + const salesChannel = await simpleSalesChannelFactory(connection, { + id: "test-channel", + is_default: true, + }) + await manager.insert(Product, { id: "test-product", title: "test product", @@ -29,6 +35,10 @@ module.exports = async (connection, data = {}) => { options: [{ id: "test-option", title: "Size" }], }) + await manager.query( + `insert into product_sales_channel values ('test-product', '${salesChannel.id}');` + ) + await manager.insert(ProductVariant, { id: "test-variant", title: "test variant", diff --git a/integration-tests/api/helpers/product-seeder.js b/integration-tests/api/helpers/product-seeder.js index d66a0c862b..4e48a48c1b 100644 --- a/integration-tests/api/helpers/product-seeder.js +++ b/integration-tests/api/helpers/product-seeder.js @@ -8,6 +8,7 @@ const { ShippingProfile, ProductVariant, Image, + Store, } = require("@medusajs/medusa") module.exports = async (connection, data = {}) => { diff --git a/integration-tests/plugins/__tests__/medusa-plugin-sendgrid/__snapshots__/index.js.snap b/integration-tests/plugins/__tests__/medusa-plugin-sendgrid/__snapshots__/index.js.snap index c3ee82a6ed..7fba9b66fc 100644 --- a/integration-tests/plugins/__tests__/medusa-plugin-sendgrid/__snapshots__/index.js.snap +++ b/integration-tests/plugins/__tests__/medusa-plugin-sendgrid/__snapshots__/index.js.snap @@ -107,6 +107,7 @@ Object { "object": "order", "payment_status": "captured", "region_id": "test-region", + "sales_channel_id": null, "shipping_address": Object { "address_1": "84185 Lindsey Centers", "address_2": null, @@ -260,6 +261,7 @@ Object { "object": "order", "payment_status": "captured", "region_id": "test-region", + "sales_channel_id": null, "shipping_address": Object { "address_1": "84185 Lindsey Centers", "address_2": null, @@ -579,6 +581,7 @@ Object { "updated_at": Any, }, ], + "sales_channel_id": null, "shipping_address": Object { "address_1": "84185 Lindsey Centers", "address_2": null, @@ -897,6 +900,7 @@ Object { }, "region_id": "test-region", "returns": Array [], + "sales_channel_id": null, "shipping_address": Object { "address_1": "84185 Lindsey Centers", "address_2": null, @@ -1149,6 +1153,7 @@ Object { }, "region_id": "test-region", "returns": Array [], + "sales_channel_id": null, "shipping_address": Object { "address_1": "84185 Lindsey Centers", "address_2": null, @@ -1400,6 +1405,7 @@ Object { }, "region_id": "test-region", "returns": Array [], + "sales_channel_id": null, "shipping_address": Object { "address_1": "84185 Lindsey Centers", "address_2": null, @@ -1754,6 +1760,7 @@ Object { "updated_at": Any, }, ], + "sales_channel_id": null, "shipping_address": Object { "address_1": "84185 Lindsey Centers", "address_2": null, @@ -2168,6 +2175,7 @@ Object { "updated_at": Any, }, "region_id": "test-region", + "sales_channel_id": null, "shipping_address_id": Any, "status": "pending", "swaps": Array [ diff --git a/integration-tests/plugins/__tests__/medusa-plugin-sendgrid/index.js b/integration-tests/plugins/__tests__/medusa-plugin-sendgrid/index.js index 50f13fdf1d..36d8398d8a 100644 --- a/integration-tests/plugins/__tests__/medusa-plugin-sendgrid/index.js +++ b/integration-tests/plugins/__tests__/medusa-plugin-sendgrid/index.js @@ -41,7 +41,6 @@ describe("medusa-plugin-sendgrid", () => { const db = useDb() await db.shutdown() express.close() - // medusaProcess.kill() }) afterEach(async () => { @@ -72,6 +71,7 @@ describe("medusa-plugin-sendgrid", () => { date: expect.any(String), id: expect.any(String), display_id: expect.any(Number), + sales_channel_id: null, created_at: expect.any(Date), canceled_at: expect.any(Date), updated_at: expect.any(Date), @@ -678,6 +678,7 @@ describe("medusa-plugin-sendgrid", () => { items: [{ order_id: expect.any(String), ...itemSnap }], customer_id: expect.any(String), shipping_address_id: expect.any(String), + sales_channel_id: null, swaps: [swapSnap], region: { id: expect.any(String), @@ -725,6 +726,7 @@ describe("medusa-plugin-sendgrid", () => { }) test("swap created data", async () => { + await simpleStoreFactory(dbConnection) await adminSeeder(dbConnection) const order = await createReturnableOrder(dbConnection) diff --git a/integration-tests/plugins/factories/simple-store-factory.ts b/integration-tests/plugins/factories/simple-store-factory.ts index f6dc2af393..67b7a29c80 100644 --- a/integration-tests/plugins/factories/simple-store-factory.ts +++ b/integration-tests/plugins/factories/simple-store-factory.ts @@ -1,6 +1,6 @@ -import { Connection } from "typeorm" +import { SalesChannel, Store } from "@medusajs/medusa" import faker from "faker" -import { Store } from "@medusajs/medusa" +import { Connection } from "typeorm" export type StoreFactoryData = { swap_link_template?: string @@ -20,5 +20,14 @@ export const simpleStoreFactory = async ( store.swap_link_template = data.swap_link_template ?? "something/{cart_id}" - return await manager.save(store) + await manager.insert(SalesChannel, { + id: "test-channel", + name: "Default" + }) + + const storeToSave = await manager.save(store) + + await manager.query(`update store set default_sales_channel_id = 'test-channel' where id = '${storeToSave!.id}'`) + + return storeToSave! } diff --git a/packages/medusa/src/api/routes/admin/orders/__tests__/get-order.js b/packages/medusa/src/api/routes/admin/orders/__tests__/get-order.js index 9bf02e2413..996cd1684d 100644 --- a/packages/medusa/src/api/routes/admin/orders/__tests__/get-order.js +++ b/packages/medusa/src/api/routes/admin/orders/__tests__/get-order.js @@ -43,7 +43,7 @@ describe("GET /admin/orders", () => { "gift_card_tax_total", ].includes(field) }), - relations: defaultAdminOrdersRelations, + relations: [...defaultAdminOrdersRelations], } ) }) diff --git a/packages/medusa/src/api/routes/admin/orders/index.ts b/packages/medusa/src/api/routes/admin/orders/index.ts index 5b75852b78..aa361f1e8b 100644 --- a/packages/medusa/src/api/routes/admin/orders/index.ts +++ b/packages/medusa/src/api/routes/admin/orders/index.ts @@ -4,12 +4,11 @@ import { Order } from "../../../.." import { DeleteResponse, FindParams, - PaginatedResponse, + PaginatedResponse } from "../../../../types/common" +import { FlagRouter } from "../../../../utils/flag-router" import middlewares, { transformQuery } from "../../../middlewares" import { AdminGetOrdersParams } from "./list-orders" -import { FlagRouter } from "../../../../utils/flag-router" -import SalesChannelFeatureFlag from "../../../../loaders/feature-flags/sales-channels" const route = Router() @@ -17,9 +16,6 @@ export default (app, featureFlagRouter: FlagRouter) => { app.use("/orders", route) const relations = [...defaultAdminOrdersRelations] - if (featureFlagRouter.isFeatureEnabled(SalesChannelFeatureFlag.key)) { - relations.push("sales_channel") - } /** * List orders @@ -286,6 +282,7 @@ export const defaultAdminOrdersRelations = [ "swaps.additional_items", "swaps.fulfillments", "swaps.fulfillments.tracking_links", + "sales_channel", ] export const defaultAdminOrdersFields = [ @@ -297,6 +294,7 @@ export const defaultAdminOrdersFields = [ "cart_id", "draft_order_id", "customer_id", + "sales_channel_id", "email", "region_id", "currency_code", @@ -330,6 +328,7 @@ export const filterableAdminOrdersFields = [ "customer_id", "email", "region_id", + "sales_channel_id", "currency_code", "tax_rate", "canceled_at", @@ -362,3 +361,4 @@ export * from "./refund-payment" export * from "./request-return" export * from "./update-claim" export * from "./update-order" + diff --git a/packages/medusa/src/api/routes/admin/products/__tests__/get-product.js b/packages/medusa/src/api/routes/admin/products/__tests__/get-product.js index 36e8ab7292..87a54663cc 100644 --- a/packages/medusa/src/api/routes/admin/products/__tests__/get-product.js +++ b/packages/medusa/src/api/routes/admin/products/__tests__/get-product.js @@ -65,6 +65,7 @@ describe("GET /admin/products/:id", () => { "tags", "type", "collection", + "sales_channels", ], } ) diff --git a/packages/medusa/src/api/routes/admin/store/__tests__/get-store.js b/packages/medusa/src/api/routes/admin/store/__tests__/get-store.js index cfa1257d42..a456a243c7 100644 --- a/packages/medusa/src/api/routes/admin/store/__tests__/get-store.js +++ b/packages/medusa/src/api/routes/admin/store/__tests__/get-store.js @@ -23,10 +23,7 @@ describe("GET /admin/store", () => { it("calls service retrieve", () => { expect(StoreServiceMock.retrieve).toHaveBeenCalledTimes(1) expect(StoreServiceMock.retrieve).toHaveBeenCalledWith({ - relations: [ - "currencies", - "default_currency", - ] + relations: ["currencies", "default_currency", "default_sales_channel"], }) }) }) diff --git a/packages/medusa/src/loaders/feature-flags/sales-channels.ts b/packages/medusa/src/loaders/feature-flags/sales-channels.ts index 908a693c60..99f6a9c10a 100644 --- a/packages/medusa/src/loaders/feature-flags/sales-channels.ts +++ b/packages/medusa/src/loaders/feature-flags/sales-channels.ts @@ -2,7 +2,7 @@ import { FlagSettings } from "../../types/feature-flags" const SalesChannelFeatureFlag: FlagSettings = { key: "sales_channels", - default_val: false, + default_val: true, env_key: "MEDUSA_FF_SALES_CHANNELS", description: "[WIP] Enable the sales channels feature", } diff --git a/packages/medusa/src/services/__mocks__/order.js b/packages/medusa/src/services/__mocks__/order.js index ed9118b818..8c3980ecaf 100644 --- a/packages/medusa/src/services/__mocks__/order.js +++ b/packages/medusa/src/services/__mocks__/order.js @@ -4,6 +4,10 @@ export const orders = { testOrder: { id: IdMap.getId("test-order"), email: "virgil@vandijk.dk", + sales_channel_id: "test-channel", + sales_channel: { + id: "test-channel", + }, billing_address: { first_name: "Virgil", last_name: "Van Dijk", diff --git a/packages/medusa/src/services/event-bus.ts b/packages/medusa/src/services/event-bus.ts index 912490aabd..8ee60ce875 100644 --- a/packages/medusa/src/services/event-bus.ts +++ b/packages/medusa/src/services/event-bus.ts @@ -174,8 +174,6 @@ export default class EventBusService { (sub) => sub.id === subscriberId ) - console.log(subscriberId) - if (subscriberAlreadyExists) { throw Error(`Subscriber with id ${subscriberId} already exists`) } diff --git a/packages/medusa/src/strategies/batch-jobs/product/import.ts b/packages/medusa/src/strategies/batch-jobs/product/import.ts index a9802f6091..042e987bcb 100644 --- a/packages/medusa/src/strategies/batch-jobs/product/import.ts +++ b/packages/medusa/src/strategies/batch-jobs/product/import.ts @@ -1,9 +1,10 @@ /* eslint-disable valid-jsdoc */ -import { EntityManager } from "typeorm" import { computerizeAmount, MedusaError } from "medusa-core-utils" +import { EntityManager } from "typeorm" import { AbstractBatchJobStrategy, IFileService } from "../../../interfaces" -import CsvParser from "../../../services/csv-parser" +import SalesChannelFeatureFlag from "../../../loaders/feature-flags/sales-channels" +import { BatchJob, SalesChannel } from "../../../models" import { BatchJobService, ProductCollectionService, @@ -11,29 +12,28 @@ import { ProductVariantService, RegionService, SalesChannelService, - ShippingProfileService, + ShippingProfileService } from "../../../services" +import CsvParser from "../../../services/csv-parser" import { CreateProductInput } from "../../../types/product" import { CreateProductVariantInput, - UpdateProductVariantInput, + UpdateProductVariantInput } from "../../../types/product-variant" -import { BatchJob, SalesChannel } from "../../../models" import { FlagRouter } from "../../../utils/flag-router" -import { transformProductData, transformVariantData } from "./utils" -import SalesChannelFeatureFlag from "../../../loaders/feature-flags/sales-channels" import { OperationType, ProductImportBatchJob, ProductImportCsvSchema, ProductImportInjectedProps, ProductImportJobContext, - TParsedProductImportRowData, + TParsedProductImportRowData } from "./types" import { productImportColumnsDefinition, - productImportSalesChannelsColumnsDefinition, + productImportSalesChannelsColumnsDefinition } from "./types/columns-definition" +import { transformProductData, transformVariantData } from "./utils" /** * Process this many variant rows before reporting progress. @@ -462,7 +462,7 @@ class ProductImportStrategy extends AbstractBatchJobStrategy { for (const productOp of productOps) { const productData = transformProductData(productOp) try { - if (isSalesChannelsFeatureOn) { + if (isSalesChannelsFeatureOn && productOp["product.sales_channels"]) { productData["sales_channels"] = await this.processSalesChannels( productOp["product.sales_channels"] as Pick< SalesChannel,