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
This commit is contained in:
committed by
GitHub
parent
26e2f81c24
commit
4d326fbbdf
@@ -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)
|
||||
|
||||
|
||||
@@ -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", () => {
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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" } }
|
||||
|
||||
|
||||
@@ -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" } }
|
||||
|
||||
|
||||
@@ -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`,
|
||||
|
||||
@@ -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", () => {
|
||||
|
||||
@@ -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", () => {
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
+68
-68
@@ -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<Date>,
|
||||
"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<Date>,
|
||||
"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<Date>,
|
||||
"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<Date>,
|
||||
"customer_id": null,
|
||||
"deleted_at": null,
|
||||
"first_name": "Chyna",
|
||||
"first_name": "Cornell",
|
||||
"id": Any<String>,
|
||||
"last_name": "Osinski",
|
||||
"last_name": "Shanahan",
|
||||
"metadata": null,
|
||||
"phone": null,
|
||||
"postal_code": "51510",
|
||||
"postal_code": "15102-3998",
|
||||
"province": null,
|
||||
"updated_at": Any<Date>,
|
||||
},
|
||||
@@ -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<Date>,
|
||||
"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<Date>,
|
||||
"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<Date>,
|
||||
"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<Date>,
|
||||
"customer_id": null,
|
||||
"deleted_at": null,
|
||||
"first_name": "Chyna",
|
||||
"first_name": "Cornell",
|
||||
"id": Any<String>,
|
||||
"last_name": "Osinski",
|
||||
"last_name": "Shanahan",
|
||||
"metadata": null,
|
||||
"phone": null,
|
||||
"postal_code": "51510",
|
||||
"postal_code": "15102-3998",
|
||||
"province": null,
|
||||
"updated_at": Any<Date>,
|
||||
},
|
||||
@@ -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<Date>,
|
||||
"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<Date>,
|
||||
"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<Date>,
|
||||
@@ -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<Date>,
|
||||
"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<Date>,
|
||||
"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<Date>,
|
||||
"customer_id": null,
|
||||
"deleted_at": null,
|
||||
"first_name": "Chyna",
|
||||
"first_name": "Cornell",
|
||||
"id": Any<String>,
|
||||
"last_name": "Osinski",
|
||||
"last_name": "Shanahan",
|
||||
"metadata": null,
|
||||
"phone": null,
|
||||
"postal_code": "51510",
|
||||
"postal_code": "15102-3998",
|
||||
"province": null,
|
||||
"updated_at": Any<Date>,
|
||||
},
|
||||
@@ -657,7 +657,7 @@ Object {
|
||||
},
|
||||
],
|
||||
"thumbnail": "",
|
||||
"title": "Intelligent Plastic Chips",
|
||||
"title": "Incredible Plastic Mouse",
|
||||
"unit_price": 1000,
|
||||
"updated_at": Any<Date>,
|
||||
"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<Date>,
|
||||
"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<Date>,
|
||||
"variant_rank": 0,
|
||||
@@ -756,12 +756,12 @@ Object {
|
||||
"created_at": Any<Date>,
|
||||
"deleted_at": null,
|
||||
"email": "test@testson.com",
|
||||
"first_name": null,
|
||||
"has_account": false,
|
||||
"first_name": "Lonzo",
|
||||
"has_account": true,
|
||||
"id": Any<String>,
|
||||
"last_name": null,
|
||||
"last_name": "Kemmer",
|
||||
"metadata": null,
|
||||
"phone": null,
|
||||
"phone": "499-811-0832",
|
||||
"updated_at": Any<Date>,
|
||||
},
|
||||
"customer_id": Any<String>,
|
||||
@@ -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<Date>,
|
||||
@@ -983,12 +983,12 @@ Object {
|
||||
"created_at": Any<Date>,
|
||||
"deleted_at": null,
|
||||
"email": "test@testson.com",
|
||||
"first_name": null,
|
||||
"has_account": false,
|
||||
"first_name": "Reba",
|
||||
"has_account": true,
|
||||
"id": Any<String>,
|
||||
"last_name": null,
|
||||
"last_name": "Waelchi",
|
||||
"metadata": null,
|
||||
"phone": null,
|
||||
"phone": "1-308-426-4696",
|
||||
"updated_at": Any<Date>,
|
||||
},
|
||||
"customer_id": Any<String>,
|
||||
@@ -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<Date>,
|
||||
"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<Date>,
|
||||
"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<Date>,
|
||||
"customer_id": null,
|
||||
"deleted_at": null,
|
||||
"first_name": "Chyna",
|
||||
"first_name": "Cornell",
|
||||
"id": Any<String>,
|
||||
"last_name": "Osinski",
|
||||
"last_name": "Shanahan",
|
||||
"metadata": null,
|
||||
"phone": null,
|
||||
"postal_code": "51510",
|
||||
"postal_code": "15102-3998",
|
||||
"province": null,
|
||||
"updated_at": Any<Date>,
|
||||
},
|
||||
@@ -1235,12 +1235,12 @@ Object {
|
||||
"created_at": Any<Date>,
|
||||
"deleted_at": null,
|
||||
"email": "test@testson.com",
|
||||
"first_name": null,
|
||||
"has_account": false,
|
||||
"first_name": "Reba",
|
||||
"has_account": true,
|
||||
"id": Any<String>,
|
||||
"last_name": null,
|
||||
"last_name": "Waelchi",
|
||||
"metadata": null,
|
||||
"phone": null,
|
||||
"phone": "1-308-426-4696",
|
||||
"updated_at": Any<Date>,
|
||||
},
|
||||
"customer_id": Any<String>,
|
||||
@@ -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<Date>,
|
||||
@@ -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<Date>,
|
||||
"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<Date>,
|
||||
"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<Date>,
|
||||
"customer_id": null,
|
||||
"deleted_at": null,
|
||||
"first_name": "Chyna",
|
||||
"first_name": "Cornell",
|
||||
"id": Any<String>,
|
||||
"last_name": "Osinski",
|
||||
"last_name": "Shanahan",
|
||||
"metadata": null,
|
||||
"phone": null,
|
||||
"postal_code": "51510",
|
||||
"postal_code": "15102-3998",
|
||||
"province": null,
|
||||
"updated_at": Any<Date>,
|
||||
},
|
||||
@@ -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<Date>,
|
||||
"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<Date>,
|
||||
"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<Date>,
|
||||
@@ -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<Date>,
|
||||
"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<Date>,
|
||||
"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<Date>,
|
||||
"customer_id": null,
|
||||
"deleted_at": null,
|
||||
"first_name": "Chyna",
|
||||
"first_name": "Cornell",
|
||||
"id": Any<String>,
|
||||
"last_name": "Osinski",
|
||||
"last_name": "Shanahan",
|
||||
"metadata": null,
|
||||
"phone": null,
|
||||
"postal_code": "51510",
|
||||
"postal_code": "15102-3998",
|
||||
"province": null,
|
||||
"updated_at": Any<Date>,
|
||||
},
|
||||
@@ -1832,7 +1832,7 @@ Object {
|
||||
},
|
||||
],
|
||||
"thumbnail": "",
|
||||
"title": "Intelligent Plastic Chips",
|
||||
"title": "Incredible Plastic Mouse",
|
||||
"unit_price": 1000,
|
||||
"updated_at": Any<Date>,
|
||||
"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<Date>,
|
||||
"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<Date>,
|
||||
"variant_rank": 0,
|
||||
@@ -2103,7 +2103,7 @@ Object {
|
||||
},
|
||||
],
|
||||
"thumbnail": "",
|
||||
"title": "Intelligent Plastic Chips",
|
||||
"title": "Handcrafted Frozen Tuna",
|
||||
"unit_price": 1000,
|
||||
"updated_at": Any<Date>,
|
||||
"variant": Object {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -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"
|
||||
@@ -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<Address> => {
|
||||
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)
|
||||
}
|
||||
@@ -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<Cart> => {
|
||||
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
|
||||
}
|
||||
@@ -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<Discount> => {
|
||||
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
|
||||
}
|
||||
@@ -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<LineItem> => {
|
||||
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
|
||||
}
|
||||
@@ -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<Order> => {
|
||||
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<Order> = {
|
||||
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
|
||||
}
|
||||
@@ -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<Product> => {
|
||||
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
|
||||
}
|
||||
@@ -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<ProductTaxRate> => {
|
||||
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)
|
||||
}
|
||||
@@ -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<ProductTypeTaxRate> => {
|
||||
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)
|
||||
}
|
||||
@@ -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<ProductVariant> => {
|
||||
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
|
||||
}
|
||||
@@ -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<Region> => {
|
||||
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
|
||||
}
|
||||
@@ -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<ShippingMethod> => {
|
||||
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
|
||||
}
|
||||
@@ -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<ShippingOption> => {
|
||||
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
|
||||
}
|
||||
@@ -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<ShippingTaxRate> => {
|
||||
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)
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
import { SalesChannel, Store } from "@medusajs/medusa"
|
||||
import faker from "faker"
|
||||
import { DataSource, Not, IsNull } from "typeorm"
|
||||
|
||||
export type StoreFactoryData = {
|
||||
swap_link_template?: string
|
||||
}
|
||||
|
||||
export const simpleStoreFactory = async (
|
||||
dataSource: DataSource,
|
||||
data: StoreFactoryData = {},
|
||||
seed?: number
|
||||
): Promise<Store | undefined> => {
|
||||
if (typeof seed !== "undefined") {
|
||||
faker.seed(seed)
|
||||
}
|
||||
|
||||
const manager = dataSource.manager
|
||||
const stores = await manager.find(Store, { where: { id: Not(IsNull()) } })
|
||||
const store = stores[0]
|
||||
|
||||
if (!store) {
|
||||
return
|
||||
}
|
||||
|
||||
store.swap_link_template = data.swap_link_template ?? "something/{cart_id}"
|
||||
|
||||
await manager.insert(SalesChannel, {
|
||||
id: "test-channel",
|
||||
name: "Default"
|
||||
})
|
||||
|
||||
const storeToSave = await manager.save(store)
|
||||
|
||||
await manager.query(`update store set default_sales_channel_id = 'test-channel' where id = '${storeToSave!.id}'`)
|
||||
|
||||
return storeToSave!
|
||||
}
|
||||
@@ -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<TaxRate> => {
|
||||
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)
|
||||
}
|
||||
@@ -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,
|
||||
})
|
||||
}
|
||||
@@ -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]
|
||||
}
|
||||
@@ -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)
|
||||
}
|
||||
@@ -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: {},
|
||||
})
|
||||
}
|
||||
@@ -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",
|
||||
})
|
||||
}
|
||||
@@ -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,
|
||||
},
|
||||
],
|
||||
})
|
||||
}
|
||||
@@ -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)
|
||||
}
|
||||
@@ -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)
|
||||
}
|
||||
@@ -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)
|
||||
}
|
||||
@@ -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,
|
||||
})
|
||||
}
|
||||
@@ -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: {},
|
||||
})
|
||||
}
|
||||
@@ -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)
|
||||
}
|
||||
@@ -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: {
|
||||
|
||||
Reference in New Issue
Block a user