From 4d326fbbdfa334b8c2b326b0da65f91891d18401 Mon Sep 17 00:00:00 2001 From: Adrien de Peretti Date: Thu, 20 Jul 2023 13:16:04 +0200 Subject: [PATCH] chore: Move factories and helpers to a better place (#4551) * chore: Move factories and helpers to a better place * align factory product variant * fix factory cart * add simple store fac * fix tests * fix tests * fix * fix cart seeder --- .../api/__tests__/admin/analytics-config.js | 10 +- integration-tests/api/__tests__/admin/auth.js | 8 +- .../api/__tests__/admin/colllections.js | 12 +- .../api/__tests__/admin/currency.js | 10 +- .../api/__tests__/admin/customer-groups.js | 12 +- .../api/__tests__/admin/customer.js | 10 +- .../api/__tests__/admin/discount.js | 14 +- .../admin/draft-order/draft-order.js | 12 +- .../ff-tax-inclusive-draft-order.js | 12 +- .../api/__tests__/admin/gift-cards.js | 8 +- .../api/__tests__/admin/invite.js | 10 +- integration-tests/api/__tests__/admin/note.js | 8 +- .../order-edit/ff-tax-inclusive-pricing.js | 10 +- .../__tests__/admin/order-edit/order-edit.js | 14 +- .../admin/order/ff-tax-inclusive-pricing.js | 10 +- .../api/__tests__/admin/order/order.js | 18 +- .../api/__tests__/admin/payment-collection.js | 10 +- .../api/__tests__/admin/payment.js | 12 +- .../api/__tests__/admin/price-list.js | 18 +- .../api/__tests__/admin/product-category.ts | 611 +++++++++--------- .../api/__tests__/admin/product-tag.js | 12 +- .../api/__tests__/admin/product-type.js | 12 +- .../api/__tests__/admin/product.js | 14 +- .../admin/products/ff-product-categories.js | 12 +- .../__tests__/admin/publishable-api-key.js | 12 +- .../api/__tests__/admin/region.js | 12 +- .../api/__tests__/admin/return-reason.js | 8 +- .../api/__tests__/admin/returns.js | 10 +- .../api/__tests__/admin/sales-channels.js | 16 +- .../api/__tests__/admin/shipping-options.js | 14 +- .../api/__tests__/admin/shipping-profile.js | 10 +- .../api/__tests__/admin/store.js | 8 +- .../api/__tests__/admin/swaps.js | 18 +- integration-tests/api/__tests__/admin/user.js | 14 +- .../api/__tests__/admin/variant.js | 14 +- .../api/__tests__/batch-jobs/api.js | 12 +- .../api/__tests__/batch-jobs/order/export.js | 12 +- .../__tests__/batch-jobs/price-list/import.js | 10 +- .../__tests__/batch-jobs/product/export.js | 14 +- .../batch-jobs/product/ff-product-category.js | 16 +- .../batch-jobs/product/ff-sales-channel.js | 16 +- .../__tests__/batch-jobs/product/import.js | 16 +- .../api/__tests__/claims/index.js | 10 +- .../api/__tests__/database/index.js | 4 +- .../line-item-adjustments/ff-sales-channel.js | 11 +- .../__tests__/line-item-adjustments/index.js | 15 +- .../api/__tests__/price-selection/index.js | 10 +- .../price-selection/tax-inclusive-prices.js | 12 +- .../returns/ff-tax-inclusive-pricing.js | 13 +- .../api/__tests__/returns/index.js | 12 +- integration-tests/api/__tests__/store/auth.js | 6 +- .../api/__tests__/store/cart/cart.js | 18 +- .../__tests__/store/cart/ff-sales-channels.js | 8 +- .../store/cart/ff-tax-inclusive-pricing.js | 8 +- .../tax-calculation-ff-tax-inclusive.js | 8 +- .../store/cart/gift-cards/tax-calculation.js | 8 +- .../api/__tests__/store/collections.js | 8 +- .../api/__tests__/store/customer.js | 8 +- .../api/__tests__/store/draft-order.js | 8 +- .../api/__tests__/store/gift-cards.js | 6 +- .../api/__tests__/store/order-edit.js | 18 +- .../api/__tests__/store/orders.js | 8 +- .../api/__tests__/store/payment-collection.js | 14 +- .../api/__tests__/store/product-category.ts | 12 +- .../api/__tests__/store/product-tags.js | 8 +- .../api/__tests__/store/product-type.js | 10 +- .../api/__tests__/store/product-variants.js | 12 +- .../api/__tests__/store/products.js | 12 +- .../store/products/ff-product-categories.ts | 14 +- .../api/__tests__/store/regions.js | 6 +- .../api/__tests__/store/return-reason.js | 6 +- .../api/__tests__/store/returns.js | 6 +- .../api/__tests__/store/sales-channels.js | 10 +- .../api/__tests__/store/shipping-options.js | 14 +- .../api/__tests__/store/swaps.js | 8 +- .../api/__tests__/swaps/index.js | 10 +- .../api/__tests__/taxes/admin-tax-rates.js | 10 +- .../api/__tests__/taxes/automatic-taxes.js | 8 +- integration-tests/api/__tests__/taxes/cart.js | 10 +- .../api/__tests__/taxes/manual-taxes.js | 8 +- .../taxes/orders/ff-tax-inclusive-pricing.js | 8 +- .../api/__tests__/taxes/orders/orders.js | 8 +- .../api/__tests__/taxes/shipping-options.js | 10 +- .../api/__tests__/totals/orders.js | 10 +- integration-tests/api/medusa-config.js | 7 +- .../bootstrap-app.js | 0 .../setup-server.js | 0 .../start-server-with-environment.js | 0 .../test-server.js | 0 .../use-api.js | 0 .../use-db.js | 0 .../use-server.js | 0 .../use-template-db.js | 0 .../{api => }/factories/index.ts | 1 + .../factories/simple-address-factory.ts | 0 .../simple-analytics-config-factory.ts | 0 .../factories/simple-batch-job-factory.ts | 0 .../factories/simple-cart-factory.ts | 3 +- .../simple-custom-shipping-option-factory.ts | 0 .../factories/simple-customer-factory.ts | 0 .../simple-customer-group-factory.ts | 0 .../simple-discount-condition-factory.ts | 0 .../factories/simple-discount-factory.ts | 0 .../factories/simple-gift-card-factory.ts | 0 .../factories/simple-line-item-factory.ts | 0 .../factories/simple-order-edit-factory.ts | 0 .../factories/simple-order-factory.ts | 0 .../simple-order-item-change-factory.ts | 0 .../simple-payment-collection-factory.ts | 0 .../factories/simple-payment-factory.ts | 0 .../factories/simple-price-list-factory.ts | 0 .../simple-product-category-factory.ts | 2 +- .../simple-product-collection-factory.ts | 0 .../factories/simple-product-factory.ts | 49 +- .../factories/simple-product-tag-factory.ts | 0 .../simple-product-tax-rate-factory.ts | 0 .../simple-product-type-tax-rate-factory.ts | 0 .../simple-product-variant-factory.ts | 9 +- .../simple-publishable-api-key-factory.ts | 0 .../factories/simple-region-factory.ts | 0 .../factories/simple-sales-channel-factory.ts | 0 .../simple-shipping-method-factory.ts | 0 .../simple-shipping-option-factory.ts | 0 .../simple-shipping-profile-factory.ts | 0 .../simple-shipping-tax-rate-factory.ts | 0 .../factories/simple-store-factory.ts | 10 +- .../factories/simple-tax-rate-factory.ts | 0 integration-tests/globalSetup.js | 2 +- integration-tests/globalTeardown.js | 2 +- .../{api => }/helpers/admin-seeder.js | 0 .../helpers/admin-variants-seeder.js | 0 .../{api => }/helpers/batch-job-seeder.js | 0 .../{api => }/helpers/call-helpers.js | 4 +- .../{api => }/helpers/cart-seeder.js | 9 + .../{api => }/helpers/claim-seeder.js | 2 +- .../helpers/client-authentication.ts | 0 .../{api => }/helpers/customer-seeder.js | 0 .../{api => }/helpers/discount-seeder.js | 0 .../{api => }/helpers/draft-order-seeder.js | 0 .../{api => }/helpers/order-seeder.js | 0 .../{api => }/helpers/price-list-seeder.js | 0 .../helpers/price-selection-seeder.js | 0 .../{api => }/helpers/product-seeder.js | 0 .../helpers/shipping-option-seeder.js | 0 .../{api => }/helpers/store-product-seeder.js | 0 .../{api => }/helpers/swap-seeder.js | 0 .../{api => }/helpers/user-seeder.js | 0 .../plugins/__tests__/inventory/cart/cart.js | 16 +- .../inventory/inventory-items/index.js | 12 +- .../__tests__/inventory/order/draft-order.js | 24 +- .../__tests__/inventory/order/order.js | 16 +- .../inventory/products/create-variant.js | 12 +- .../inventory/products/delete-variant.js | 12 +- .../inventory/products/get-product.js | 16 +- .../inventory/products/get-variant.js | 16 +- .../inventory/products/list-products.js | 22 +- .../inventory/products/list-variants.js | 17 +- .../inventory/reservation-items/index.js | 14 +- .../plugins/__tests__/inventory/service.js | 4 +- .../inventory/variant-inventory-service.js | 9 +- .../__snapshots__/index.js.snap | 136 ++-- .../__tests__/medusa-plugin-sendgrid/index.js | 10 +- .../stock-location/delete-sales-channels.js | 8 +- .../stock-location/delete-stock-location.js | 8 +- .../stock-location/sales-channels.js | 8 +- .../__tests__/stock-location/service.js | 4 +- integration-tests/plugins/factories/index.ts | 13 - .../factories/simple-address-factory.ts | 34 - .../plugins/factories/simple-cart-factory.ts | 72 --- .../factories/simple-discount-factory.ts | 55 -- .../factories/simple-line-item-factory.ts | 84 --- .../plugins/factories/simple-order-factory.ts | 146 ----- .../factories/simple-product-factory.ts | 92 --- .../simple-product-tax-rate-factory.ts | 48 -- .../simple-product-type-tax-rate-factory.ts | 48 -- .../simple-product-variant-factory.ts | 69 -- .../factories/simple-region-factory.ts | 47 -- .../simple-shipping-method-factory.ts | 68 -- .../simple-shipping-option-factory.ts | 45 -- .../simple-shipping-tax-rate-factory.ts | 48 -- .../factories/simple-tax-rate-factory.ts | 32 - .../plugins/helpers/admin-seeder.js | 18 - .../plugins/helpers/call-helpers.js | 100 --- .../plugins/helpers/cart-seeder.js | 546 ---------------- .../plugins/helpers/claim-seeder.js | 118 ---- .../plugins/helpers/customer-seeder.js | 33 - .../plugins/helpers/discount-seeder.js | 35 - .../plugins/helpers/draft-order-seeder.js | 264 -------- .../plugins/helpers/order-seeder.js | 399 ------------ .../plugins/helpers/product-seeder.js | 289 --------- .../plugins/helpers/shipping-option-seeder.js | 86 --- .../plugins/helpers/swap-seeder.js | 434 ------------- .../plugins/helpers/user-seeder.js | 53 -- integration-tests/plugins/medusa-config.js | 2 +- .../__tests__/product-categories/queries.ts | 126 ++-- .../repositories/factories/index.ts | 1 - .../simple-product-category-factory.ts | 12 - 197 files changed, 1073 insertions(+), 4332 deletions(-) rename integration-tests/{helpers => environment-helpers}/bootstrap-app.js (100%) rename integration-tests/{helpers => environment-helpers}/setup-server.js (100%) rename integration-tests/{helpers => environment-helpers}/start-server-with-environment.js (100%) rename integration-tests/{helpers => environment-helpers}/test-server.js (100%) rename integration-tests/{helpers => environment-helpers}/use-api.js (100%) rename integration-tests/{helpers => environment-helpers}/use-db.js (100%) rename integration-tests/{helpers => environment-helpers}/use-server.js (100%) rename integration-tests/{helpers => environment-helpers}/use-template-db.js (100%) rename integration-tests/{api => }/factories/index.ts (96%) rename integration-tests/{api => }/factories/simple-address-factory.ts (100%) rename integration-tests/{api => }/factories/simple-analytics-config-factory.ts (100%) rename integration-tests/{api => }/factories/simple-batch-job-factory.ts (100%) rename integration-tests/{api => }/factories/simple-cart-factory.ts (96%) rename integration-tests/{api => }/factories/simple-custom-shipping-option-factory.ts (100%) rename integration-tests/{api => }/factories/simple-customer-factory.ts (100%) rename integration-tests/{api => }/factories/simple-customer-group-factory.ts (100%) rename integration-tests/{api => }/factories/simple-discount-condition-factory.ts (100%) rename integration-tests/{api => }/factories/simple-discount-factory.ts (100%) rename integration-tests/{api => }/factories/simple-gift-card-factory.ts (100%) rename integration-tests/{api => }/factories/simple-line-item-factory.ts (100%) rename integration-tests/{api => }/factories/simple-order-edit-factory.ts (100%) rename integration-tests/{api => }/factories/simple-order-factory.ts (100%) rename integration-tests/{api => }/factories/simple-order-item-change-factory.ts (100%) rename integration-tests/{api => }/factories/simple-payment-collection-factory.ts (100%) rename integration-tests/{api => }/factories/simple-payment-factory.ts (100%) rename integration-tests/{api => }/factories/simple-price-list-factory.ts (100%) rename integration-tests/{api => }/factories/simple-product-category-factory.ts (83%) rename integration-tests/{api => }/factories/simple-product-collection-factory.ts (100%) rename integration-tests/{api => }/factories/simple-product-factory.ts (83%) rename integration-tests/{api => }/factories/simple-product-tag-factory.ts (100%) rename integration-tests/{api => }/factories/simple-product-tax-rate-factory.ts (100%) rename integration-tests/{api => }/factories/simple-product-type-tax-rate-factory.ts (100%) rename integration-tests/{api => }/factories/simple-product-variant-factory.ts (85%) rename integration-tests/{api => }/factories/simple-publishable-api-key-factory.ts (100%) rename integration-tests/{api => }/factories/simple-region-factory.ts (100%) rename integration-tests/{api => }/factories/simple-sales-channel-factory.ts (100%) rename integration-tests/{api => }/factories/simple-shipping-method-factory.ts (100%) rename integration-tests/{api => }/factories/simple-shipping-option-factory.ts (100%) rename integration-tests/{api => }/factories/simple-shipping-profile-factory.ts (100%) rename integration-tests/{api => }/factories/simple-shipping-tax-rate-factory.ts (100%) rename integration-tests/{plugins => }/factories/simple-store-factory.ts (78%) rename integration-tests/{api => }/factories/simple-tax-rate-factory.ts (100%) rename integration-tests/{api => }/helpers/admin-seeder.js (100%) rename integration-tests/{api => }/helpers/admin-variants-seeder.js (100%) rename integration-tests/{api => }/helpers/batch-job-seeder.js (100%) rename integration-tests/{api => }/helpers/call-helpers.js (95%) rename integration-tests/{api => }/helpers/cart-seeder.js (98%) rename integration-tests/{api => }/helpers/claim-seeder.js (98%) rename integration-tests/{api => }/helpers/client-authentication.ts (100%) rename integration-tests/{api => }/helpers/customer-seeder.js (100%) rename integration-tests/{api => }/helpers/discount-seeder.js (100%) rename integration-tests/{api => }/helpers/draft-order-seeder.js (100%) rename integration-tests/{api => }/helpers/order-seeder.js (100%) rename integration-tests/{api => }/helpers/price-list-seeder.js (100%) rename integration-tests/{api => }/helpers/price-selection-seeder.js (100%) rename integration-tests/{api => }/helpers/product-seeder.js (100%) rename integration-tests/{api => }/helpers/shipping-option-seeder.js (100%) rename integration-tests/{api => }/helpers/store-product-seeder.js (100%) rename integration-tests/{api => }/helpers/swap-seeder.js (100%) rename integration-tests/{api => }/helpers/user-seeder.js (100%) delete mode 100644 integration-tests/plugins/factories/index.ts delete mode 100644 integration-tests/plugins/factories/simple-address-factory.ts delete mode 100644 integration-tests/plugins/factories/simple-cart-factory.ts delete mode 100644 integration-tests/plugins/factories/simple-discount-factory.ts delete mode 100644 integration-tests/plugins/factories/simple-line-item-factory.ts delete mode 100644 integration-tests/plugins/factories/simple-order-factory.ts delete mode 100644 integration-tests/plugins/factories/simple-product-factory.ts delete mode 100644 integration-tests/plugins/factories/simple-product-tax-rate-factory.ts delete mode 100644 integration-tests/plugins/factories/simple-product-type-tax-rate-factory.ts delete mode 100644 integration-tests/plugins/factories/simple-product-variant-factory.ts delete mode 100644 integration-tests/plugins/factories/simple-region-factory.ts delete mode 100644 integration-tests/plugins/factories/simple-shipping-method-factory.ts delete mode 100644 integration-tests/plugins/factories/simple-shipping-option-factory.ts delete mode 100644 integration-tests/plugins/factories/simple-shipping-tax-rate-factory.ts delete mode 100644 integration-tests/plugins/factories/simple-tax-rate-factory.ts delete mode 100644 integration-tests/plugins/helpers/admin-seeder.js delete mode 100644 integration-tests/plugins/helpers/call-helpers.js delete mode 100644 integration-tests/plugins/helpers/cart-seeder.js delete mode 100644 integration-tests/plugins/helpers/claim-seeder.js delete mode 100644 integration-tests/plugins/helpers/customer-seeder.js delete mode 100644 integration-tests/plugins/helpers/discount-seeder.js delete mode 100644 integration-tests/plugins/helpers/draft-order-seeder.js delete mode 100644 integration-tests/plugins/helpers/order-seeder.js delete mode 100644 integration-tests/plugins/helpers/product-seeder.js delete mode 100644 integration-tests/plugins/helpers/shipping-option-seeder.js delete mode 100644 integration-tests/plugins/helpers/swap-seeder.js delete mode 100644 integration-tests/plugins/helpers/user-seeder.js delete mode 100644 integration-tests/repositories/factories/index.ts delete mode 100644 integration-tests/repositories/factories/simple-product-category-factory.ts diff --git a/integration-tests/api/__tests__/admin/analytics-config.js b/integration-tests/api/__tests__/admin/analytics-config.js index 6d06b6df88..e140bf2314 100644 --- a/integration-tests/api/__tests__/admin/analytics-config.js +++ b/integration-tests/api/__tests__/admin/analytics-config.js @@ -1,12 +1,12 @@ const path = require("path") const startServerWithEnvironment = - require("../../../helpers/start-server-with-environment").default -const { useApi } = require("../../../helpers/use-api") -const { useDb } = require("../../../helpers/use-db") + require("../../../environment-helpers/start-server-with-environment").default +const { useApi } = require("../../../environment-helpers/use-api") +const { useDb } = require("../../../environment-helpers/use-db") const { simpleAnalyticsConfigFactory, -} = require("../../factories/simple-analytics-config-factory") -const adminSeeder = require("../../helpers/admin-seeder") +} = require("../../../factories/simple-analytics-config-factory") +const adminSeeder = require("../../../helpers/admin-seeder") const adminReqConfig = { headers: { diff --git a/integration-tests/api/__tests__/admin/auth.js b/integration-tests/api/__tests__/admin/auth.js index 3473e55a06..65a4ebf62e 100644 --- a/integration-tests/api/__tests__/admin/auth.js +++ b/integration-tests/api/__tests__/admin/auth.js @@ -1,10 +1,10 @@ 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 setupServer = require("../../../environment-helpers/setup-server") +const { useApi } = require("../../../environment-helpers/use-api") +const { initDb, useDb } = require("../../../environment-helpers/use-db") +const adminSeeder = require("../../../helpers/admin-seeder") const { exportAllDeclaration } = require("@babel/types") jest.setTimeout(30000) diff --git a/integration-tests/api/__tests__/admin/colllections.js b/integration-tests/api/__tests__/admin/colllections.js index 5244ecbe99..7f109e8ee1 100644 --- a/integration-tests/api/__tests__/admin/colllections.js +++ b/integration-tests/api/__tests__/admin/colllections.js @@ -1,10 +1,10 @@ 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("../../../environment-helpers/setup-server") +const { useApi } = require("../../../environment-helpers/use-api") +const { initDb, useDb } = require("../../../environment-helpers/use-db") -const productSeeder = require("../../helpers/product-seeder") -const adminSeeder = require("../../helpers/admin-seeder") +const productSeeder = require("../../../helpers/product-seeder") +const adminSeeder = require("../../../helpers/admin-seeder") const { DiscountRuleType, AllocationType, @@ -15,7 +15,7 @@ const { IdMap } = require("medusa-test-utils") const { simpleDiscountFactory, simpleSalesChannelFactory, -} = require("../../factories") +} = require("../../../factories") jest.setTimeout(30000) diff --git a/integration-tests/api/__tests__/admin/currency.js b/integration-tests/api/__tests__/admin/currency.js index 1f045671c4..107e955213 100644 --- a/integration-tests/api/__tests__/admin/currency.js +++ b/integration-tests/api/__tests__/admin/currency.js @@ -1,10 +1,10 @@ const path = require("path") -const setupServer = require("../../../helpers/setup-server") +const setupServer = require("../../../environment-helpers/setup-server") const startServerWithEnvironment = - require("../../../helpers/start-server-with-environment").default -const { useApi } = require("../../../helpers/use-api") -const { useDb, initDb } = require("../../../helpers/use-db") -const adminSeeder = require("../../helpers/admin-seeder") + require("../../../environment-helpers/start-server-with-environment").default +const { useApi } = require("../../../environment-helpers/use-api") +const { useDb, initDb } = require("../../../environment-helpers/use-db") +const adminSeeder = require("../../../helpers/admin-seeder") const adminReqConfig = { headers: { diff --git a/integration-tests/api/__tests__/admin/customer-groups.js b/integration-tests/api/__tests__/admin/customer-groups.js index a91a85fbdd..3404287880 100644 --- a/integration-tests/api/__tests__/admin/customer-groups.js +++ b/integration-tests/api/__tests__/admin/customer-groups.js @@ -2,19 +2,19 @@ const path = require("path") const { IdMap } = require("medusa-test-utils") -const setupServer = require("../../../helpers/setup-server") -const { useApi } = require("../../../helpers/use-api") -const { useDb, initDb } = require("../../../helpers/use-db") +const setupServer = require("../../../environment-helpers/setup-server") +const { useApi } = require("../../../environment-helpers/use-api") +const { useDb, initDb } = require("../../../environment-helpers/use-db") -const customerSeeder = require("../../helpers/customer-seeder") -const adminSeeder = require("../../helpers/admin-seeder") +const customerSeeder = require("../../../helpers/customer-seeder") +const adminSeeder = require("../../../helpers/admin-seeder") const { DiscountRuleType, AllocationType, DiscountConditionType, DiscountConditionOperator, } = require("@medusajs/medusa") -const { simpleDiscountFactory } = require("../../factories") +const { simpleDiscountFactory } = require("../../../factories") jest.setTimeout(30000) diff --git a/integration-tests/api/__tests__/admin/customer.js b/integration-tests/api/__tests__/admin/customer.js index 2d89a6c0b7..2e4bdb5601 100644 --- a/integration-tests/api/__tests__/admin/customer.js +++ b/integration-tests/api/__tests__/admin/customer.js @@ -1,11 +1,11 @@ const path = require("path") -const setupServer = require("../../../helpers/setup-server") -const { useApi } = require("../../../helpers/use-api") -const { useDb, initDb } = require("../../../helpers/use-db") +const setupServer = require("../../../environment-helpers/setup-server") +const { useApi } = require("../../../environment-helpers/use-api") +const { useDb, initDb } = require("../../../environment-helpers/use-db") -const customerSeeder = require("../../helpers/customer-seeder") -const adminSeeder = require("../../helpers/admin-seeder") +const customerSeeder = require("../../../helpers/customer-seeder") +const adminSeeder = require("../../../helpers/admin-seeder") jest.setTimeout(30000) diff --git a/integration-tests/api/__tests__/admin/discount.js b/integration-tests/api/__tests__/admin/discount.js index d73a44b3d2..da034ce7c9 100644 --- a/integration-tests/api/__tests__/admin/discount.js +++ b/integration-tests/api/__tests__/admin/discount.js @@ -6,15 +6,15 @@ const { CustomerGroup, } = 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 discountSeeder = require("../../helpers/discount-seeder") -const { simpleProductFactory } = require("../../factories") +const setupServer = require("../../../environment-helpers/setup-server") +const { useApi } = require("../../../environment-helpers/use-api") +const { initDb, useDb } = require("../../../environment-helpers/use-db") +const adminSeeder = require("../../../helpers/admin-seeder") +const discountSeeder = require("../../../helpers/discount-seeder") +const { simpleProductFactory } = require("../../../factories") const { simpleDiscountFactory, -} = require("../../factories/simple-discount-factory") +} = require("../../../factories/simple-discount-factory") jest.setTimeout(30000) diff --git a/integration-tests/api/__tests__/admin/draft-order/draft-order.js b/integration-tests/api/__tests__/admin/draft-order/draft-order.js index fe12d897fe..55808a95c5 100644 --- a/integration-tests/api/__tests__/admin/draft-order/draft-order.js +++ b/integration-tests/api/__tests__/admin/draft-order/draft-order.js @@ -1,12 +1,12 @@ 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("../../../../environment-helpers/setup-server") +const { useApi } = require("../../../../environment-helpers/use-api") +const { initDb, useDb } = require("../../../../environment-helpers/use-db") -const draftOrderSeeder = require("../../../helpers/draft-order-seeder") -const adminSeeder = require("../../../helpers/admin-seeder") -const { simpleDiscountFactory } = require("../../../factories") +const draftOrderSeeder = require("../../../../helpers/draft-order-seeder") +const adminSeeder = require("../../../../helpers/admin-seeder") +const { simpleDiscountFactory } = require("../../../../factories") jest.setTimeout(30000) diff --git a/integration-tests/api/__tests__/admin/draft-order/ff-tax-inclusive-draft-order.js b/integration-tests/api/__tests__/admin/draft-order/ff-tax-inclusive-draft-order.js index aeeb01851a..35b980fe83 100644 --- a/integration-tests/api/__tests__/admin/draft-order/ff-tax-inclusive-draft-order.js +++ b/integration-tests/api/__tests__/admin/draft-order/ff-tax-inclusive-draft-order.js @@ -1,16 +1,16 @@ const path = require("path") -const draftOrderSeeder = require("../../../helpers/draft-order-seeder") -const adminSeeder = require("../../../helpers/admin-seeder") +const draftOrderSeeder = require("../../../../helpers/draft-order-seeder") +const adminSeeder = require("../../../../helpers/admin-seeder") const { simpleDiscountFactory, simpleRegionFactory, simpleShippingOptionFactory, -} = require("../../../factories") +} = require("../../../../factories") const startServerWithEnvironment = - require("../../../../helpers/start-server-with-environment").default -const { useDb } = require("../../../../helpers/use-db") -const { useApi } = require("../../../../helpers/use-api") + require("../../../../environment-helpers/start-server-with-environment").default +const { useDb } = require("../../../../environment-helpers/use-db") +const { useApi } = require("../../../../environment-helpers/use-api") jest.setTimeout(30000) diff --git a/integration-tests/api/__tests__/admin/gift-cards.js b/integration-tests/api/__tests__/admin/gift-cards.js index 56a5539190..f6ccda4107 100644 --- a/integration-tests/api/__tests__/admin/gift-cards.js +++ b/integration-tests/api/__tests__/admin/gift-cards.js @@ -1,10 +1,10 @@ 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 adminSeeder = require("../../helpers/admin-seeder") +const setupServer = require("../../../environment-helpers/setup-server") +const { useApi } = require("../../../environment-helpers/use-api") +const { initDb, useDb } = require("../../../environment-helpers/use-db") +const adminSeeder = require("../../../helpers/admin-seeder") jest.setTimeout(30000) diff --git a/integration-tests/api/__tests__/admin/invite.js b/integration-tests/api/__tests__/admin/invite.js index c9b1b33343..e5d25c9b8f 100644 --- a/integration-tests/api/__tests__/admin/invite.js +++ b/integration-tests/api/__tests__/admin/invite.js @@ -1,11 +1,11 @@ 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("../../../environment-helpers/setup-server") +const { useApi } = require("../../../environment-helpers/use-api") +const { initDb, useDb } = require("../../../environment-helpers/use-db") -const userSeeder = require("../../helpers/user-seeder") -const adminSeeder = require("../../helpers/admin-seeder") +const userSeeder = require("../../../helpers/user-seeder") +const adminSeeder = require("../../../helpers/admin-seeder") jest.setTimeout(30000) diff --git a/integration-tests/api/__tests__/admin/note.js b/integration-tests/api/__tests__/admin/note.js index c785b59f33..09ef8c7414 100644 --- a/integration-tests/api/__tests__/admin/note.js +++ b/integration-tests/api/__tests__/admin/note.js @@ -1,11 +1,11 @@ const path = require("path") const { Note } = 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("../../../environment-helpers/setup-server") +const { useApi } = require("../../../environment-helpers/use-api") +const { initDb, useDb } = require("../../../environment-helpers/use-db") -const adminSeeder = require("../../helpers/admin-seeder") +const adminSeeder = require("../../../helpers/admin-seeder") jest.setTimeout(30000) diff --git a/integration-tests/api/__tests__/admin/order-edit/ff-tax-inclusive-pricing.js b/integration-tests/api/__tests__/admin/order-edit/ff-tax-inclusive-pricing.js index 2bbb39b924..0e87c51392 100644 --- a/integration-tests/api/__tests__/admin/order-edit/ff-tax-inclusive-pricing.js +++ b/integration-tests/api/__tests__/admin/order-edit/ff-tax-inclusive-pricing.js @@ -2,17 +2,17 @@ const path = require("path") const { IdMap } = require("medusa-test-utils") const startServerWithEnvironment = - require("../../../../helpers/start-server-with-environment").default -const { useApi } = require("../../../../helpers/use-api") -const { useDb } = require("../../../../helpers/use-db") + require("../../../../environment-helpers/start-server-with-environment").default +const { useApi } = require("../../../../environment-helpers/use-api") +const { useDb } = require("../../../../environment-helpers/use-db") -const adminSeeder = require("../../../helpers/admin-seeder") +const adminSeeder = require("../../../../helpers/admin-seeder") const { simpleProductFactory, simpleRegionFactory, simpleCartFactory, -} = require("../../../factories") +} = require("../../../../factories") jest.setTimeout(30000) diff --git a/integration-tests/api/__tests__/admin/order-edit/order-edit.js b/integration-tests/api/__tests__/admin/order-edit/order-edit.js index 716e9779ad..e7cef852b0 100644 --- a/integration-tests/api/__tests__/admin/order-edit/order-edit.js +++ b/integration-tests/api/__tests__/admin/order-edit/order-edit.js @@ -2,15 +2,15 @@ const path = require("path") const { OrderEditItemChangeType, OrderEdit } = require("@medusajs/medusa") const { IdMap } = require("medusa-test-utils") -const { useApi } = require("../../../../helpers/use-api") -const { useDb, initDb } = require("../../../../helpers/use-db") -const adminSeeder = require("../../../helpers/admin-seeder") +const { useApi } = require("../../../../environment-helpers/use-api") +const { useDb, initDb } = require("../../../../environment-helpers/use-db") +const adminSeeder = require("../../../../helpers/admin-seeder") const { simpleOrderEditFactory, -} = require("../../../factories/simple-order-edit-factory") +} = require("../../../../factories/simple-order-edit-factory") const { simpleOrderItemChangeFactory, -} = require("../../../factories/simple-order-item-change-factory") +} = require("../../../../factories/simple-order-item-change-factory") const { simpleLineItemFactory, simpleProductFactory, @@ -18,8 +18,8 @@ const { simpleDiscountFactory, simpleCartFactory, simpleRegionFactory, -} = require("../../../factories") -const setupServer = require("../../../../helpers/setup-server") +} = require("../../../../factories") +const setupServer = require("../../../../environment-helpers/setup-server") jest.setTimeout(30000) diff --git a/integration-tests/api/__tests__/admin/order/ff-tax-inclusive-pricing.js b/integration-tests/api/__tests__/admin/order/ff-tax-inclusive-pricing.js index d2708417ab..3ec5a593b8 100644 --- a/integration-tests/api/__tests__/admin/order/ff-tax-inclusive-pricing.js +++ b/integration-tests/api/__tests__/admin/order/ff-tax-inclusive-pricing.js @@ -1,18 +1,18 @@ const path = require("path") const startServerWithEnvironment = - require("../../../../helpers/start-server-with-environment").default -const { useApi } = require("../../../../helpers/use-api") -const { useDb } = require("../../../../helpers/use-db") + require("../../../../environment-helpers/start-server-with-environment").default +const { useApi } = require("../../../../environment-helpers/use-api") +const { useDb } = require("../../../../environment-helpers/use-db") -const adminSeeder = require("../../../helpers/admin-seeder") +const adminSeeder = require("../../../../helpers/admin-seeder") const { simpleRegionFactory, simpleShippingOptionFactory, simpleOrderFactory, simpleProductFactory, -} = require("../../../factories") +} = require("../../../../factories") jest.setTimeout(30000) diff --git a/integration-tests/api/__tests__/admin/order/order.js b/integration-tests/api/__tests__/admin/order/order.js index fd6bb21b67..836dbc6e84 100644 --- a/integration-tests/api/__tests__/admin/order/order.js +++ b/integration-tests/api/__tests__/admin/order/order.js @@ -9,28 +9,28 @@ const { } = require("@medusajs/medusa") const idMap = require("medusa-test-utils/src/id-map").default -const setupServer = require("../../../../helpers/setup-server") -const { useApi } = require("../../../../helpers/use-api") -const { initDb, useDb } = require("../../../../helpers/use-db") +const setupServer = require("../../../../environment-helpers/setup-server") +const { useApi } = require("../../../../environment-helpers/use-api") +const { initDb, useDb } = require("../../../../environment-helpers/use-db") -const orderSeeder = require("../../../helpers/order-seeder") -const swapSeeder = require("../../../helpers/swap-seeder") -const adminSeeder = require("../../../helpers/admin-seeder") -const claimSeeder = require("../../../helpers/claim-seeder") +const orderSeeder = require("../../../../helpers/order-seeder") +const swapSeeder = require("../../../../helpers/swap-seeder") +const adminSeeder = require("../../../../helpers/admin-seeder") +const claimSeeder = require("../../../../helpers/claim-seeder") const { expectPostCallToReturn, expectAllPostCallsToReturn, callGet, partial, -} = require("../../../helpers/call-helpers") +} = require("../../../../helpers/call-helpers") const { simpleShippingOptionFactory, simpleOrderFactory, simplePaymentFactory, simpleProductFactory, simpleLineItemFactory, -} = require("../../../factories") +} = require("../../../../factories") const adminReqConfig = { headers: { diff --git a/integration-tests/api/__tests__/admin/payment-collection.js b/integration-tests/api/__tests__/admin/payment-collection.js index d756c23824..3ef37eaae0 100644 --- a/integration-tests/api/__tests__/admin/payment-collection.js +++ b/integration-tests/api/__tests__/admin/payment-collection.js @@ -1,14 +1,14 @@ const path = require("path") const startServerWithEnvironment = - require("../../../helpers/start-server-with-environment").default -const { useApi } = require("../../../helpers/use-api") -const { useDb } = require("../../../helpers/use-db") -const adminSeeder = require("../../helpers/admin-seeder") + require("../../../environment-helpers/start-server-with-environment").default +const { useApi } = require("../../../environment-helpers/use-api") +const { useDb } = require("../../../environment-helpers/use-db") +const adminSeeder = require("../../../helpers/admin-seeder") const { simplePaymentCollectionFactory, -} = require("../../factories/simple-payment-collection-factory") +} = require("../../../factories/simple-payment-collection-factory") jest.setTimeout(30000) diff --git a/integration-tests/api/__tests__/admin/payment.js b/integration-tests/api/__tests__/admin/payment.js index f6d7bec856..39ac280094 100644 --- a/integration-tests/api/__tests__/admin/payment.js +++ b/integration-tests/api/__tests__/admin/payment.js @@ -1,17 +1,17 @@ const path = require("path") const startServerWithEnvironment = - require("../../../helpers/start-server-with-environment").default -const { useApi } = require("../../../helpers/use-api") -const { useDb } = require("../../../helpers/use-db") -const adminSeeder = require("../../helpers/admin-seeder") + require("../../../environment-helpers/start-server-with-environment").default +const { useApi } = require("../../../environment-helpers/use-api") +const { useDb } = require("../../../environment-helpers/use-db") +const adminSeeder = require("../../../helpers/admin-seeder") const { simplePaymentCollectionFactory, -} = require("../../factories/simple-payment-collection-factory") +} = require("../../../factories/simple-payment-collection-factory") const { simpleCustomerFactory, -} = require("../../factories/simple-customer-factory") +} = require("../../../factories/simple-customer-factory") jest.setTimeout(30000) diff --git a/integration-tests/api/__tests__/admin/price-list.js b/integration-tests/api/__tests__/admin/price-list.js index 587805baf5..bf763f33dd 100644 --- a/integration-tests/api/__tests__/admin/price-list.js +++ b/integration-tests/api/__tests__/admin/price-list.js @@ -1,21 +1,21 @@ const path = require("path") const { Region } = require("@medusajs/medusa") -const setupServer = require("../../../helpers/setup-server") +const setupServer = require("../../../environment-helpers/setup-server") const startServerWithEnvironment = - require("../../../helpers/start-server-with-environment").default -const { useApi } = require("../../../helpers/use-api") -const { useDb, initDb } = require("../../../helpers/use-db") + require("../../../environment-helpers/start-server-with-environment").default +const { useApi } = require("../../../environment-helpers/use-api") +const { useDb, initDb } = require("../../../environment-helpers/use-db") const { simpleProductFactory, simplePriceListFactory, simpleRegionFactory, -} = require("../../factories") -const adminSeeder = require("../../helpers/admin-seeder") -const customerSeeder = require("../../helpers/customer-seeder") -const priceListSeeder = require("../../helpers/price-list-seeder") -const productSeeder = require("../../helpers/product-seeder") +} = require("../../../factories") +const adminSeeder = require("../../../helpers/admin-seeder") +const customerSeeder = require("../../../helpers/customer-seeder") +const priceListSeeder = require("../../../helpers/price-list-seeder") +const productSeeder = require("../../../helpers/product-seeder") const adminReqConfig = { headers: { diff --git a/integration-tests/api/__tests__/admin/product-category.ts b/integration-tests/api/__tests__/admin/product-category.ts index 6dea27b420..b140e7fd05 100644 --- a/integration-tests/api/__tests__/admin/product-category.ts +++ b/integration-tests/api/__tests__/admin/product-category.ts @@ -2,15 +2,14 @@ import path from "path" import { Product, ProductCategory } from "@medusajs/medusa" import { In } from "typeorm" -import startServerWithEnvironment - from "../../../helpers/start-server-with-environment" -import { useApi } from "../../../helpers/use-api" -import { useDb } from "../../../helpers/use-db" -import adminSeeder from "../../helpers/admin-seeder" +import startServerWithEnvironment from "../../../environment-helpers/start-server-with-environment" +import { useApi } from "../../../environment-helpers/use-api" +import { useDb } from "../../../environment-helpers/use-db" +import adminSeeder from "../../../helpers/admin-seeder" import { simpleProductCategoryFactory, simpleProductFactory, -} from "../../factories" +} from "../../../factories" jest.setTimeout(30000) @@ -111,11 +110,11 @@ describe("/admin/product-categories", () => { id: productCategoryChild2.id, name: productCategoryChild2.name, handle: productCategoryChild2.handle, - category_children: [] - }) - ] - }) - ] + category_children: [], + }), + ], + }), + ], }) ) @@ -136,37 +135,37 @@ describe("/admin/product-categories", () => { name: "sweater", parent_category: productCategoryParent, is_internal: true, - rank: 0 + rank: 0, }) productCategoryChild = await simpleProductCategoryFactory(dbConnection, { name: "cashmere", parent_category: productCategory, - rank: 0 + rank: 0, }) productCategoryChild0 = await simpleProductCategoryFactory(dbConnection, { name: "rank 2", parent_category: productCategoryChild, - rank: 2 + rank: 2, }) productCategoryChild1 = await simpleProductCategoryFactory(dbConnection, { name: "rank 1", parent_category: productCategoryChild, - rank: 1 + rank: 1, }) productCategoryChild2 = await simpleProductCategoryFactory(dbConnection, { name: "rank 0", parent_category: productCategoryChild, - rank: 0 + rank: 0, }) productCategoryChild3 = await simpleProductCategoryFactory(dbConnection, { name: "rank 3", parent_category: productCategoryChild, - rank: 3 + rank: 3, }) }) @@ -188,108 +187,106 @@ describe("/admin/product-categories", () => { expect(response.data.offset).toEqual(0) expect(response.data.limit).toEqual(7) - expect(response.data.product_categories).toEqual( - [ - expect.objectContaining({ - id: productCategoryChild.id, - parent_category: expect.objectContaining({ + expect(response.data.product_categories).toEqual([ + expect.objectContaining({ + id: productCategoryChild.id, + parent_category: expect.objectContaining({ + id: productCategory.id, + handle: productCategory.handle, + rank: 0, + }), + category_children: [ + expect.objectContaining({ + id: productCategoryChild2.id, + handle: productCategoryChild2.handle, + rank: 0, + }), + expect.objectContaining({ + id: productCategoryChild1.id, + handle: productCategoryChild1.handle, + rank: 1, + }), + expect.objectContaining({ + id: productCategoryChild0.id, + handle: productCategoryChild0.handle, + rank: 2, + }), + expect.objectContaining({ + id: productCategoryChild3.id, + handle: productCategoryChild3.handle, + rank: 3, + }), + ], + }), + expect.objectContaining({ + id: productCategoryParent.id, + parent_category: null, + category_children: [ + expect.objectContaining({ id: productCategory.id, handle: productCategory.handle, - rank: 0 - }), - category_children: [ - expect.objectContaining({ - id: productCategoryChild2.id, - handle: productCategoryChild2.handle, - rank: 0 - }), - expect.objectContaining({ - id: productCategoryChild1.id, - handle: productCategoryChild1.handle, - rank: 1 - }), - expect.objectContaining({ - id: productCategoryChild0.id, - handle: productCategoryChild0.handle, - rank: 2 - }), - expect.objectContaining({ - id: productCategoryChild3.id, - handle: productCategoryChild3.handle, - rank: 3 - }), - ], - }), - expect.objectContaining({ - id: productCategoryParent.id, - parent_category: null, - category_children: [ - expect.objectContaining({ - id: productCategory.id, - handle: productCategory.handle, - rank: 0 - }) - ], - }), - expect.objectContaining({ - id: productCategoryChild2.id, - parent_category: expect.objectContaining({ - id: productCategoryChild.id, - }), - category_children: [], - rank: 0, - handle: productCategoryChild2.handle, - }), - expect.objectContaining({ - id: productCategory.id, - parent_category: expect.objectContaining({ - id: productCategoryParent.id, rank: 0, - handle: productCategoryParent.handle, }), - category_children: [ - expect.objectContaining({ - id: productCategoryChild.id, - handle: productCategoryChild.handle, - rank: 0, - }) - ], + ], + }), + expect.objectContaining({ + id: productCategoryChild2.id, + parent_category: expect.objectContaining({ + id: productCategoryChild.id, }), - expect.objectContaining({ - id: productCategoryChild1.id, - parent_category: expect.objectContaining({ + category_children: [], + rank: 0, + handle: productCategoryChild2.handle, + }), + expect.objectContaining({ + id: productCategory.id, + parent_category: expect.objectContaining({ + id: productCategoryParent.id, + rank: 0, + handle: productCategoryParent.handle, + }), + category_children: [ + expect.objectContaining({ id: productCategoryChild.id, handle: productCategoryChild.handle, - rank: 0 + rank: 0, }), - category_children: [], - handle: productCategoryChild1.handle, - rank: 1 + ], + }), + expect.objectContaining({ + id: productCategoryChild1.id, + parent_category: expect.objectContaining({ + id: productCategoryChild.id, + handle: productCategoryChild.handle, + rank: 0, }), - expect.objectContaining({ - id: productCategoryChild0.id, - parent_category: expect.objectContaining({ - id: productCategoryChild.id, - handle: productCategoryChild.handle, - rank: 0 - }), - category_children: [], - handle: productCategoryChild0.handle, - rank: 2 + category_children: [], + handle: productCategoryChild1.handle, + rank: 1, + }), + expect.objectContaining({ + id: productCategoryChild0.id, + parent_category: expect.objectContaining({ + id: productCategoryChild.id, + handle: productCategoryChild.handle, + rank: 0, }), - expect.objectContaining({ - id: productCategoryChild3.id, - parent_category: expect.objectContaining({ - id: productCategoryChild.id, - handle: productCategoryChild.handle, - rank: 0 - }), - category_children: [], - handle: productCategoryChild3.handle, - rank: 3 + category_children: [], + handle: productCategoryChild0.handle, + rank: 2, + }), + expect.objectContaining({ + id: productCategoryChild3.id, + parent_category: expect.objectContaining({ + id: productCategoryChild.id, + handle: productCategoryChild.handle, + rank: 0, }), - ] - ) + category_children: [], + handle: productCategoryChild3.handle, + rank: 3, + }), + ]) }) it("filters based on whitelisted attributes of the data model", async () => { @@ -297,7 +294,7 @@ describe("/admin/product-categories", () => { const response = await api.get( `/admin/product-categories?is_internal=true&limit=7`, - adminHeaders, + adminHeaders ) expect(response.status).toEqual(200) @@ -310,7 +307,7 @@ describe("/admin/product-categories", () => { const response = await api.get( `/admin/product-categories?handle=${productCategory.handle}&limit=2`, - adminHeaders, + adminHeaders ) expect(response.status).toEqual(200) @@ -323,12 +320,14 @@ describe("/admin/product-categories", () => { const response = await api.get( `/admin/product-categories?q=men&limit=1`, - adminHeaders, + adminHeaders ) expect(response.status).toEqual(200) expect(response.data.count).toEqual(1) - expect(response.data.product_categories[0].id).toEqual(productCategoryParent.id) + expect(response.data.product_categories[0].id).toEqual( + productCategoryParent.id + ) }) it("filters based on parent category", async () => { @@ -336,21 +335,22 @@ describe("/admin/product-categories", () => { const response = await api.get( `/admin/product-categories?parent_category_id=${productCategoryParent.id}&limit=7`, - adminHeaders, + adminHeaders ) expect(response.status).toEqual(200) expect(response.data.count).toEqual(1) expect(response.data.product_categories[0].id).toEqual(productCategory.id) - const nullCategoryResponse = await api.get( - `/admin/product-categories?parent_category_id=null`, - adminHeaders, - ).catch(e => e) + const nullCategoryResponse = await api + .get(`/admin/product-categories?parent_category_id=null`, adminHeaders) + .catch((e) => e) expect(nullCategoryResponse.status).toEqual(200) expect(nullCategoryResponse.data.count).toEqual(1) - expect(nullCategoryResponse.data.product_categories[0].id).toEqual(productCategoryParent.id) + expect(nullCategoryResponse.data.product_categories[0].id).toEqual( + productCategoryParent.id + ) }) it("adds all descendants to categories in a nested way", async () => { @@ -363,53 +363,51 @@ describe("/admin/product-categories", () => { expect(response.status).toEqual(200) expect(response.data.count).toEqual(1) - expect(response.data.product_categories).toEqual( - [ - expect.objectContaining({ - id: productCategoryParent.id, - rank: 0, - handle: productCategoryParent.handle, - category_children: [ - expect.objectContaining({ - id: productCategory.id, - rank: 0, - handle: productCategory.handle, - category_children: [ - expect.objectContaining({ - id: productCategoryChild.id, - category_children: [ - expect.objectContaining({ - id: productCategoryChild2.id, - category_children: [], - handle: productCategoryChild2.handle, - rank: 0 - }), - expect.objectContaining({ - id: productCategoryChild1.id, - category_children: [], - handle: productCategoryChild1.handle, - rank: 1 - }), - expect.objectContaining({ - id: productCategoryChild0.id, - category_children: [], - handle: productCategoryChild0.handle, - rank: 2 - }), - expect.objectContaining({ - id: productCategoryChild3.id, - category_children: [], - handle: productCategoryChild3.handle, - rank: 3 - }) - ], - }) - ] - }) - ], - }), - ] - ) + expect(response.data.product_categories).toEqual([ + expect.objectContaining({ + id: productCategoryParent.id, + rank: 0, + handle: productCategoryParent.handle, + category_children: [ + expect.objectContaining({ + id: productCategory.id, + rank: 0, + handle: productCategory.handle, + category_children: [ + expect.objectContaining({ + id: productCategoryChild.id, + category_children: [ + expect.objectContaining({ + id: productCategoryChild2.id, + category_children: [], + handle: productCategoryChild2.handle, + rank: 0, + }), + expect.objectContaining({ + id: productCategoryChild1.id, + category_children: [], + handle: productCategoryChild1.handle, + rank: 1, + }), + expect.objectContaining({ + id: productCategoryChild0.id, + category_children: [], + handle: productCategoryChild0.handle, + rank: 2, + }), + expect.objectContaining({ + id: productCategoryChild3.id, + category_children: [], + handle: productCategoryChild3.handle, + rank: 3, + }), + ], + }), + ], + }), + ], + }), + ]) }) }) @@ -437,11 +435,9 @@ describe("/admin/product-categories", () => { it("throws an error if required fields are missing", async () => { const api = useApi() - const error = await api.post( - `/admin/product-categories`, - {}, - adminHeaders - ).catch(e => e) + const error = await api + .post(`/admin/product-categories`, {}, adminHeaders) + .catch((e) => e) expect(error.response.status).toEqual(400) expect(error.response.data.type).toEqual("invalid_data") @@ -455,14 +451,12 @@ describe("/admin/product-categories", () => { const payload = { name: "test", handle: "test", - description: null + description: null, } - const error = await api.post( - `/admin/product-categories`, - payload, - adminHeaders - ).catch(e => e) + const error = await api + .post(`/admin/product-categories`, payload, adminHeaders) + .catch((e) => e) expect(error.response.status).toEqual(400) expect(error.response.data.type).toEqual("invalid_data") @@ -478,7 +472,7 @@ describe("/admin/product-categories", () => { handle: "test", is_internal: true, parent_category_id: productCategory.id, - description: "test" + description: "test", } const response = await api.post( @@ -499,7 +493,7 @@ describe("/admin/product-categories", () => { created_at: expect.any(String), updated_at: expect.any(String), parent_category: expect.objectContaining({ - id: payload.parent_category_id + id: payload.parent_category_id, }), category_children: [], rank: 0, @@ -534,7 +528,7 @@ describe("/admin/product-categories", () => { created_at: expect.any(String), updated_at: expect.any(String), parent_category: expect.objectContaining({ - id: productCategoryParent.id + id: productCategoryParent.id, }), category_children: [], rank: 1, @@ -570,11 +564,11 @@ describe("/admin/product-categories", () => { category_children: [ expect.objectContaining({ id: lastDescendant.id, - category_children: [] - }) - ] - }) - ] + category_children: [], + }), + ], + }), + ], }) ) }) @@ -598,13 +592,13 @@ describe("/admin/product-categories", () => { productCategory1 = await simpleProductCategoryFactory(dbConnection, { name: "category-1", parent_category: productCategoryParent, - rank: 1 + rank: 1, }) productCategory2 = await simpleProductCategoryFactory(dbConnection, { name: "category-2", parent_category: productCategoryParent, - rank: 2 + rank: 2, }) }) @@ -630,10 +624,12 @@ describe("/admin/product-categories", () => { it("throws a not allowed error for a category with children", async () => { const api = useApi() - const error = await api.delete( - `/admin/product-categories/${productCategoryParent.id}`, - adminHeaders - ).catch(e => e) + const error = await api + .delete( + `/admin/product-categories/${productCategoryParent.id}`, + adminHeaders + ) + .catch((e) => e) expect(error.response.status).toEqual(400) expect(error.response.data.type).toEqual("not_allowed") @@ -645,20 +641,18 @@ describe("/admin/product-categories", () => { it("deletes a product category with no children successfully", async () => { const api = useApi() - const deleteResponse = await api.delete( - `/admin/product-categories/${productCategory.id}`, - adminHeaders - ).catch(e => e) + const deleteResponse = await api + .delete(`/admin/product-categories/${productCategory.id}`, adminHeaders) + .catch((e) => e) expect(deleteResponse.status).toEqual(200) expect(deleteResponse.data.id).toEqual(productCategory.id) expect(deleteResponse.data.deleted).toBeTruthy() expect(deleteResponse.data.object).toEqual("product-category") - const errorFetchingDeleted = await api.get( - `/admin/product-categories/${productCategory.id}`, - adminHeaders - ).catch(e => e) + const errorFetchingDeleted = await api + .get(`/admin/product-categories/${productCategory.id}`, adminHeaders) + .catch((e) => e) expect(errorFetchingDeleted.response.status).toEqual(404) }) @@ -666,30 +660,29 @@ describe("/admin/product-categories", () => { it("deleting a product category reorders siblings accurately", async () => { const api = useApi() - const deleteResponse = await api.delete( - `/admin/product-categories/${productCategory.id}`, - adminHeaders - ).catch(e => e) + const deleteResponse = await api + .delete(`/admin/product-categories/${productCategory.id}`, adminHeaders) + .catch((e) => e) expect(deleteResponse.status).toEqual(200) - const siblingsResponse = await api.get( - `/admin/product-categories?parent_category_id=${productCategoryParent.id}`, - adminHeaders - ).catch(e => e) + const siblingsResponse = await api + .get( + `/admin/product-categories?parent_category_id=${productCategoryParent.id}`, + adminHeaders + ) + .catch((e) => e) - expect(siblingsResponse.data.product_categories).toEqual( - [ - expect.objectContaining({ - id: productCategory1.id, - rank: 0 - }), - expect.objectContaining({ - id: productCategory2.id, - rank: 1 - }), - ] - ) + expect(siblingsResponse.data.product_categories).toEqual([ + expect.objectContaining({ + id: productCategory1.id, + rank: 0, + }), + expect.objectContaining({ + id: productCategory2.id, + rank: 1, + }), + ]) }) }) @@ -704,19 +697,19 @@ describe("/admin/product-categories", () => { productCategory = await simpleProductCategoryFactory(dbConnection, { name: "category-0", parent_category: productCategoryParent, - rank: 0 + rank: 0, }) productCategory1 = await simpleProductCategoryFactory(dbConnection, { name: "category-1", parent_category: productCategoryParent, - rank: 1 + rank: 1, }) productCategory2 = await simpleProductCategoryFactory(dbConnection, { name: "category-2", parent_category: productCategoryParent, - rank: 2 + rank: 2, }) productCategoryChild = await simpleProductCategoryFactory(dbConnection, { @@ -734,7 +727,7 @@ describe("/admin/product-categories", () => { productCategoryChild1 = await simpleProductCategoryFactory(dbConnection, { name: "category child 1", parent_category: productCategoryChild, - rank: 1 + rank: 1, }) productCategoryChild2 = await simpleProductCategoryFactory(dbConnection, { @@ -758,13 +751,15 @@ describe("/admin/product-categories", () => { it("throws an error if invalid ID is sent", async () => { const api = useApi() - const error = await api.post( - `/admin/product-categories/not-found-id`, - { - name: 'testing' - }, - adminHeaders - ).catch(e => e) + const error = await api + .post( + `/admin/product-categories/not-found-id`, + { + name: "testing", + }, + adminHeaders + ) + .catch((e) => e) expect(error.response.status).toEqual(404) expect(error.response.data.type).toEqual("not_found") @@ -776,13 +771,15 @@ describe("/admin/product-categories", () => { it("throws an error if rank is negative", async () => { const api = useApi() - const error = await api.post( - `/admin/product-categories/not-found-id`, - { - rank: -1 - }, - adminHeaders - ).catch(e => e) + const error = await api + .post( + `/admin/product-categories/not-found-id`, + { + rank: -1, + }, + adminHeaders + ) + .catch((e) => e) expect(error.response.status).toEqual(400) expect(error.response.data.type).toEqual("invalid_data") @@ -794,13 +791,15 @@ describe("/admin/product-categories", () => { it("throws an error if invalid attribute is sent", async () => { const api = useApi() - const error = await api.post( - `/admin/product-categories/${productCategory.id}`, - { - invalid_property: 'string' - }, - adminHeaders - ).catch(e => e) + const error = await api + .post( + `/admin/product-categories/${productCategory.id}`, + { + invalid_property: "string", + }, + adminHeaders + ) + .catch((e) => e) expect(error.response.status).toEqual(400) expect(error.response.data.type).toEqual("invalid_data") @@ -888,20 +887,20 @@ describe("/admin/product-categories", () => { expect.objectContaining({ id: productCategoryChild.id, rank: 0, - }) + }), ], }), expect.objectContaining({ id: productCategory1.id, category_children: [], - rank: 1 + rank: 1, }), expect.objectContaining({ id: productCategory2.id, category_children: [], - rank: 2 + rank: 2, }), - ] + ], }) ) }) @@ -961,7 +960,7 @@ describe("/admin/product-categories", () => { const response = await api.post( `/admin/product-categories/${productCategoryChild1.id}`, { - rank: 0 + rank: 0, }, adminHeaders ) @@ -982,7 +981,7 @@ describe("/admin/product-categories", () => { const response = await api.post( `/admin/product-categories/${productCategoryChild1.id}`, { - rank: 99 + rank: 99, }, adminHeaders ) @@ -1002,7 +1001,7 @@ describe("/admin/product-categories", () => { const response = await api.post( `/admin/product-categories/${productCategoryChild2.id}`, { - rank: 0 + rank: 0, }, adminHeaders ) @@ -1018,7 +1017,7 @@ describe("/admin/product-categories", () => { category_children: [ expect.objectContaining({ id: productCategoryChild2.id, - rank: 0 + rank: 0, }), expect.objectContaining({ id: productCategoryChild0.id, @@ -1026,13 +1025,13 @@ describe("/admin/product-categories", () => { }), expect.objectContaining({ id: productCategoryChild1.id, - rank: 2 + rank: 2, }), expect.objectContaining({ id: productCategoryChild3.id, - rank: 3 + rank: 3, }), - ] + ], }) ) }) @@ -1091,14 +1090,14 @@ describe("/admin/product-categories", () => { expect(products[0].categories).toEqual([ expect.objectContaining({ - id: productCategory.id - }) + id: productCategory.id, + }), ]) expect(products[1].categories).toEqual([ expect.objectContaining({ - id: productCategory.id - }) + id: productCategory.id, + }), ]) }) @@ -1109,16 +1108,19 @@ describe("/admin/product-categories", () => { product_ids: [{ id: "product-id-invalid" }], } - const error = await api.post( - `/admin/product-categories/${productCategory.id}/products/batch`, - payload, - adminHeaders - ).catch(e => e) + const error = await api + .post( + `/admin/product-categories/${productCategory.id}/products/batch`, + payload, + adminHeaders + ) + .catch((e) => e) expect(error.response.status).toEqual(400) expect(error.response.data).toEqual({ errors: ["Products product-id-invalid do not exist"], - message: "Provided request body contains errors. Please check the data and retry the request" + message: + "Provided request body contains errors. Please check the data and retry the request", }) }) @@ -1126,11 +1128,13 @@ describe("/admin/product-categories", () => { const api = useApi() const payload = { product_ids: [] } - const error = await api.post( - `/admin/product-categories/invalid-category-id/products/batch`, - payload, - adminHeaders - ).catch(e => e) + const error = await api + .post( + `/admin/product-categories/invalid-category-id/products/batch`, + payload, + adminHeaders + ) + .catch((e) => e) expect(error.response.status).toEqual(404) expect(error.response.data).toEqual({ @@ -1143,11 +1147,13 @@ describe("/admin/product-categories", () => { const api = useApi() const payload = { product_ids: [] } - const error = await api.post( - `/admin/product-categories/invalid-category-id/products/batch?expand=products`, - payload, - adminHeaders - ).catch(e => e) + const error = await api + .post( + `/admin/product-categories/invalid-category-id/products/batch?expand=products`, + payload, + adminHeaders + ) + .catch((e) => e) expect(error.response.status).toEqual(400) expect(error.response.data).toEqual({ @@ -1176,7 +1182,7 @@ describe("/admin/product-categories", () => { productCategory = await simpleProductCategoryFactory(dbConnection, { id: "test-category", name: "test category", - products: [testProduct1, testProduct2] + products: [testProduct1, testProduct2], }) }) @@ -1216,8 +1222,8 @@ describe("/admin/product-categories", () => { expect(products[0].categories).toEqual([ expect.objectContaining({ - id: productCategory.id - }) + id: productCategory.id, + }), ]) expect(products[1].categories).toEqual([]) @@ -1230,18 +1236,21 @@ describe("/admin/product-categories", () => { product_ids: [{ id: "product-id-invalid" }], } - const error = await api.delete( - `/admin/product-categories/${productCategory.id}/products/batch`, - { - ...adminHeaders, - data: payload, - } - ).catch(e => e) + const error = await api + .delete( + `/admin/product-categories/${productCategory.id}/products/batch`, + { + ...adminHeaders, + data: payload, + } + ) + .catch((e) => e) expect(error.response.status).toEqual(400) expect(error.response.data).toEqual({ errors: ["Products product-id-invalid do not exist"], - message: "Provided request body contains errors. Please check the data and retry the request" + message: + "Provided request body contains errors. Please check the data and retry the request", }) }) @@ -1249,13 +1258,15 @@ describe("/admin/product-categories", () => { const api = useApi() const payload = { product_ids: [] } - const error = await api.delete( - `/admin/product-categories/invalid-category-id/products/batch`, - { - ...adminHeaders, - data: payload, - } - ).catch(e => e) + const error = await api + .delete( + `/admin/product-categories/invalid-category-id/products/batch`, + { + ...adminHeaders, + data: payload, + } + ) + .catch((e) => e) expect(error.response.status).toEqual(404) expect(error.response.data).toEqual({ @@ -1268,13 +1279,15 @@ describe("/admin/product-categories", () => { const api = useApi() const payload = { product_ids: [] } - const error = await api.delete( - `/admin/product-categories/invalid-category-id/products/batch?expand=products`, - { - ...adminHeaders, - data: payload, - } - ).catch(e => e) + const error = await api + .delete( + `/admin/product-categories/invalid-category-id/products/batch?expand=products`, + { + ...adminHeaders, + data: payload, + } + ) + .catch((e) => e) expect(error.response.status).toEqual(400) expect(error.response.data).toEqual({ diff --git a/integration-tests/api/__tests__/admin/product-tag.js b/integration-tests/api/__tests__/admin/product-tag.js index af26d63c13..06796975c5 100644 --- a/integration-tests/api/__tests__/admin/product-tag.js +++ b/integration-tests/api/__tests__/admin/product-tag.js @@ -2,17 +2,17 @@ const path = require("path") const { IdMap } = require("medusa-test-utils") -const setupServer = require("../../../helpers/setup-server") -const { useApi } = require("../../../helpers/use-api") -const { initDb, useDb } = require("../../../helpers/use-db") +const setupServer = require("../../../environment-helpers/setup-server") +const { useApi } = require("../../../environment-helpers/use-api") +const { initDb, useDb } = require("../../../environment-helpers/use-db") -const adminSeeder = require("../../helpers/admin-seeder") -const productSeeder = require("../../helpers/product-seeder") +const adminSeeder = require("../../../helpers/admin-seeder") +const productSeeder = require("../../../helpers/product-seeder") const { DiscountConditionType, DiscountConditionOperator, } = require("@medusajs/medusa") -const { simpleDiscountFactory } = require("../../factories") +const { simpleDiscountFactory } = require("../../../factories") const { DiscountRuleType, AllocationType } = require("@medusajs/medusa/dist") jest.setTimeout(50000) diff --git a/integration-tests/api/__tests__/admin/product-type.js b/integration-tests/api/__tests__/admin/product-type.js index b9c9b18f14..f1bf11e0a4 100644 --- a/integration-tests/api/__tests__/admin/product-type.js +++ b/integration-tests/api/__tests__/admin/product-type.js @@ -2,19 +2,19 @@ const path = require("path") const { IdMap } = require("medusa-test-utils") -const setupServer = require("../../../helpers/setup-server") -const { useApi } = require("../../../helpers/use-api") -const { initDb, useDb } = require("../../../helpers/use-db") +const setupServer = require("../../../environment-helpers/setup-server") +const { useApi } = require("../../../environment-helpers/use-api") +const { initDb, useDb } = require("../../../environment-helpers/use-db") -const adminSeeder = require("../../helpers/admin-seeder") -const productSeeder = require("../../helpers/product-seeder") +const adminSeeder = require("../../../helpers/admin-seeder") +const productSeeder = require("../../../helpers/product-seeder") const { DiscountRuleType, AllocationType, DiscountConditionType, DiscountConditionOperator, } = require("@medusajs/medusa") -const { simpleDiscountFactory } = require("../../factories") +const { simpleDiscountFactory } = require("../../../factories") jest.setTimeout(50000) diff --git a/integration-tests/api/__tests__/admin/product.js b/integration-tests/api/__tests__/admin/product.js index e20f0f23e5..e373bb2974 100644 --- a/integration-tests/api/__tests__/admin/product.js +++ b/integration-tests/api/__tests__/admin/product.js @@ -1,11 +1,11 @@ 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("../../../environment-helpers/setup-server") +const { useApi } = require("../../../environment-helpers/use-api") +const { initDb, useDb } = require("../../../environment-helpers/use-db") -const adminSeeder = require("../../helpers/admin-seeder") -const productSeeder = require("../../helpers/product-seeder") +const adminSeeder = require("../../../helpers/admin-seeder") +const productSeeder = require("../../../helpers/product-seeder") const { ProductVariant, @@ -14,13 +14,13 @@ const { DiscountConditionType, DiscountConditionOperator, } = require("@medusajs/medusa") -const priceListSeeder = require("../../helpers/price-list-seeder") +const priceListSeeder = require("../../../helpers/price-list-seeder") const { simpleProductFactory, simpleDiscountFactory, simpleSalesChannelFactory, simpleRegionFactory, -} = require("../../factories") +} = require("../../../factories") const { DiscountRuleType, AllocationType } = require("@medusajs/medusa/dist") const { IdMap } = require("medusa-test-utils") diff --git a/integration-tests/api/__tests__/admin/products/ff-product-categories.js b/integration-tests/api/__tests__/admin/products/ff-product-categories.js index f366d182d6..809d6e8578 100644 --- a/integration-tests/api/__tests__/admin/products/ff-product-categories.js +++ b/integration-tests/api/__tests__/admin/products/ff-product-categories.js @@ -1,15 +1,15 @@ const path = require("path") const { ProductCategory } = 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 productSeeder = require("../../../helpers/product-seeder") +const setupServer = require("../../../../environment-helpers/setup-server") +const { useApi } = require("../../../../environment-helpers/use-api") +const { initDb, useDb } = require("../../../../environment-helpers/use-db") +const adminSeeder = require("../../../../helpers/admin-seeder") +const productSeeder = require("../../../../helpers/product-seeder") const { simpleProductCategoryFactory, simpleSalesChannelFactory, -} = require("../../../factories") +} = require("../../../../factories") const testProductId = "test-product" const testProduct1Id = "test-product1" diff --git a/integration-tests/api/__tests__/admin/publishable-api-key.js b/integration-tests/api/__tests__/admin/publishable-api-key.js index 709c72388b..2dbe536ea7 100644 --- a/integration-tests/api/__tests__/admin/publishable-api-key.js +++ b/integration-tests/api/__tests__/admin/publishable-api-key.js @@ -1,18 +1,18 @@ const path = require("path") const { IdMap } = require("medusa-test-utils") -const { useApi } = require("../../../helpers/use-api") -const { useDb, initDb } = require("../../../helpers/use-db") -const adminSeeder = require("../../helpers/admin-seeder") +const { useApi } = require("../../../environment-helpers/use-api") +const { useDb, initDb } = require("../../../environment-helpers/use-db") +const adminSeeder = require("../../../helpers/admin-seeder") const { simplePublishableApiKeyFactory, -} = require("../../factories/simple-publishable-api-key-factory") +} = require("../../../factories/simple-publishable-api-key-factory") const { simpleSalesChannelFactory, simpleProductFactory, simpleRegionFactory, -} = require("../../factories") -const setupServer = require("../../../helpers/setup-server") +} = require("../../../factories") +const setupServer = require("../../../environment-helpers/setup-server") jest.setTimeout(50000) diff --git a/integration-tests/api/__tests__/admin/region.js b/integration-tests/api/__tests__/admin/region.js index 8a37e3a282..972a6cbfff 100644 --- a/integration-tests/api/__tests__/admin/region.js +++ b/integration-tests/api/__tests__/admin/region.js @@ -1,13 +1,13 @@ const path = require("path") const { Region } = require("@medusajs/medusa") -const setupServer = require("../../../helpers/setup-server") +const setupServer = require("../../../environment-helpers/setup-server") const startServerWithEnvironment = - require("../../../helpers/start-server-with-environment").default -const { useApi } = require("../../../helpers/use-api") -const { initDb, useDb } = require("../../../helpers/use-db") -const adminSeeder = require("../../helpers/admin-seeder") -const { simpleRegionFactory } = require("../../factories") + require("../../../environment-helpers/start-server-with-environment").default +const { useApi } = require("../../../environment-helpers/use-api") +const { initDb, useDb } = require("../../../environment-helpers/use-db") +const adminSeeder = require("../../../helpers/admin-seeder") +const { simpleRegionFactory } = require("../../../factories") const adminReqConfig = { headers: { diff --git a/integration-tests/api/__tests__/admin/return-reason.js b/integration-tests/api/__tests__/admin/return-reason.js index 917ea05e4e..061f291170 100644 --- a/integration-tests/api/__tests__/admin/return-reason.js +++ b/integration-tests/api/__tests__/admin/return-reason.js @@ -1,10 +1,10 @@ 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("../../../environment-helpers/setup-server") +const { useApi } = require("../../../environment-helpers/use-api") +const { initDb, useDb } = require("../../../environment-helpers/use-db") -const adminSeeder = require("../../helpers/admin-seeder") +const adminSeeder = require("../../../helpers/admin-seeder") jest.setTimeout(30000) diff --git a/integration-tests/api/__tests__/admin/returns.js b/integration-tests/api/__tests__/admin/returns.js index ecb4507580..c89b7eae31 100644 --- a/integration-tests/api/__tests__/admin/returns.js +++ b/integration-tests/api/__tests__/admin/returns.js @@ -2,12 +2,12 @@ const path = require("path") import { ReturnReason, ShippingMethod } from "@medusajs/medusa" import { createReturnableOrder } from "../claims" -const setupServer = require("../../../helpers/setup-server") -const { useApi } = require("../../../helpers/use-api") -const { initDb, useDb } = require("../../../helpers/use-db") +const setupServer = require("../../../environment-helpers/setup-server") +const { useApi } = require("../../../environment-helpers/use-api") +const { initDb, useDb } = require("../../../environment-helpers/use-db") -const orderSeeder = require("../../helpers/order-seeder") -const adminSeeder = require("../../helpers/admin-seeder") +const orderSeeder = require("../../../helpers/order-seeder") +const adminSeeder = require("../../../helpers/admin-seeder") jest.setTimeout(30000) diff --git a/integration-tests/api/__tests__/admin/sales-channels.js b/integration-tests/api/__tests__/admin/sales-channels.js index 4a14d77f65..197c47a014 100644 --- a/integration-tests/api/__tests__/admin/sales-channels.js +++ b/integration-tests/api/__tests__/admin/sales-channels.js @@ -2,20 +2,20 @@ const path = require("path") const { SalesChannel, Product } = require("@medusajs/medusa") -const { useApi } = require("../../../helpers/use-api") -const { useDb } = require("../../../helpers/use-db") +const { useApi } = require("../../../environment-helpers/use-api") +const { useDb } = require("../../../environment-helpers/use-db") -const adminSeeder = require("../../helpers/admin-seeder") +const adminSeeder = require("../../../helpers/admin-seeder") const { simpleSalesChannelFactory, simpleProductFactory, -} = require("../../factories") -const { simpleOrderFactory } = require("../../factories") -const orderSeeder = require("../../helpers/order-seeder") -const productSeeder = require("../../helpers/product-seeder") +} = require("../../../factories") +const { simpleOrderFactory } = require("../../../factories") +const orderSeeder = require("../../../helpers/order-seeder") +const productSeeder = require("../../../helpers/product-seeder") const startServerWithEnvironment = - require("../../../helpers/start-server-with-environment").default + require("../../../environment-helpers/start-server-with-environment").default const adminReqConfig = { headers: { diff --git a/integration-tests/api/__tests__/admin/shipping-options.js b/integration-tests/api/__tests__/admin/shipping-options.js index 95ebdca49c..c194c1f374 100644 --- a/integration-tests/api/__tests__/admin/shipping-options.js +++ b/integration-tests/api/__tests__/admin/shipping-options.js @@ -1,17 +1,17 @@ const path = require("path") const { ShippingProfile } = require("@medusajs/medusa") -const setupServer = require("../../../helpers/setup-server") +const setupServer = require("../../../environment-helpers/setup-server") const startServerWithEnvironment = - require("../../../helpers/start-server-with-environment").default -const { useApi } = require("../../../helpers/use-api") -const { initDb, useDb } = require("../../../helpers/use-db") -const adminSeeder = require("../../helpers/admin-seeder") -const shippingOptionSeeder = require("../../helpers/shipping-option-seeder") + require("../../../environment-helpers/start-server-with-environment").default +const { useApi } = require("../../../environment-helpers/use-api") +const { initDb, useDb } = require("../../../environment-helpers/use-db") +const adminSeeder = require("../../../helpers/admin-seeder") +const shippingOptionSeeder = require("../../../helpers/shipping-option-seeder") const { simpleShippingOptionFactory, simpleRegionFactory, -} = require("../../factories") +} = require("../../../factories") const adminReqConfig = { headers: { diff --git a/integration-tests/api/__tests__/admin/shipping-profile.js b/integration-tests/api/__tests__/admin/shipping-profile.js index 2abfefe8fb..40d7401660 100644 --- a/integration-tests/api/__tests__/admin/shipping-profile.js +++ b/integration-tests/api/__tests__/admin/shipping-profile.js @@ -1,14 +1,14 @@ 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("../../../environment-helpers/setup-server") +const { useApi } = require("../../../environment-helpers/use-api") +const { initDb, useDb } = require("../../../environment-helpers/use-db") const { simpleProductFactory, simpleShippingOptionFactory, simpleShippingProfileFactory, -} = require("../../factories") -const adminSeeder = require("../../helpers/admin-seeder") +} = require("../../../factories") +const adminSeeder = require("../../../helpers/admin-seeder") const adminReqConfig = { headers: { diff --git a/integration-tests/api/__tests__/admin/store.js b/integration-tests/api/__tests__/admin/store.js index fc93e339e1..628b1ba417 100644 --- a/integration-tests/api/__tests__/admin/store.js +++ b/integration-tests/api/__tests__/admin/store.js @@ -1,11 +1,11 @@ const { Store } = require("@medusajs/medusa") 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("../../../environment-helpers/setup-server") +const { useApi } = require("../../../environment-helpers/use-api") +const { initDb, useDb } = require("../../../environment-helpers/use-db") -const adminSeeder = require("../../helpers/admin-seeder") +const adminSeeder = require("../../../helpers/admin-seeder") jest.setTimeout(30000) diff --git a/integration-tests/api/__tests__/admin/swaps.js b/integration-tests/api/__tests__/admin/swaps.js index 0e09861eb4..4dc87b4ebd 100644 --- a/integration-tests/api/__tests__/admin/swaps.js +++ b/integration-tests/api/__tests__/admin/swaps.js @@ -1,12 +1,12 @@ 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("../../../environment-helpers/setup-server") +const { useApi } = require("../../../environment-helpers/use-api") +const { initDb, useDb } = require("../../../environment-helpers/use-db") -const orderSeeder = require("../../helpers/order-seeder") -const swapSeeder = require("../../helpers/swap-seeder") -const adminSeeder = require("../../helpers/admin-seeder") +const orderSeeder = require("../../../helpers/order-seeder") +const swapSeeder = require("../../../helpers/swap-seeder") +const adminSeeder = require("../../../helpers/admin-seeder") const { simpleProductFactory, @@ -14,13 +14,13 @@ const { simpleDiscountFactory, simpleRegionFactory, simpleShippingOptionFactory, -} = require("../../factories") +} = require("../../../factories") const { simpleCustomerFactory, -} = require("../../factories/simple-customer-factory") +} = require("../../../factories/simple-customer-factory") const { default: startServerWithEnvironment, -} = require("../../../helpers/start-server-with-environment") +} = require("../../../environment-helpers/start-server-with-environment") jest.setTimeout(30000) diff --git a/integration-tests/api/__tests__/admin/user.js b/integration-tests/api/__tests__/admin/user.js index 4870c6158e..319735bea5 100644 --- a/integration-tests/api/__tests__/admin/user.js +++ b/integration-tests/api/__tests__/admin/user.js @@ -1,17 +1,17 @@ const jwt = require("jsonwebtoken") 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("../../../environment-helpers/setup-server") +const { useApi } = require("../../../environment-helpers/use-api") +const { initDb, useDb } = require("../../../environment-helpers/use-db") -const userSeeder = require("../../helpers/user-seeder") -const adminSeeder = require("../../helpers/admin-seeder") +const userSeeder = require("../../../helpers/user-seeder") +const adminSeeder = require("../../../helpers/admin-seeder") const { simpleAnalyticsConfigFactory, -} = require("../../factories/simple-analytics-config-factory") +} = require("../../../factories/simple-analytics-config-factory") const startServerWithEnvironment = - require("../../../helpers/start-server-with-environment").default + require("../../../environment-helpers/start-server-with-environment").default jest.setTimeout(30000) diff --git a/integration-tests/api/__tests__/admin/variant.js b/integration-tests/api/__tests__/admin/variant.js index fa82c077e3..b82e045b3c 100644 --- a/integration-tests/api/__tests__/admin/variant.js +++ b/integration-tests/api/__tests__/admin/variant.js @@ -1,13 +1,13 @@ const path = require("path") -const setupServer = require("../../../helpers/setup-server") -const { useApi } = require("../../../helpers/use-api") -const { initDb, useDb } = require("../../../helpers/use-db") -const { simpleProductFactory } = require("../../factories") +const setupServer = require("../../../environment-helpers/setup-server") +const { useApi } = require("../../../environment-helpers/use-api") +const { initDb, useDb } = require("../../../environment-helpers/use-db") +const { simpleProductFactory } = require("../../../factories") -const adminSeeder = require("../../helpers/admin-seeder") -const adminVariantsSeeder = require("../../helpers/admin-variants-seeder") -const productSeeder = require("../../helpers/product-seeder") +const adminSeeder = require("../../../helpers/admin-seeder") +const adminVariantsSeeder = require("../../../helpers/admin-variants-seeder") +const productSeeder = require("../../../helpers/product-seeder") const adminHeaders = { headers: { diff --git a/integration-tests/api/__tests__/batch-jobs/api.js b/integration-tests/api/__tests__/batch-jobs/api.js index c1ff1e7518..9bb561c87b 100644 --- a/integration-tests/api/__tests__/batch-jobs/api.js +++ b/integration-tests/api/__tests__/batch-jobs/api.js @@ -1,13 +1,13 @@ 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("../../../environment-helpers/setup-server") +const { useApi } = require("../../../environment-helpers/use-api") +const { initDb, useDb } = require("../../../environment-helpers/use-db") -const adminSeeder = require("../../helpers/admin-seeder") -const userSeeder = require("../../helpers/user-seeder") +const adminSeeder = require("../../../helpers/admin-seeder") +const userSeeder = require("../../../helpers/user-seeder") -const { simpleBatchJobFactory } = require("../../factories") +const { simpleBatchJobFactory } = require("../../../factories") jest.setTimeout(50000) diff --git a/integration-tests/api/__tests__/batch-jobs/order/export.js b/integration-tests/api/__tests__/batch-jobs/order/export.js index 63be7859f6..fcf92e91d3 100644 --- a/integration-tests/api/__tests__/batch-jobs/order/export.js +++ b/integration-tests/api/__tests__/batch-jobs/order/export.js @@ -2,13 +2,13 @@ const path = require("path") const fs = require("fs/promises") import { resolve, sep } from "path" -const setupServer = require("../../../../helpers/setup-server") -const { useApi } = require("../../../../helpers/use-api") -const { initDb, useDb } = require("../../../../helpers/use-db") +const setupServer = require("../../../../environment-helpers/setup-server") +const { useApi } = require("../../../../environment-helpers/use-api") +const { initDb, useDb } = require("../../../../environment-helpers/use-db") -const adminSeeder = require("../../../helpers/admin-seeder") -const userSeeder = require("../../../helpers/user-seeder") -const orderSeeder = require("../../../helpers/order-seeder") +const adminSeeder = require("../../../../helpers/admin-seeder") +const userSeeder = require("../../../../helpers/user-seeder") +const orderSeeder = require("../../../../helpers/order-seeder") const adminReqConfig = { headers: { diff --git a/integration-tests/api/__tests__/batch-jobs/price-list/import.js b/integration-tests/api/__tests__/batch-jobs/price-list/import.js index 02605049c5..1913550148 100644 --- a/integration-tests/api/__tests__/batch-jobs/price-list/import.js +++ b/integration-tests/api/__tests__/batch-jobs/price-list/import.js @@ -1,16 +1,16 @@ const fs = require("fs") 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("../../../../environment-helpers/setup-server") +const { useApi } = require("../../../../environment-helpers/use-api") +const { initDb, useDb } = require("../../../../environment-helpers/use-db") -const adminSeeder = require("../../../helpers/admin-seeder") +const adminSeeder = require("../../../../helpers/admin-seeder") const { simpleRegionFactory, simplePriceListFactory, simpleProductFactory, -} = require("../../../factories") +} = require("../../../../factories") const adminReqConfig = { headers: { diff --git a/integration-tests/api/__tests__/batch-jobs/product/export.js b/integration-tests/api/__tests__/batch-jobs/product/export.js index 69255c34d2..5f04a8aeab 100644 --- a/integration-tests/api/__tests__/batch-jobs/product/export.js +++ b/integration-tests/api/__tests__/batch-jobs/product/export.js @@ -1,15 +1,15 @@ const path = require("path") const fs = require("fs/promises") import { resolve, sep } from "path" -import { simpleSalesChannelFactory } from "../../../factories" +import { simpleSalesChannelFactory } from "../../../../factories" -const setupServer = require("../../../../helpers/setup-server") -const { useApi } = require("../../../../helpers/use-api") -const { initDb, useDb } = require("../../../../helpers/use-db") +const setupServer = require("../../../../environment-helpers/setup-server") +const { useApi } = require("../../../../environment-helpers/use-api") +const { initDb, useDb } = require("../../../../environment-helpers/use-db") -const adminSeeder = require("../../../helpers/admin-seeder") -const userSeeder = require("../../../helpers/user-seeder") -const productSeeder = require("../../../helpers/product-seeder") +const adminSeeder = require("../../../../helpers/admin-seeder") +const userSeeder = require("../../../../helpers/user-seeder") +const productSeeder = require("../../../../helpers/product-seeder") const adminReqConfig = { headers: { diff --git a/integration-tests/api/__tests__/batch-jobs/product/ff-product-category.js b/integration-tests/api/__tests__/batch-jobs/product/ff-product-category.js index f424a9a522..1174f67467 100644 --- a/integration-tests/api/__tests__/batch-jobs/product/ff-product-category.js +++ b/integration-tests/api/__tests__/batch-jobs/product/ff-product-category.js @@ -1,19 +1,19 @@ const fs = require("fs") const path = require("path") -const { useApi } = require("../../../../helpers/use-api") -const { useDb } = require("../../../../helpers/use-db") +const { useApi } = require("../../../../environment-helpers/use-api") +const { useDb } = require("../../../../environment-helpers/use-db") -const adminSeeder = require("../../../helpers/admin-seeder") -const userSeeder = require("../../../helpers/user-seeder") -const { simpleProductCategoryFactory } = require("../../../factories") -const batchJobSeeder = require("../../../helpers/batch-job-seeder") +const adminSeeder = require("../../../../helpers/admin-seeder") +const userSeeder = require("../../../../helpers/user-seeder") +const { simpleProductCategoryFactory } = require("../../../../factories") +const batchJobSeeder = require("../../../../helpers/batch-job-seeder") const { simpleProductCollectionFactory, -} = require("../../../factories/simple-product-collection-factory") +} = require("../../../../factories/simple-product-collection-factory") const startServerWithEnvironment = - require("../../../../helpers/start-server-with-environment").default + require("../../../../environment-helpers/start-server-with-environment").default jest.setTimeout(30000) diff --git a/integration-tests/api/__tests__/batch-jobs/product/ff-sales-channel.js b/integration-tests/api/__tests__/batch-jobs/product/ff-sales-channel.js index 920331249f..95b46a16b5 100644 --- a/integration-tests/api/__tests__/batch-jobs/product/ff-sales-channel.js +++ b/integration-tests/api/__tests__/batch-jobs/product/ff-sales-channel.js @@ -1,19 +1,19 @@ const fs = require("fs") const path = require("path") -const { useApi } = require("../../../../helpers/use-api") -const { useDb } = require("../../../../helpers/use-db") +const { useApi } = require("../../../../environment-helpers/use-api") +const { useDb } = require("../../../../environment-helpers/use-db") -const adminSeeder = require("../../../helpers/admin-seeder") -const userSeeder = require("../../../helpers/user-seeder") -const { simpleSalesChannelFactory } = require("../../../factories") -const batchJobSeeder = require("../../../helpers/batch-job-seeder") +const adminSeeder = require("../../../../helpers/admin-seeder") +const userSeeder = require("../../../../helpers/user-seeder") +const { simpleSalesChannelFactory } = require("../../../../factories") +const batchJobSeeder = require("../../../../helpers/batch-job-seeder") const { simpleProductCollectionFactory, -} = require("../../../factories/simple-product-collection-factory") +} = require("../../../../factories/simple-product-collection-factory") const startServerWithEnvironment = - require("../../../../helpers/start-server-with-environment").default + require("../../../../environment-helpers/start-server-with-environment").default jest.setTimeout(30000) diff --git a/integration-tests/api/__tests__/batch-jobs/product/import.js b/integration-tests/api/__tests__/batch-jobs/product/import.js index 0f875df5cc..e5bfb8f0c5 100644 --- a/integration-tests/api/__tests__/batch-jobs/product/import.js +++ b/integration-tests/api/__tests__/batch-jobs/product/import.js @@ -1,17 +1,17 @@ const fs = require("fs") 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("../../../../environment-helpers/setup-server") +const { useApi } = require("../../../../environment-helpers/use-api") +const { initDb, useDb } = require("../../../../environment-helpers/use-db") -const adminSeeder = require("../../../helpers/admin-seeder") -const batchJobSeeder = require("../../../helpers/batch-job-seeder") -const userSeeder = require("../../../helpers/user-seeder") -const { simpleProductFactory } = require("../../../factories") +const adminSeeder = require("../../../../helpers/admin-seeder") +const batchJobSeeder = require("../../../../helpers/batch-job-seeder") +const userSeeder = require("../../../../helpers/user-seeder") +const { simpleProductFactory } = require("../../../../factories") const { simpleProductCollectionFactory, -} = require("../../../factories/simple-product-collection-factory") +} = require("../../../../factories/simple-product-collection-factory") const adminReqConfig = { headers: { diff --git a/integration-tests/api/__tests__/claims/index.js b/integration-tests/api/__tests__/claims/index.js index cc7690bc28..63413b7183 100644 --- a/integration-tests/api/__tests__/claims/index.js +++ b/integration-tests/api/__tests__/claims/index.js @@ -1,17 +1,17 @@ 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("../../../environment-helpers/setup-server") +const { useApi } = require("../../../environment-helpers/use-api") +const { initDb, useDb } = require("../../../environment-helpers/use-db") -const adminSeeder = require("../../helpers/admin-seeder") +const adminSeeder = require("../../../helpers/admin-seeder") const { simpleOrderFactory, simpleShippingOptionFactory, simplePaymentFactory, simpleProductFactory, -} = require("../../factories") +} = require("../../../factories") describe("Claims", () => { let medusaProcess diff --git a/integration-tests/api/__tests__/database/index.js b/integration-tests/api/__tests__/database/index.js index 27d3ae4b19..8243880213 100644 --- a/integration-tests/api/__tests__/database/index.js +++ b/integration-tests/api/__tests__/database/index.js @@ -1,7 +1,7 @@ const path = require("path") -const setupServer = require("../../../helpers/setup-server") -const { initDb, useDb } = require("../../../helpers/use-db") +const setupServer = require("../../../environment-helpers/setup-server") +const { initDb, useDb } = require("../../../environment-helpers/use-db") jest.setTimeout(30000) diff --git a/integration-tests/api/__tests__/line-item-adjustments/ff-sales-channel.js b/integration-tests/api/__tests__/line-item-adjustments/ff-sales-channel.js index e3d85a809f..b9238cd61f 100644 --- a/integration-tests/api/__tests__/line-item-adjustments/ff-sales-channel.js +++ b/integration-tests/api/__tests__/line-item-adjustments/ff-sales-channel.js @@ -1,11 +1,14 @@ const path = require("path") -const { useDb } = require("../../../helpers/use-db") -const { useApi } = require("../../../helpers/use-api") -const { simpleCartFactory, simpleProductFactory } = require("../../factories") +const { useDb } = require("../../../environment-helpers/use-db") +const { useApi } = require("../../../environment-helpers/use-api") +const { + simpleCartFactory, + simpleProductFactory, +} = require("../../../factories") const startServerWithEnvironment = - require("../../../helpers/start-server-with-environment").default + require("../../../environment-helpers/start-server-with-environment").default jest.setTimeout(30000) diff --git a/integration-tests/api/__tests__/line-item-adjustments/index.js b/integration-tests/api/__tests__/line-item-adjustments/index.js index 72c961adde..8574b68cd1 100644 --- a/integration-tests/api/__tests__/line-item-adjustments/index.js +++ b/integration-tests/api/__tests__/line-item-adjustments/index.js @@ -1,13 +1,16 @@ const path = require("path") const { LineItemAdjustment } = require("@medusajs/medusa") -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 { simpleCartFactory, simpleLineItemFactory } = require("../../factories") +const setupServer = require("../../../environment-helpers/setup-server") +const { useApi } = require("../../../environment-helpers/use-api") +const { initDb, useDb } = require("../../../environment-helpers/use-db") +const cartSeeder = require("../../../helpers/cart-seeder") +const { + simpleCartFactory, + simpleLineItemFactory, +} = require("../../../factories") const { simpleDiscountFactory, -} = require("../../factories/simple-discount-factory") +} = require("../../../factories/simple-discount-factory") jest.setTimeout(30000) diff --git a/integration-tests/api/__tests__/price-selection/index.js b/integration-tests/api/__tests__/price-selection/index.js index 58c55f732d..47e318b500 100644 --- a/integration-tests/api/__tests__/price-selection/index.js +++ b/integration-tests/api/__tests__/price-selection/index.js @@ -1,11 +1,11 @@ const path = require("path") -const setupServer = require("../../../helpers/setup-server") -const { useApi } = require("../../../helpers/use-api") -const { useDb, initDb } = require("../../../helpers/use-db") +const setupServer = require("../../../environment-helpers/setup-server") +const { useApi } = require("../../../environment-helpers/use-api") +const { useDb, initDb } = require("../../../environment-helpers/use-db") -const adminSeeder = require("../../helpers/admin-seeder") -const promotionsSeeder = require("../../helpers/price-selection-seeder") +const adminSeeder = require("../../../helpers/admin-seeder") +const promotionsSeeder = require("../../../helpers/price-selection-seeder") jest.setTimeout(30000) diff --git a/integration-tests/api/__tests__/price-selection/tax-inclusive-prices.js b/integration-tests/api/__tests__/price-selection/tax-inclusive-prices.js index 0f14358cf5..9bee85d65f 100644 --- a/integration-tests/api/__tests__/price-selection/tax-inclusive-prices.js +++ b/integration-tests/api/__tests__/price-selection/tax-inclusive-prices.js @@ -2,9 +2,9 @@ const { Currency, Region } = require("@medusajs/medusa") const path = require("path") const startServerWithEnvironment = - require("../../../helpers/start-server-with-environment").default -const { useApi } = require("../../../helpers/use-api") -const { useDb } = require("../../../helpers/use-db") + require("../../../environment-helpers/start-server-with-environment").default +const { useApi } = require("../../../environment-helpers/use-api") +const { useDb } = require("../../../environment-helpers/use-db") const { simpleProductFactory, simpleRegionFactory, @@ -12,10 +12,10 @@ const { simpleProductTaxRateFactory, simpleShippingOptionFactory, simpleShippingTaxRateFactory, -} = require("../../factories") +} = require("../../../factories") -const adminSeeder = require("../../helpers/admin-seeder") -const promotionsSeeder = require("../../helpers/price-selection-seeder") +const adminSeeder = require("../../../helpers/admin-seeder") +const promotionsSeeder = require("../../../helpers/price-selection-seeder") jest.setTimeout(30000) diff --git a/integration-tests/api/__tests__/returns/ff-tax-inclusive-pricing.js b/integration-tests/api/__tests__/returns/ff-tax-inclusive-pricing.js index 5b724a78ee..dbbeea9819 100644 --- a/integration-tests/api/__tests__/returns/ff-tax-inclusive-pricing.js +++ b/integration-tests/api/__tests__/returns/ff-tax-inclusive-pricing.js @@ -1,12 +1,15 @@ const path = require("path") const startServerWithEnvironment = - require("../../../helpers/start-server-with-environment").default -const { useApi } = require("../../../helpers/use-api") -const { useDb } = require("../../../helpers/use-db") + require("../../../environment-helpers/start-server-with-environment").default +const { useApi } = require("../../../environment-helpers/use-api") +const { useDb } = require("../../../environment-helpers/use-db") -const { simpleProductFactory, simpleOrderFactory } = require("../../factories") -const adminSeeder = require("../../helpers/admin-seeder") +const { + simpleProductFactory, + simpleOrderFactory, +} = require("../../../factories") +const adminSeeder = require("../../../helpers/admin-seeder") const createReturnableOrder = async (dbConnection, options) => { await simpleProductFactory( diff --git a/integration-tests/api/__tests__/returns/index.js b/integration-tests/api/__tests__/returns/index.js index de02d11553..c71fb1e8fd 100644 --- a/integration-tests/api/__tests__/returns/index.js +++ b/integration-tests/api/__tests__/returns/index.js @@ -1,20 +1,20 @@ 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("../../../environment-helpers/setup-server") +const { useApi } = require("../../../environment-helpers/use-api") +const { initDb, useDb } = require("../../../environment-helpers/use-db") -const adminSeeder = require("../../helpers/admin-seeder") +const adminSeeder = require("../../../helpers/admin-seeder") const { simpleOrderFactory, simpleProductFactory, simpleShippingOptionFactory, simpleRegionFactory, -} = require("../../factories") +} = require("../../../factories") const { simpleDiscountFactory, -} = require("../../factories/simple-discount-factory") +} = require("../../../factories/simple-discount-factory") jest.setTimeout(30000) diff --git a/integration-tests/api/__tests__/store/auth.js b/integration-tests/api/__tests__/store/auth.js index bbbad80746..24021abc2d 100644 --- a/integration-tests/api/__tests__/store/auth.js +++ b/integration-tests/api/__tests__/store/auth.js @@ -1,8 +1,8 @@ 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("../../../environment-helpers/setup-server") +const { useApi } = require("../../../environment-helpers/use-api") +const { initDb, useDb } = require("../../../environment-helpers/use-db") const { Customer } = require("@medusajs/medusa") diff --git a/integration-tests/api/__tests__/store/cart/cart.js b/integration-tests/api/__tests__/store/cart/cart.js index 8d0d22b93f..6555ee1ad8 100644 --- a/integration-tests/api/__tests__/store/cart/cart.js +++ b/integration-tests/api/__tests__/store/cart/cart.js @@ -9,12 +9,12 @@ const { MoneyAmount, } = 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("../../../../environment-helpers/setup-server") +const { useApi } = require("../../../../environment-helpers/use-api") +const { initDb, useDb } = require("../../../../environment-helpers/use-db") -const cartSeeder = require("../../../helpers/cart-seeder") -const swapSeeder = require("../../../helpers/swap-seeder") +const cartSeeder = require("../../../../helpers/cart-seeder") +const swapSeeder = require("../../../../helpers/swap-seeder") const { simpleCartFactory, simpleRegionFactory, @@ -22,16 +22,16 @@ const { simpleShippingOptionFactory, simpleLineItemFactory, simpleSalesChannelFactory, -} = require("../../../factories") +} = require("../../../../factories") const { simpleDiscountFactory, -} = require("../../../factories/simple-discount-factory") +} = require("../../../../factories/simple-discount-factory") const { simpleCustomerFactory, -} = require("../../../factories/simple-customer-factory") +} = require("../../../../factories/simple-customer-factory") const { simpleCustomerGroupFactory, -} = require("../../../factories/simple-customer-group-factory") +} = require("../../../../factories/simple-customer-group-factory") jest.setTimeout(30000) diff --git a/integration-tests/api/__tests__/store/cart/ff-sales-channels.js b/integration-tests/api/__tests__/store/cart/ff-sales-channels.js index 367374723e..0fbf62d56d 100644 --- a/integration-tests/api/__tests__/store/cart/ff-sales-channels.js +++ b/integration-tests/api/__tests__/store/cart/ff-sales-channels.js @@ -1,14 +1,14 @@ const path = require("path") const startServerWithEnvironment = - require("../../../../helpers/start-server-with-environment").default -const { useApi } = require("../../../../helpers/use-api") -const { useDb } = require("../../../../helpers/use-db") + require("../../../../environment-helpers/start-server-with-environment").default +const { useApi } = require("../../../../environment-helpers/use-api") +const { useDb } = require("../../../../environment-helpers/use-db") const { simpleRegionFactory, simpleProductFactory, -} = require("../../../factories") +} = require("../../../../factories") jest.setTimeout(30000) 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 d53ed406ce..2cbd2d4650 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 @@ -1,9 +1,9 @@ const path = require("path") const startServerWithEnvironment = - require("../../../../helpers/start-server-with-environment").default -const { useApi } = require("../../../../helpers/use-api") -const { useDb } = require("../../../../helpers/use-db") + require("../../../../environment-helpers/start-server-with-environment").default +const { useApi } = require("../../../../environment-helpers/use-api") +const { useDb } = require("../../../../environment-helpers/use-db") const { simpleCartFactory, @@ -14,7 +14,7 @@ const { simplePriceListFactory, simpleDiscountFactory, simpleSalesChannelFactory, -} = require("../../../factories") +} = require("../../../../factories") const { IdMap } = require("medusa-test-utils") jest.setTimeout(30000) diff --git a/integration-tests/api/__tests__/store/cart/gift-cards/tax-calculation-ff-tax-inclusive.js b/integration-tests/api/__tests__/store/cart/gift-cards/tax-calculation-ff-tax-inclusive.js index b5edf586f2..3e247d1ce8 100644 --- a/integration-tests/api/__tests__/store/cart/gift-cards/tax-calculation-ff-tax-inclusive.js +++ b/integration-tests/api/__tests__/store/cart/gift-cards/tax-calculation-ff-tax-inclusive.js @@ -1,8 +1,8 @@ const startServerWithEnvironment = - require("../../../../../helpers/start-server-with-environment").default + require("../../../../../environment-helpers/start-server-with-environment").default const path = require("path") -const { useApi } = require("../../../../../helpers/use-api") -const { useDb } = require("../../../../../helpers/use-db") +const { useApi } = require("../../../../../environment-helpers/use-api") +const { useDb } = require("../../../../../environment-helpers/use-db") const { GiftCard, TaxRate } = require("@medusajs/medusa") const { @@ -11,7 +11,7 @@ const { simpleCartFactory, simpleCustomerFactory, simpleGiftCardFactory, -} = require("../../../../factories") +} = require("../../../../../factories") jest.setTimeout(30000) 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 cee5e8a0bb..6b81d23dc6 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 @@ -1,8 +1,8 @@ const startServerWithEnvironment = - require("../../../../../helpers/start-server-with-environment").default + require("../../../../../environment-helpers/start-server-with-environment").default const path = require("path") -const { useApi } = require("../../../../../helpers/use-api") -const { useDb } = require("../../../../../helpers/use-db") +const { useApi } = require("../../../../../environment-helpers/use-api") +const { useDb } = require("../../../../../environment-helpers/use-db") const { GiftCard } = require("@medusajs/medusa") const { @@ -11,7 +11,7 @@ const { simpleCartFactory, simpleCustomerFactory, simpleGiftCardFactory, -} = require("../../../../factories") +} = require("../../../../../factories") jest.setTimeout(30000) diff --git a/integration-tests/api/__tests__/store/collections.js b/integration-tests/api/__tests__/store/collections.js index a630f6aca7..19432db870 100644 --- a/integration-tests/api/__tests__/store/collections.js +++ b/integration-tests/api/__tests__/store/collections.js @@ -1,10 +1,10 @@ const { ProductCollection } = require("@medusajs/medusa") 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("../../../environment-helpers/setup-server") +const { useApi } = require("../../../environment-helpers/use-api") +const { initDb, useDb } = require("../../../environment-helpers/use-db") -const productSeeder = require("../../helpers/product-seeder") +const productSeeder = require("../../../helpers/product-seeder") jest.setTimeout(30000) describe("/store/collections", () => { diff --git a/integration-tests/api/__tests__/store/customer.js b/integration-tests/api/__tests__/store/customer.js index d93e828491..93fff76be2 100644 --- a/integration-tests/api/__tests__/store/customer.js +++ b/integration-tests/api/__tests__/store/customer.js @@ -2,10 +2,10 @@ const jwt = require("jsonwebtoken") const path = require("path") const { Address, Customer, Order, Region } = require("@medusajs/medusa") -const setupServer = require("../../../helpers/setup-server") -const { useApi } = require("../../../helpers/use-api") -const { initDb, useDb } = require("../../../helpers/use-db") -const { simpleOrderFactory } = require("../../factories") +const setupServer = require("../../../environment-helpers/setup-server") +const { useApi } = require("../../../environment-helpers/use-api") +const { initDb, useDb } = require("../../../environment-helpers/use-db") +const { simpleOrderFactory } = require("../../../factories") jest.setTimeout(30000) diff --git a/integration-tests/api/__tests__/store/draft-order.js b/integration-tests/api/__tests__/store/draft-order.js index 7a0e8961c9..84c8a41c25 100644 --- a/integration-tests/api/__tests__/store/draft-order.js +++ b/integration-tests/api/__tests__/store/draft-order.js @@ -1,10 +1,10 @@ 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("../../../environment-helpers/setup-server") +const { useApi } = require("../../../environment-helpers/use-api") +const { initDb, useDb } = require("../../../environment-helpers/use-db") -const draftOrderSeeder = require("../../helpers/draft-order-seeder") +const draftOrderSeeder = require("../../../helpers/draft-order-seeder") jest.setTimeout(30000) diff --git a/integration-tests/api/__tests__/store/gift-cards.js b/integration-tests/api/__tests__/store/gift-cards.js index 83b72f86ff..a139867e67 100644 --- a/integration-tests/api/__tests__/store/gift-cards.js +++ b/integration-tests/api/__tests__/store/gift-cards.js @@ -1,9 +1,9 @@ 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("../../../environment-helpers/setup-server") +const { useApi } = require("../../../environment-helpers/use-api") +const { initDb, useDb } = require("../../../environment-helpers/use-db") jest.setTimeout(30000) diff --git a/integration-tests/api/__tests__/store/order-edit.js b/integration-tests/api/__tests__/store/order-edit.js index 4cf67e3d10..1a1172d269 100644 --- a/integration-tests/api/__tests__/store/order-edit.js +++ b/integration-tests/api/__tests__/store/order-edit.js @@ -1,28 +1,28 @@ const path = require("path") const startServerWithEnvironment = - require("../../../helpers/start-server-with-environment").default -const { useApi } = require("../../../helpers/use-api") -const { useDb, initDb } = require("../../../helpers/use-db") -const adminSeeder = require("../../helpers/admin-seeder") + require("../../../environment-helpers/start-server-with-environment").default +const { useApi } = require("../../../environment-helpers/use-api") +const { useDb, initDb } = require("../../../environment-helpers/use-db") +const adminSeeder = require("../../../helpers/admin-seeder") const { getClientAuthenticationCookie, -} = require("../../helpers/client-authentication") +} = require("../../../helpers/client-authentication") const { simpleOrderEditFactory, -} = require("../../factories/simple-order-edit-factory") +} = require("../../../factories/simple-order-edit-factory") const { IdMap } = require("medusa-test-utils") const { simpleOrderItemChangeFactory, -} = require("../../factories/simple-order-item-change-factory") +} = require("../../../factories/simple-order-item-change-factory") const { simpleLineItemFactory, simpleProductFactory, simpleOrderFactory, simpleCustomerFactory, -} = require("../../factories") +} = require("../../../factories") const { OrderEditItemChangeType } = require("@medusajs/medusa") -const setupServer = require("../../../helpers/setup-server") +const setupServer = require("../../../environment-helpers/setup-server") jest.setTimeout(30000) diff --git a/integration-tests/api/__tests__/store/orders.js b/integration-tests/api/__tests__/store/orders.js index b39fe6d3b9..f85a892bc4 100644 --- a/integration-tests/api/__tests__/store/orders.js +++ b/integration-tests/api/__tests__/store/orders.js @@ -11,16 +11,16 @@ const { PaymentSession, } = 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("../../../environment-helpers/setup-server") +const { useApi } = require("../../../environment-helpers/use-api") +const { initDb, useDb } = require("../../../environment-helpers/use-db") const { simpleRegionFactory, simpleProductFactory, simpleCartFactory, simpleShippingOptionFactory, simpleOrderFactory, -} = require("../../factories") +} = require("../../../factories") const { MedusaError } = require("medusa-core-utils") jest.setTimeout(30000) diff --git a/integration-tests/api/__tests__/store/payment-collection.js b/integration-tests/api/__tests__/store/payment-collection.js index f5cbaddce8..81e6ab5914 100644 --- a/integration-tests/api/__tests__/store/payment-collection.js +++ b/integration-tests/api/__tests__/store/payment-collection.js @@ -1,20 +1,20 @@ const path = require("path") const startServerWithEnvironment = - require("../../../helpers/start-server-with-environment").default -const { useApi } = require("../../../helpers/use-api") -const { useDb } = require("../../../helpers/use-db") -const adminSeeder = require("../../helpers/admin-seeder") + require("../../../environment-helpers/start-server-with-environment").default +const { useApi } = require("../../../environment-helpers/use-api") +const { useDb } = require("../../../environment-helpers/use-db") +const adminSeeder = require("../../../helpers/admin-seeder") const { getClientAuthenticationCookie, -} = require("../../helpers/client-authentication") +} = require("../../../helpers/client-authentication") const { simplePaymentCollectionFactory, -} = require("../../factories/simple-payment-collection-factory") +} = require("../../../factories/simple-payment-collection-factory") const { simpleCustomerFactory, -} = require("../../factories/simple-customer-factory") +} = require("../../../factories/simple-customer-factory") jest.setTimeout(30000) diff --git a/integration-tests/api/__tests__/store/product-category.ts b/integration-tests/api/__tests__/store/product-category.ts index 2c32ad556d..1a2a8200b2 100644 --- a/integration-tests/api/__tests__/store/product-category.ts +++ b/integration-tests/api/__tests__/store/product-category.ts @@ -1,10 +1,10 @@ import { ProductCategory } from "@medusajs/medusa" import path from "path" -import startServerWithEnvironment from "../../../helpers/start-server-with-environment" -import { useApi } from "../../../helpers/use-api" -import { useDb } from "../../../helpers/use-db" -import { simpleProductCategoryFactory } from "../../factories" +import startServerWithEnvironment from "../../../environment-helpers/start-server-with-environment" +import { useApi } from "../../../environment-helpers/use-api" +import { useDb } from "../../../environment-helpers/use-db" +import { simpleProductCategoryFactory } from "../../../factories" jest.setTimeout(30000) @@ -180,9 +180,7 @@ describe("/store/product-categories", () => { it("gets list of product category with immediate children and parents", async () => { const api = useApi() - const response = await api.get( - `/store/product-categories?limit=10`, - ) + const response = await api.get(`/store/product-categories?limit=10`) expect(response.status).toEqual(200) expect(response.data.count).toEqual(4) diff --git a/integration-tests/api/__tests__/store/product-tags.js b/integration-tests/api/__tests__/store/product-tags.js index 5b0983b344..61b2532d68 100644 --- a/integration-tests/api/__tests__/store/product-tags.js +++ b/integration-tests/api/__tests__/store/product-tags.js @@ -1,12 +1,12 @@ 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("../../../environment-helpers/setup-server") +const { useApi } = require("../../../environment-helpers/use-api") +const { initDb, useDb } = require("../../../environment-helpers/use-db") const { simpleProductTagFactory, -} = require("../../factories/simple-product-tag-factory") +} = require("../../../factories/simple-product-tag-factory") jest.setTimeout(30000) diff --git a/integration-tests/api/__tests__/store/product-type.js b/integration-tests/api/__tests__/store/product-type.js index 9dae07294a..5baf861902 100644 --- a/integration-tests/api/__tests__/store/product-type.js +++ b/integration-tests/api/__tests__/store/product-type.js @@ -2,18 +2,18 @@ const path = require("path") const { IdMap } = require("medusa-test-utils") -const setupServer = require("../../../helpers/setup-server") -const { useApi } = require("../../../helpers/use-api") -const { initDb, useDb } = require("../../../helpers/use-db") +const setupServer = require("../../../environment-helpers/setup-server") +const { useApi } = require("../../../environment-helpers/use-api") +const { initDb, useDb } = require("../../../environment-helpers/use-db") -const productSeeder = require("../../helpers/product-seeder") +const productSeeder = require("../../../helpers/product-seeder") const { DiscountRuleType, AllocationType, DiscountConditionType, DiscountConditionOperator, } = require("@medusajs/medusa") -const { simpleDiscountFactory } = require("../../factories") +const { simpleDiscountFactory } = require("../../../factories") jest.setTimeout(50000) diff --git a/integration-tests/api/__tests__/store/product-variants.js b/integration-tests/api/__tests__/store/product-variants.js index efdce8b785..4d49e4b96d 100644 --- a/integration-tests/api/__tests__/store/product-variants.js +++ b/integration-tests/api/__tests__/store/product-variants.js @@ -1,12 +1,12 @@ const { ProductVariant } = require("@medusajs/medusa") const path = require("path") -const setupServer = require("../../../helpers/setup-server") -const { useApi } = require("../../../helpers/use-api") -const { initDb, useDb } = require("../../../helpers/use-db") -const { simpleProductFactory } = require("../../factories") +const setupServer = require("../../../environment-helpers/setup-server") +const { useApi } = require("../../../environment-helpers/use-api") +const { initDb, useDb } = require("../../../environment-helpers/use-db") +const { simpleProductFactory } = require("../../../factories") -const productSeeder = require("../../helpers/product-seeder") -const storeProductSeeder = require("../../helpers/store-product-seeder") +const productSeeder = require("../../../helpers/product-seeder") +const storeProductSeeder = require("../../../helpers/store-product-seeder") jest.setTimeout(30000) describe("/store/variants", () => { let medusaProcess diff --git a/integration-tests/api/__tests__/store/products.js b/integration-tests/api/__tests__/store/products.js index bc765f1ce5..42db88c7d9 100644 --- a/integration-tests/api/__tests__/store/products.js +++ b/integration-tests/api/__tests__/store/products.js @@ -1,15 +1,15 @@ 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("../../../environment-helpers/setup-server") +const { useApi } = require("../../../environment-helpers/use-api") +const { initDb, useDb } = require("../../../environment-helpers/use-db") const { simpleProductFactory, simpleSalesChannelFactory, -} = require("../../factories") +} = require("../../../factories") -const productSeeder = require("../../helpers/store-product-seeder") -const adminSeeder = require("../../helpers/admin-seeder") +const productSeeder = require("../../../helpers/store-product-seeder") +const adminSeeder = require("../../../helpers/admin-seeder") const { allowedStoreProductsFields, defaultStoreProductsRelations, diff --git a/integration-tests/api/__tests__/store/products/ff-product-categories.ts b/integration-tests/api/__tests__/store/products/ff-product-categories.ts index b2b946990d..e9b8cae226 100644 --- a/integration-tests/api/__tests__/store/products/ff-product-categories.ts +++ b/integration-tests/api/__tests__/store/products/ff-product-categories.ts @@ -1,14 +1,14 @@ -import { simpleSalesChannelFactory } from "../../../factories" +import { simpleSalesChannelFactory } from "../../../../factories" 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("../../../../environment-helpers/setup-server") +const { useApi } = require("../../../../environment-helpers/use-api") +const { initDb, useDb } = require("../../../../environment-helpers/use-db") -const { simpleProductCategoryFactory } = require("../../../factories") +const { simpleProductCategoryFactory } = require("../../../../factories") -const productSeeder = require("../../../helpers/store-product-seeder") -const adminSeeder = require("../../../helpers/admin-seeder") +const productSeeder = require("../../../../helpers/store-product-seeder") +const adminSeeder = require("../../../../helpers/admin-seeder") jest.setTimeout(30000) diff --git a/integration-tests/api/__tests__/store/regions.js b/integration-tests/api/__tests__/store/regions.js index 4365692dec..cac9e7ddd1 100644 --- a/integration-tests/api/__tests__/store/regions.js +++ b/integration-tests/api/__tests__/store/regions.js @@ -14,9 +14,9 @@ const { DiscountRule, } = 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("../../../environment-helpers/setup-server") +const { useApi } = require("../../../environment-helpers/use-api") +const { initDb, useDb } = require("../../../environment-helpers/use-db") jest.setTimeout(30000) diff --git a/integration-tests/api/__tests__/store/return-reason.js b/integration-tests/api/__tests__/store/return-reason.js index ee8e66699f..5e2a13a48c 100644 --- a/integration-tests/api/__tests__/store/return-reason.js +++ b/integration-tests/api/__tests__/store/return-reason.js @@ -2,9 +2,9 @@ const path = require("path") 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("../../../environment-helpers/setup-server") +const { useApi } = require("../../../environment-helpers/use-api") +const { initDb, useDb } = require("../../../environment-helpers/use-db") jest.setTimeout(30000) diff --git a/integration-tests/api/__tests__/store/returns.js b/integration-tests/api/__tests__/store/returns.js index 6b11fcc227..9823d4664f 100644 --- a/integration-tests/api/__tests__/store/returns.js +++ b/integration-tests/api/__tests__/store/returns.js @@ -14,9 +14,9 @@ const { DiscountRule, } = 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("../../../environment-helpers/setup-server") +const { useApi } = require("../../../environment-helpers/use-api") +const { initDb, useDb } = require("../../../environment-helpers/use-db") jest.setTimeout(30000) diff --git a/integration-tests/api/__tests__/store/sales-channels.js b/integration-tests/api/__tests__/store/sales-channels.js index 20ddec88d7..0c41677b18 100644 --- a/integration-tests/api/__tests__/store/sales-channels.js +++ b/integration-tests/api/__tests__/store/sales-channels.js @@ -1,18 +1,18 @@ const path = require("path") -const { useApi } = require("../../../helpers/use-api") -const { useDb } = require("../../../helpers/use-db") +const { useApi } = require("../../../environment-helpers/use-api") +const { useDb } = require("../../../environment-helpers/use-db") -const adminSeeder = require("../../helpers/admin-seeder") +const adminSeeder = require("../../../helpers/admin-seeder") const { simpleSalesChannelFactory, simpleCartFactory, simpleRegionFactory, simpleProductFactory, -} = require("../../factories") +} = require("../../../factories") const startServerWithEnvironment = - require("../../../helpers/start-server-with-environment").default + require("../../../environment-helpers/start-server-with-environment").default const adminReqConfig = { headers: { diff --git a/integration-tests/api/__tests__/store/shipping-options.js b/integration-tests/api/__tests__/store/shipping-options.js index d9b70310c8..babeb7382f 100644 --- a/integration-tests/api/__tests__/store/shipping-options.js +++ b/integration-tests/api/__tests__/store/shipping-options.js @@ -6,20 +6,20 @@ const { ShippingProfileType, } = require("@medusajs/medusa") -const setupServer = require("../../../helpers/setup-server") -const { useApi } = require("../../../helpers/use-api") -const { useDb } = require("../../../helpers/use-db") -const cartSeeder = require("../../helpers/cart-seeder") -const swapSeeder = require("../../helpers/swap-seeder") +const setupServer = require("../../../environment-helpers/setup-server") +const { useApi } = require("../../../environment-helpers/use-api") +const { useDb } = require("../../../environment-helpers/use-db") +const cartSeeder = require("../../../helpers/cart-seeder") +const swapSeeder = require("../../../helpers/swap-seeder") const { simpleRegionFactory, simpleShippingOptionFactory, simpleCartFactory, simpleProductFactory, -} = require("../../factories") +} = require("../../../factories") const { default: startServerWithEnvironment, -} = require("../../../helpers/start-server-with-environment") +} = require("../../../environment-helpers/start-server-with-environment") jest.setTimeout(30000) diff --git a/integration-tests/api/__tests__/store/swaps.js b/integration-tests/api/__tests__/store/swaps.js index 43eb467eb6..2666e90c7e 100644 --- a/integration-tests/api/__tests__/store/swaps.js +++ b/integration-tests/api/__tests__/store/swaps.js @@ -5,11 +5,11 @@ const { ShippingProfileType, } = 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("../../../environment-helpers/setup-server") +const { useApi } = require("../../../environment-helpers/use-api") +const { initDb, useDb } = require("../../../environment-helpers/use-db") -const orderSeeder = require("../../helpers/order-seeder") +const orderSeeder = require("../../../helpers/order-seeder") jest.setTimeout(30000) diff --git a/integration-tests/api/__tests__/swaps/index.js b/integration-tests/api/__tests__/swaps/index.js index 6859a4adc2..581a0030f8 100644 --- a/integration-tests/api/__tests__/swaps/index.js +++ b/integration-tests/api/__tests__/swaps/index.js @@ -1,16 +1,16 @@ 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("../../../environment-helpers/setup-server") +const { useApi } = require("../../../environment-helpers/use-api") +const { initDb, useDb } = require("../../../environment-helpers/use-db") -const adminSeeder = require("../../helpers/admin-seeder") +const adminSeeder = require("../../../helpers/admin-seeder") const { simpleOrderFactory, simpleShippingOptionFactory, simpleProductFactory, -} = require("../../factories") +} = require("../../../factories") jest.setTimeout(30000) diff --git a/integration-tests/api/__tests__/taxes/admin-tax-rates.js b/integration-tests/api/__tests__/taxes/admin-tax-rates.js index 618ddbb934..3a8f693c16 100644 --- a/integration-tests/api/__tests__/taxes/admin-tax-rates.js +++ b/integration-tests/api/__tests__/taxes/admin-tax-rates.js @@ -1,17 +1,17 @@ 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("../../../environment-helpers/setup-server") +const { useApi } = require("../../../environment-helpers/use-api") +const { initDb, useDb } = require("../../../environment-helpers/use-db") -const adminSeeder = require("../../helpers/admin-seeder") +const adminSeeder = require("../../../helpers/admin-seeder") const { simpleProductFactory, simpleShippingOptionFactory, simpleRegionFactory, simpleTaxRateFactory, -} = require("../../factories") +} = require("../../../factories") jest.setTimeout(30000) diff --git a/integration-tests/api/__tests__/taxes/automatic-taxes.js b/integration-tests/api/__tests__/taxes/automatic-taxes.js index bf1427f8ea..84f24815b3 100644 --- a/integration-tests/api/__tests__/taxes/automatic-taxes.js +++ b/integration-tests/api/__tests__/taxes/automatic-taxes.js @@ -1,8 +1,8 @@ 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("../../../environment-helpers/setup-server") +const { useApi } = require("../../../environment-helpers/use-api") +const { initDb, useDb } = require("../../../environment-helpers/use-db") const { simpleProductTaxRateFactory, @@ -12,7 +12,7 @@ const { simpleCartFactory, simpleRegionFactory, simpleProductFactory, -} = require("../../factories") +} = require("../../../factories") jest.setTimeout(30000) diff --git a/integration-tests/api/__tests__/taxes/cart.js b/integration-tests/api/__tests__/taxes/cart.js index 5011730ca7..f56e7053dd 100644 --- a/integration-tests/api/__tests__/taxes/cart.js +++ b/integration-tests/api/__tests__/taxes/cart.js @@ -1,16 +1,16 @@ const path = require("path") -const setupServer = require("../../../helpers/setup-server") -const { useApi } = require("../../../helpers/use-api") -const { useDb, initDb } = require("../../../helpers/use-db") +const setupServer = require("../../../environment-helpers/setup-server") +const { useApi } = require("../../../environment-helpers/use-api") +const { useDb, initDb } = require("../../../environment-helpers/use-db") const { simpleDiscountFactory, simpleRegionFactory, simpleProductFactory, simpleProductTaxRateFactory, -} = require("../../factories") +} = require("../../../factories") -const adminSeeder = require("../../helpers/admin-seeder") +const adminSeeder = require("../../../helpers/admin-seeder") jest.setTimeout(30000) diff --git a/integration-tests/api/__tests__/taxes/manual-taxes.js b/integration-tests/api/__tests__/taxes/manual-taxes.js index 4ae9a017d7..8d384feeef 100644 --- a/integration-tests/api/__tests__/taxes/manual-taxes.js +++ b/integration-tests/api/__tests__/taxes/manual-taxes.js @@ -1,15 +1,15 @@ 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("../../../environment-helpers/setup-server") +const { useApi } = require("../../../environment-helpers/use-api") +const { initDb, useDb } = require("../../../environment-helpers/use-db") const { simpleProductTaxRateFactory, simpleCartFactory, simpleRegionFactory, simpleProductFactory, -} = require("../../factories") +} = require("../../../factories") jest.setTimeout(30000) diff --git a/integration-tests/api/__tests__/taxes/orders/ff-tax-inclusive-pricing.js b/integration-tests/api/__tests__/taxes/orders/ff-tax-inclusive-pricing.js index 09cd79ee14..0b871bce43 100644 --- a/integration-tests/api/__tests__/taxes/orders/ff-tax-inclusive-pricing.js +++ b/integration-tests/api/__tests__/taxes/orders/ff-tax-inclusive-pricing.js @@ -1,15 +1,15 @@ const path = require("path") -const { useApi } = require("../../../../helpers/use-api") -const { useDb } = require("../../../../helpers/use-db") +const { useApi } = require("../../../../environment-helpers/use-api") +const { useDb } = require("../../../../environment-helpers/use-db") const startServerWithEnvironment = - require("../../../../helpers/start-server-with-environment").default + require("../../../../environment-helpers/start-server-with-environment").default const { simpleOrderFactory, simpleProductFactory, -} = require("../../../factories") +} = require("../../../../factories") jest.setTimeout(30000) diff --git a/integration-tests/api/__tests__/taxes/orders/orders.js b/integration-tests/api/__tests__/taxes/orders/orders.js index 27964365c7..21b7313da2 100644 --- a/integration-tests/api/__tests__/taxes/orders/orders.js +++ b/integration-tests/api/__tests__/taxes/orders/orders.js @@ -1,8 +1,8 @@ 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("../../../../environment-helpers/setup-server") +const { useApi } = require("../../../../environment-helpers/use-api") +const { initDb, useDb } = require("../../../../environment-helpers/use-db") const { simpleOrderFactory, @@ -10,7 +10,7 @@ const { simpleCartFactory, simpleProductFactory, simpleProductTaxRateFactory, -} = require("../../../factories") +} = require("../../../../factories") jest.setTimeout(30000) diff --git a/integration-tests/api/__tests__/taxes/shipping-options.js b/integration-tests/api/__tests__/taxes/shipping-options.js index b262dd93fd..057b1daa70 100644 --- a/integration-tests/api/__tests__/taxes/shipping-options.js +++ b/integration-tests/api/__tests__/taxes/shipping-options.js @@ -1,16 +1,16 @@ const path = require("path") -const setupServer = require("../../../helpers/setup-server") -const { useApi } = require("../../../helpers/use-api") -const { useDb, initDb } = require("../../../helpers/use-db") +const setupServer = require("../../../environment-helpers/setup-server") +const { useApi } = require("../../../environment-helpers/use-api") +const { useDb, initDb } = require("../../../environment-helpers/use-db") const { simpleRegionFactory, simpleProductFactory, simpleShippingTaxRateFactory, simpleShippingOptionFactory, -} = require("../../factories") +} = require("../../../factories") -const adminSeeder = require("../../helpers/admin-seeder") +const adminSeeder = require("../../../helpers/admin-seeder") jest.setTimeout(30000) diff --git a/integration-tests/api/__tests__/totals/orders.js b/integration-tests/api/__tests__/totals/orders.js index ff250f1fb9..4a9b3811f3 100644 --- a/integration-tests/api/__tests__/totals/orders.js +++ b/integration-tests/api/__tests__/totals/orders.js @@ -1,16 +1,16 @@ const path = require("path") -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 setupServer = require("../../../environment-helpers/setup-server") +const { useApi } = require("../../../environment-helpers/use-api") +const { initDb, useDb } = require("../../../environment-helpers/use-db") +const adminSeeder = require("../../../helpers/admin-seeder") const { simpleRegionFactory, simpleCartFactory, simpleGiftCardFactory, simpleProductFactory, -} = require("../../factories") +} = require("../../../factories") jest.setTimeout(30000) diff --git a/integration-tests/api/medusa-config.js b/integration-tests/api/medusa-config.js index 744822ab9a..527900350a 100644 --- a/integration-tests/api/medusa-config.js +++ b/integration-tests/api/medusa-config.js @@ -5,7 +5,8 @@ const DB_NAME = process.env.DB_TEMP_NAME const redisUrl = process.env.REDIS_URL || "redis://localhost:6379" const cacheTTL = process.env.CACHE_TTL || 15 -const enableResponseCompression = process.env.ENABLE_RESPONSE_COMPRESSION || true +const enableResponseCompression = + process.env.ENABLE_RESPONSE_COMPRESSION || true module.exports = { plugins: [], @@ -16,8 +17,8 @@ module.exports = { jwt_secret: "test", cookie_secret: "test", http_compression: { - enabled: enableResponseCompression - } + enabled: enableResponseCompression, + }, }, modules: { cacheService: { diff --git a/integration-tests/helpers/bootstrap-app.js b/integration-tests/environment-helpers/bootstrap-app.js similarity index 100% rename from integration-tests/helpers/bootstrap-app.js rename to integration-tests/environment-helpers/bootstrap-app.js diff --git a/integration-tests/helpers/setup-server.js b/integration-tests/environment-helpers/setup-server.js similarity index 100% rename from integration-tests/helpers/setup-server.js rename to integration-tests/environment-helpers/setup-server.js diff --git a/integration-tests/helpers/start-server-with-environment.js b/integration-tests/environment-helpers/start-server-with-environment.js similarity index 100% rename from integration-tests/helpers/start-server-with-environment.js rename to integration-tests/environment-helpers/start-server-with-environment.js diff --git a/integration-tests/helpers/test-server.js b/integration-tests/environment-helpers/test-server.js similarity index 100% rename from integration-tests/helpers/test-server.js rename to integration-tests/environment-helpers/test-server.js diff --git a/integration-tests/helpers/use-api.js b/integration-tests/environment-helpers/use-api.js similarity index 100% rename from integration-tests/helpers/use-api.js rename to integration-tests/environment-helpers/use-api.js diff --git a/integration-tests/helpers/use-db.js b/integration-tests/environment-helpers/use-db.js similarity index 100% rename from integration-tests/helpers/use-db.js rename to integration-tests/environment-helpers/use-db.js diff --git a/integration-tests/helpers/use-server.js b/integration-tests/environment-helpers/use-server.js similarity index 100% rename from integration-tests/helpers/use-server.js rename to integration-tests/environment-helpers/use-server.js diff --git a/integration-tests/helpers/use-template-db.js b/integration-tests/environment-helpers/use-template-db.js similarity index 100% rename from integration-tests/helpers/use-template-db.js rename to integration-tests/environment-helpers/use-template-db.js diff --git a/integration-tests/api/factories/index.ts b/integration-tests/factories/index.ts similarity index 96% rename from integration-tests/api/factories/index.ts rename to integration-tests/factories/index.ts index 6647208a5b..40a248a494 100644 --- a/integration-tests/api/factories/index.ts +++ b/integration-tests/factories/index.ts @@ -23,3 +23,4 @@ export * from "./simple-shipping-option-factory" export * from "./simple-shipping-profile-factory" export * from "./simple-shipping-tax-rate-factory" export * from "./simple-tax-rate-factory" +export * from "./simple-store-factory" diff --git a/integration-tests/api/factories/simple-address-factory.ts b/integration-tests/factories/simple-address-factory.ts similarity index 100% rename from integration-tests/api/factories/simple-address-factory.ts rename to integration-tests/factories/simple-address-factory.ts diff --git a/integration-tests/api/factories/simple-analytics-config-factory.ts b/integration-tests/factories/simple-analytics-config-factory.ts similarity index 100% rename from integration-tests/api/factories/simple-analytics-config-factory.ts rename to integration-tests/factories/simple-analytics-config-factory.ts diff --git a/integration-tests/api/factories/simple-batch-job-factory.ts b/integration-tests/factories/simple-batch-job-factory.ts similarity index 100% rename from integration-tests/api/factories/simple-batch-job-factory.ts rename to integration-tests/factories/simple-batch-job-factory.ts diff --git a/integration-tests/api/factories/simple-cart-factory.ts b/integration-tests/factories/simple-cart-factory.ts similarity index 96% rename from integration-tests/api/factories/simple-cart-factory.ts rename to integration-tests/factories/simple-cart-factory.ts index 40d038f893..d734b50de2 100644 --- a/integration-tests/api/factories/simple-cart-factory.ts +++ b/integration-tests/factories/simple-cart-factory.ts @@ -29,6 +29,7 @@ export type CartFactoryData = { shipping_address?: AddressFactoryData shipping_methods?: ShippingMethodFactoryData[] sales_channel?: SalesChannelFactoryData + sales_channel_id?: string } export const simpleCartFactory = async ( @@ -83,7 +84,7 @@ export const simpleCartFactory = async ( region_id: regionId, customer_id: customerId, shipping_address_id: address.id, - sales_channel_id: sales_channel?.id ?? null, + sales_channel_id: sales_channel?.id ?? data.sales_channel_id ?? null, }) const cart = await manager.save(toSave) diff --git a/integration-tests/api/factories/simple-custom-shipping-option-factory.ts b/integration-tests/factories/simple-custom-shipping-option-factory.ts similarity index 100% rename from integration-tests/api/factories/simple-custom-shipping-option-factory.ts rename to integration-tests/factories/simple-custom-shipping-option-factory.ts diff --git a/integration-tests/api/factories/simple-customer-factory.ts b/integration-tests/factories/simple-customer-factory.ts similarity index 100% rename from integration-tests/api/factories/simple-customer-factory.ts rename to integration-tests/factories/simple-customer-factory.ts diff --git a/integration-tests/api/factories/simple-customer-group-factory.ts b/integration-tests/factories/simple-customer-group-factory.ts similarity index 100% rename from integration-tests/api/factories/simple-customer-group-factory.ts rename to integration-tests/factories/simple-customer-group-factory.ts diff --git a/integration-tests/api/factories/simple-discount-condition-factory.ts b/integration-tests/factories/simple-discount-condition-factory.ts similarity index 100% rename from integration-tests/api/factories/simple-discount-condition-factory.ts rename to integration-tests/factories/simple-discount-condition-factory.ts diff --git a/integration-tests/api/factories/simple-discount-factory.ts b/integration-tests/factories/simple-discount-factory.ts similarity index 100% rename from integration-tests/api/factories/simple-discount-factory.ts rename to integration-tests/factories/simple-discount-factory.ts diff --git a/integration-tests/api/factories/simple-gift-card-factory.ts b/integration-tests/factories/simple-gift-card-factory.ts similarity index 100% rename from integration-tests/api/factories/simple-gift-card-factory.ts rename to integration-tests/factories/simple-gift-card-factory.ts diff --git a/integration-tests/api/factories/simple-line-item-factory.ts b/integration-tests/factories/simple-line-item-factory.ts similarity index 100% rename from integration-tests/api/factories/simple-line-item-factory.ts rename to integration-tests/factories/simple-line-item-factory.ts diff --git a/integration-tests/api/factories/simple-order-edit-factory.ts b/integration-tests/factories/simple-order-edit-factory.ts similarity index 100% rename from integration-tests/api/factories/simple-order-edit-factory.ts rename to integration-tests/factories/simple-order-edit-factory.ts diff --git a/integration-tests/api/factories/simple-order-factory.ts b/integration-tests/factories/simple-order-factory.ts similarity index 100% rename from integration-tests/api/factories/simple-order-factory.ts rename to integration-tests/factories/simple-order-factory.ts diff --git a/integration-tests/api/factories/simple-order-item-change-factory.ts b/integration-tests/factories/simple-order-item-change-factory.ts similarity index 100% rename from integration-tests/api/factories/simple-order-item-change-factory.ts rename to integration-tests/factories/simple-order-item-change-factory.ts diff --git a/integration-tests/api/factories/simple-payment-collection-factory.ts b/integration-tests/factories/simple-payment-collection-factory.ts similarity index 100% rename from integration-tests/api/factories/simple-payment-collection-factory.ts rename to integration-tests/factories/simple-payment-collection-factory.ts diff --git a/integration-tests/api/factories/simple-payment-factory.ts b/integration-tests/factories/simple-payment-factory.ts similarity index 100% rename from integration-tests/api/factories/simple-payment-factory.ts rename to integration-tests/factories/simple-payment-factory.ts diff --git a/integration-tests/api/factories/simple-price-list-factory.ts b/integration-tests/factories/simple-price-list-factory.ts similarity index 100% rename from integration-tests/api/factories/simple-price-list-factory.ts rename to integration-tests/factories/simple-price-list-factory.ts diff --git a/integration-tests/api/factories/simple-product-category-factory.ts b/integration-tests/factories/simple-product-category-factory.ts similarity index 83% rename from integration-tests/api/factories/simple-product-category-factory.ts rename to integration-tests/factories/simple-product-category-factory.ts index be9df1a6a5..e1d90a19e3 100644 --- a/integration-tests/api/factories/simple-product-category-factory.ts +++ b/integration-tests/factories/simple-product-category-factory.ts @@ -8,5 +8,5 @@ export const simpleProductCategoryFactory = async ( const manager = dataSource.manager const productCategory = manager.create(ProductCategory, data) - return await manager.save(productCategory) + return (await manager.save(productCategory)) as ProductCategory } diff --git a/integration-tests/api/factories/simple-product-collection-factory.ts b/integration-tests/factories/simple-product-collection-factory.ts similarity index 100% rename from integration-tests/api/factories/simple-product-collection-factory.ts rename to integration-tests/factories/simple-product-collection-factory.ts diff --git a/integration-tests/api/factories/simple-product-factory.ts b/integration-tests/factories/simple-product-factory.ts similarity index 83% rename from integration-tests/api/factories/simple-product-factory.ts rename to integration-tests/factories/simple-product-factory.ts index 9e39af8528..5365ad745f 100644 --- a/integration-tests/api/factories/simple-product-factory.ts +++ b/integration-tests/factories/simple-product-factory.ts @@ -45,21 +45,22 @@ export const simpleProductFactory = async ( const defaultProfile = await manager.findOne(ShippingProfile, { where: { type: ShippingProfileType.DEFAULT, - } + }, }) const gcProfile = await manager.findOne(ShippingProfile, { where: { type: ShippingProfileType.GIFT_CARD, - } + }, }) let sales_channels if (data.sales_channels) { sales_channels = await Promise.all( - data.sales_channels.map( - async (salesChannel) => - await simpleSalesChannelFactory(dataSource, salesChannel) + data.sales_channels.map(async (salesChannel) => + salesChannel + ? await simpleSalesChannelFactory(dataSource, salesChannel) + : null ) ) } else { @@ -118,7 +119,7 @@ export const simpleProductFactory = async ( toSave.sales_channels = sales_channels - await manager.save(toSave) + const product = await manager.save(toSave) const optionId = `${prodId}-option` const options = data.options || [{ id: optionId, title: "Size" }] @@ -140,26 +141,20 @@ export const simpleProductFactory = async ( }, ] - for (const pv of variants) { - const factoryData = { - ...pv, - product_id: prodId, - } - if (typeof pv.options === "undefined") { - factoryData.options = [ - { option_id: optionId, value: faker.commerce.productAdjective() }, - ] - } - await simpleProductVariantFactory(dataSource, factoryData) - } - - return await manager.findOne( - Product, - { - where: { - id: prodId - }, - relations: { tags: true, variants: { prices: true }} - } + product.variants = await Promise.all( + variants.map(async (pv) => { + const factoryData = { + ...pv, + product_id: prodId, + } + if (typeof pv.options === "undefined") { + factoryData.options = [ + { option_id: optionId, value: faker.commerce.productAdjective() }, + ] + } + return await simpleProductVariantFactory(dataSource, factoryData) + }) ) + + return product } diff --git a/integration-tests/api/factories/simple-product-tag-factory.ts b/integration-tests/factories/simple-product-tag-factory.ts similarity index 100% rename from integration-tests/api/factories/simple-product-tag-factory.ts rename to integration-tests/factories/simple-product-tag-factory.ts diff --git a/integration-tests/api/factories/simple-product-tax-rate-factory.ts b/integration-tests/factories/simple-product-tax-rate-factory.ts similarity index 100% rename from integration-tests/api/factories/simple-product-tax-rate-factory.ts rename to integration-tests/factories/simple-product-tax-rate-factory.ts diff --git a/integration-tests/api/factories/simple-product-type-tax-rate-factory.ts b/integration-tests/factories/simple-product-type-tax-rate-factory.ts similarity index 100% rename from integration-tests/api/factories/simple-product-type-tax-rate-factory.ts rename to integration-tests/factories/simple-product-type-tax-rate-factory.ts diff --git a/integration-tests/api/factories/simple-product-variant-factory.ts b/integration-tests/factories/simple-product-variant-factory.ts similarity index 85% rename from integration-tests/api/factories/simple-product-variant-factory.ts rename to integration-tests/factories/simple-product-variant-factory.ts index 25c43ee5b7..e5922eafe9 100644 --- a/integration-tests/api/factories/simple-product-variant-factory.ts +++ b/integration-tests/factories/simple-product-variant-factory.ts @@ -11,8 +11,10 @@ export type ProductVariantFactoryData = { id?: string is_giftcard?: boolean sku?: string + manage_inventory?: boolean inventory_quantity?: number title?: string + allow_backorder?: boolean options?: { option_id: string; value: string }[] prices?: { currency: string; amount: number; region_id?: string }[] } @@ -33,6 +35,11 @@ export const simpleProductVariantFactory = async ( id, product_id: data.product_id, sku: data.sku, + allow_backorder: data.allow_backorder ?? false, + manage_inventory: + typeof data.manage_inventory !== "undefined" + ? data.manage_inventory + : true, inventory_quantity: typeof data.inventory_quantity !== "undefined" ? data.inventory_quantity @@ -45,7 +52,7 @@ export const simpleProductVariantFactory = async ( const options = data.options || [{ option_id: "test-option", value: "Large" }] for (const o of options) { await manager.insert(ProductOptionValue, { - id: `${variant.id}-${o.option_id ?? Math.random()}`, + id: `${o.value}-${o.option_id ?? Math.random()}`, value: o.value, variant_id: id, option_id: o.option_id, diff --git a/integration-tests/api/factories/simple-publishable-api-key-factory.ts b/integration-tests/factories/simple-publishable-api-key-factory.ts similarity index 100% rename from integration-tests/api/factories/simple-publishable-api-key-factory.ts rename to integration-tests/factories/simple-publishable-api-key-factory.ts diff --git a/integration-tests/api/factories/simple-region-factory.ts b/integration-tests/factories/simple-region-factory.ts similarity index 100% rename from integration-tests/api/factories/simple-region-factory.ts rename to integration-tests/factories/simple-region-factory.ts diff --git a/integration-tests/api/factories/simple-sales-channel-factory.ts b/integration-tests/factories/simple-sales-channel-factory.ts similarity index 100% rename from integration-tests/api/factories/simple-sales-channel-factory.ts rename to integration-tests/factories/simple-sales-channel-factory.ts diff --git a/integration-tests/api/factories/simple-shipping-method-factory.ts b/integration-tests/factories/simple-shipping-method-factory.ts similarity index 100% rename from integration-tests/api/factories/simple-shipping-method-factory.ts rename to integration-tests/factories/simple-shipping-method-factory.ts diff --git a/integration-tests/api/factories/simple-shipping-option-factory.ts b/integration-tests/factories/simple-shipping-option-factory.ts similarity index 100% rename from integration-tests/api/factories/simple-shipping-option-factory.ts rename to integration-tests/factories/simple-shipping-option-factory.ts diff --git a/integration-tests/api/factories/simple-shipping-profile-factory.ts b/integration-tests/factories/simple-shipping-profile-factory.ts similarity index 100% rename from integration-tests/api/factories/simple-shipping-profile-factory.ts rename to integration-tests/factories/simple-shipping-profile-factory.ts diff --git a/integration-tests/api/factories/simple-shipping-tax-rate-factory.ts b/integration-tests/factories/simple-shipping-tax-rate-factory.ts similarity index 100% rename from integration-tests/api/factories/simple-shipping-tax-rate-factory.ts rename to integration-tests/factories/simple-shipping-tax-rate-factory.ts diff --git a/integration-tests/plugins/factories/simple-store-factory.ts b/integration-tests/factories/simple-store-factory.ts similarity index 78% rename from integration-tests/plugins/factories/simple-store-factory.ts rename to integration-tests/factories/simple-store-factory.ts index 893c71c1f3..3c068e6746 100644 --- a/integration-tests/plugins/factories/simple-store-factory.ts +++ b/integration-tests/factories/simple-store-factory.ts @@ -1,6 +1,6 @@ import { SalesChannel, Store } from "@medusajs/medusa" import faker from "faker" -import { DataSource, Not, IsNull } from "typeorm" +import { DataSource, IsNull, Not } from "typeorm" export type StoreFactoryData = { swap_link_template?: string @@ -27,12 +27,16 @@ export const simpleStoreFactory = async ( await manager.insert(SalesChannel, { id: "test-channel", - name: "Default" + name: "Default", }) const storeToSave = await manager.save(store) - await manager.query(`update store set default_sales_channel_id = 'test-channel' where id = '${storeToSave!.id}'`) + await manager.query( + `update store set default_sales_channel_id = 'test-channel' where id = '${ + storeToSave!.id + }'` + ) return storeToSave! } diff --git a/integration-tests/api/factories/simple-tax-rate-factory.ts b/integration-tests/factories/simple-tax-rate-factory.ts similarity index 100% rename from integration-tests/api/factories/simple-tax-rate-factory.ts rename to integration-tests/factories/simple-tax-rate-factory.ts diff --git a/integration-tests/globalSetup.js b/integration-tests/globalSetup.js index a7f0bd0474..5a254dbb2b 100644 --- a/integration-tests/globalSetup.js +++ b/integration-tests/globalSetup.js @@ -1,4 +1,4 @@ -const dbFactory = require("./helpers/use-template-db") +const dbFactory = require("./environment-helpers/use-template-db") const path = require("path") module.exports = async () => { diff --git a/integration-tests/globalTeardown.js b/integration-tests/globalTeardown.js index 7245b52f91..856f66345c 100644 --- a/integration-tests/globalTeardown.js +++ b/integration-tests/globalTeardown.js @@ -1,4 +1,4 @@ -const dbFactory = require("./helpers/use-template-db") +const dbFactory = require("./environment-helpers/use-template-db") module.exports = async () => { await dbFactory.destroy() diff --git a/integration-tests/api/helpers/admin-seeder.js b/integration-tests/helpers/admin-seeder.js similarity index 100% rename from integration-tests/api/helpers/admin-seeder.js rename to integration-tests/helpers/admin-seeder.js diff --git a/integration-tests/api/helpers/admin-variants-seeder.js b/integration-tests/helpers/admin-variants-seeder.js similarity index 100% rename from integration-tests/api/helpers/admin-variants-seeder.js rename to integration-tests/helpers/admin-variants-seeder.js diff --git a/integration-tests/api/helpers/batch-job-seeder.js b/integration-tests/helpers/batch-job-seeder.js similarity index 100% rename from integration-tests/api/helpers/batch-job-seeder.js rename to integration-tests/helpers/batch-job-seeder.js diff --git a/integration-tests/api/helpers/call-helpers.js b/integration-tests/helpers/call-helpers.js similarity index 95% rename from integration-tests/api/helpers/call-helpers.js rename to integration-tests/helpers/call-helpers.js index 9a9233d42d..61270f6d05 100644 --- a/integration-tests/api/helpers/call-helpers.js +++ b/integration-tests/helpers/call-helpers.js @@ -1,4 +1,4 @@ -const { useApi } = require("../../helpers/use-api") +const { useApi } = require("../environment-helpers/use-api") const header = { headers: { @@ -88,7 +88,7 @@ module.exports.expectAllPostCallsToReturn = async function ( * @param {Object} param0 - contains the path which to * call (path), and the object within the response.data (get) * we want to retrieve. - * @returns {Object} found within response.data corresponding + * @return {Object} found within response.data corresponding * to the get parameter provided. */ module.exports.callGet = async function ({ path, get }) { diff --git a/integration-tests/api/helpers/cart-seeder.js b/integration-tests/helpers/cart-seeder.js similarity index 98% rename from integration-tests/api/helpers/cart-seeder.js rename to integration-tests/helpers/cart-seeder.js index 210686384f..6cd3f8aa8d 100644 --- a/integration-tests/api/helpers/cart-seeder.js +++ b/integration-tests/helpers/cart-seeder.js @@ -20,6 +20,8 @@ const { } = require("@medusajs/medusa") module.exports = async (dataSource, data = {}) => { + const salesChannelId = data?.sales_channel_id + const yesterday = ((today) => new Date(today.setDate(today.getDate() - 1)))( new Date() ) @@ -641,6 +643,7 @@ module.exports = async (dataSource, data = {}) => { id: "test-cart", customer_id: "some-customer", email: "some-customer@email.com", + sales_channel_id: salesChannelId, shipping_address: { id: "test-shipping-address", first_name: "lebron", @@ -658,6 +661,7 @@ module.exports = async (dataSource, data = {}) => { customer_id: "some-customer", email: "some-customer@email.com", discounts: [totalFixed100], + sales_channel_id: salesChannelId, shipping_address: { id: "test-shipping-address", first_name: "lebron", @@ -675,6 +679,7 @@ module.exports = async (dataSource, data = {}) => { customer_id: "some-customer", email: "some-customer@email.com", discounts: [itemFixed200], + sales_channel_id: salesChannelId, shipping_address: { id: "test-shipping-address", first_name: "lebron", @@ -692,6 +697,7 @@ module.exports = async (dataSource, data = {}) => { customer_id: "some-customer", email: "some-customer@email.com", discounts: [tenPercent], + sales_channel_id: salesChannelId, shipping_address: { id: "test-shipping-address", first_name: "lebron", @@ -709,6 +715,7 @@ module.exports = async (dataSource, data = {}) => { customer_id: "some-customer", email: "some-customer@email.com", discounts: [itemPerc15], + sales_channel_id: salesChannelId, shipping_address: { id: "test-shipping-address", first_name: "lebron", @@ -725,6 +732,7 @@ module.exports = async (dataSource, data = {}) => { id: "test-cart-2", customer_id: "some-customer", email: "some-customer@email.com", + sales_channel_id: salesChannelId, shipping_address: { id: "test-shipping-address", first_name: "lebron", @@ -741,6 +749,7 @@ module.exports = async (dataSource, data = {}) => { type: "swap", customer_id: "some-customer", email: "some-customer@email.com", + sales_channel_id: salesChannelId, shipping_address: { id: "test-shipping-address", first_name: "lebron", diff --git a/integration-tests/api/helpers/claim-seeder.js b/integration-tests/helpers/claim-seeder.js similarity index 98% rename from integration-tests/api/helpers/claim-seeder.js rename to integration-tests/helpers/claim-seeder.js index abeeb045d5..42a806de6e 100644 --- a/integration-tests/api/helpers/claim-seeder.js +++ b/integration-tests/helpers/claim-seeder.js @@ -9,7 +9,7 @@ const { module.exports = async (dataSource, data = {}) => { const manager = dataSource.manager - let orderWithClaim = manager.create(Order, { + const orderWithClaim = manager.create(Order, { id: "order-with-claim", customer_id: "test-customer", email: "test@email.com", diff --git a/integration-tests/api/helpers/client-authentication.ts b/integration-tests/helpers/client-authentication.ts similarity index 100% rename from integration-tests/api/helpers/client-authentication.ts rename to integration-tests/helpers/client-authentication.ts diff --git a/integration-tests/api/helpers/customer-seeder.js b/integration-tests/helpers/customer-seeder.js similarity index 100% rename from integration-tests/api/helpers/customer-seeder.js rename to integration-tests/helpers/customer-seeder.js diff --git a/integration-tests/api/helpers/discount-seeder.js b/integration-tests/helpers/discount-seeder.js similarity index 100% rename from integration-tests/api/helpers/discount-seeder.js rename to integration-tests/helpers/discount-seeder.js diff --git a/integration-tests/api/helpers/draft-order-seeder.js b/integration-tests/helpers/draft-order-seeder.js similarity index 100% rename from integration-tests/api/helpers/draft-order-seeder.js rename to integration-tests/helpers/draft-order-seeder.js diff --git a/integration-tests/api/helpers/order-seeder.js b/integration-tests/helpers/order-seeder.js similarity index 100% rename from integration-tests/api/helpers/order-seeder.js rename to integration-tests/helpers/order-seeder.js diff --git a/integration-tests/api/helpers/price-list-seeder.js b/integration-tests/helpers/price-list-seeder.js similarity index 100% rename from integration-tests/api/helpers/price-list-seeder.js rename to integration-tests/helpers/price-list-seeder.js diff --git a/integration-tests/api/helpers/price-selection-seeder.js b/integration-tests/helpers/price-selection-seeder.js similarity index 100% rename from integration-tests/api/helpers/price-selection-seeder.js rename to integration-tests/helpers/price-selection-seeder.js diff --git a/integration-tests/api/helpers/product-seeder.js b/integration-tests/helpers/product-seeder.js similarity index 100% rename from integration-tests/api/helpers/product-seeder.js rename to integration-tests/helpers/product-seeder.js diff --git a/integration-tests/api/helpers/shipping-option-seeder.js b/integration-tests/helpers/shipping-option-seeder.js similarity index 100% rename from integration-tests/api/helpers/shipping-option-seeder.js rename to integration-tests/helpers/shipping-option-seeder.js diff --git a/integration-tests/api/helpers/store-product-seeder.js b/integration-tests/helpers/store-product-seeder.js similarity index 100% rename from integration-tests/api/helpers/store-product-seeder.js rename to integration-tests/helpers/store-product-seeder.js diff --git a/integration-tests/api/helpers/swap-seeder.js b/integration-tests/helpers/swap-seeder.js similarity index 100% rename from integration-tests/api/helpers/swap-seeder.js rename to integration-tests/helpers/swap-seeder.js diff --git a/integration-tests/api/helpers/user-seeder.js b/integration-tests/helpers/user-seeder.js similarity index 100% rename from integration-tests/api/helpers/user-seeder.js rename to integration-tests/helpers/user-seeder.js diff --git a/integration-tests/plugins/__tests__/inventory/cart/cart.js b/integration-tests/plugins/__tests__/inventory/cart/cart.js index 337182d5c2..d9b88c7767 100644 --- a/integration-tests/plugins/__tests__/inventory/cart/cart.js +++ b/integration-tests/plugins/__tests__/inventory/cart/cart.js @@ -1,13 +1,15 @@ const path = require("path") -const { bootstrapApp } = require("../../../../helpers/bootstrap-app") -const { initDb, useDb } = require("../../../../helpers/use-db") -const { setPort, useApi } = require("../../../../helpers/use-api") +const { + bootstrapApp, +} = require("../../../../environment-helpers/bootstrap-app") +const { initDb, useDb } = require("../../../../environment-helpers/use-db") +const { setPort, useApi } = require("../../../../environment-helpers/use-api") -const adminSeeder = require("../../../helpers/admin-seeder") -const cartSeeder = require("../../../helpers/cart-seeder") -const { simpleProductFactory } = require("../../../../api/factories") -const { simpleSalesChannelFactory } = require("../../../../api/factories") +const adminSeeder = require("../../../../helpers/admin-seeder") +const cartSeeder = require("../../../../helpers/cart-seeder") +const { simpleProductFactory } = require("../../../../factories") +const { simpleSalesChannelFactory } = require("../../../../factories") jest.setTimeout(30000) diff --git a/integration-tests/plugins/__tests__/inventory/inventory-items/index.js b/integration-tests/plugins/__tests__/inventory/inventory-items/index.js index 9d5c9e2e75..4b0d536116 100644 --- a/integration-tests/plugins/__tests__/inventory/inventory-items/index.js +++ b/integration-tests/plugins/__tests__/inventory/inventory-items/index.js @@ -1,17 +1,19 @@ const path = require("path") -const { bootstrapApp } = require("../../../../helpers/bootstrap-app") -const { initDb, useDb } = require("../../../../helpers/use-db") -const { setPort, useApi } = require("../../../../helpers/use-api") +const { + bootstrapApp, +} = require("../../../../environment-helpers/bootstrap-app") +const { initDb, useDb } = require("../../../../environment-helpers/use-db") +const { setPort, useApi } = require("../../../../environment-helpers/use-api") -const adminSeeder = require("../../../helpers/admin-seeder") +const adminSeeder = require("../../../../helpers/admin-seeder") jest.setTimeout(30000) const { simpleProductFactory, simpleOrderFactory, -} = require("../../../factories") +} = require("../../../../factories") const adminHeaders = { headers: { Authorization: "Bearer test_token" } } describe("Inventory Items endpoints", () => { diff --git a/integration-tests/plugins/__tests__/inventory/order/draft-order.js b/integration-tests/plugins/__tests__/inventory/order/draft-order.js index 0012ad78ca..335ecff77c 100644 --- a/integration-tests/plugins/__tests__/inventory/order/draft-order.js +++ b/integration-tests/plugins/__tests__/inventory/order/draft-order.js @@ -1,29 +1,23 @@ const path = require("path") -const { bootstrapApp } = require("../../../../helpers/bootstrap-app") -const { initDb, useDb } = require("../../../../helpers/use-db") -const { setPort, useApi } = require("../../../../helpers/use-api") +const { + bootstrapApp, +} = require("../../../../environment-helpers/bootstrap-app") +const { initDb, useDb } = require("../../../../environment-helpers/use-db") +const { setPort, useApi } = require("../../../../environment-helpers/use-api") -const adminSeeder = require("../../../helpers/admin-seeder") -const cartSeeder = require("../../../helpers/cart-seeder") +const adminSeeder = require("../../../../helpers/admin-seeder") const { simpleProductFactory, simpleCustomerFactory, -} = require("../../../../api/factories") -const { simpleSalesChannelFactory } = require("../../../../api/factories") +} = require("../../../../factories") const { - simpleOrderFactory, simpleRegionFactory, - simpleCartFactory, simpleShippingOptionFactory, -} = require("../../../factories") -const { - simpleDiscountFactory, -} = require("../../../factories/simple-discount-factory") -const draftOrderSeeder = require("../../../../api/helpers/draft-order-seeder") +} = require("../../../../factories") const { simpleAddressFactory, -} = require("../../../factories/simple-address-factory") +} = require("../../../../factories/simple-address-factory") jest.setTimeout(30000) diff --git a/integration-tests/plugins/__tests__/inventory/order/order.js b/integration-tests/plugins/__tests__/inventory/order/order.js index f4ddbdfa2b..148af8a601 100644 --- a/integration-tests/plugins/__tests__/inventory/order/order.js +++ b/integration-tests/plugins/__tests__/inventory/order/order.js @@ -1,21 +1,23 @@ const path = require("path") -const { bootstrapApp } = require("../../../../helpers/bootstrap-app") -const { initDb, useDb } = require("../../../../helpers/use-db") -const { setPort, useApi } = require("../../../../helpers/use-api") +const { + bootstrapApp, +} = require("../../../../environment-helpers/bootstrap-app") +const { initDb, useDb } = require("../../../../environment-helpers/use-db") +const { setPort, useApi } = require("../../../../environment-helpers/use-api") -const adminSeeder = require("../../../helpers/admin-seeder") +const adminSeeder = require("../../../../helpers/admin-seeder") const { simpleProductFactory, simpleCustomerFactory, -} = require("../../../../api/factories") -const { simpleSalesChannelFactory } = require("../../../../api/factories") +} = require("../../../../factories") +const { simpleSalesChannelFactory } = require("../../../../factories") const { simpleOrderFactory, simpleRegionFactory, simpleCartFactory, simpleShippingOptionFactory, -} = require("../../../factories") +} = require("../../../../factories") jest.setTimeout(150000) diff --git a/integration-tests/plugins/__tests__/inventory/products/create-variant.js b/integration-tests/plugins/__tests__/inventory/products/create-variant.js index 4ac6b2c1b4..6defce0243 100644 --- a/integration-tests/plugins/__tests__/inventory/products/create-variant.js +++ b/integration-tests/plugins/__tests__/inventory/products/create-variant.js @@ -1,19 +1,21 @@ const path = require("path") -const { bootstrapApp } = require("../../../../helpers/bootstrap-app") -const { initDb, useDb } = require("../../../../helpers/use-db") -const { setPort, useApi } = require("../../../../helpers/use-api") +const { + bootstrapApp, +} = require("../../../../environment-helpers/bootstrap-app") +const { initDb, useDb } = require("../../../../environment-helpers/use-db") +const { setPort, useApi } = require("../../../../environment-helpers/use-api") const { ProductVariantInventoryService, ProductVariantService, } = require("@medusajs/medusa") -const adminSeeder = require("../../../helpers/admin-seeder") +const adminSeeder = require("../../../../helpers/admin-seeder") jest.setTimeout(30000) -const { simpleProductFactory } = require("../../../factories") +const { simpleProductFactory } = require("../../../../factories") describe("Create Variant", () => { let appContainer diff --git a/integration-tests/plugins/__tests__/inventory/products/delete-variant.js b/integration-tests/plugins/__tests__/inventory/products/delete-variant.js index e9d256328b..52517c0bd9 100644 --- a/integration-tests/plugins/__tests__/inventory/products/delete-variant.js +++ b/integration-tests/plugins/__tests__/inventory/products/delete-variant.js @@ -1,14 +1,16 @@ const path = require("path") -const { bootstrapApp } = require("../../../../helpers/bootstrap-app") -const { initDb, useDb } = require("../../../../helpers/use-db") -const { setPort, useApi } = require("../../../../helpers/use-api") +const { + bootstrapApp, +} = require("../../../../environment-helpers/bootstrap-app") +const { initDb, useDb } = require("../../../../environment-helpers/use-db") +const { setPort, useApi } = require("../../../../environment-helpers/use-api") -const adminSeeder = require("../../../helpers/admin-seeder") +const adminSeeder = require("../../../../helpers/admin-seeder") jest.setTimeout(30000) -const { simpleProductFactory } = require("../../../factories") +const { simpleProductFactory } = require("../../../../factories") describe("Delete Variant", () => { let appContainer diff --git a/integration-tests/plugins/__tests__/inventory/products/get-product.js b/integration-tests/plugins/__tests__/inventory/products/get-product.js index 399dc4922a..abb06e24a8 100644 --- a/integration-tests/plugins/__tests__/inventory/products/get-product.js +++ b/integration-tests/plugins/__tests__/inventory/products/get-product.js @@ -1,20 +1,16 @@ const path = require("path") -const { bootstrapApp } = require("../../../../helpers/bootstrap-app") -const { initDb, useDb } = require("../../../../helpers/use-db") -const { setPort, useApi } = require("../../../../helpers/use-api") - const { - ProductVariantInventoryService, - ProductVariantService, -} = require("@medusajs/medusa") + bootstrapApp, +} = require("../../../../environment-helpers/bootstrap-app") +const { initDb, useDb } = require("../../../../environment-helpers/use-db") +const { setPort, useApi } = require("../../../../environment-helpers/use-api") -const adminSeeder = require("../../../helpers/admin-seeder") +const adminSeeder = require("../../../../helpers/admin-seeder") jest.setTimeout(30000) -const { simpleProductFactory } = require("../../../factories") -const { simpleSalesChannelFactory } = require("../../../../api/factories") +const { simpleProductFactory } = require("../../../../factories") const adminHeaders = { headers: { Authorization: "Bearer test_token" } } diff --git a/integration-tests/plugins/__tests__/inventory/products/get-variant.js b/integration-tests/plugins/__tests__/inventory/products/get-variant.js index fc2adb332a..bc9957e556 100644 --- a/integration-tests/plugins/__tests__/inventory/products/get-variant.js +++ b/integration-tests/plugins/__tests__/inventory/products/get-variant.js @@ -1,20 +1,16 @@ const path = require("path") -const { bootstrapApp } = require("../../../../helpers/bootstrap-app") -const { initDb, useDb } = require("../../../../helpers/use-db") -const { setPort, useApi } = require("../../../../helpers/use-api") - const { - ProductVariantInventoryService, - ProductVariantService, -} = require("@medusajs/medusa") + bootstrapApp, +} = require("../../../../environment-helpers/bootstrap-app") +const { initDb, useDb } = require("../../../../environment-helpers/use-db") +const { setPort, useApi } = require("../../../../environment-helpers/use-api") -const adminSeeder = require("../../../helpers/admin-seeder") +const adminSeeder = require("../../../../helpers/admin-seeder") jest.setTimeout(30000) -const { simpleProductFactory } = require("../../../factories") -const { simpleSalesChannelFactory } = require("../../../../api/factories") +const { simpleProductFactory } = require("../../../../factories") const adminHeaders = { headers: { Authorization: "Bearer test_token" } } diff --git a/integration-tests/plugins/__tests__/inventory/products/list-products.js b/integration-tests/plugins/__tests__/inventory/products/list-products.js index 8c3faaef42..f45493d6ff 100644 --- a/integration-tests/plugins/__tests__/inventory/products/list-products.js +++ b/integration-tests/plugins/__tests__/inventory/products/list-products.js @@ -1,20 +1,17 @@ const path = require("path") -const { bootstrapApp } = require("../../../../helpers/bootstrap-app") -const { initDb, useDb } = require("../../../../helpers/use-db") -const { setPort, useApi } = require("../../../../helpers/use-api") - const { - ProductVariantInventoryService, - ProductVariantService, -} = require("@medusajs/medusa") + bootstrapApp, +} = require("../../../../environment-helpers/bootstrap-app") +const { initDb, useDb } = require("../../../../environment-helpers/use-db") +const { setPort, useApi } = require("../../../../environment-helpers/use-api") -const adminSeeder = require("../../../helpers/admin-seeder") +const adminSeeder = require("../../../../helpers/admin-seeder") jest.setTimeout(30000) -const { simpleProductFactory } = require("../../../factories") -const { simpleSalesChannelFactory } = require("../../../../api/factories") +const { simpleProductFactory } = require("../../../../factories") +const { simpleSalesChannelFactory } = require("../../../../factories") const adminHeaders = { headers: { Authorization: "Bearer test_token" } } @@ -68,6 +65,7 @@ describe("Create Variant", () => { { id: productId, status: "published", + sales_channels: [], variants: [{ id: variantId }], }, 100 @@ -135,6 +133,7 @@ describe("Create Variant", () => { { id: `${productId}-1`, status: "published", + sales_channels: [], variants: [ { id: `${variantId}-1`, @@ -150,6 +149,7 @@ describe("Create Variant", () => { id: `${productId}-2`, status: "published", variants: [{ id: `${variantId}-2`, manage_inventory: true }], + sales_channels: [], }, 102 ) @@ -158,6 +158,7 @@ describe("Create Variant", () => { { id: `${productId}-3`, status: "published", + sales_channels: [], variants: [ { id: `${variantId}-3`, @@ -180,6 +181,7 @@ describe("Create Variant", () => { { id: `${productId}-4`, status: "published", + sales_channels: [], variants: [ { id: `${variantId}-4`, diff --git a/integration-tests/plugins/__tests__/inventory/products/list-variants.js b/integration-tests/plugins/__tests__/inventory/products/list-variants.js index 59f96feea1..b3251f237c 100644 --- a/integration-tests/plugins/__tests__/inventory/products/list-variants.js +++ b/integration-tests/plugins/__tests__/inventory/products/list-variants.js @@ -1,20 +1,17 @@ const path = require("path") -const { bootstrapApp } = require("../../../../helpers/bootstrap-app") -const { initDb, useDb } = require("../../../../helpers/use-db") -const { setPort, useApi } = require("../../../../helpers/use-api") - const { - ProductVariantInventoryService, - ProductVariantService, -} = require("@medusajs/medusa") + bootstrapApp, +} = require("../../../../environment-helpers/bootstrap-app") +const { initDb, useDb } = require("../../../../environment-helpers/use-db") +const { setPort, useApi } = require("../../../../environment-helpers/use-api") -const adminSeeder = require("../../../helpers/admin-seeder") +const adminSeeder = require("../../../../helpers/admin-seeder") jest.setTimeout(30000) -const { simpleProductFactory } = require("../../../factories") -const { simpleSalesChannelFactory } = require("../../../../api/factories") +const { simpleProductFactory } = require("../../../../factories") +const { simpleSalesChannelFactory } = require("../../../../factories") const adminHeaders = { headers: { Authorization: "Bearer test_token" } } describe("List Variants", () => { diff --git a/integration-tests/plugins/__tests__/inventory/reservation-items/index.js b/integration-tests/plugins/__tests__/inventory/reservation-items/index.js index a3053d1b10..26226d9454 100644 --- a/integration-tests/plugins/__tests__/inventory/reservation-items/index.js +++ b/integration-tests/plugins/__tests__/inventory/reservation-items/index.js @@ -1,10 +1,12 @@ const path = require("path") -const { bootstrapApp } = require("../../../../helpers/bootstrap-app") -const { initDb, useDb } = require("../../../../helpers/use-db") -const { setPort, useApi } = require("../../../../helpers/use-api") +const { + bootstrapApp, +} = require("../../../../environment-helpers/bootstrap-app") +const { initDb, useDb } = require("../../../../environment-helpers/use-db") +const { setPort, useApi } = require("../../../../environment-helpers/use-api") -const adminSeeder = require("../../../helpers/admin-seeder") +const adminSeeder = require("../../../../helpers/admin-seeder") jest.setTimeout(30000) @@ -12,8 +14,8 @@ const { simpleProductFactory, simpleOrderFactory, simpleRegionFactory, -} = require("../../../factories") -const { simpleSalesChannelFactory } = require("../../../../api/factories") +} = require("../../../../factories") +const { simpleSalesChannelFactory } = require("../../../../factories") const adminHeaders = { headers: { Authorization: "Bearer test_token" } } describe("Inventory Items endpoints", () => { diff --git a/integration-tests/plugins/__tests__/inventory/service.js b/integration-tests/plugins/__tests__/inventory/service.js index ef32c30f2a..44f9330cdb 100644 --- a/integration-tests/plugins/__tests__/inventory/service.js +++ b/integration-tests/plugins/__tests__/inventory/service.js @@ -1,7 +1,7 @@ const path = require("path") -const { bootstrapApp } = require("../../../helpers/bootstrap-app") -const { initDb, useDb } = require("../../../helpers/use-db") +const { bootstrapApp } = require("../../../environment-helpers/bootstrap-app") +const { initDb, useDb } = require("../../../environment-helpers/use-db") jest.setTimeout(50000) diff --git a/integration-tests/plugins/__tests__/inventory/variant-inventory-service.js b/integration-tests/plugins/__tests__/inventory/variant-inventory-service.js index 28c0b00f23..022045fc45 100644 --- a/integration-tests/plugins/__tests__/inventory/variant-inventory-service.js +++ b/integration-tests/plugins/__tests__/inventory/variant-inventory-service.js @@ -1,11 +1,8 @@ const path = require("path") -const { bootstrapApp } = require("../../../helpers/bootstrap-app") -const { initDb, useDb } = require("../../../helpers/use-db") -const { - simpleProductVariantFactory, - simpleProductFactory, -} = require("../../factories") +const { bootstrapApp } = require("../../../environment-helpers/bootstrap-app") +const { initDb, useDb } = require("../../../environment-helpers/use-db") +const { simpleProductFactory } = require("../../../factories") jest.setTimeout(50000) 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 35e26ceb1e..e688ddc941 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 @@ -47,7 +47,7 @@ Object { "should_merge": true, "swap_id": null, "thumbnail": "", - "title": "Intelligent Plastic Chips", + "title": "Incredible Plastic Mouse", "unit_price": 1000, "updated_at": Any, "variant": Object { @@ -87,7 +87,7 @@ Object { "status": "draft", "subtitle": null, "thumbnail": null, - "title": "Awesome Metal Ball", + "title": "Gorgeous Cotton Table", "type_id": null, "updated_at": Any, "weight": null, @@ -95,7 +95,7 @@ Object { }, "product_id": "test-product", "sku": null, - "title": "Practical Granite Pizza", + "title": "Refined Wooden Chair", "upc": null, "updated_at": Any, "variant_rank": 0, @@ -112,7 +112,7 @@ Object { "region_id": "test-region", "sales_channel_id": null, "shipping_address": Object { - "address_1": "84185 Lindsey Centers", + "address_1": "1850 Corine Tunnel", "address_2": null, "city": null, "company": null, @@ -120,12 +120,12 @@ Object { "created_at": Any, "customer_id": null, "deleted_at": null, - "first_name": "Chyna", + "first_name": "Cornell", "id": Any, - "last_name": "Osinski", + "last_name": "Shanahan", "metadata": null, "phone": null, - "postal_code": "51510", + "postal_code": "15102-3998", "province": null, "updated_at": Any, }, @@ -204,7 +204,7 @@ Object { "should_merge": true, "swap_id": null, "thumbnail": "", - "title": "Intelligent Plastic Chips", + "title": "Incredible Plastic Mouse", "unit_price": 1000, "updated_at": Any, "variant": Object { @@ -244,7 +244,7 @@ Object { "status": "draft", "subtitle": null, "thumbnail": null, - "title": "Awesome Metal Ball", + "title": "Gorgeous Cotton Table", "type_id": null, "updated_at": Any, "weight": null, @@ -252,7 +252,7 @@ Object { }, "product_id": "test-product", "sku": null, - "title": "Practical Granite Pizza", + "title": "Refined Wooden Chair", "upc": null, "updated_at": Any, "variant_rank": 0, @@ -269,7 +269,7 @@ Object { "region_id": "test-region", "sales_channel_id": null, "shipping_address": Object { - "address_1": "84185 Lindsey Centers", + "address_1": "1850 Corine Tunnel", "address_2": null, "city": null, "company": null, @@ -277,12 +277,12 @@ Object { "created_at": Any, "customer_id": null, "deleted_at": null, - "first_name": "Chyna", + "first_name": "Cornell", "id": Any, - "last_name": "Osinski", + "last_name": "Shanahan", "metadata": null, "phone": null, - "postal_code": "51510", + "postal_code": "15102-3998", "province": null, "updated_at": Any, }, @@ -336,7 +336,7 @@ Object { }, ], "thumbnail": null, - "title": "Intelligent Plastic Chips", + "title": "Incredible Plastic Mouse", "totals": Object { "discount_total": 0, "original_tax_total": 200, @@ -399,7 +399,7 @@ Object { "status": "draft", "subtitle": null, "thumbnail": null, - "title": "Awesome Metal Ball", + "title": "Gorgeous Cotton Table", "type_id": null, "updated_at": Any, "weight": null, @@ -407,7 +407,7 @@ Object { }, "product_id": "test-product", "sku": null, - "title": "Practical Granite Pizza", + "title": "Refined Wooden Chair", "upc": null, "updated_at": Any, "variant_rank": 0, @@ -478,7 +478,7 @@ Object { ], "tax_total": 400, "thumbnail": "", - "title": "Intelligent Plastic Chips", + "title": "Incredible Plastic Mouse", "total": 2400, "unit_price": 1000, "updated_at": Any, @@ -519,7 +519,7 @@ Object { "status": "draft", "subtitle": null, "thumbnail": null, - "title": "Awesome Metal Ball", + "title": "Gorgeous Cotton Table", "type_id": null, "updated_at": Any, "weight": null, @@ -527,7 +527,7 @@ Object { }, "product_id": "test-product", "sku": null, - "title": "Practical Granite Pizza", + "title": "Refined Wooden Chair", "upc": null, "updated_at": Any, "variant_rank": 0, @@ -590,7 +590,7 @@ Object { ], "sales_channel_id": null, "shipping_address": Object { - "address_1": "84185 Lindsey Centers", + "address_1": "1850 Corine Tunnel", "address_2": null, "city": null, "company": null, @@ -598,12 +598,12 @@ Object { "created_at": Any, "customer_id": null, "deleted_at": null, - "first_name": "Chyna", + "first_name": "Cornell", "id": Any, - "last_name": "Osinski", + "last_name": "Shanahan", "metadata": null, "phone": null, - "postal_code": "51510", + "postal_code": "15102-3998", "province": null, "updated_at": Any, }, @@ -657,7 +657,7 @@ Object { }, ], "thumbnail": "", - "title": "Intelligent Plastic Chips", + "title": "Incredible Plastic Mouse", "unit_price": 1000, "updated_at": Any, "variant": Object { @@ -697,7 +697,7 @@ Object { "status": "draft", "subtitle": null, "thumbnail": null, - "title": "Awesome Metal Ball", + "title": "Gorgeous Cotton Table", "type_id": null, "updated_at": Any, "weight": null, @@ -705,7 +705,7 @@ Object { }, "product_id": "test-product", "sku": null, - "title": "Practical Granite Pizza", + "title": "Refined Wooden Chair", "upc": null, "updated_at": Any, "variant_rank": 0, @@ -756,12 +756,12 @@ Object { "created_at": Any, "deleted_at": null, "email": "test@testson.com", - "first_name": null, - "has_account": false, + "first_name": "Lonzo", + "has_account": true, "id": Any, - "last_name": null, + "last_name": "Kemmer", "metadata": null, - "phone": null, + "phone": "499-811-0832", "updated_at": Any, }, "customer_id": Any, @@ -824,7 +824,7 @@ Object { ], "tax_total": 400, "thumbnail": null, - "title": "Intelligent Plastic Chips", + "title": "Handcrafted Frozen Tuna", "total": 2400, "unit_price": 1000, "updated_at": Any, @@ -983,12 +983,12 @@ Object { "created_at": Any, "deleted_at": null, "email": "test@testson.com", - "first_name": null, - "has_account": false, + "first_name": "Reba", + "has_account": true, "id": Any, - "last_name": null, + "last_name": "Waelchi", "metadata": null, - "phone": null, + "phone": "1-308-426-4696", "updated_at": Any, }, "customer_id": Any, @@ -1052,7 +1052,7 @@ Object { ], "tax_total": 400, "thumbnail": null, - "title": "Intelligent Plastic Chips", + "title": "Incredible Plastic Mouse", "total": 2400, "totals": Object { "discount_total": 0, @@ -1116,7 +1116,7 @@ Object { "status": "draft", "subtitle": null, "thumbnail": null, - "title": "Awesome Metal Ball", + "title": "Gorgeous Cotton Table", "type_id": null, "updated_at": Any, "weight": null, @@ -1124,7 +1124,7 @@ Object { }, "product_id": "test-product", "sku": null, - "title": "Practical Granite Pizza", + "title": "Refined Wooden Chair", "upc": null, "updated_at": Any, "variant_rank": 0, @@ -1160,7 +1160,7 @@ Object { "returns": Array [], "sales_channel_id": null, "shipping_address": Object { - "address_1": "84185 Lindsey Centers", + "address_1": "1850 Corine Tunnel", "address_2": null, "city": null, "company": null, @@ -1168,12 +1168,12 @@ Object { "created_at": Any, "customer_id": null, "deleted_at": null, - "first_name": "Chyna", + "first_name": "Cornell", "id": Any, - "last_name": "Osinski", + "last_name": "Shanahan", "metadata": null, "phone": null, - "postal_code": "51510", + "postal_code": "15102-3998", "province": null, "updated_at": Any, }, @@ -1235,12 +1235,12 @@ Object { "created_at": Any, "deleted_at": null, "email": "test@testson.com", - "first_name": null, - "has_account": false, + "first_name": "Reba", + "has_account": true, "id": Any, - "last_name": null, + "last_name": "Waelchi", "metadata": null, - "phone": null, + "phone": "1-308-426-4696", "updated_at": Any, }, "customer_id": Any, @@ -1324,7 +1324,7 @@ Object { ], "tax_total": 400, "thumbnail": "", - "title": "Intelligent Plastic Chips", + "title": "Incredible Plastic Mouse", "total": 2400, "unit_price": 1000, "updated_at": Any, @@ -1365,7 +1365,7 @@ Object { "status": "draft", "subtitle": null, "thumbnail": null, - "title": "Awesome Metal Ball", + "title": "Gorgeous Cotton Table", "type_id": null, "updated_at": Any, "weight": null, @@ -1373,7 +1373,7 @@ Object { }, "product_id": "test-product", "sku": null, - "title": "Practical Granite Pizza", + "title": "Refined Wooden Chair", "upc": null, "updated_at": Any, "variant_rank": 0, @@ -1409,7 +1409,7 @@ Object { "returns": Array [], "sales_channel_id": null, "shipping_address": Object { - "address_1": "84185 Lindsey Centers", + "address_1": "1850 Corine Tunnel", "address_2": null, "city": null, "company": null, @@ -1417,12 +1417,12 @@ Object { "created_at": Any, "customer_id": null, "deleted_at": null, - "first_name": "Chyna", + "first_name": "Cornell", "id": Any, - "last_name": "Osinski", + "last_name": "Shanahan", "metadata": null, "phone": null, - "postal_code": "51510", + "postal_code": "15102-3998", "province": null, "updated_at": Any, }, @@ -1511,7 +1511,7 @@ Object { }, ], "thumbnail": null, - "title": "Intelligent Plastic Chips", + "title": "Incredible Plastic Mouse", "totals": Object { "discount_total": 0, "original_tax_total": 200, @@ -1574,7 +1574,7 @@ Object { "status": "draft", "subtitle": null, "thumbnail": null, - "title": "Awesome Metal Ball", + "title": "Gorgeous Cotton Table", "type_id": null, "updated_at": Any, "weight": null, @@ -1582,7 +1582,7 @@ Object { }, "product_id": "test-product", "sku": null, - "title": "Practical Granite Pizza", + "title": "Refined Wooden Chair", "upc": null, "updated_at": Any, "variant_rank": 0, @@ -1653,7 +1653,7 @@ Object { ], "tax_total": 400, "thumbnail": "", - "title": "Intelligent Plastic Chips", + "title": "Incredible Plastic Mouse", "total": 2400, "unit_price": 1000, "updated_at": Any, @@ -1694,7 +1694,7 @@ Object { "status": "draft", "subtitle": null, "thumbnail": null, - "title": "Awesome Metal Ball", + "title": "Gorgeous Cotton Table", "type_id": null, "updated_at": Any, "weight": null, @@ -1702,7 +1702,7 @@ Object { }, "product_id": "test-product", "sku": null, - "title": "Practical Granite Pizza", + "title": "Refined Wooden Chair", "upc": null, "updated_at": Any, "variant_rank": 0, @@ -1765,7 +1765,7 @@ Object { ], "sales_channel_id": null, "shipping_address": Object { - "address_1": "84185 Lindsey Centers", + "address_1": "1850 Corine Tunnel", "address_2": null, "city": null, "company": null, @@ -1773,12 +1773,12 @@ Object { "created_at": Any, "customer_id": null, "deleted_at": null, - "first_name": "Chyna", + "first_name": "Cornell", "id": Any, - "last_name": "Osinski", + "last_name": "Shanahan", "metadata": null, "phone": null, - "postal_code": "51510", + "postal_code": "15102-3998", "province": null, "updated_at": Any, }, @@ -1832,7 +1832,7 @@ Object { }, ], "thumbnail": "", - "title": "Intelligent Plastic Chips", + "title": "Incredible Plastic Mouse", "unit_price": 1000, "updated_at": Any, "variant": Object { @@ -1872,7 +1872,7 @@ Object { "status": "draft", "subtitle": null, "thumbnail": null, - "title": "Awesome Metal Ball", + "title": "Gorgeous Cotton Table", "type_id": null, "updated_at": Any, "weight": null, @@ -1880,7 +1880,7 @@ Object { }, "product_id": "test-product", "sku": null, - "title": "Practical Granite Pizza", + "title": "Refined Wooden Chair", "upc": null, "updated_at": Any, "variant_rank": 0, @@ -2103,7 +2103,7 @@ Object { }, ], "thumbnail": "", - "title": "Intelligent Plastic Chips", + "title": "Handcrafted Frozen Tuna", "unit_price": 1000, "updated_at": Any, "variant": Object { diff --git a/integration-tests/plugins/__tests__/medusa-plugin-sendgrid/index.js b/integration-tests/plugins/__tests__/medusa-plugin-sendgrid/index.js index 51f85c2519..99031e696b 100644 --- a/integration-tests/plugins/__tests__/medusa-plugin-sendgrid/index.js +++ b/integration-tests/plugins/__tests__/medusa-plugin-sendgrid/index.js @@ -1,10 +1,10 @@ const path = require("path") -const { bootstrapApp } = require("../../../helpers/bootstrap-app") -const { initDb, useDb } = require("../../../helpers/use-db") -const { setPort, useApi } = require("../../../helpers/use-api") +const { bootstrapApp } = require("../../../environment-helpers/bootstrap-app") +const { initDb, useDb } = require("../../../environment-helpers/use-db") +const { setPort, useApi } = require("../../../environment-helpers/use-api") -const adminSeeder = require("../../helpers/admin-seeder") +const adminSeeder = require("../../../helpers/admin-seeder") jest.setTimeout(10000) @@ -13,7 +13,7 @@ const { simpleStoreFactory, simpleProductFactory, simpleShippingOptionFactory, -} = require("../../factories") +} = require("../../../factories") describe("medusa-plugin-sendgrid", () => { let appContainer diff --git a/integration-tests/plugins/__tests__/stock-location/delete-sales-channels.js b/integration-tests/plugins/__tests__/stock-location/delete-sales-channels.js index 63a7474fa8..78b3651b8f 100644 --- a/integration-tests/plugins/__tests__/stock-location/delete-sales-channels.js +++ b/integration-tests/plugins/__tests__/stock-location/delete-sales-channels.js @@ -1,10 +1,10 @@ const path = require("path") -const { bootstrapApp } = require("../../../helpers/bootstrap-app") -const { initDb, useDb } = require("../../../helpers/use-db") -const { setPort, useApi } = require("../../../helpers/use-api") +const { bootstrapApp } = require("../../../environment-helpers/bootstrap-app") +const { initDb, useDb } = require("../../../environment-helpers/use-db") +const { setPort, useApi } = require("../../../environment-helpers/use-api") -const adminSeeder = require("../../helpers/admin-seeder") +const adminSeeder = require("../../../helpers/admin-seeder") jest.setTimeout(30000) diff --git a/integration-tests/plugins/__tests__/stock-location/delete-stock-location.js b/integration-tests/plugins/__tests__/stock-location/delete-stock-location.js index 5c1d37abf6..ba1ea58cb3 100644 --- a/integration-tests/plugins/__tests__/stock-location/delete-stock-location.js +++ b/integration-tests/plugins/__tests__/stock-location/delete-stock-location.js @@ -1,10 +1,10 @@ const path = require("path") -const { bootstrapApp } = require("../../../helpers/bootstrap-app") -const { initDb, useDb } = require("../../../helpers/use-db") -const { setPort, useApi } = require("../../../helpers/use-api") +const { bootstrapApp } = require("../../../environment-helpers/bootstrap-app") +const { initDb, useDb } = require("../../../environment-helpers/use-db") +const { setPort, useApi } = require("../../../environment-helpers/use-api") -const adminSeeder = require("../../helpers/admin-seeder") +const adminSeeder = require("../../../helpers/admin-seeder") jest.setTimeout(30000) diff --git a/integration-tests/plugins/__tests__/stock-location/sales-channels.js b/integration-tests/plugins/__tests__/stock-location/sales-channels.js index f85f10f4e9..039e82cc8f 100644 --- a/integration-tests/plugins/__tests__/stock-location/sales-channels.js +++ b/integration-tests/plugins/__tests__/stock-location/sales-channels.js @@ -1,10 +1,10 @@ const path = require("path") -const { bootstrapApp } = require("../../../helpers/bootstrap-app") -const { initDb, useDb } = require("../../../helpers/use-db") -const { setPort, useApi } = require("../../../helpers/use-api") +const { bootstrapApp } = require("../../../environment-helpers/bootstrap-app") +const { initDb, useDb } = require("../../../environment-helpers/use-db") +const { setPort, useApi } = require("../../../environment-helpers/use-api") -const adminSeeder = require("../../helpers/admin-seeder") +const adminSeeder = require("../../../helpers/admin-seeder") jest.setTimeout(30000) diff --git a/integration-tests/plugins/__tests__/stock-location/service.js b/integration-tests/plugins/__tests__/stock-location/service.js index fc633efc2e..9cec2189ef 100644 --- a/integration-tests/plugins/__tests__/stock-location/service.js +++ b/integration-tests/plugins/__tests__/stock-location/service.js @@ -1,7 +1,7 @@ const path = require("path") -const { bootstrapApp } = require("../../../helpers/bootstrap-app") -const { initDb, useDb } = require("../../../helpers/use-db") +const { bootstrapApp } = require("../../../environment-helpers/bootstrap-app") +const { initDb, useDb } = require("../../../environment-helpers/use-db") jest.setTimeout(30000) diff --git a/integration-tests/plugins/factories/index.ts b/integration-tests/plugins/factories/index.ts deleted file mode 100644 index 2830eed241..0000000000 --- a/integration-tests/plugins/factories/index.ts +++ /dev/null @@ -1,13 +0,0 @@ -export * from "./simple-order-factory" -export * from "./simple-cart-factory" -export * from "./simple-region-factory" -export * from "./simple-line-item-factory" -export * from "./simple-product-factory" -export * from "./simple-product-variant-factory" -export * from "./simple-product-tax-rate-factory" -export * from "./simple-shipping-tax-rate-factory" -export * from "./simple-tax-rate-factory" -export * from "./simple-shipping-option-factory" -export * from "./simple-shipping-method-factory" -export * from "./simple-product-type-tax-rate-factory" -export * from "./simple-store-factory" diff --git a/integration-tests/plugins/factories/simple-address-factory.ts b/integration-tests/plugins/factories/simple-address-factory.ts deleted file mode 100644 index cb40d162d8..0000000000 --- a/integration-tests/plugins/factories/simple-address-factory.ts +++ /dev/null @@ -1,34 +0,0 @@ -import { Connection } from "typeorm" -import faker from "faker" -import { Address } from "@medusajs/medusa" - -export type AddressFactoryData = { - first_name?: string - last_name?: string - country_code?: string - address_1?: string - postal_code?: string -} - -export const simpleAddressFactory = async ( - connection: Connection, - data: AddressFactoryData = {}, - seed?: number -): Promise
=> { - if (typeof seed !== "undefined") { - faker.seed(seed) - } - - const manager = connection.manager - - const address = manager.create(Address, { - id: `simple-id-${Math.random() * 1000}`, - first_name: data.first_name || faker.name.firstName(), - last_name: data.last_name || faker.name.lastName(), - country_code: data.country_code || "us", - address_1: data.address_1 || faker.address.streetAddress(), - postal_code: data.postal_code || faker.address.zipCode(), - }) - - return await manager.save(address) -} diff --git a/integration-tests/plugins/factories/simple-cart-factory.ts b/integration-tests/plugins/factories/simple-cart-factory.ts deleted file mode 100644 index e6c2d493f3..0000000000 --- a/integration-tests/plugins/factories/simple-cart-factory.ts +++ /dev/null @@ -1,72 +0,0 @@ -import { - AddressFactoryData, - simpleAddressFactory, -} from "./simple-address-factory" -import { Connection, DataSource } from "typeorm" -import { - LineItemFactoryData, - simpleLineItemFactory, -} from "./simple-line-item-factory" -import { RegionFactoryData, simpleRegionFactory } from "./simple-region-factory" -import { - ShippingMethodFactoryData, - simpleShippingMethodFactory, -} from "./simple-shipping-method-factory" - -import { Cart } from "@medusajs/medusa" -import faker from "faker" - -export type CartFactoryData = { - id?: string - region?: RegionFactoryData | string - email?: string | null - line_items?: LineItemFactoryData[] - shipping_address?: AddressFactoryData - shipping_methods?: ShippingMethodFactoryData[] - sales_channel_id?: string -} - -export const simpleCartFactory = async ( - dataSource: DataSource, - data: CartFactoryData = {}, - seed: number -): Promise => { - if (typeof seed !== "undefined") { - faker.seed(seed) - } - - const manager = dataSource.manager - - let regionId: string - if (typeof data.region === "string") { - regionId = data.region - } else { - const region = await simpleRegionFactory(dataSource, data.region) - regionId = region.id - } - const address = await simpleAddressFactory(dataSource, data.shipping_address) - - const id = data.id || `simple-cart-${Math.random() * 1000}` - const toSave = manager.create(Cart, { - id, - email: - typeof data.email !== "undefined" ? data.email : faker.internet.email(), - region_id: regionId, - shipping_address_id: address.id, - sales_channel_id: data.sales_channel_id || null, - }) - - const cart = await manager.save(toSave) - - const shippingMethods = data.shipping_methods || [] - for (const sm of shippingMethods) { - await simpleShippingMethodFactory(dataSource, { ...sm, cart_id: id }) - } - - const items = data.line_items - for (const item of items || []) { - await simpleLineItemFactory(dataSource, { ...item, cart_id: id }) - } - - return cart -} diff --git a/integration-tests/plugins/factories/simple-discount-factory.ts b/integration-tests/plugins/factories/simple-discount-factory.ts deleted file mode 100644 index 8fbb13cd28..0000000000 --- a/integration-tests/plugins/factories/simple-discount-factory.ts +++ /dev/null @@ -1,55 +0,0 @@ -import { Connection } from "typeorm" -import faker from "faker" -import { - Discount, - DiscountRule, - DiscountRuleType, - AllocationType, -} from "@medusajs/medusa" - -export type DiscountRuleFactoryData = { - type?: DiscountRuleType - value?: number - allocation?: AllocationType -} - -export type DiscountFactoryData = { - id?: string - code?: string - is_dynamic?: boolean - rule?: DiscountRuleFactoryData - regions?: string[] -} - -export const simpleDiscountFactory = async ( - connection: Connection, - data: DiscountFactoryData = {}, - seed?: number -): Promise => { - if (typeof seed !== "undefined") { - faker.seed(seed) - } - - const manager = connection.manager - - const ruleData = data.rule ?? {} - const ruleToSave = manager.create(DiscountRule, { - type: ruleData.type ?? DiscountRuleType.PERCENTAGE, - value: ruleData.value ?? 10, - allocation: ruleData.allocation ?? AllocationType.TOTAL, - }) - - const dRule = await manager.save(ruleToSave) - - const toSave = manager.create(Discount, { - id: data.id, - is_dynamic: data.is_dynamic ?? false, - is_disabled: false, - rule_id: dRule.id, - code: data.code ?? "TESTCODE", - regions: data.regions?.map((r) => ({ id: r })) || [], - }) - - const discount = await manager.save(toSave) - return discount -} diff --git a/integration-tests/plugins/factories/simple-line-item-factory.ts b/integration-tests/plugins/factories/simple-line-item-factory.ts deleted file mode 100644 index 84995c79f3..0000000000 --- a/integration-tests/plugins/factories/simple-line-item-factory.ts +++ /dev/null @@ -1,84 +0,0 @@ -import { Connection } from "typeorm" -import faker from "faker" -import { LineItem, LineItemTaxLine } from "@medusajs/medusa" - -type TaxLineFactoryData = { - rate: number - code: string - name: string -} - -export type LineItemFactoryData = { - id?: string - cart_id?: string - order_id?: string - variant_id: string | null - title?: string - description?: string - thumbnail?: string - should_merge?: boolean - allow_discounts?: boolean - unit_price?: number - quantity?: number - fulfilled_quantity?: boolean - shipped_quantity?: boolean - returned_quantity?: boolean - tax_lines?: TaxLineFactoryData[] -} - -export const simpleLineItemFactory = async ( - connection: Connection, - data: LineItemFactoryData, - seed?: number -): Promise => { - if ( - typeof data.cart_id === "undefined" && - typeof data.order_id === "undefined" - ) { - throw Error() - } - - if (typeof seed !== "undefined") { - faker.seed(seed) - Math - } - - const manager = connection.manager - - const id = data.id || `simple-line-${Math.random() * 1000}` - const toSave = manager.create(LineItem, { - id, - cart_id: data.cart_id, - order_id: data.order_id, - title: data.title || faker.commerce.productName(), - description: data.description || "", - thumbnail: data.thumbnail || "", - should_merge: - typeof data.should_merge !== "undefined" ? data.should_merge : true, - allow_discounts: - typeof data.allow_discounts !== "undefined" ? data.allow_discounts : true, - unit_price: typeof data.unit_price !== "undefined" ? data.unit_price : 100, - variant_id: data.variant_id, - quantity: data.quantity || 1, - fulfilled_quantity: data.fulfilled_quantity || null, - shipped_quantity: data.shipped_quantity || null, - returned_quantity: data.returned_quantity || null, - }) - - const line = await manager.save(toSave) - - if (typeof data.tax_lines !== "undefined") { - const taxLinesToSave = data.tax_lines.map((tl) => - manager.create(LineItemTaxLine, { - item_id: id, - rate: tl.rate, - code: tl.code, - name: tl.name, - }) - ) - - await manager.save(taxLinesToSave) - } - - return line -} diff --git a/integration-tests/plugins/factories/simple-order-factory.ts b/integration-tests/plugins/factories/simple-order-factory.ts deleted file mode 100644 index 052878bb2c..0000000000 --- a/integration-tests/plugins/factories/simple-order-factory.ts +++ /dev/null @@ -1,146 +0,0 @@ -import { Connection } from "typeorm" -import faker from "faker" -import { - Customer, - Order, - PaymentStatus, - FulfillmentStatus, - SalesChannel, - Discount, - isString, -} from "@medusajs/medusa" - -import { - DiscountFactoryData, - simpleDiscountFactory, -} from "./simple-discount-factory" -import { RegionFactoryData, simpleRegionFactory } from "./simple-region-factory" -import { - LineItemFactoryData, - simpleLineItemFactory, -} from "./simple-line-item-factory" -import { - AddressFactoryData, - simpleAddressFactory, -} from "./simple-address-factory" -import { - ShippingMethodFactoryData, - simpleShippingMethodFactory, -} from "./simple-shipping-method-factory" -import { - SalesChannelFactoryData, - simpleSalesChannelFactory, -} from "../../api/factories" -import { isDefined } from "medusa-core-utils" - -export type OrderFactoryData = { - id?: string - payment_status?: PaymentStatus - fulfillment_status?: FulfillmentStatus - region?: RegionFactoryData | string - email?: string | null - currency_code?: string - tax_rate?: number | null - sales_channel?: string | SalesChannelFactoryData - line_items?: LineItemFactoryData[] - discounts?: DiscountFactoryData[] - shipping_address?: AddressFactoryData - shipping_methods?: ShippingMethodFactoryData[] -} - -export const simpleOrderFactory = async ( - connection: Connection, - data: OrderFactoryData = {}, - seed: number -): Promise => { - if (typeof seed !== "undefined") { - faker.seed(seed) - } - - const manager = connection.manager - - let currencyCode: string - let regionId: string - let taxRate: number - if (typeof data.region === "string") { - currencyCode = data.currency_code - regionId = data.region - taxRate = data.tax_rate - } else { - const region = await simpleRegionFactory(connection, data.region) - taxRate = - typeof data.tax_rate !== "undefined" ? data.tax_rate : region.tax_rate - currencyCode = region.currency_code - regionId = region.id - } - const address = await simpleAddressFactory(connection, data.shipping_address) - - const customerToSave = manager.create(Customer, { - email: - typeof data.email !== "undefined" ? data.email : faker.internet.email(), - }) - const customer = await manager.save(customerToSave) - - let discounts: Discount[] = [] - if (typeof data.discounts !== "undefined") { - discounts = await Promise.all( - data.discounts.map((d) => simpleDiscountFactory(connection, d, seed)) - ) - } - const id = data.id || `simple-order-${Math.random() * 1000}` - const toCreate: Partial = { - id, - discounts, - payment_status: data.payment_status ?? PaymentStatus.AWAITING, - fulfillment_status: - data.fulfillment_status ?? FulfillmentStatus.NOT_FULFILLED, - customer_id: customer.id, - email: customer.email, - region_id: regionId, - currency_code: currencyCode, - tax_rate: taxRate, - shipping_address_id: address.id, - } - - let sc_id - if (isDefined(data.sales_channel)) { - let sc - - if (isString(data.sales_channel)) { - sc = await manager.findOne(SalesChannel, { - where: { id: data.sales_channel }, - }) - } - - if (!sc) { - sc = await simpleSalesChannelFactory( - connection, - isString(data.sales_channel) - ? { id: data.sales_channel } - : data.sales_channel - ) - } - - sc_id = sc.id - } - - if (sc_id) { - toCreate.sales_channel_id = sc_id - } - - const toSave = manager.create(Order, toCreate) - - const order = await manager.save(Order, toSave) - - const shippingMethods = data.shipping_methods || [] - for (const sm of shippingMethods) { - await simpleShippingMethodFactory(connection, { ...sm, order_id: order.id }) - } - - const items = data.line_items || [] - for (const item of items) { - await simpleLineItemFactory(connection, { ...item, order_id: id }) - } - - return order -} diff --git a/integration-tests/plugins/factories/simple-product-factory.ts b/integration-tests/plugins/factories/simple-product-factory.ts deleted file mode 100644 index 3d7cf86202..0000000000 --- a/integration-tests/plugins/factories/simple-product-factory.ts +++ /dev/null @@ -1,92 +0,0 @@ -import { Product, ProductOption, ProductStatus, ProductType, ShippingProfile, ShippingProfileType, } from "@medusajs/medusa" -import { ProductVariantFactoryData, simpleProductVariantFactory, } from "./simple-product-variant-factory" - -import { Connection } from "typeorm" -import faker from "faker" - -export type ProductFactoryData = { - id?: string - is_giftcard?: boolean - title?: string - type?: string - status?: ProductStatus - options?: { id: string; title: string }[] - variants?: ProductVariantFactoryData[] -} - -export const simpleProductFactory = async ( - connection: Connection, - data: ProductFactoryData = {}, - seed?: number -): Promise => { - if (typeof seed !== "undefined") { - faker.seed(seed) - } - - const manager = connection.manager - - const defaultProfile = await manager.findOne(ShippingProfile, { - where: { type: ShippingProfileType.DEFAULT }, - }) - - const gcProfile = await manager.findOne(ShippingProfile, { - where: { type: ShippingProfileType.GIFT_CARD }, - }) - - let typeId: string - if (typeof data.type !== "undefined") { - const toSave = manager.create(ProductType, { - value: data.type, - }) - const res = await manager.save(toSave) - typeId = res.id - } - - const prodId = data.id || `simple-product-${Math.random() * 1000}` - const toSave = manager.create(Product, { - id: prodId, - type_id: typeId, - status: data.status || ProductStatus.DRAFT, - title: data.title || faker.commerce.productName(), - is_giftcard: data.is_giftcard || false, - discountable: !data.is_giftcard, - profile_id: data.is_giftcard ? gcProfile.id : defaultProfile.id, - }) - - const product = await manager.save(toSave) - - const optionId = `${prodId}-option` - const options = data.options || [{ id: optionId, title: "Size" }] - for (const o of options) { - await manager.insert(ProductOption, { - id: o.id, - title: o.title, - product_id: prodId, - }) - } - - const variants = data.variants || [ - { - id: `simple-test-variant-${Math.random() * 1000}`, - title: "Test", - product_id: prodId, - prices: [{ currency: "usd", amount: 100 }], - options: [{ option_id: optionId, value: "Large" }], - }, - ] - - product.variants = await Promise.all(variants.map(async (pv) => { - const factoryData = { - ...pv, - product_id: prodId, - } - if (typeof pv.options === "undefined") { - factoryData.options = [ - { option_id: optionId, value: faker.commerce.productAdjective() }, - ] - } - return await simpleProductVariantFactory(connection, factoryData) - })) - - return product -} diff --git a/integration-tests/plugins/factories/simple-product-tax-rate-factory.ts b/integration-tests/plugins/factories/simple-product-tax-rate-factory.ts deleted file mode 100644 index 4b731c51b3..0000000000 --- a/integration-tests/plugins/factories/simple-product-tax-rate-factory.ts +++ /dev/null @@ -1,48 +0,0 @@ -import { Connection } from "typeorm" -import faker from "faker" -import { ProductTaxRate, TaxRate } from "@medusajs/medusa" - -type RateFactoryData = { - region_id: string - rate?: number | null - code?: string - name?: string -} - -export type ProductTaxRateFactoryData = { - product_id: string - rate: RateFactoryData | string -} - -export const simpleProductTaxRateFactory = async ( - connection: Connection, - data: ProductTaxRateFactoryData, - seed?: number -): Promise => { - if (typeof seed !== "undefined") { - faker.seed(seed) - } - - const manager = connection.manager - - let rateId: string - if (typeof data.rate === "string") { - rateId = data.rate - } else { - const newRate = manager.create(TaxRate, { - region_id: data.rate.region_id, - rate: data.rate.rate, - code: data.rate.code || "sales_tax", - name: data.rate.name || "Sales Tax", - }) - const rate = await manager.save(newRate) - rateId = rate.id - } - - const toSave = manager.create(ProductTaxRate, { - product_id: data.product_id, - rate_id: rateId, - }) - - return await manager.save(toSave) -} diff --git a/integration-tests/plugins/factories/simple-product-type-tax-rate-factory.ts b/integration-tests/plugins/factories/simple-product-type-tax-rate-factory.ts deleted file mode 100644 index 47402a6cbf..0000000000 --- a/integration-tests/plugins/factories/simple-product-type-tax-rate-factory.ts +++ /dev/null @@ -1,48 +0,0 @@ -import { Connection } from "typeorm" -import faker from "faker" -import { ProductTypeTaxRate, TaxRate } from "@medusajs/medusa" - -type RateFactoryData = { - region_id: string - rate?: number | null - code?: string - name?: string -} - -export type ProductTypeTaxRateFactoryData = { - product_type_id: string - rate: RateFactoryData | string -} - -export const simpleProductTypeTaxRateFactory = async ( - connection: Connection, - data: ProductTypeTaxRateFactoryData, - seed?: number -): Promise => { - if (typeof seed !== "undefined") { - faker.seed(seed) - } - - const manager = connection.manager - - let rateId: string - if (typeof data.rate === "string") { - rateId = data.rate - } else { - const newRate = manager.create(TaxRate, { - region_id: data.rate.region_id, - rate: data.rate.rate, - code: data.rate.code || "sales_tax", - name: data.rate.name || "Sales Tax", - }) - const rate = await manager.save(newRate) - rateId = rate.id - } - - const toSave = manager.create(ProductTypeTaxRate, { - product_type_id: data.product_type_id, - rate_id: rateId, - }) - - return await manager.save(toSave) -} diff --git a/integration-tests/plugins/factories/simple-product-variant-factory.ts b/integration-tests/plugins/factories/simple-product-variant-factory.ts deleted file mode 100644 index 81913e44ad..0000000000 --- a/integration-tests/plugins/factories/simple-product-variant-factory.ts +++ /dev/null @@ -1,69 +0,0 @@ -import { - MoneyAmount, - ProductOptionValue, - ProductVariant, -} from "@medusajs/medusa" - -import { Connection } from "typeorm" -import faker from "faker" - -export type ProductVariantFactoryData = { - product_id: string - id?: string - is_giftcard?: boolean - inventory_quantity?: number - title?: string - allow_backorder?: boolean - manage_inventory?: boolean - options?: { option_id: string; value: string }[] - prices?: { currency: string; amount: number }[] -} - -export const simpleProductVariantFactory = async ( - connection: Connection, - data: ProductVariantFactoryData, - seed?: number -): Promise => { - if (typeof seed !== "undefined") { - faker.seed(seed) - } - - const manager = connection.manager - - const id = data.id || `simple-variant-${Math.random() * 1000}` - const toSave = manager.create(ProductVariant, { - id, - product_id: data.product_id, - allow_backorder: data.allow_backorder || false, - manage_inventory: typeof data.manage_inventory !== 'undefined' ? data.manage_inventory : true, - inventory_quantity: - typeof data.inventory_quantity !== "undefined" - ? data.inventory_quantity - : 10, - title: data.title || faker.commerce.productName(), - }) - - const variant = await manager.save(toSave) - - const options = data.options || [{ option_id: "test-option", value: "Large" }] - for (const o of options) { - await manager.insert(ProductOptionValue, { - id: `${o.value}-${o.option_id}`, - value: o.value, - variant_id: id, - option_id: o.option_id, - }) - } - - const prices = data.prices || [{ currency: "usd", amount: 100 }] - for (const p of prices) { - await manager.insert(MoneyAmount, { - id: `${p.currency}-${p.amount}-${Math.random()}`, - variant_id: id, - currency_code: p.currency, - amount: p.amount, - }) - } - - return variant -} diff --git a/integration-tests/plugins/factories/simple-region-factory.ts b/integration-tests/plugins/factories/simple-region-factory.ts deleted file mode 100644 index 0cd08ea702..0000000000 --- a/integration-tests/plugins/factories/simple-region-factory.ts +++ /dev/null @@ -1,47 +0,0 @@ -import { Connection } from "typeorm" -import faker from "faker" -import { Region } from "@medusajs/medusa" - -export type RegionFactoryData = { - id?: string - name?: string - currency_code?: string - tax_rate?: number - countries?: string[] - automatic_taxes?: boolean -} - -export const simpleRegionFactory = async ( - connection: Connection, - data: RegionFactoryData = {}, - seed?: number -): Promise => { - if (typeof seed !== "undefined") { - faker.seed(seed) - } - - const manager = connection.manager - - const regionId = data.id || `simple-region-${Math.random() * 1000}` - const r = manager.create(Region, { - id: regionId, - name: data.name || "Test Region", - currency_code: data.currency_code || "usd", - tax_rate: data.tax_rate || 0, - payment_providers: [{ id: "test-pay" }], - automatic_taxes: - typeof data.automatic_taxes !== "undefined" ? data.automatic_taxes : true, - }) - - const region = await manager.save(r) - - const countries = data.countries || ["us"] - - for (const cc of countries) { - await manager.query( - `UPDATE "country" SET region_id='${regionId}' WHERE iso_2 = '${cc}'` - ) - } - - return region -} diff --git a/integration-tests/plugins/factories/simple-shipping-method-factory.ts b/integration-tests/plugins/factories/simple-shipping-method-factory.ts deleted file mode 100644 index 3fde22e63d..0000000000 --- a/integration-tests/plugins/factories/simple-shipping-method-factory.ts +++ /dev/null @@ -1,68 +0,0 @@ -import { Connection } from "typeorm" -import faker from "faker" -import { ShippingMethodTaxLine, ShippingMethod } from "@medusajs/medusa" - -import { - ShippingOptionFactoryData, - simpleShippingOptionFactory, -} from "./simple-shipping-option-factory" - -export type ShippingMethodFactoryData = { - id?: string - cart_id?: string - order_id?: string - data?: object - price?: number - shipping_option: string | ShippingOptionFactoryData - tax_lines?: ShippingMethodTaxLine[] -} - -export const simpleShippingMethodFactory = async ( - connection: Connection, - data: ShippingMethodFactoryData, - seed?: number -): Promise => { - if (typeof seed !== "undefined") { - faker.seed(seed) - } - - const manager = connection.manager - - let shippingOptionId: string - if (typeof data.shipping_option === "string") { - shippingOptionId = data.shipping_option - } else { - const option = await simpleShippingOptionFactory( - connection, - data.shipping_option - ) - shippingOptionId = option.id - } - - const id = data.id || `simple-sm-${Math.random() * 1000}` - const toSave = manager.create(ShippingMethod, { - id, - cart_id: data.cart_id, - order_id: data.order_id, - shipping_option_id: shippingOptionId, - data: data.data || {}, - price: typeof data.price !== "undefined" ? data.price : 500, - }) - - const shippingMethod = await manager.save(toSave) - - if (typeof data.tax_lines !== "undefined") { - const taxLinesToSave = data.tax_lines.map((tl) => - manager.create(ShippingMethodTaxLine, { - shipping_method_id: shippingMethod.id, - rate: tl.rate, - code: tl.code || "default", - name: tl.name || "default", - }) - ) - - await manager.save(taxLinesToSave) - } - - return shippingMethod -} diff --git a/integration-tests/plugins/factories/simple-shipping-option-factory.ts b/integration-tests/plugins/factories/simple-shipping-option-factory.ts deleted file mode 100644 index 78ae470f0e..0000000000 --- a/integration-tests/plugins/factories/simple-shipping-option-factory.ts +++ /dev/null @@ -1,45 +0,0 @@ -import { Connection } from "typeorm" -import faker from "faker" -import { ShippingOption, ShippingOptionPriceType, ShippingProfile, ShippingProfileType, } from "@medusajs/medusa" - -export type ShippingOptionFactoryData = { - id?: string - name?: string - region_id: string - is_return?: boolean - is_giftcard?: boolean - price?: number -} - -export const simpleShippingOptionFactory = async ( - connection: Connection, - data: ShippingOptionFactoryData, - seed?: number -): Promise => { - if (typeof seed !== "undefined") { - faker.seed(seed) - } - - const manager = connection.manager - const defaultProfile = await manager.findOne(ShippingProfile, { - where: { type: ShippingProfileType.DEFAULT }, - }) - - const gcProfile = await manager.findOne(ShippingProfile, { - where: { type: ShippingProfileType.GIFT_CARD }, - }) - - const created = manager.create(ShippingOption, { - id: data.id || `simple-so-${Math.random() * 1000}`, - name: data.name || "Test Method", - is_return: data.is_return ?? false, - region_id: data.region_id, - provider_id: "test-ful", - profile_id: data.is_giftcard ? gcProfile.id : defaultProfile.id, - price_type: ShippingOptionPriceType.FLAT_RATE, - data: {}, - amount: typeof data.price !== "undefined" ? data.price : 500, - }) - const option = await manager.save(created) - return option -} diff --git a/integration-tests/plugins/factories/simple-shipping-tax-rate-factory.ts b/integration-tests/plugins/factories/simple-shipping-tax-rate-factory.ts deleted file mode 100644 index 1ce21cdda9..0000000000 --- a/integration-tests/plugins/factories/simple-shipping-tax-rate-factory.ts +++ /dev/null @@ -1,48 +0,0 @@ -import { Connection } from "typeorm" -import faker from "faker" -import { ShippingTaxRate, TaxRate } from "@medusajs/medusa" - -type RateFactoryData = { - region_id: string - rate?: number | null - code?: string - name?: string -} - -export type ShippingTaxRateFactoryData = { - shipping_option_id: string - rate: RateFactoryData | string -} - -export const simpleShippingTaxRateFactory = async ( - connection: Connection, - data: ShippingTaxRateFactoryData, - seed?: number -): Promise => { - if (typeof seed !== "undefined") { - faker.seed(seed) - } - - const manager = connection.manager - - let rateId: string - if (typeof data.rate === "string") { - rateId = data.rate - } else { - const newRate = manager.create(TaxRate, { - region_id: data.rate.region_id, - rate: data.rate.rate, - code: data.rate.code || "sales_tax", - name: data.rate.name || "Sales Tax", - }) - const rate = await manager.save(newRate) - rateId = rate.id - } - - const toSave = manager.create(ShippingTaxRate, { - shipping_option_id: data.shipping_option_id, - rate_id: rateId, - }) - - return await manager.save(toSave) -} diff --git a/integration-tests/plugins/factories/simple-tax-rate-factory.ts b/integration-tests/plugins/factories/simple-tax-rate-factory.ts deleted file mode 100644 index 44987da67e..0000000000 --- a/integration-tests/plugins/factories/simple-tax-rate-factory.ts +++ /dev/null @@ -1,32 +0,0 @@ -import { Connection } from "typeorm" -import faker from "faker" -import { TaxRate } from "@medusajs/medusa" - -export type TaxRateFactoryData = { - region_id: string - rate?: number | null - code?: string - name?: string -} - -export const simpleTaxRateFactory = async ( - connection: Connection, - data: TaxRateFactoryData, - seed?: number -): Promise => { - if (typeof seed !== "undefined") { - faker.seed(seed) - } - - const manager = connection.manager - - const toSave = manager.create(TaxRate, { - region_id: data.region_id, - rate: - data.rate ?? faker.datatype.number({ min: 0, max: 100, precision: 2 }), - code: data.code || faker.random.word(), - name: data.name || faker.random.words(2), - }) - - return await manager.save(toSave) -} diff --git a/integration-tests/plugins/helpers/admin-seeder.js b/integration-tests/plugins/helpers/admin-seeder.js deleted file mode 100644 index 660bad0470..0000000000 --- a/integration-tests/plugins/helpers/admin-seeder.js +++ /dev/null @@ -1,18 +0,0 @@ -const Scrypt = require("scrypt-kdf") -const { User } = require("@medusajs/medusa") - -module.exports = async (connection, data = {}) => { - const manager = connection.manager - - const buf = await Scrypt.kdf("secret_password", { logN: 1, r: 1, p: 1 }) - const password_hash = buf.toString("base64") - - await manager.insert(User, { - id: "admin_user", - email: "admin@medusa.js", - api_token: "test_token", - role: "admin", - password_hash, - ...data, - }) -} diff --git a/integration-tests/plugins/helpers/call-helpers.js b/integration-tests/plugins/helpers/call-helpers.js deleted file mode 100644 index 9a9233d42d..0000000000 --- a/integration-tests/plugins/helpers/call-helpers.js +++ /dev/null @@ -1,100 +0,0 @@ -const { useApi } = require("../../helpers/use-api") - -const header = { - headers: { - authorization: "Bearer test_token", - }, -} - -const resolveCall = async (path, payload, header) => { - const api = useApi() - let res - try { - const resp = await api.post(path, payload, header) - res = resp.status - } catch (expectedException) { - try { - res = expectedException.response.status - } catch (_) { - console.error(expectedException) - } - } - return res -} - -const determineFail = (actual, expected, path) => { - if (expected !== actual) { - console.log(`failed at path : ${path}`) - } - expect(actual).toEqual(expected) -} - -/** - * Allows you to wrap a Call function so that you may reuse some input values. - * @param {Function} fun - the function to call with partial information - * @param {Object} input - the constant input which we want to supply now - * @returns - */ -module.exports.partial = function (fun, input = {}) { - return async (remaining) => await fun({ ...remaining, ...input }) -} - -/** - * Allows you to assert a specific code result from a POST call. - * @param {Object} input - the information needed to make the call - * (path & payload) and the expected code (code) - */ -module.exports.expectPostCallToReturn = async function ( - input = { - code, - path, - payload: {}, - } -) { - const res = await resolveCall(input.path, input.payload, header) - determineFail(res, input.code, input.path) -} - -/** - * Allows you to assert a specific code result from multiple POST - * calls. - * @param {Object} input - the collection of objects to execute - * calls from (col), a function which yields the path (pathf), - * and another one which provides the payload (payloadf), as - * well as the code (code) which we want to assert. - */ -module.exports.expectAllPostCallsToReturn = async function ( - input = { - code, - col, - pathf, - payloadf, - } -) { - for (const i of input.col) { - const res = await resolveCall( - input.pathf(i), - input.payloadf ? input.payloadf(i) : {}, - header - ) - determineFail(res, input.code, input.pathf(i)) - } -} - -/** - * Allows you to retrieve a specific object the response - * from get call, - * and simultaneously assert that the call was successful. - * @param {Object} param0 - contains the path which to - * call (path), and the object within the response.data (get) - * we want to retrieve. - * @returns {Object} found within response.data corresponding - * to the get parameter provided. - */ -module.exports.callGet = async function ({ path, get }) { - const api = useApi() - const res = await api.get(path, header) - - determineFail(res.status, 200, path) - return res?.data[get] -} diff --git a/integration-tests/plugins/helpers/cart-seeder.js b/integration-tests/plugins/helpers/cart-seeder.js deleted file mode 100644 index 3e8f488140..0000000000 --- a/integration-tests/plugins/helpers/cart-seeder.js +++ /dev/null @@ -1,546 +0,0 @@ -const { - Customer, - Region, - Cart, - DiscountRule, - Discount, - ShippingProfile, - ShippingOption, - ShippingMethod, - Address, - Product, - ProductVariant, - MoneyAmount, - LineItem, - Payment, - PaymentSession, - ShippingProfileType, -} = require("@medusajs/medusa") - -module.exports = async (connection, data = {}) => { - const salesChannelId = data?.sales_channel_id - - const yesterday = ((today) => new Date(today.setDate(today.getDate() - 1)))( - new Date() - ) - const tomorrow = ((today) => new Date(today.setDate(today.getDate() + 1)))( - new Date() - ) - const tenDaysAgo = ((today) => new Date(today.setDate(today.getDate() - 10)))( - new Date() - ) - const tenDaysFromToday = ((today) => - new Date(today.setDate(today.getDate() + 10)))(new Date()) - - const manager = connection.manager - - const defaultProfile = await manager.findOne(ShippingProfile, { - where: { - type: ShippingProfileType.DEFAULT, - }, - }) - - const gcProfile = await manager.findOne(ShippingProfile, { - where: { - type: ShippingProfileType.GIFT_CARD, - }, - }) - - await manager.insert(Address, { - id: "test-general-address", - first_name: "superman", - country_code: "us", - }) - - const r = manager.create(Region, { - id: "test-region", - name: "Test Region", - currency_code: "usd", - tax_rate: 0, - }) - - // Region with multiple countries - const regionWithMultipleCoutries = manager.create(Region, { - id: "test-region-multiple", - name: "Test Region", - currency_code: "eur", - tax_rate: 0, - }) - - await manager.save(regionWithMultipleCoutries) - await manager.query( - `UPDATE "country" SET region_id='test-region-multiple' WHERE iso_2 = 'no'` - ) - await manager.query( - `UPDATE "country" SET region_id='test-region-multiple' WHERE iso_2 = 'dk'` - ) - - const freeRule = manager.create(DiscountRule, { - id: "free-shipping-rule", - description: "Free shipping rule", - type: "free_shipping", - value: 100, - allocation: "total", - }) - - const freeDisc = manager.create(Discount, { - id: "free-shipping", - code: "FREE_SHIPPING", - is_dynamic: false, - is_disabled: false, - }) - - freeDisc.regions = [r] - freeDisc.rule = freeRule - await manager.save(freeDisc) - - const tenPercentRule = manager.create(DiscountRule, { - id: "tenpercent-rule", - description: "Ten percent rule", - type: "percentage", - value: 10, - allocation: "total", - }) - - const tenPercent = manager.create(Discount, { - id: "10Percent", - code: "10PERCENT", - is_dynamic: false, - is_disabled: false, - starts_at: tenDaysAgo, - ends_at: tenDaysFromToday, - }) - - tenPercent.regions = [r] - tenPercent.rule = tenPercentRule - await manager.save(tenPercent) - - const dUsageLimit = await manager.create(Discount, { - id: "test-discount-usage-limit", - code: "SPENT", - is_dynamic: false, - is_disabled: false, - usage_limit: 10, - usage_count: 10, - }) - - const drUsage = await manager.create(DiscountRule, { - id: "test-discount-rule-usage-limit", - description: "Created", - type: "fixed", - value: 10000, - allocation: "total", - }) - - dUsageLimit.rule = drUsage - dUsageLimit.regions = [r] - - await manager.save(dUsageLimit) - - const d = await manager.create(Discount, { - id: "test-discount", - code: "CREATED", - is_dynamic: false, - is_disabled: false, - }) - - const dr = await manager.create(DiscountRule, { - id: "test-discount-rule", - description: "Created", - type: "fixed", - value: 10000, - allocation: "total", - }) - - d.rule = dr - d.regions = [r] - - await manager.save(d) - - const usedDiscount = manager.create(Discount, { - id: "used-discount", - code: "USED", - is_dynamic: false, - is_disabled: false, - usage_limit: 1, - usage_count: 1, - }) - - await manager.save(usedDiscount) - - const expiredRule = manager.create(DiscountRule, { - id: "expiredRule", - description: "expired rule", - type: "fixed", - value: 100, - allocation: "total", - }) - - const expiredDisc = manager.create(Discount, { - id: "expiredDisc", - code: "EXP_DISC", - is_dynamic: false, - is_disabled: false, - starts_at: tenDaysAgo, - ends_at: yesterday, - }) - - expiredDisc.regions = [r] - expiredDisc.rule = expiredRule - await manager.save(expiredDisc) - - const prematureRule = manager.create(DiscountRule, { - id: "prematureRule", - description: "premature rule", - type: "fixed", - value: 100, - allocation: "total", - }) - - const prematureDiscount = manager.create(Discount, { - id: "prematureDiscount", - code: "PREM_DISC", - is_dynamic: false, - is_disabled: false, - starts_at: tomorrow, - ends_at: tenDaysFromToday, - }) - - prematureDiscount.regions = [r] - prematureDiscount.rule = prematureRule - await manager.save(prematureDiscount) - - const invalidDynamicRule = manager.create(DiscountRule, { - id: "invalidDynamicRule", - description: "invalidDynamic rule", - type: "fixed", - value: 100, - allocation: "total", - }) - - const invalidDynamicDiscount = manager.create(Discount, { - id: "invalidDynamicDiscount", - code: "INV_DYN_DISC", - is_dynamic: true, - is_disabled: false, - starts_at: tenDaysAgo, - ends_at: tenDaysFromToday, - valid_duration: "P1D", // one day - }) - - invalidDynamicDiscount.regions = [r] - invalidDynamicDiscount.rule = invalidDynamicRule - await manager.save(invalidDynamicDiscount) - - const DynamicRule = manager.create(DiscountRule, { - id: "DynamicRule", - description: "Dynamic rule", - type: "fixed", - value: 10000, - allocation: "total", - }) - - const DynamicDiscount = manager.create(Discount, { - id: "DynamicDiscount", - code: "DYN_DISC", - is_dynamic: true, - is_disabled: false, - starts_at: tenDaysAgo, - ends_at: tenDaysFromToday, - valid_duration: "P1M", // one month - }) - - DynamicDiscount.regions = [r] - DynamicDiscount.rule = DynamicRule - await manager.save(DynamicDiscount) - - await manager.query( - `UPDATE "country" SET region_id='test-region' WHERE iso_2 = 'us'` - ) - - await manager.insert(Customer, { - id: "test-customer", - email: "test@email.com", - }) - - await manager.insert(Customer, { - id: "test-customer-2", - email: "test-2@email.com", - }) - - await manager.insert(Customer, { - id: "some-customer", - email: "some-customer@email.com", - }) - - await manager.insert(ShippingOption, { - id: "test-option", - name: "test-option", - provider_id: "test-ful", - region_id: "test-region", - profile_id: defaultProfile.id, - price_type: "flat_rate", - amount: 1000, - data: {}, - }) - - await manager.insert(ShippingOption, { - id: "gc-option", - name: "Digital copy", - provider_id: "test-ful", - region_id: "test-region", - profile_id: gcProfile.id, - price_type: "flat_rate", - amount: 0, - data: {}, - }) - - await manager.insert(ShippingOption, { - id: "test-option-2", - name: "test-option-2", - provider_id: "test-ful", - region_id: "test-region", - profile_id: defaultProfile.id, - price_type: "flat_rate", - amount: 500, - data: {}, - }) - - await manager.insert(Product, { - id: "giftcard-product", - title: "Giftcard", - is_giftcard: true, - discountable: false, - profile_id: gcProfile.id, - options: [{ id: "denom", title: "Denomination" }], - }) - - await manager.insert(ProductVariant, { - id: "giftcard-denom", - title: "1000", - product_id: "giftcard-product", - inventory_quantity: 1, - options: [ - { - option_id: "denom", - value: "1000", - }, - ], - }) - - 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", - title: "test variant", - product_id: "test-product", - inventory_quantity: 1, - options: [ - { - option_id: "test-option", - value: "Size", - }, - ], - }) - - await manager.insert(ProductVariant, { - id: "test-variant-2", - title: "test variant 2", - product_id: "test-product", - inventory_quantity: 0, - options: [ - { - option_id: "test-option", - value: "Size", - }, - ], - }) - - const ma = manager.create(MoneyAmount, { - variant_id: "test-variant", - currency_code: "usd", - amount: 1000, - }) - - await manager.save(ma) - - const ma2 = manager.create(MoneyAmount, { - variant_id: "test-variant-2", - currency_code: "usd", - amount: 8000, - }) - - await manager.save(ma2) - - const ma3 = manager.create(MoneyAmount, { - variant_id: "giftcard-denom", - currency_code: "usd", - amount: 1000, - }) - - await manager.save(ma3) - - const cart = manager.create(Cart, { - id: "test-cart", - customer_id: "some-customer", - sales_channel_id: salesChannelId, - email: "some-customer@email.com", - shipping_address: { - id: "test-shipping-address", - first_name: "lebron", - country_code: "us", - }, - region_id: "test-region", - currency_code: "usd", - items: [], - }) - - await manager.save(cart) - - const cart2 = manager.create(Cart, { - id: "test-cart-2", - customer_id: "some-customer", - sales_channel_id: salesChannelId, - email: "some-customer@email.com", - shipping_address: { - id: "test-shipping-address", - first_name: "lebron", - country_code: "us", - }, - region_id: "test-region", - currency_code: "usd", - completed_at: null, - items: [], - }) - - const swapCart = manager.create(Cart, { - id: "swap-cart", - type: "swap", - customer_id: "some-customer", - sales_channel_id: salesChannelId, - email: "some-customer@email.com", - shipping_address: { - id: "test-shipping-address", - first_name: "lebron", - country_code: "us", - }, - region_id: "test-region", - currency_code: "usd", - completed_at: null, - items: [], - metadata: { - swap_id: "test-swap", - }, - }) - - const pay = manager.create(Payment, { - id: "test-payment", - amount: 10000, - currency_code: "usd", - amount_refunded: 0, - provider_id: "test-pay", - data: {}, - }) - - await manager.save(pay) - - cart2.payment = pay - - await manager.save(cart2) - const swapPay = manager.create(Payment, { - id: "test-swap-payment", - amount: 10000, - currency_code: "usd", - amount_refunded: 0, - provider_id: "test-pay", - data: {}, - }) - - await manager.save(pay) - await manager.save(swapPay) - - cart2.payment = pay - swapCart.payment = swapPay - - await manager.save(cart2) - await manager.save(swapCart) - - await manager.insert(PaymentSession, { - id: "test-session", - cart_id: "test-cart-2", - provider_id: "test-pay", - is_selected: true, - data: {}, - status: "authorized", - }) - - await manager.insert(PaymentSession, { - id: "test-swap-session", - cart_id: "swap-cart", - provider_id: "test-pay", - is_selected: true, - data: {}, - status: "authorized", - }) - - await manager.insert(ShippingMethod, { - id: "test-method", - shipping_option_id: "test-option", - cart_id: "test-cart", - price: 1000, - data: {}, - }) - - const li = manager.create(LineItem, { - id: "test-item", - title: "Line Item", - description: "Line Item Desc", - thumbnail: "https://test.js/1234", - unit_price: 8000, - quantity: 1, - variant_id: "test-variant", - cart_id: "test-cart-2", - }) - await manager.save(li) - - const cart3 = manager.create(Cart, { - id: "test-cart-3", - 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", - completed_at: null, - items: [], - }) - await manager.save(cart3) - - await manager.insert(ShippingMethod, { - id: "test-method-2", - shipping_option_id: "test-option", - cart_id: "test-cart-3", - price: 0, - data: {}, - }) - - const li2 = manager.create(LineItem, { - id: "test-item-2", - title: "Line Item", - description: "Line Item Desc", - thumbnail: "https://test.js/1234", - unit_price: 8000, - quantity: 1, - variant_id: "test-variant", - cart_id: "test-cart-3", - }) - await manager.save(li2) -} diff --git a/integration-tests/plugins/helpers/claim-seeder.js b/integration-tests/plugins/helpers/claim-seeder.js deleted file mode 100644 index ae19e09e68..0000000000 --- a/integration-tests/plugins/helpers/claim-seeder.js +++ /dev/null @@ -1,118 +0,0 @@ -const { - ClaimOrder, - Order, - LineItem, - Fulfillment, - Return, -} = require("@medusajs/medusa") - -module.exports = async (connection, data = {}) => { - const manager = connection.manager - - let orderWithClaim = manager.create(Order, { - id: "order-with-claim", - customer_id: "test-customer", - email: "test@email.com", - payment_status: "captured", - fulfillment_status: "fulfilled", - billing_address: { - id: "test-billing-address", - first_name: "lebron", - }, - shipping_address: { - id: "test-shipping-address", - first_name: "lebron", - country_code: "us", - }, - region_id: "test-region", - currency_code: "usd", - tax_rate: 0, - discounts: [], - payments: [ - { - id: "test-payment-for-claim-order", - amount: 10000, - currency_code: "usd", - amount_refunded: 0, - provider_id: "test-pay", - data: {}, - }, - ], - items: [], - ...data, - }) - - await manager.save(orderWithClaim) - - const li = manager.create(LineItem, { - id: "test-item-co-2", - fulfilled_quantity: 1, - title: "Line Item", - description: "Line Item Desc", - thumbnail: "https://test.js/1234", - unit_price: 8000, - quantity: 1, - variant_id: "test-variant", - order_id: orderWithClaim.id, - }) - - await manager.save(li) - - const li2 = manager.create(LineItem, { - id: "test-item-co-3", - fulfilled_quantity: 4, - title: "Line Item", - description: "Line Item Desc", - thumbnail: "https://test.js/1234", - unit_price: 8000, - quantity: 4, - variant_id: "test-variant", - order_id: orderWithClaim.id, - }) - - await manager.save(li2) - - const claimWithFulfillment = manager.create(ClaimOrder, { - id: "claim-w-f", - type: "replace", - payment_status: "na", - fulfillment_status: "not_fulfilled", - order_id: "order-with-claim", - ...data, - }) - - const ful1 = manager.create(Fulfillment, { - id: "fulfillment-co-1", - data: {}, - provider_id: "test-ful", - }) - - const ful2 = manager.create(Fulfillment, { - id: "fulfillment-co-2", - data: {}, - provider_id: "test-ful", - }) - - claimWithFulfillment.fulfillments = [ful1, ful2] - - await manager.save(claimWithFulfillment) - - const claimWithReturn = manager.create(ClaimOrder, { - id: "claim-w-r", - type: "replace", - payment_status: "na", - fulfillment_status: "not_fulfilled", - order_id: "order-with-claim", - ...data, - }) - - await manager.save(claimWithReturn) - - await manager.insert(Return, { - id: "return-id-2", - claim_order_id: "claim-w-r", - status: "requested", - refund_amount: 0, - data: {}, - }) -} diff --git a/integration-tests/plugins/helpers/customer-seeder.js b/integration-tests/plugins/helpers/customer-seeder.js deleted file mode 100644 index acef948bbd..0000000000 --- a/integration-tests/plugins/helpers/customer-seeder.js +++ /dev/null @@ -1,33 +0,0 @@ -const { Customer, Address } = require("@medusajs/medusa") - -module.exports = async (connection, data = {}) => { - const manager = connection.manager - - await manager.insert(Customer, { - id: "test-customer-1", - email: "test1@email.com", - }) - - await manager.insert(Customer, { - id: "test-customer-2", - email: "test2@email.com", - }) - - await manager.insert(Customer, { - id: "test-customer-3", - email: "test3@email.com", - }) - - await manager.insert(Customer, { - id: "test-customer-has_account", - email: "test4@email.com", - has_account: true, - }) - - await manager.insert(Address, { - id: "test-address", - first_name: "Lebron", - last_name: "James", - customer_id: "test-customer-1", - }) -} diff --git a/integration-tests/plugins/helpers/discount-seeder.js b/integration-tests/plugins/helpers/discount-seeder.js deleted file mode 100644 index cc623bab33..0000000000 --- a/integration-tests/plugins/helpers/discount-seeder.js +++ /dev/null @@ -1,35 +0,0 @@ -const { - ShippingProfile, - Region, - Discount, - DiscountRule, -} = require("@medusajs/medusa") -module.exports = async (connection, data = {}) => { - const manager = connection.manager - - await manager.insert(Region, { - id: "test-region", - name: "Test Region", - currency_code: "usd", - tax_rate: 0, - payment_providers: [ - { - id: "test-pay", - is_installed: true, - }, - ], - }) - - await manager.insert(Region, { - id: "test-region-2", - name: "Test Region 2", - currency_code: "eur", - tax_rate: 0, - payment_providers: [ - { - id: "test-pay", - is_installed: true, - }, - ], - }) -} diff --git a/integration-tests/plugins/helpers/draft-order-seeder.js b/integration-tests/plugins/helpers/draft-order-seeder.js deleted file mode 100644 index 4013a13cd0..0000000000 --- a/integration-tests/plugins/helpers/draft-order-seeder.js +++ /dev/null @@ -1,264 +0,0 @@ -const { - ShippingProfile, - Customer, - MoneyAmount, - ShippingOption, - ShippingOptionRequirement, - Product, - ProductVariant, - Region, - Address, - Cart, - PaymentSession, - DraftOrder, - Discount, - DiscountRule, - Payment, - ShippingProfileType, -} = require("@medusajs/medusa") - -module.exports = async (connection, data = {}) => { - const manager = connection.manager - - const defaultProfile = await manager.findOne(ShippingProfile, { - where: { - type: ShippingProfileType.DEFAULT, - }, - }) - - await manager.insert(Product, { - id: "test-product", - title: "test product", - profile_id: defaultProfile.id, - options: [{ id: "test-option", title: "Size" }], - }) - - await manager.insert(Address, { - id: "oli-shipping", - first_name: "oli", - last_name: "test", - country_code: "us", - }) - - await manager.insert(Product, { - id: "test-product-2", - title: "test product 2", - profile_id: defaultProfile.id, - options: [{ id: "test-option-color", title: "Color" }], - }) - - await manager.insert(ProductVariant, { - id: "test-variant", - title: "test variant", - product_id: "test-product", - inventory_quantity: 1, - options: [ - { - option_id: "test-option", - value: "Size", - }, - ], - }) - - await manager.insert(ProductVariant, { - id: "test-variant-2", - title: "test variant-2", - product_id: "test-product-2", - inventory_quantity: 4, - options: [ - { - option_id: "test-option-color", - value: "Color", - }, - ], - }) - - const ma = manager.create(MoneyAmount, { - variant_id: "test-variant", - currency_code: "usd", - amount: 8000, - }) - await manager.save(ma) - - const ma2 = manager.create(MoneyAmount, { - variant_id: "test-variant-2", - currency_code: "usd", - amount: 10000, - }) - - await manager.save(ma2) - - await manager.insert(Region, { - id: "test-region", - name: "Test Region", - currency_code: "usd", - tax_rate: 0, - payment_providers: [ - { - id: "test-pay", - is_installed: true, - }, - ], - }) - - await manager.insert(Region, { - id: "test-region-2", - name: "Test Region 2", - currency_code: "eur", - tax_rate: 0, - payment_providers: [ - { - id: "test-pay", - is_installed: true, - }, - ], - }) - - await manager.insert(DiscountRule, { - id: "discount_rule_id", - description: "test description", - value: 10, - allocation: "total", - type: "percentage", - }) - - const d = manager.create(Discount, { - id: "test-discount", - code: "TEST", - is_dynamic: false, - is_disabled: false, - rule_id: "discount_rule_id", - }) - - d.regions = [ - { - id: "test-region", - name: "Test Region", - currency_code: "usd", - tax_rate: 0, - }, - ] - - await manager.save(d) - - await manager.query( - `UPDATE "country" SET region_id='test-region' WHERE iso_2 = 'us'` - ) - - await manager.query( - `UPDATE "country" SET region_id='test-region-2' WHERE iso_2 = 'de'` - ) - - await manager.insert(Customer, { - id: "oli-test", - email: "oli@test.dk", - }) - - await manager.insert(Customer, { - id: "lebron-james", - email: "lebron@james.com", - }) - - await manager.insert(ShippingOption, { - id: "test-option", - name: "test-option", - provider_id: "test-ful", - region_id: "test-region", - profile_id: defaultProfile.id, - price_type: "flat_rate", - amount: 1000, - data: {}, - }) - - await manager.insert(ShippingOption, { - id: "test-option-req", - name: "test-option-req", - provider_id: "test-ful", - region_id: "test-region", - profile_id: defaultProfile.id, - price_type: "flat_rate", - amount: 1000, - data: {}, - }) - - await manager.insert(ShippingOptionRequirement, { - id: "option-req", - shipping_option_id: "test-option-req", - type: "min_subtotal", - amount: 10, - }) - - const c = manager.create(Cart, { - id: "test-cart", - customer_id: "oli-test", - email: "oli@test.dk", - shipping_address_id: "oli-shipping", - region_id: "test-region", - currency_code: "usd", - payment_sessions: [], - items: [ - { - id: "test-item", - fulfilled_quantity: 1, - title: "Line Item", - description: "Line Item Desc", - thumbnail: "https://test.js/1234", - unit_price: 8000, - quantity: 1, - variant_id: "test-variant", - }, - ], - type: "draft_order", - metadata: { draft_order_id: "test-draft-order" }, - }) - - const pay = manager.create(Payment, { - id: "test-payment", - amount: 10000, - currency_code: "usd", - amount_refunded: 0, - provider_id: "test-pay", - data: {}, - }) - - await manager.save(pay) - - c.payment = pay - - await manager.save(c) - - await manager.insert(PaymentSession, { - id: "test-session", - cart_id: "test-cart", - provider_id: "test-pay", - is_selected: true, - data: {}, - status: "authorized", - }) - - const draftOrder = manager.create(DraftOrder, { - id: "test-draft-order", - status: "open", - display_id: 4, - cart_id: "test-cart", - customer_id: "oli-test", - items: [ - { - id: "test-item", - fulfilled_quantity: 1, - title: "Line Item", - description: "Line Item Desc", - thumbnail: "https://test.js/1234", - unit_price: 8000, - quantity: 1, - variant_id: "test-variant", - }, - ], - email: "oli@test.dk", - region_id: "test-region", - discounts: [], - ...data, - }) - - await manager.save(draftOrder) -} diff --git a/integration-tests/plugins/helpers/order-seeder.js b/integration-tests/plugins/helpers/order-seeder.js deleted file mode 100644 index b4a5774a97..0000000000 --- a/integration-tests/plugins/helpers/order-seeder.js +++ /dev/null @@ -1,399 +0,0 @@ -const { - Customer, - Discount, - DiscountRule, - LineItem, - MoneyAmount, - Order, - Payment, - Product, - ProductVariant, - Region, - ShippingMethod, - ShippingOption, - ShippingProfile, - Swap, - ShippingProfileType, -} = require("@medusajs/medusa") - -module.exports = async (connection, data = {}) => { - const manager = connection.manager - - const defaultProfile = await manager.findOne(ShippingProfile, { - where: { - type: ShippingProfileType.DEFAULT, - }, - }) - - await manager.insert(Product, { - id: "test-product", - title: "test product", - profile_id: defaultProfile.id, - options: [{ id: "test-option", title: "Size" }], - }) - - await manager.insert(ProductVariant, { - id: "test-variant", - title: "test variant", - product_id: "test-product", - inventory_quantity: 1, - options: [ - { - option_id: "test-option", - value: "Size", - }, - ], - }) - - await manager.insert(ProductVariant, { - id: "test-variant-2", - title: "Swap product", - product_id: "test-product", - inventory_quantity: 1, - options: [ - { - option_id: "test-option", - value: "Large", - }, - ], - }) - - const ma2 = manager.create(MoneyAmount, { - variant_id: "test-variant-2", - currency_code: "usd", - amount: 8000, - }) - await manager.save(ma2) - - const ma = manager.create(MoneyAmount, { - variant_id: "test-variant", - currency_code: "usd", - amount: 8000, - }) - await manager.save(ma) - - await manager.insert(Region, { - id: "test-region", - name: "Test Region", - currency_code: "usd", - tax_rate: 0, - }) - - await manager.query( - `UPDATE "country" SET region_id='test-region' WHERE iso_2 = 'us'` - ) - - await manager.insert(Customer, { - id: "test-customer", - email: "test@email.com", - }) - - await manager.insert(ShippingOption, { - id: "test-option", - name: "test-option", - provider_id: "test-ful", - region_id: "test-region", - profile_id: defaultProfile.id, - price_type: "flat_rate", - amount: 1000, - data: {}, - }) - - await manager.insert(ShippingOption, { - id: "test-return-option", - name: "Test ret", - profile_id: defaultProfile.id, - region_id: "test-region", - provider_id: "test-ful", - data: {}, - price_type: "flat_rate", - amount: 1000, - is_return: true, - }) - - const order = manager.create(Order, { - id: "test-order", - customer_id: "test-customer", - email: "test@email.com", - payment_status: "captured", - fulfillment_status: "fulfilled", - billing_address: { - id: "test-billing-address", - first_name: "lebron", - }, - shipping_address: { - id: "test-shipping-address", - first_name: "lebron", - country_code: "us", - }, - region_id: "test-region", - currency_code: "usd", - tax_rate: 0, - discounts: [ - { - id: "test-discount", - code: "TEST134", - is_dynamic: false, - rule: { - id: "test-rule", - description: "Test Discount", - type: "percentage", - value: 10, - allocation: "total", - }, - is_disabled: false, - regions: [ - { - id: "test-region", - }, - ], - }, - ], - payments: [ - { - id: "test-payment", - amount: 10000, - currency_code: "usd", - amount_refunded: 0, - provider_id: "test-pay", - data: {}, - }, - ], - items: [], - ...data, - }) - - await manager.save(order) - - const li = manager.create(LineItem, { - id: "test-item", - fulfilled_quantity: 1, - returned_quantity: 0, - title: "Line Item", - description: "Line Item Desc", - thumbnail: "https://test.js/1234", - unit_price: 8000, - quantity: 1, - variant_id: "test-variant", - order_id: "test-order", - }) - - await manager.save(li) - - await manager.insert(ShippingMethod, { - id: "test-method", - order_id: "test-order", - shipping_option_id: "test-option", - price: 1000, - data: {}, - }) - - const orderTemplate = () => { - return { - customer_id: "test-customer", - email: "test@gmail.com", - payment_status: "not_paid", - fulfillment_status: "not_fulfilled", - region_id: "test-region", - currency_code: "usd", - tax_rate: 0, - ...data, - } - } - - const paymentTemplate = () => { - return { - amount: 10000, - currency_code: "usd", - provider_id: "test-pay", - data: {}, - } - } - - const orderWithClaim = manager.create(Order, { - id: "test-order-w-c", - claims: [ - { - type: "replace", - id: "claim-1", - payment_status: "na", - fulfillment_status: "not_fulfilled", - payment_provider: "test-pay", - }, - ], - ...orderTemplate(), - }) - - await manager.save(orderWithClaim) - - await manager.insert(Payment, { - order_id: "test-order-w-c", - id: "o-pay1", - ...paymentTemplate(), - }) - - const orderWithSwap = manager.create(Order, { - id: "test-order-w-s", - ...orderTemplate(), - }) - - await manager.save(orderWithSwap) - - await manager.insert(Payment, { - order_id: "test-order-w-s", - id: "o-pay2", - ...paymentTemplate(), - }) - - const swap1 = manager.create(Swap, { - id: "swap-1", - order_id: "test-order-w-s", - fulfillment_status: "not_fulfilled", - payment_status: "not_paid", - }) - - const pay1 = manager.create(Payment, { - id: "pay1", - ...paymentTemplate(), - }) - - swap1.payment = pay1 - - const swap2 = manager.create(Swap, { - id: "swap-2", - order_id: "test-order-w-s", - fulfillment_status: "not_fulfilled", - payment_status: "not_paid", - }) - - const pay2 = manager.create(Payment, { - id: "pay2", - ...paymentTemplate(), - }) - - swap2.payment = pay2 - - await manager.save(swap1) - await manager.save(swap2) - - const orderWithFulfillment = manager.create(Order, { - id: "test-order-w-f", - fulfillments: [ - { - id: "fulfillment-on-order-1", - data: {}, - provider_id: "test-ful", - }, - { - id: "fulfillment-on-order-2", - data: {}, - provider_id: "test-ful", - }, - ], - ...orderTemplate(), - }) - - await manager.save(orderWithFulfillment) - - await manager.insert(Payment, { - order_id: "test-order-w-f", - id: "o-pay3", - ...paymentTemplate(), - }) - - const orderWithReturn = manager.create(Order, { - id: "test-order-w-r", - returns: [ - { - id: "return-on-order-1", - refund_amount: 0, - }, - { - id: "return-on-order-2", - refund_amount: 0, - }, - ], - ...orderTemplate(), - }) - - await manager.save(orderWithReturn) - - await manager.insert(Payment, { - order_id: "test-order-w-r", - id: "o-pay4", - ...paymentTemplate(), - }) - - const drule = manager.create(DiscountRule, { - id: "test-rule", - description: "Test Discount", - type: "percentage", - value: 10, - allocation: "total", - }) - - const discount = manager.create(Discount, { - id: "test-discount-o", - code: "TEST1234", - is_dynamic: false, - rule: drule, - is_disabled: false, - regions: [ - { - id: "test-region", - }, - ], - }) - await manager.save(discount) - - const payment = manager.create(Payment, { - id: "test-payment-d", - amount: 10000, - currency_code: "usd", - amount_refunded: 0, - provider_id: "test-pay", - captured_at: new Date(), - data: {}, - }) - - const discountedOrder = manager.create(Order, { - id: "discount-order", - customer_id: "test-customer", - email: "test-discount@email.com", - payment_status: "captured", - fulfillment_status: "fulfilled", - discounts: [discount], - billing_address: { - id: "test-discount-billing-address", - first_name: "lebron", - }, - shipping_address: { - id: "test-shipping-address", - first_name: "lebron", - country_code: "us", - }, - region_id: "test-region", - currency_code: "usd", - tax_rate: 0, - payments: [payment], - items: [], - ...data, - }) - - await manager.save(discountedOrder) - - const dli = manager.create(LineItem, { - id: "test-item-1", - fulfilled_quantity: 1, - returned_quantity: 0, - title: "Line Item", - description: "Line Item Desc", - thumbnail: "https://test.js/1234", - unit_price: 8000, - quantity: 1, - variant_id: "test-variant", - order_id: "discount-order", - }) - - await manager.save(dli) -} diff --git a/integration-tests/plugins/helpers/product-seeder.js b/integration-tests/plugins/helpers/product-seeder.js deleted file mode 100644 index 14f5246557..0000000000 --- a/integration-tests/plugins/helpers/product-seeder.js +++ /dev/null @@ -1,289 +0,0 @@ -const { - ProductCollection, - ProductTag, - ProductType, - ProductOption, - Region, - Product, - ShippingProfile, - ProductVariant, - Image, - ShippingProfileType, -} = require("@medusajs/medusa") - -module.exports = async (connection, data = {}) => { - const manager = connection.manager - - const defaultProfile = await manager.findOne(ShippingProfile, { - where: { - type: ShippingProfileType.DEFAULT, - }, - }) - - const coll = manager.create(ProductCollection, { - id: "test-collection", - handle: "test-collection", - title: "Test collection", - }) - - await manager.save(coll) - - const coll1 = manager.create(ProductCollection, { - id: "test-collection1", - handle: "test-collection1", - title: "Test collection 1", - }) - - await manager.save(coll1) - - const coll2 = manager.create(ProductCollection, { - id: "test-collection2", - handle: "test-collection2", - title: "Test collection 2", - }) - - await manager.save(coll2) - - const tag = manager.create(ProductTag, { - id: "tag1", - value: "123", - }) - - await manager.save(tag) - - const tag3 = manager.create(ProductTag, { - id: "tag3", - value: "123", - }) - - await manager.save(tag3) - - const tag4 = manager.create(ProductTag, { - id: "tag4", - value: "123", - }) - - await manager.save(tag4) - - const type = manager.create(ProductType, { - id: "test-type", - value: "test-type", - }) - - await manager.save(type) - - const image = manager.create(Image, { - id: "test-image", - url: "test-image.png", - }) - - await manager.save(image) - - await manager.insert(Region, { - id: "test-region", - name: "Test Region", - currency_code: "usd", - tax_rate: 0, - }) - - const p = manager.create(Product, { - id: "test-product", - handle: "test-product", - title: "Test product", - profile_id: defaultProfile.id, - description: "test-product-description", - collection_id: "test-collection", - type: { id: "test-type", value: "test-type" }, - tags: [ - { id: "tag1", value: "123" }, - { tag: "tag2", value: "456" }, - ], - }) - - p.images = [image] - - await manager.save(p) - - await manager.save(ProductOption, { - id: "test-option", - title: "test-option", - product_id: "test-product", - }) - - const variant1 = await manager.create(ProductVariant, { - id: "test-variant", - inventory_quantity: 10, - title: "Test variant", - variant_rank: 0, - sku: "test-sku", - ean: "test-ean", - upc: "test-upc", - barcode: "test-barcode", - product_id: "test-product", - prices: [{ id: "test-price", currency_code: "usd", amount: 100 }], - options: [ - { - id: "test-variant-option", - value: "Default variant", - option_id: "test-option", - }, - ], - }) - - await manager.save(variant1) - - const variant2 = await manager.create(ProductVariant, { - id: "test-variant_1", - inventory_quantity: 10, - title: "Test variant rank (1)", - variant_rank: 2, - sku: "test-sku1", - ean: "test-ean1", - upc: "test-upc1", - barcode: "test-barcode 1", - product_id: "test-product", - prices: [{ id: "test-price1", currency_code: "usd", amount: 100 }], - options: [ - { - id: "test-variant-option-1", - value: "Default variant 1", - option_id: "test-option", - }, - ], - }) - - await manager.save(variant2) - - const variant3 = await manager.create(ProductVariant, { - id: "test-variant_2", - inventory_quantity: 10, - title: "Test variant rank (2)", - variant_rank: 1, - sku: "test-sku2", - ean: "test-ean2", - upc: "test-upc2", - product_id: "test-product", - prices: [{ id: "test-price2", currency_code: "usd", amount: 100 }], - options: [ - { - id: "test-variant-option-2", - value: "Default variant 2", - option_id: "test-option", - }, - ], - }) - - await manager.save(variant3) - - const p1 = manager.create(Product, { - id: "test-product1", - handle: "test-product1", - title: "Test product1", - profile_id: defaultProfile.id, - description: "test-product-description1", - collection_id: "test-collection", - type: { id: "test-type", value: "test-type" }, - tags: [ - { id: "tag1", value: "123" }, - { tag: "tag2", value: "456" }, - ], - }) - - await manager.save(p1) - - const variant4 = await manager.create(ProductVariant, { - id: "test-variant_3", - inventory_quantity: 10, - title: "Test variant rank (2)", - variant_rank: 1, - sku: "test-sku3", - ean: "test-ean3", - upc: "test-upc3", - product_id: "test-product1", - prices: [{ id: "test-price3", currency_code: "usd", amount: 100 }], - options: [ - { - id: "test-variant-option-3", - value: "Default variant 3", - option_id: "test-option", - }, - ], - }) - - await manager.save(variant4) - - const variant5 = await manager.create(ProductVariant, { - id: "test-variant_4", - inventory_quantity: 10, - title: "Test variant rank (2)", - variant_rank: 0, - sku: "test-sku4", - ean: "test-ean4", - upc: "test-upc4", - product_id: "test-product1", - prices: [{ id: "test-price4", currency_code: "usd", amount: 100 }], - options: [ - { - id: "test-variant-option-4", - value: "Default variant 4", - option_id: "test-option", - }, - ], - }) - - await manager.save(variant5) - - const product1 = manager.create(Product, { - id: "test-product_filtering_1", - handle: "test-product_filtering_1", - title: "Test product filtering 1", - profile_id: defaultProfile.id, - description: "test-product-description", - type: { id: "test-type", value: "test-type" }, - collection_id: "test-collection1", - status: "proposed", - tags: [{ id: "tag3", value: "123" }], - }) - - await manager.save(product1) - - const product2 = manager.create(Product, { - id: "test-product_filtering_2", - handle: "test-product_filtering_2", - title: "Test product filtering 2", - profile_id: defaultProfile.id, - description: "test-product-description", - type: { id: "test-type", value: "test-type" }, - collection_id: "test-collection2", - status: "published", - tags: [{ id: "tag3", value: "123" }], - }) - - await manager.save(product2) - - const product3 = manager.create(Product, { - id: "test-product_filtering_3", - handle: "test-product_filtering_3", - title: "Test product filtering 3", - profile_id: defaultProfile.id, - description: "test-product-description", - type: { id: "test-type", value: "test-type" }, - collection_id: "test-collection1", - status: "draft", - tags: [{ id: "tag4", value: "1234" }], - }) - - await manager.save(product3) - - const product4 = manager.create(Product, { - id: "test-product_filtering_4", - handle: "test-product_filtering_4", - title: "Test product filtering 4", - profile_id: defaultProfile.id, - description: "test-product-description", - status: "proposed", - deleted_at: new Date().toISOString(), - }) - - await manager.save(product4) -} diff --git a/integration-tests/plugins/helpers/shipping-option-seeder.js b/integration-tests/plugins/helpers/shipping-option-seeder.js deleted file mode 100644 index 3f9f149088..0000000000 --- a/integration-tests/plugins/helpers/shipping-option-seeder.js +++ /dev/null @@ -1,86 +0,0 @@ -const { - Region, - ShippingProfile, - ShippingOption, - ShippingOptionRequirement, - ShippingProfileType, -} = require("@medusajs/medusa") - -module.exports = async (connection, data = {}) => { - const manager = connection.manager - - await manager.insert(Region, { - id: "region", - name: "Test Region", - currency_code: "usd", - tax_rate: 0, - }) - - const defaultProfile = await manager.findOne(ShippingProfile, { - where: { - type: ShippingProfileType.DEFAULT, - }, - }) - - await manager.insert(ShippingOption, { - id: "test-out", - name: "Test out", - profile_id: defaultProfile.id, - region_id: "region", - provider_id: "test-ful", - data: {}, - price_type: "flat_rate", - amount: 2000, - is_return: false, - }) - - await manager.insert(ShippingOption, { - id: "test-option-req", - name: "With req", - profile_id: defaultProfile.id, - region_id: "region", - provider_id: "test-ful", - data: {}, - price_type: "flat_rate", - amount: 2000, - is_return: false, - }) - - await manager.insert(ShippingOption, { - id: "test-option-req-admin-only", - name: "With req", - profile_id: defaultProfile.id, - region_id: "region", - admin_only: true, - provider_id: "test-ful", - data: {}, - price_type: "flat_rate", - amount: 2000, - is_return: false, - }) - await manager.insert(ShippingOption, { - id: "test-option-req-return", - name: "With req", - profile_id: defaultProfile.id, - region_id: "region", - is_return: true, - provider_id: "test-ful", - data: {}, - price_type: "flat_rate", - amount: 2000, - }) - - await manager.insert(ShippingOptionRequirement, { - id: "option-req", - shipping_option_id: "test-option-req", - type: "min_subtotal", - amount: 5, - }) - - await manager.insert(ShippingOptionRequirement, { - id: "option-req-2", - shipping_option_id: "test-option-req", - type: "max_subtotal", - amount: 10, - }) -} diff --git a/integration-tests/plugins/helpers/swap-seeder.js b/integration-tests/plugins/helpers/swap-seeder.js deleted file mode 100644 index dc52b77458..0000000000 --- a/integration-tests/plugins/helpers/swap-seeder.js +++ /dev/null @@ -1,434 +0,0 @@ -const { - Discount, - DiscountRule, - LineItem, - ShippingMethod, - Order, - Swap, - Cart, - Return, -} = require("@medusajs/medusa") -const { - CustomShippingOption, -} = require("@medusajs/medusa/dist/models/custom-shipping-option") - -module.exports = async (connection, data = {}) => { - const manager = connection.manager - - let orderWithSwap = manager.create(Order, { - id: "order-with-swap", - customer_id: "test-customer", - email: "test@email.com", - payment_status: "captured", - fulfillment_status: "fulfilled", - billing_address: { - id: "test-billing-address", - first_name: "lebron", - }, - shipping_address: { - id: "test-shipping-address", - first_name: "lebron", - country_code: "us", - }, - region_id: "test-region", - currency_code: "usd", - tax_rate: 0, - discounts: [], - payments: [ - { - id: "test-payment", - amount: 10000, - currency_code: "usd", - amount_refunded: 0, - provider_id: "test-pay", - data: {}, - }, - ], - items: [], - ...data, - }) - - orderWithSwap = await manager.save(orderWithSwap) - - const cart = manager.create(Cart, { - id: "test-cart-w-swap", - customer_id: "test-customer", - email: "test-customer@email.com", - shipping_address_id: "test-shipping-address", - billing_address_id: "test-billing-address", - region_id: "test-region", - type: "swap", - metadata: { - swap_id: "test-swap", - parent_order_id: orderWithSwap.id, - }, - }) - - await manager.save(cart) - - const swap = manager.create(Swap, { - id: "test-swap", - order_id: "order-with-swap", - payment_status: "captured", - fulfillment_status: "fulfilled", - cart_id: "test-cart-w-swap", - payment: { - id: "test-payment-swap", - amount: 10000, - currency_code: "usd", - amount_refunded: 0, - provider_id: "test-pay", - data: {}, - }, - additional_items: [ - { - id: "test-item-swapped", - fulfilled_quantity: 1, - title: "Line Item", - description: "Line Item Desc", - thumbnail: "https://test.js/1234", - unit_price: 9000, - quantity: 1, - variant_id: "test-variant-2", - cart_id: "test-cart-w-swap", - }, - ], - }) - - await manager.save(swap) - - const cartWithCustomSo = manager.create(Cart, { - id: "test-cart-rma", - customer_id: "test-customer", - email: "test-customer@email.com", - shipping_address_id: "test-shipping-address", - billing_address_id: "test-billing-address", - region_id: "test-region", - type: "swap", - metadata: { - swap_id: "test-swap", - parent_order_id: orderWithSwap.id, - }, - }) - - await manager.save(cartWithCustomSo) - - const liRma = manager.create(LineItem, { - id: "test-item-rma", - title: "Line Item RMA", - description: "Line Item Desc", - thumbnail: "https://test.js/1234", - unit_price: 8000, - quantity: 1, - variant_id: "test-variant", - cart_id: "test-cart-rma", - }) - await manager.save(liRma) - - await manager.insert(CustomShippingOption, { - id: "cso-test", - cart_id: cartWithCustomSo.id, - price: 0, - shipping_option_id: "test-option", - }) - - const swapWithRMAMethod = manager.create(Swap, { - id: "test-swap-rma", - order_id: "order-with-swap", - payment_status: "captured", - fulfillment_status: "fulfilled", - cart_id: cartWithCustomSo.id, - payment: { - id: "test-payment-swap", - amount: 10000, - currency_code: "usd", - amount_refunded: 0, - provider_id: "test-pay", - data: {}, - }, - additional_items: [ - { - id: "test-item-swapped", - fulfilled_quantity: 1, - title: "Line Item", - description: "Line Item Desc", - thumbnail: "https://test.js/1234", - unit_price: 9000, - quantity: 1, - variant_id: "test-variant-2", - cart_id: "test-cart", - }, - ], - }) - - await manager.save(swapWithRMAMethod) - - const cartTemplate = async (cartId) => { - const cart = manager.create(Cart, { - id: cartId, - customer_id: "test-customer", - email: "test-customer@email.com", - shipping_address_id: "test-shipping-address", - billing_address_id: "test-billing-address", - region_id: "test-region", - type: "swap", - metadata: {}, - ...data, - }) - - await manager.save(cart) - } - - const swapTemplate = async (cartId) => { - await cartTemplate(cartId) - return { - order_id: orderWithSwap.id, - fulfillment_status: "fulfilled", - payment_status: "not_paid", - cart_id: cartId, - payment: { - amount: 5000, - currency_code: "usd", - amount_refunded: 0, - provider_id: "test-pay", - data: {}, - }, - ...data, - } - } - - const swapWithFulfillments = manager.create(Swap, { - id: "swap-w-f", - fulfillments: [ - { - id: "fulfillment-1", - data: {}, - provider_id: "test-ful", - }, - { - id: "fulfillment-2", - data: {}, - provider_id: "test-ful", - }, - ], - ...(await swapTemplate("sc-w-f")), - }) - - await manager.save(swapWithFulfillments) - - const swapWithReturn = manager.create(Swap, { - id: "swap-w-r", - return_order: { - id: "return-id", - status: "requested", - refund_amount: 0, - }, - ...(await swapTemplate("sc-w-r")), - }) - - await manager.save(swapWithReturn) - const li = manager.create(LineItem, { - id: "return-item-1", - fulfilled_quantity: 1, - title: "Return Line Item", - description: "Line Item Desc", - thumbnail: "https://test.js/1234", - unit_price: 8000, - quantity: 1, - variant_id: "test-variant", - order_id: orderWithSwap.id, - cart_id: cart.id, - }) - - await manager.save(li) - - const li2 = manager.create(LineItem, { - id: "test-item-many", - fulfilled_quantity: 4, - title: "Line Item", - description: "Line Item Desc", - thumbnail: "https://test.js/1234", - unit_price: 8000, - quantity: 4, - variant_id: "test-variant", - order_id: orderWithSwap.id, - }) - - await manager.save(li2) - - const swapReturn = await manager.create(Return, { - swap_id: swap.id, - order_id: orderWithSwap.id, - item_id: li.id, - refund_amount: li.quantity * li.unit_price, - }) - - await manager.save(swapReturn) - - const return_item1 = manager.create(LineItem, { - ...li, - unit_price: -1 * li.unit_price, - }) - - await manager.save(return_item1) - - await manager.insert(ShippingMethod, { - id: "another-test-method", - shipping_option_id: "test-option", - cart_id: "test-cart-w-swap", - price: 1000, - data: {}, - }) - - const swapOnSwap = manager.create(Swap, { - id: "swap-on-swap", - order_id: "order-with-swap", - payment_status: "captured", - fulfillment_status: "fulfilled", - return_order: { - id: "return-on-swap", - refund_amount: 9000, - items: [ - { - return_id: "return-on-swap", - item_id: "test-item-swapped", - quantity: 1, - }, - ], - }, - payment: { - id: "test-payment-swap-on-swap", - amount: 10000, - currency_code: "usd", - amount_refunded: 0, - provider_id: "test-pay", - data: {}, - }, - additional_items: [ - { - id: "test-item-swap-on-swap", - fulfilled_quantity: 1, - title: "Line Item", - description: "Line Item Desc", - thumbnail: "https://test.js/1234", - unit_price: 8000, - quantity: 1, - variant_id: "test-variant", - }, - ], - }) - - await manager.save(swapOnSwap) - - await manager.insert(ShippingMethod, { - id: "test-method-swap-order", - shipping_option_id: "test-option", - order_id: "order-with-swap", - price: 1000, - data: {}, - }) - - await createSwap({ id: "disc-swap" }, manager) -} - -const createSwap = async (options, manager) => { - const swapId = options.id - - const dRule = manager.create(DiscountRule, { - id: `${swapId}-cart-discount-rule`, - description: "Ten percent rule", - type: "percentage", - value: 10, - allocation: "total", - }) - await manager.save(dRule) - - const discount = manager.create(Discount, { - code: `${swapId}`, - is_dynamic: false, - is_disabled: false, - rule: dRule, - }) - await manager.save(discount) - - const cart = manager.create(Cart, { - id: `${swapId}-cart`, - customer_id: "test-customer", - email: "test-customer@email.com", - shipping_address_id: "test-shipping-address", - billing_address_id: "test-billing-address", - region_id: "test-region", - type: "swap", - discounts: [discount], - metadata: { - swap_id: swapId, - parent_order_id: "order-with-swap", - }, - }) - - await manager.save(cart) - - const swapTemplate = async () => { - return { - order_id: `order-with-swap`, - fulfillment_status: "fulfilled", - payment_status: "not_paid", - cart_id: cart.id, - } - } - - const swapWithReturn = manager.create(Swap, { - id: swapId, - return_order: { - id: `${swapId}-return-id`, - status: "requested", - refund_amount: 0, - }, - ...(await swapTemplate(swapId)), - }) - - await manager.save(swapWithReturn) - const li = manager.create(LineItem, { - id: `${swapId}-return-item-1`, - fulfilled_quantity: 1, - title: "Return Line Item", - description: "Line Item Desc", - thumbnail: "https://test.js/1234", - unit_price: 8000, - quantity: 1, - variant_id: "test-variant", - order_id: "order-with-swap", - cart_id: cart.id, - }) - - await manager.save(li) - - const li2 = manager.create(LineItem, { - id: `${swapId}-test-item-many`, - fulfilled_quantity: 4, - title: "Line Item", - description: "Line Item Desc", - thumbnail: "https://test.js/1234", - unit_price: 8000, - quantity: 4, - variant_id: "test-variant", - order_id: "order-with-swap", - }) - - await manager.save(li2) - - const return_item1 = manager.create(LineItem, { - ...li, - unit_price: -1 * li.unit_price, - }) - - await manager.save(return_item1) - - await manager.insert(ShippingMethod, { - id: `${swapId}-test-method`, - shipping_option_id: "test-option", - cart_id: cart.id, - price: 1000, - data: {}, - }) -} diff --git a/integration-tests/plugins/helpers/user-seeder.js b/integration-tests/plugins/helpers/user-seeder.js deleted file mode 100644 index bdea83131c..0000000000 --- a/integration-tests/plugins/helpers/user-seeder.js +++ /dev/null @@ -1,53 +0,0 @@ -const { User, Invite } = require("@medusajs/medusa") -import jwt from "jsonwebtoken" - -const generateToken = (data) => { - return jwt.sign(data, "test", { - expiresIn: "7d", - }) -} - -const expires_at = new Date() - -expires_at.setDate(expires_at.getDate() + 8) - -module.exports = async (connection, data = {}) => { - const manager = connection.manager - - const memberUser = await manager.create(User, { - id: "member-user", - role: "member", - email: "member@test.com", - first_name: "member", - last_name: "user", - }) - await manager.save(memberUser) - - const memberInvite = await manager.create(Invite, { - id: "memberInvite", - user_email: "invite-member@test.com", - role: "member", - token: generateToken({ - invite_id: "memberInvite", - role: "member", - user_email: "invite-member@test.com", - }), - accepted: false, - expires_at: expires_at, - }) - await manager.save(memberInvite) - - const adminInvite = await manager.create(Invite, { - id: "adminInvite", - user_email: "invite-admin@test.com", - role: "admin", - accepted: false, - token: generateToken({ - invite_id: "adminInvite", - role: "admin", - user_email: "invite-admin@test.com", - }), - expires_at: expires_at, - }) - await manager.save(adminInvite) -} diff --git a/integration-tests/plugins/medusa-config.js b/integration-tests/plugins/medusa-config.js index 3666d9ab4e..d6cbf105ba 100644 --- a/integration-tests/plugins/medusa-config.js +++ b/integration-tests/plugins/medusa-config.js @@ -27,7 +27,7 @@ module.exports = { database_type: "postgres", jwt_secret: "test", cookie_secret: "test", - database_extra: { idle_in_transaction_session_timeout: 0 } + database_extra: { idle_in_transaction_session_timeout: 0 }, }, modules: { stockLocationService: { diff --git a/integration-tests/repositories/__tests__/product-categories/queries.ts b/integration-tests/repositories/__tests__/product-categories/queries.ts index 4f4fe943ac..1d2da73532 100644 --- a/integration-tests/repositories/__tests__/product-categories/queries.ts +++ b/integration-tests/repositories/__tests__/product-categories/queries.ts @@ -1,7 +1,6 @@ import path from "path" -import { ProductCategory } from "@medusajs/medusa" -import { initDb, useDb } from "../../../helpers/use-db" -import { simpleProductCategoryFactory } from '../../factories' +import { initDb, useDb } from "../../../environment-helpers/use-db" +import { simpleProductCategoryFactory } from "../../../factories" import { ProductCategoryRepository } from "@medusajs/medusa/dist/repositories/product-category" describe("Product Categories", () => { @@ -28,31 +27,33 @@ describe("Product Categories", () => { beforeEach(async () => { a1 = await simpleProductCategoryFactory(dbConnection, { - name: 'a1', + name: "a1", is_active: true, rank: 0, }) a11 = await simpleProductCategoryFactory(dbConnection, { - name: 'a11', + name: "a11", parent_category: a1, is_active: true, rank: 0, }) a111 = await simpleProductCategoryFactory(dbConnection, { - name: 'a111', + name: "a111", parent_category: a11, is_active: true, is_internal: true, rank: 0, }) a12 = await simpleProductCategoryFactory(dbConnection, { - name: 'a12', + name: "a12", parent_category: a1, is_active: false, rank: 1, }) - productCategoryRepository = dbConnection.manager.withRepository(ProductCategoryRepository) + productCategoryRepository = dbConnection.manager.withRepository( + ProductCategoryRepository + ) }) it("can fetch all root categories", async () => { @@ -61,7 +62,7 @@ describe("Product Categories", () => { expect(rootCategories).toEqual([ expect.objectContaining({ name: "a1", - }) + }), ]) }) @@ -103,51 +104,46 @@ describe("Product Categories", () => { let productCategoryRepository beforeEach(async () => { - a1 = await simpleProductCategoryFactory( - dbConnection, { - name: 'skinny jeans', - handle: 'skinny-jeans', - is_active: true, - rank: 0, - } - ) + a1 = await simpleProductCategoryFactory(dbConnection, { + name: "skinny jeans", + handle: "skinny-jeans", + is_active: true, + rank: 0, + }) - a11 = await simpleProductCategoryFactory( - dbConnection, { - name: 'winter shirts', - handle: 'winter-shirts', - parent_category: a1, - is_active: true, - rank: 0, - } - ) + a11 = await simpleProductCategoryFactory(dbConnection, { + name: "winter shirts", + handle: "winter-shirts", + parent_category: a1, + is_active: true, + rank: 0, + }) - a111 = await simpleProductCategoryFactory( - dbConnection, { - name: 'running shoes', - handle: 'running-shoes', - parent_category: a11, - rank: 0, - } - ) + a111 = await simpleProductCategoryFactory(dbConnection, { + name: "running shoes", + handle: "running-shoes", + parent_category: a11, + rank: 0, + }) - a12 = await simpleProductCategoryFactory( - dbConnection, { - name: 'casual shoes', - handle: 'casual-shoes', - parent_category: a1, - is_internal: true, - rank: 1, - } - ) + a12 = await simpleProductCategoryFactory(dbConnection, { + name: "casual shoes", + handle: "casual-shoes", + parent_category: a1, + is_internal: true, + rank: 1, + }) - productCategoryRepository = dbConnection.manager.withRepository(ProductCategoryRepository) + productCategoryRepository = dbConnection.manager.withRepository( + ProductCategoryRepository + ) }) it("fetches all active categories", async () => { - const [ categories, count ] = await productCategoryRepository.getFreeTextSearchResultsAndCount( - { where: { is_active: true } }, - ) + const [categories, count] = + await productCategoryRepository.getFreeTextSearchResultsAndCount({ + where: { is_active: true }, + }) expect(count).toEqual(2) expect(categories).toEqual([ @@ -161,9 +157,10 @@ describe("Product Categories", () => { }) it("fetches all internal categories", async () => { - const [ categories, count ] = await productCategoryRepository.getFreeTextSearchResultsAndCount( - { where: { is_internal: true } }, - ) + const [categories, count] = + await productCategoryRepository.getFreeTextSearchResultsAndCount({ + where: { is_internal: true }, + }) expect(count).toEqual(1) expect(categories).toEqual([ @@ -174,10 +171,11 @@ describe("Product Categories", () => { }) it("fetches all categories with query shoes", async () => { - const [ categories, count ] = await productCategoryRepository.getFreeTextSearchResultsAndCount( - { where: {} }, - 'shoes' - ) + const [categories, count] = + await productCategoryRepository.getFreeTextSearchResultsAndCount( + { where: {} }, + "shoes" + ) expect(count).toEqual(2) expect(categories).toEqual([ @@ -191,10 +189,11 @@ describe("Product Categories", () => { }) it("fetches all categories with query casual-", async () => { - const [ categories, count ] = await productCategoryRepository.getFreeTextSearchResultsAndCount( - { where: {} }, - 'casual-' - ) + const [categories, count] = + await productCategoryRepository.getFreeTextSearchResultsAndCount( + { where: {} }, + "casual-" + ) expect(count).toEqual(1) expect(categories).toEqual([ @@ -205,12 +204,11 @@ describe("Product Categories", () => { }) it("builds relations for categories", async () => { - const [ categories, count ] = await productCategoryRepository.getFreeTextSearchResultsAndCount( - { + const [categories, count] = + await productCategoryRepository.getFreeTextSearchResultsAndCount({ where: { id: a11.id }, relations: { parent_category: true, category_children: true }, - }, - ) + }) expect(count).toEqual(1) expect(categories[0]).toEqual( @@ -222,8 +220,8 @@ describe("Product Categories", () => { category_children: [ expect.objectContaining({ id: a111.id, - }) - ] + }), + ], }) ) }) diff --git a/integration-tests/repositories/factories/index.ts b/integration-tests/repositories/factories/index.ts deleted file mode 100644 index fee1d05994..0000000000 --- a/integration-tests/repositories/factories/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from "./simple-product-category-factory" diff --git a/integration-tests/repositories/factories/simple-product-category-factory.ts b/integration-tests/repositories/factories/simple-product-category-factory.ts deleted file mode 100644 index 30a10bbf71..0000000000 --- a/integration-tests/repositories/factories/simple-product-category-factory.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { Connection } from "typeorm" -import { ProductCategory } from "@medusajs/medusa" - -export const simpleProductCategoryFactory = async ( - connection: Connection, - data: Partial = {} -): Promise => { - const manager = connection.manager - const address = manager.create(ProductCategory, data) - - return await manager.save(address) -}