Chore/integration tests modules utils (#6581)

new wrapper for medusa integration tests.
for now it is only applied to the modules directory, but it could be used in the api integration tests or any other integrations that requires a db and a server up and running. 

It is not perfect, but I wanted to have something working and centralised before improving it, also avoiding too many conflicts with other prs
This commit is contained in:
Adrien de Peretti authored and GitHub committed 2024-03-06 10:03:07 +00:00
1 parent a6736c7ee0
commit 51bb6f1e89
99 files changed
+1945 -2084

No files matched your search

+5
View File
@@ -0,0 +1,5 @@
---
"medusa-test-utils": patch
---
Chore/integration tests modules utils
+1
View File
@@ -2,3 +2,4 @@
DB_HOST=localhost DB_HOST=localhost
DB_USERNAME=postgres DB_USERNAME=postgres
DB_PASSWORD='' DB_PASSWORD=''
LOG_LEVEL=error
@@ -1,13 +1,8 @@
import { initDb, useDb } from "../../../../environment-helpers/use-db"
import { ApiKeyType } from "@medusajs/utils" import { ApiKeyType } from "@medusajs/utils"
import { IApiKeyModuleService, IRegionModuleService } from "@medusajs/types" import { IRegionModuleService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { ModuleRegistrationName } from "@medusajs/modules-sdk"
import { createAdminUser } from "../../../helpers/create-admin-user" import { createAdminUser } from "../../../helpers/create-admin-user"
import { getContainer } from "../../../../environment-helpers/use-container" import { medusaIntegrationTestRunner } from "medusa-test-utils"
import path from "path"
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
import { useApi } from "../../../../environment-helpers/use-api"
jest.setTimeout(50000) jest.setTimeout(50000)
@@ -16,42 +11,31 @@ const adminHeaders = {
headers: { "x-medusa-access-token": "test_token" }, headers: { "x-medusa-access-token": "test_token" },
} }
medusaIntegrationTestRunner({
env,
testSuite: ({ dbConnection, getContainer, api }) => {
describe("API Keys - Admin", () => { describe("API Keys - Admin", () => {
let dbConnection
let appContainer
let shutdownServer
let service: IApiKeyModuleService
let regionService: IRegionModuleService let regionService: IRegionModuleService
let container
beforeAll(async () => { beforeAll(async () => {
const cwd = path.resolve(path.join(__dirname, "..", "..", "..")) container = getContainer()
dbConnection = await initDb({ cwd, env } as any) regionService = container.resolve(
shutdownServer = await startBootstrapApp({ cwd, env }) ModuleRegistrationName.REGION
appContainer = getContainer() ) as IRegionModuleService
service = appContainer.resolve(ModuleRegistrationName.API_KEY)
regionService = appContainer.resolve(ModuleRegistrationName.REGION)
})
afterAll(async () => {
const db = useDb()
await db.shutdown()
await shutdownServer()
}) })
beforeEach(async () => { beforeEach(async () => {
await createAdminUser(dbConnection, adminHeaders) await createAdminUser(dbConnection, adminHeaders, container)
}) })
afterEach(async () => { afterEach(async () => {
const db = useDb()
// TODO: Once teardown doesn't skip constraint checks and cascades, we can remove this // TODO: Once teardown doesn't skip constraint checks and cascades, we can remove this
const existingRegions = await regionService.list({}) const existingRegions = await regionService.list({})
await regionService.delete(existingRegions.map((r) => r.id)) await regionService.delete(existingRegions.map((r) => r.id))
await db.teardown()
}) })
it("should correctly implement the entire lifecycle of an api key", async () => { it("should correctly implement the entire lifecycle of an api key", async () => {
const api = useApi() as any
const created = await api.post( const created = await api.post(
`/admin/api-keys`, `/admin/api-keys`,
{ {
@@ -114,7 +98,6 @@ describe("API Keys - Admin", () => {
}) })
it("can use a secret api key for authentication", async () => { it("can use a secret api key for authentication", async () => {
const api = useApi() as any
const created = await api.post( const created = await api.post(
`/admin/api-keys`, `/admin/api-keys`,
{ {
@@ -143,7 +126,6 @@ describe("API Keys - Admin", () => {
}) })
it("falls back to other mode of authentication when an api key is not valid", async () => { it("falls back to other mode of authentication when an api key is not valid", async () => {
const api = useApi() as any
const created = await api.post( const created = await api.post(
`/admin/api-keys`, `/admin/api-keys`,
{ {
@@ -195,3 +177,5 @@ describe("API Keys - Admin", () => {
expect(createdRegion.data.region.name).toEqual("Test Region") expect(createdRegion.data.region.name).toEqual("Test Region")
}) })
}) })
},
})
@@ -1,48 +1,31 @@
import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { ModuleRegistrationName } from "@medusajs/modules-sdk"
import { IAuthModuleService, ICustomerModuleService } from "@medusajs/types" import { IAuthModuleService, ICustomerModuleService } from "@medusajs/types"
import path from "path"
import Scrypt from "scrypt-kdf" import Scrypt from "scrypt-kdf"
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
import { useApi } from "../../../../environment-helpers/use-api"
import { getContainer } from "../../../../environment-helpers/use-container"
import { initDb, useDb } from "../../../../environment-helpers/use-db"
import adminSeeder from "../../../../helpers/admin-seeder" import adminSeeder from "../../../../helpers/admin-seeder"
import { medusaIntegrationTestRunner } from "medusa-test-utils"
jest.setTimeout(50000) jest.setTimeout(50000)
const env = { MEDUSA_FF_MEDUSA_V2: true } const env = { MEDUSA_FF_MEDUSA_V2: true }
medusaIntegrationTestRunner({
env,
testSuite: ({ dbConnection, getContainer, api }) => {
describe("POST /auth/emailpass", () => { describe("POST /auth/emailpass", () => {
let dbConnection
let appContainer let appContainer
let shutdownServer
let customerModuleService: ICustomerModuleService let customerModuleService: ICustomerModuleService
beforeAll(async () => { beforeAll(async () => {
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
dbConnection = await initDb({ cwd, env } as any)
shutdownServer = await startBootstrapApp({ cwd, env })
appContainer = getContainer() appContainer = getContainer()
customerModuleService = appContainer.resolve( customerModuleService = appContainer.resolve(
ModuleRegistrationName.CUSTOMER ModuleRegistrationName.CUSTOMER
) )
}) })
afterAll(async () => {
const db = useDb()
await db.shutdown()
await shutdownServer()
})
beforeEach(async () => { beforeEach(async () => {
await adminSeeder(dbConnection) await adminSeeder(dbConnection)
}) })
afterEach(async () => {
const db = useDb()
await db.teardown()
})
const password = "supersecret" const password = "supersecret"
const email = "test@test.com" const email = "test@test.com"
@@ -63,7 +46,6 @@ describe("POST /auth/emailpass", () => {
}, },
}) })
const api = useApi() as any
const response = await api const response = await api
.post(`/auth/admin/emailpass`, { .post(`/auth/admin/emailpass`, {
email: email, email: email,
@@ -96,7 +78,6 @@ describe("POST /auth/emailpass", () => {
}, },
}) })
const api = useApi() as any
const error = await api const error = await api
.post(`/auth/admin/emailpass`, { .post(`/auth/admin/emailpass`, {
email: email, email: email,
@@ -116,7 +97,6 @@ describe("POST /auth/emailpass", () => {
await Scrypt.kdf(password, { logN: 15, r: 8, p: 1 }) await Scrypt.kdf(password, { logN: 15, r: 8, p: 1 })
).toString("base64") ).toString("base64")
const api = useApi() as any
const error = await api const error = await api
.post(`/auth/admin/emailpass`, { .post(`/auth/admin/emailpass`, {
email: "should-not-exist", email: "should-not-exist",
@@ -133,3 +113,5 @@ describe("POST /auth/emailpass", () => {
}) })
}) })
}) })
},
})
@@ -6,29 +6,23 @@ import {
} from "@medusajs/modules-sdk" } from "@medusajs/modules-sdk"
import { ICartModuleService, IPromotionModuleService } from "@medusajs/types" import { ICartModuleService, IPromotionModuleService } from "@medusajs/types"
import { PromotionType } from "@medusajs/utils" import { PromotionType } from "@medusajs/utils"
import path from "path"
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
import { useApi } from "../../../../environment-helpers/use-api"
import { getContainer } from "../../../../environment-helpers/use-container"
import { initDb, useDb } from "../../../../environment-helpers/use-db"
import adminSeeder from "../../../../helpers/admin-seeder" import adminSeeder from "../../../../helpers/admin-seeder"
import { medusaIntegrationTestRunner } from "medusa-test-utils"
jest.setTimeout(50000) jest.setTimeout(50000)
const env = { MEDUSA_FF_MEDUSA_V2: true } const env = { MEDUSA_FF_MEDUSA_V2: true }
medusaIntegrationTestRunner({
env,
testSuite: ({ dbConnection, getContainer, api }) => {
describe("Store Carts API: Add promotions to cart", () => { describe("Store Carts API: Add promotions to cart", () => {
let dbConnection
let appContainer let appContainer
let shutdownServer
let cartModuleService: ICartModuleService let cartModuleService: ICartModuleService
let promotionModuleService: IPromotionModuleService let promotionModuleService: IPromotionModuleService
let remoteLinkService: RemoteLink let remoteLinkService: RemoteLink
beforeAll(async () => { beforeAll(async () => {
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
dbConnection = await initDb({ cwd, env } as any)
shutdownServer = await startBootstrapApp({ cwd, env })
appContainer = getContainer() appContainer = getContainer()
cartModuleService = appContainer.resolve(ModuleRegistrationName.CART) cartModuleService = appContainer.resolve(ModuleRegistrationName.CART)
promotionModuleService = appContainer.resolve( promotionModuleService = appContainer.resolve(
@@ -37,21 +31,10 @@ describe("Store Carts API: Add promotions to cart", () => {
remoteLinkService = appContainer.resolve(LinkModuleUtils.REMOTE_LINK) remoteLinkService = appContainer.resolve(LinkModuleUtils.REMOTE_LINK)
}) })
afterAll(async () => {
const db = useDb()
await db.shutdown()
await shutdownServer()
})
beforeEach(async () => { beforeEach(async () => {
await adminSeeder(dbConnection) await adminSeeder(dbConnection)
}) })
afterEach(async () => {
const db = useDb()
await db.teardown()
})
describe("POST /store/carts/:id/promotions", () => { describe("POST /store/carts/:id/promotions", () => {
it("should add line item adjustments to a cart based on promotions", async () => { it("should add line item adjustments to a cart based on promotions", async () => {
const appliedPromotion = await promotionModuleService.create({ const appliedPromotion = await promotionModuleService.create({
@@ -131,8 +114,6 @@ describe("Store Carts API: Add promotions to cart", () => {
[Modules.PROMOTION]: { promotion_id: appliedPromotion.id }, [Modules.PROMOTION]: { promotion_id: appliedPromotion.id },
}) })
const api = useApi() as any
const created = await api.post(`/store/carts/${cart.id}/promotions`, { const created = await api.post(`/store/carts/${cart.id}/promotions`, {
promo_codes: [createdPromotion.code], promo_codes: [createdPromotion.code],
}) })
@@ -245,9 +226,8 @@ describe("Store Carts API: Add promotions to cart", () => {
], ],
}) })
const [express, standard] = await cartModuleService.addShippingMethods( const [express, standard] =
cart.id, await cartModuleService.addShippingMethods(cart.id, [
[
{ {
amount: 500, amount: 500,
name: "express", name: "express",
@@ -256,26 +236,21 @@ describe("Store Carts API: Add promotions to cart", () => {
amount: 500, amount: 500,
name: "standard", name: "standard",
}, },
] ])
)
await remoteLinkService.create({ await remoteLinkService.create({
[Modules.CART]: { cart_id: cart.id }, [Modules.CART]: { cart_id: cart.id },
[Modules.PROMOTION]: { promotion_id: appliedPromotion.id }, [Modules.PROMOTION]: { promotion_id: appliedPromotion.id },
}) })
const [adjustment] = await cartModuleService.addShippingMethodAdjustments( const [adjustment] =
cart.id, await cartModuleService.addShippingMethodAdjustments(cart.id, [
[
{ {
shipping_method_id: express.id, shipping_method_id: express.id,
amount: 100, amount: 100,
code: appliedPromotion.code!, code: appliedPromotion.code!,
}, },
] ])
)
const api = useApi() as any
const created = await api.post(`/store/carts/${cart.id}/promotions`, { const created = await api.post(`/store/carts/${cart.id}/promotions`, {
promo_codes: [newPromotion.code], promo_codes: [newPromotion.code],
@@ -322,3 +297,5 @@ describe("Store Carts API: Add promotions to cart", () => {
}) })
}) })
}) })
},
})
@@ -19,21 +19,18 @@ import {
IRegionModuleService, IRegionModuleService,
ISalesChannelModuleService, ISalesChannelModuleService,
} from "@medusajs/types" } from "@medusajs/types"
import path from "path"
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
import { useApi } from "../../../../environment-helpers/use-api"
import { getContainer } from "../../../../environment-helpers/use-container"
import { initDb, useDb } from "../../../../environment-helpers/use-db"
import adminSeeder from "../../../../helpers/admin-seeder" import adminSeeder from "../../../../helpers/admin-seeder"
import { medusaIntegrationTestRunner } from "medusa-test-utils"
jest.setTimeout(50000) jest.setTimeout(50000)
const env = { MEDUSA_FF_MEDUSA_V2: true } const env = { MEDUSA_FF_MEDUSA_V2: true }
medusaIntegrationTestRunner({
env,
testSuite: ({ dbConnection, getContainer, api }) => {
describe("Carts workflows", () => { describe("Carts workflows", () => {
let dbConnection
let appContainer let appContainer
let shutdownServer
let cartModuleService: ICartModuleService let cartModuleService: ICartModuleService
let regionModuleService: IRegionModuleService let regionModuleService: IRegionModuleService
let scModuleService: ISalesChannelModuleService let scModuleService: ISalesChannelModuleService
@@ -46,13 +43,14 @@ describe("Carts workflows", () => {
let defaultRegion let defaultRegion
beforeAll(async () => { beforeAll(async () => {
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
dbConnection = await initDb({ cwd, env } as any)
shutdownServer = await startBootstrapApp({ cwd, env })
appContainer = getContainer() appContainer = getContainer()
cartModuleService = appContainer.resolve(ModuleRegistrationName.CART) cartModuleService = appContainer.resolve(ModuleRegistrationName.CART)
regionModuleService = appContainer.resolve(ModuleRegistrationName.REGION) regionModuleService = appContainer.resolve(
scModuleService = appContainer.resolve(ModuleRegistrationName.SALES_CHANNEL) ModuleRegistrationName.REGION
)
scModuleService = appContainer.resolve(
ModuleRegistrationName.SALES_CHANNEL
)
customerModule = appContainer.resolve(ModuleRegistrationName.CUSTOMER) customerModule = appContainer.resolve(ModuleRegistrationName.CUSTOMER)
productModule = appContainer.resolve(ModuleRegistrationName.PRODUCT) productModule = appContainer.resolve(ModuleRegistrationName.PRODUCT)
pricingModule = appContainer.resolve(ModuleRegistrationName.PRICING) pricingModule = appContainer.resolve(ModuleRegistrationName.PRICING)
@@ -61,12 +59,6 @@ describe("Carts workflows", () => {
remoteQuery = appContainer.resolve("remoteQuery") remoteQuery = appContainer.resolve("remoteQuery")
}) })
afterAll(async () => {
const db = useDb()
await db.shutdown()
await shutdownServer()
})
beforeEach(async () => { beforeEach(async () => {
await adminSeeder(dbConnection) await adminSeeder(dbConnection)
@@ -77,11 +69,6 @@ describe("Carts workflows", () => {
}) })
}) })
afterEach(async () => {
const db = useDb()
await db.teardown()
})
describe("CreateCartWorkflow", () => { describe("CreateCartWorkflow", () => {
it("should create a cart", async () => { it("should create a cart", async () => {
const region = await regionModuleService.create({ const region = await regionModuleService.create({
@@ -181,8 +168,6 @@ describe("Carts workflows", () => {
}) })
it("should throw if sales channel is disabled", async () => { it("should throw if sales channel is disabled", async () => {
const api = useApi() as any
const salesChannel = await scModuleService.create({ const salesChannel = await scModuleService.create({
name: "Webshop", name: "Webshop",
is_disabled: true, is_disabled: true,
@@ -581,7 +566,9 @@ describe("Carts workflows", () => {
}, },
]) ])
const updatedItem = await cartModuleService.retrieveLineItem(item.id) const updatedItem = await cartModuleService.retrieveLineItem(
item.id
)
expect(updatedItem).toEqual( expect(updatedItem).toEqual(
expect.objectContaining({ expect.objectContaining({
@@ -608,7 +595,9 @@ describe("Carts workflows", () => {
], ],
}) })
const items = await cartModuleService.listLineItems({ cart_id: cart.id }) const items = await cartModuleService.listLineItems({
cart_id: cart.id,
})
await deleteLineItemsWorkflow(appContainer).run({ await deleteLineItemsWorkflow(appContainer).run({
input: { input: {
@@ -630,7 +619,9 @@ describe("Carts workflows", () => {
workflow.appendAction("throw", deleteLineItemsStepId, { workflow.appendAction("throw", deleteLineItemsStepId, {
invoke: async function failStep() { invoke: async function failStep() {
throw new Error(`Failed to do something after deleting line items`) throw new Error(
`Failed to do something after deleting line items`
)
}, },
}) })
@@ -733,15 +724,20 @@ describe("Carts workflows", () => {
describe("compensation", () => { describe("compensation", () => {
it("should dismiss cart <> payment collection link and delete created payment collection", async () => { it("should dismiss cart <> payment collection link and delete created payment collection", async () => {
const workflow = createPaymentCollectionForCartWorkflow(appContainer) const workflow =
createPaymentCollectionForCartWorkflow(appContainer)
workflow.appendAction("throw", linkCartAndPaymentCollectionsStepId, { workflow.appendAction(
"throw",
linkCartAndPaymentCollectionsStepId,
{
invoke: async function failStep() { invoke: async function failStep() {
throw new Error( throw new Error(
`Failed to do something after linking cart and payment collection` `Failed to do something after linking cart and payment collection`
) )
}, },
}) }
)
const region = await regionModuleService.create({ const region = await regionModuleService.create({
name: "US", name: "US",
@@ -813,3 +809,5 @@ describe("Carts workflows", () => {
}) })
}) })
}) })
},
})
@@ -14,22 +14,19 @@ import {
ISalesChannelModuleService, ISalesChannelModuleService,
} from "@medusajs/types" } from "@medusajs/types"
import { PromotionRuleOperator, PromotionType } from "@medusajs/utils" import { PromotionRuleOperator, PromotionType } from "@medusajs/utils"
import path from "path"
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
import { useApi } from "../../../../environment-helpers/use-api"
import { getContainer } from "../../../../environment-helpers/use-container"
import { initDb, useDb } from "../../../../environment-helpers/use-db"
import adminSeeder from "../../../../helpers/admin-seeder" import adminSeeder from "../../../../helpers/admin-seeder"
import { createAuthenticatedCustomer } from "../../../helpers/create-authenticated-customer" import { createAuthenticatedCustomer } from "../../../helpers/create-authenticated-customer"
import { medusaIntegrationTestRunner } from "medusa-test-utils"
jest.setTimeout(50000) jest.setTimeout(50000)
const env = { MEDUSA_FF_MEDUSA_V2: true } const env = { MEDUSA_FF_MEDUSA_V2: true }
medusaIntegrationTestRunner({
env,
testSuite: ({ dbConnection, getContainer, api }) => {
describe("Store Carts API", () => { describe("Store Carts API", () => {
let dbConnection
let appContainer let appContainer
let shutdownServer
let cartModuleService: ICartModuleService let cartModuleService: ICartModuleService
let regionModuleService: IRegionModuleService let regionModuleService: IRegionModuleService
let scModuleService: ISalesChannelModuleService let scModuleService: ISalesChannelModuleService
@@ -42,13 +39,14 @@ describe("Store Carts API", () => {
let defaultRegion let defaultRegion
beforeAll(async () => { beforeAll(async () => {
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
dbConnection = await initDb({ cwd, env } as any)
shutdownServer = await startBootstrapApp({ cwd, env })
appContainer = getContainer() appContainer = getContainer()
cartModuleService = appContainer.resolve(ModuleRegistrationName.CART) cartModuleService = appContainer.resolve(ModuleRegistrationName.CART)
regionModuleService = appContainer.resolve(ModuleRegistrationName.REGION) regionModuleService = appContainer.resolve(
scModuleService = appContainer.resolve(ModuleRegistrationName.SALES_CHANNEL) ModuleRegistrationName.REGION
)
scModuleService = appContainer.resolve(
ModuleRegistrationName.SALES_CHANNEL
)
customerModule = appContainer.resolve(ModuleRegistrationName.CUSTOMER) customerModule = appContainer.resolve(ModuleRegistrationName.CUSTOMER)
productModule = appContainer.resolve(ModuleRegistrationName.PRODUCT) productModule = appContainer.resolve(ModuleRegistrationName.PRODUCT)
pricingModule = appContainer.resolve(ModuleRegistrationName.PRICING) pricingModule = appContainer.resolve(ModuleRegistrationName.PRICING)
@@ -56,12 +54,6 @@ describe("Store Carts API", () => {
promotionModule = appContainer.resolve(ModuleRegistrationName.PROMOTION) promotionModule = appContainer.resolve(ModuleRegistrationName.PROMOTION)
}) })
afterAll(async () => {
const db = useDb()
await db.shutdown()
await shutdownServer()
})
beforeEach(async () => { beforeEach(async () => {
await adminSeeder(dbConnection) await adminSeeder(dbConnection)
@@ -72,11 +64,6 @@ describe("Store Carts API", () => {
}) })
}) })
afterEach(async () => {
const db = useDb()
await db.teardown()
})
describe("POST /store/carts", () => { describe("POST /store/carts", () => {
it("should create a cart", async () => { it("should create a cart", async () => {
const region = await regionModuleService.create({ const region = await regionModuleService.create({
@@ -140,8 +127,6 @@ describe("Store Carts API", () => {
}, },
]) ])
const api = useApi() as any
const created = await api.post(`/store/carts`, { const created = await api.post(`/store/carts`, {
email: "tony@stark.com", email: "tony@stark.com",
currency_code: "usd", currency_code: "usd",
@@ -188,8 +173,6 @@ describe("Store Carts API", () => {
}) })
it("should create cart with customer from email", async () => { it("should create cart with customer from email", async () => {
const api = useApi() as any
const created = await api.post(`/store/carts`, { const created = await api.post(`/store/carts`, {
currency_code: "usd", currency_code: "usd",
email: "tony@stark-industries.com", email: "tony@stark-industries.com",
@@ -215,7 +198,6 @@ describe("Store Carts API", () => {
currency_code: "usd", currency_code: "usd",
}) })
const api = useApi() as any
const response = await api.post(`/store/carts`, { const response = await api.post(`/store/carts`, {
email: "tony@stark.com", email: "tony@stark.com",
currency_code: "usd", currency_code: "usd",
@@ -240,7 +222,6 @@ describe("Store Carts API", () => {
currency_code: "usd", currency_code: "usd",
}) })
const api = useApi() as any
const response = await api.post(`/store/carts`, { const response = await api.post(`/store/carts`, {
email: "tony@stark.com", email: "tony@stark.com",
region_id: region.id, region_id: region.id,
@@ -260,9 +241,10 @@ describe("Store Carts API", () => {
}) })
it("should create cart with logged-in customer", async () => { it("should create cart with logged-in customer", async () => {
const { customer, jwt } = await createAuthenticatedCustomer(appContainer) const { customer, jwt } = await createAuthenticatedCustomer(
appContainer
)
const api = useApi() as any
const response = await api.post( const response = await api.post(
`/store/carts`, `/store/carts`,
{}, {},
@@ -286,8 +268,6 @@ describe("Store Carts API", () => {
}) })
it("should respond 400 bad request on unknown props", async () => { it("should respond 400 bad request on unknown props", async () => {
const api = useApi() as any
await expect( await expect(
api.post(`/store/carts`, { api.post(`/store/carts`, {
foo: "bar", foo: "bar",
@@ -361,8 +341,6 @@ describe("Store Carts API", () => {
[Modules.PROMOTION]: { promotion_id: appliedPromotion.id }, [Modules.PROMOTION]: { promotion_id: appliedPromotion.id },
}) })
const api = useApi() as any
// Should remove earlier adjustments from other promocodes // Should remove earlier adjustments from other promocodes
let updated = await api.post(`/store/carts/${cart.id}`, { let updated = await api.post(`/store/carts/${cart.id}`, {
promo_codes: [createdPromotion.code], promo_codes: [createdPromotion.code],
@@ -419,8 +397,6 @@ describe("Store Carts API", () => {
currency_code: "eur", currency_code: "eur",
}) })
const api = useApi() as any
let updated = await api.post(`/store/carts/${cart.id}`, { let updated = await api.post(`/store/carts/${cart.id}`, {
region_id: region.id, region_id: region.id,
email: "tony@stark.com", email: "tony@stark.com",
@@ -477,8 +453,6 @@ describe("Store Carts API", () => {
name: "Webshop", name: "Webshop",
}) })
const api = useApi() as any
const created = await api.post(`/store/carts`, { const created = await api.post(`/store/carts`, {
email: "tony@stark.com", email: "tony@stark.com",
currency_code: "usd", currency_code: "usd",
@@ -500,9 +474,12 @@ describe("Store Carts API", () => {
}) })
) )
const updated = await api.post(`/store/carts/${created.data.cart.id}`, { const updated = await api.post(
`/store/carts/${created.data.cart.id}`,
{
email: "tony@stark-industries.com", email: "tony@stark-industries.com",
}) }
)
expect(updated.status).toEqual(200) expect(updated.status).toEqual(200)
expect(updated.data.cart).toEqual( expect(updated.data.cart).toEqual(
@@ -539,7 +516,6 @@ describe("Store Carts API", () => {
sales_channel_id: salesChannel.id, sales_channel_id: salesChannel.id,
}) })
const api = useApi() as any
const response = await api.get(`/store/carts/${cart.id}`) const response = await api.get(`/store/carts/${cart.id}`)
expect(response.status).toEqual(200) expect(response.status).toEqual(200)
@@ -644,11 +620,13 @@ describe("Store Carts API", () => {
[Modules.PROMOTION]: { promotion_id: appliedPromotion.id }, [Modules.PROMOTION]: { promotion_id: appliedPromotion.id },
}) })
const api = useApi() as any const response = await api.post(
const response = await api.post(`/store/carts/${cart.id}/line-items`, { `/store/carts/${cart.id}/line-items`,
{
variant_id: product.variants[0].id, variant_id: product.variants[0].id,
quantity: 1, quantity: 1,
}) }
)
expect(response.status).toEqual(200) expect(response.status).toEqual(200)
expect(response.data.cart).toEqual( expect(response.data.cart).toEqual(
@@ -697,7 +675,6 @@ describe("Store Carts API", () => {
region_id: region.id, region_id: region.id,
}) })
const api = useApi() as any
const response = await api.post( const response = await api.post(
`/store/carts/${cart.id}/payment-collections` `/store/carts/${cart.id}/payment-collections`
) )
@@ -716,3 +693,5 @@ describe("Store Carts API", () => {
}) })
}) })
}) })
},
})
@@ -6,29 +6,23 @@ import {
} from "@medusajs/modules-sdk" } from "@medusajs/modules-sdk"
import { ICartModuleService, IPromotionModuleService } from "@medusajs/types" import { ICartModuleService, IPromotionModuleService } from "@medusajs/types"
import { PromotionType } from "@medusajs/utils" import { PromotionType } from "@medusajs/utils"
import path from "path"
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
import { useApi } from "../../../../environment-helpers/use-api"
import { getContainer } from "../../../../environment-helpers/use-container"
import { initDb, useDb } from "../../../../environment-helpers/use-db"
import adminSeeder from "../../../../helpers/admin-seeder" import adminSeeder from "../../../../helpers/admin-seeder"
import { medusaIntegrationTestRunner } from "medusa-test-utils"
jest.setTimeout(50000) jest.setTimeout(50000)
const env = { MEDUSA_FF_MEDUSA_V2: true } const env = { MEDUSA_FF_MEDUSA_V2: true }
medusaIntegrationTestRunner({
env,
testSuite: ({ dbConnection, getContainer, api }) => {
describe("Store Carts API: Remove promotions from cart", () => { describe("Store Carts API: Remove promotions from cart", () => {
let dbConnection
let appContainer let appContainer
let shutdownServer
let cartModuleService: ICartModuleService let cartModuleService: ICartModuleService
let promotionModuleService: IPromotionModuleService let promotionModuleService: IPromotionModuleService
let remoteLinkService: RemoteLink let remoteLinkService: RemoteLink
beforeAll(async () => { beforeAll(async () => {
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
dbConnection = await initDb({ cwd, env } as any)
shutdownServer = await startBootstrapApp({ cwd, env })
appContainer = getContainer() appContainer = getContainer()
cartModuleService = appContainer.resolve(ModuleRegistrationName.CART) cartModuleService = appContainer.resolve(ModuleRegistrationName.CART)
remoteLinkService = appContainer.resolve(LinkModuleUtils.REMOTE_LINK) remoteLinkService = appContainer.resolve(LinkModuleUtils.REMOTE_LINK)
@@ -37,21 +31,10 @@ describe("Store Carts API: Remove promotions from cart", () => {
) )
}) })
afterAll(async () => {
const db = useDb()
await db.shutdown()
await shutdownServer()
})
beforeEach(async () => { beforeEach(async () => {
await adminSeeder(dbConnection) await adminSeeder(dbConnection)
}) })
afterEach(async () => {
const db = useDb()
await db.teardown()
})
describe("DELETE /store/carts/:id/promotions", () => { describe("DELETE /store/carts/:id/promotions", () => {
it("should remove line item adjustments from a cart based on promotions", async () => { it("should remove line item adjustments from a cart based on promotions", async () => {
const appliedPromotion = await promotionModuleService.create({ const appliedPromotion = await promotionModuleService.create({
@@ -143,17 +126,20 @@ describe("Store Carts API: Remove promotions from cart", () => {
}, },
{ {
[Modules.CART]: { cart_id: cart.id }, [Modules.CART]: { cart_id: cart.id },
[Modules.PROMOTION]: { promotion_id: appliedPromotionToRemove.id }, [Modules.PROMOTION]: {
promotion_id: appliedPromotionToRemove.id,
},
}, },
]) ])
const api = useApi() as any const response = await api.delete(
`/store/carts/${cart.id}/promotions`,
const response = await api.delete(`/store/carts/${cart.id}/promotions`, { {
data: { data: {
promo_codes: [appliedPromotionToRemove.code], promo_codes: [appliedPromotionToRemove.code],
}, },
}) }
)
expect(response.status).toEqual(200) expect(response.status).toEqual(200)
expect(response.data.cart).toEqual( expect(response.data.cart).toEqual(
@@ -254,9 +240,8 @@ describe("Store Carts API: Remove promotions from cart", () => {
], ],
}) })
const [express, standard] = await cartModuleService.addShippingMethods( const [express, standard] =
cart.id, await cartModuleService.addShippingMethods(cart.id, [
[
{ {
amount: 500, amount: 500,
name: "express", name: "express",
@@ -265,8 +250,7 @@ describe("Store Carts API: Remove promotions from cart", () => {
amount: 500, amount: 500,
name: "standard", name: "standard",
}, },
] ])
)
await cartModuleService.addShippingMethodAdjustments(cart.id, [ await cartModuleService.addShippingMethodAdjustments(cart.id, [
{ {
@@ -288,15 +272,18 @@ describe("Store Carts API: Remove promotions from cart", () => {
}, },
{ {
[Modules.CART]: { cart_id: cart.id }, [Modules.CART]: { cart_id: cart.id },
[Modules.PROMOTION]: { promotion_id: appliedPromotionToRemove.id }, [Modules.PROMOTION]: {
promotion_id: appliedPromotionToRemove.id,
},
}, },
]) ])
const api = useApi() as any const response = await api.delete(
`/store/carts/${cart.id}/promotions`,
const response = await api.delete(`/store/carts/${cart.id}/promotions`, { {
data: { promo_codes: [appliedPromotionToRemove.code] }, data: { promo_codes: [appliedPromotionToRemove.code] },
}) }
)
expect(response.status).toEqual(200) expect(response.status).toEqual(200)
expect(response.data.cart).toEqual( expect(response.data.cart).toEqual(
@@ -327,3 +314,5 @@ describe("Store Carts API: Remove promotions from cart", () => {
}) })
}) })
}) })
},
})
@@ -1,12 +1,5 @@
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
import { ICurrencyModuleService } from "@medusajs/types"
import path from "path"
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
import { useApi } from "../../../../environment-helpers/use-api"
import { getContainer } from "../../../../environment-helpers/use-container"
import { initDb, useDb } from "../../../../environment-helpers/use-db"
import { DataSource } from "typeorm"
import { createAdminUser } from "../../../helpers/create-admin-user" import { createAdminUser } from "../../../helpers/create-admin-user"
import { medusaIntegrationTestRunner } from "medusa-test-utils"
jest.setTimeout(50000) jest.setTimeout(50000)
@@ -15,37 +8,18 @@ const adminHeaders = {
headers: { "x-medusa-access-token": "test_token" }, headers: { "x-medusa-access-token": "test_token" },
} }
medusaIntegrationTestRunner({
env,
testSuite: ({ dbConnection, api, getContainer }) => {
describe("Currency - Admin", () => { describe("Currency - Admin", () => {
let dbConnection: DataSource let container
let appContainer
let shutdownServer
let service: ICurrencyModuleService
beforeAll(async () => {
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
dbConnection = await initDb({ cwd, env } as any)
shutdownServer = await startBootstrapApp({ cwd, env })
appContainer = getContainer()
service = appContainer.resolve(ModuleRegistrationName.CURRENCY)
})
afterAll(async () => {
const db = useDb()
await db.shutdown()
await shutdownServer()
})
beforeEach(async () => { beforeEach(async () => {
await createAdminUser(dbConnection, adminHeaders) container = getContainer()
}) await createAdminUser(dbConnection, adminHeaders, container)
afterEach(async () => {
const db = useDb()
await db.teardown()
}) })
it("should correctly retrieve and list currencies", async () => { it("should correctly retrieve and list currencies", async () => {
const api = useApi() as any
const listResp = await api.get("/admin/currencies", adminHeaders) const listResp = await api.get("/admin/currencies", adminHeaders)
expect(listResp.data.currencies).toEqual( expect(listResp.data.currencies).toEqual(
@@ -59,9 +33,14 @@ describe("Currency - Admin", () => {
]) ])
) )
const retrieveResp = await api.get(`/admin/currencies/aud`, adminHeaders) const retrieveResp = await api.get(
`/admin/currencies/aud`,
adminHeaders
)
expect(retrieveResp.data.currency).toEqual( expect(retrieveResp.data.currency).toEqual(
listResp.data.currencies.find((c) => c.code === "aud") listResp.data.currencies.find((c) => c.code === "aud")
) )
}) })
}) })
},
})
@@ -1,11 +1,4 @@
import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { medusaIntegrationTestRunner } from "medusa-test-utils"
import { ICurrencyModuleService } from "@medusajs/types"
import path from "path"
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
import { useApi } from "../../../../environment-helpers/use-api"
import { getContainer } from "../../../../environment-helpers/use-container"
import { initDb, useDb } from "../../../../environment-helpers/use-db"
import { DataSource } from "typeorm"
jest.setTimeout(50000) jest.setTimeout(50000)
@@ -14,33 +7,11 @@ const storeHeaders = {
headers: {}, headers: {},
} }
medusaIntegrationTestRunner({
env,
testSuite: ({ api }) => {
describe("Currency - Store", () => { describe("Currency - Store", () => {
let dbConnection: DataSource
let appContainer
let shutdownServer
let service: ICurrencyModuleService
beforeAll(async () => {
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
dbConnection = await initDb({ cwd, env } as any)
shutdownServer = await startBootstrapApp({ cwd, env })
appContainer = getContainer()
service = appContainer.resolve(ModuleRegistrationName.CURRENCY)
})
afterAll(async () => {
const db = useDb()
await db.shutdown()
await shutdownServer()
})
afterEach(async () => {
const db = useDb()
await db.teardown()
})
it("should correctly retrieve and list currencies", async () => { it("should correctly retrieve and list currencies", async () => {
const api = useApi() as any
const listResp = await api.get("/store/currencies", storeHeaders) const listResp = await api.get("/store/currencies", storeHeaders)
expect(listResp.data.currencies).toEqual( expect(listResp.data.currencies).toEqual(
@@ -54,9 +25,14 @@ describe("Currency - Store", () => {
]) ])
) )
const retrieveResp = await api.get(`/store/currencies/aud`, storeHeaders) const retrieveResp = await api.get(
`/store/currencies/aud`,
storeHeaders
)
expect(retrieveResp.data.currency).toEqual( expect(retrieveResp.data.currency).toEqual(
listResp.data.currencies.find((c) => c.code === "aud") listResp.data.currencies.find((c) => c.code === "aud")
) )
}) })
}) })
},
})
@@ -1,13 +1,7 @@
import { initDb, useDb } from "../../../../environment-helpers/use-db"
import { ICustomerModuleService } from "@medusajs/types" import { ICustomerModuleService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { ModuleRegistrationName } from "@medusajs/modules-sdk"
import adminSeeder from "../../../../helpers/admin-seeder"
import { createAdminUser } from "../../../helpers/create-admin-user" import { createAdminUser } from "../../../helpers/create-admin-user"
import { getContainer } from "../../../../environment-helpers/use-container" import { medusaIntegrationTestRunner } from "medusa-test-utils"
import path from "path"
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
import { useApi } from "../../../../environment-helpers/use-api"
jest.setTimeout(50000) jest.setTimeout(50000)
@@ -16,40 +10,25 @@ const adminHeaders = {
headers: { "x-medusa-access-token": "test_token" }, headers: { "x-medusa-access-token": "test_token" },
} }
medusaIntegrationTestRunner({
env,
testSuite: ({ dbConnection, getContainer, api }) => {
describe("POST /admin/customer-groups/:id/customers/batch", () => { describe("POST /admin/customer-groups/:id/customers/batch", () => {
let dbConnection
let appContainer let appContainer
let shutdownServer
let customerModuleService: ICustomerModuleService let customerModuleService: ICustomerModuleService
beforeAll(async () => { beforeAll(async () => {
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
dbConnection = await initDb({ cwd, env } as any)
shutdownServer = await startBootstrapApp({ cwd, env })
appContainer = getContainer() appContainer = getContainer()
customerModuleService = appContainer.resolve( customerModuleService = appContainer.resolve(
ModuleRegistrationName.CUSTOMER ModuleRegistrationName.CUSTOMER
) )
}) })
afterAll(async () => {
const db = useDb()
await db.shutdown()
await shutdownServer()
})
beforeEach(async () => { beforeEach(async () => {
await createAdminUser(dbConnection, adminHeaders) await createAdminUser(dbConnection, adminHeaders, appContainer)
})
afterEach(async () => {
const db = useDb()
await db.teardown()
}) })
it("should batch add customers to a group", async () => { it("should batch add customers to a group", async () => {
const api = useApi() as any
const group = await customerModuleService.createCustomerGroup({ const group = await customerModuleService.createCustomerGroup({
name: "VIP", name: "VIP",
}) })
@@ -87,3 +66,5 @@ describe("POST /admin/customer-groups/:id/customers/batch", () => {
expect(updatedGroup.customers?.length).toEqual(3) expect(updatedGroup.customers?.length).toEqual(3)
}) })
}) })
},
})
@@ -1,13 +1,7 @@
import { initDb, useDb } from "../../../../environment-helpers/use-db"
import { ICustomerModuleService } from "@medusajs/types" import { ICustomerModuleService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { ModuleRegistrationName } from "@medusajs/modules-sdk"
import adminSeeder from "../../../../helpers/admin-seeder"
import { createAdminUser } from "../../../helpers/create-admin-user" import { createAdminUser } from "../../../helpers/create-admin-user"
import { getContainer } from "../../../../environment-helpers/use-container" import { medusaIntegrationTestRunner } from "medusa-test-utils"
import path from "path"
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
import { useApi } from "../../../../environment-helpers/use-api"
jest.setTimeout(50000) jest.setTimeout(50000)
@@ -16,40 +10,25 @@ const adminHeaders = {
headers: { "x-medusa-access-token": "test_token" }, headers: { "x-medusa-access-token": "test_token" },
} }
medusaIntegrationTestRunner({
env,
testSuite: ({ dbConnection, getContainer, api }) => {
describe("DELETE /admin/customer-groups/:id/customers/remove", () => { describe("DELETE /admin/customer-groups/:id/customers/remove", () => {
let dbConnection
let appContainer let appContainer
let shutdownServer
let customerModuleService: ICustomerModuleService let customerModuleService: ICustomerModuleService
beforeAll(async () => { beforeAll(async () => {
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
dbConnection = await initDb({ cwd, env } as any)
shutdownServer = await startBootstrapApp({ cwd, env })
appContainer = getContainer() appContainer = getContainer()
customerModuleService = appContainer.resolve( customerModuleService = appContainer.resolve(
ModuleRegistrationName.CUSTOMER ModuleRegistrationName.CUSTOMER
) )
}) })
afterAll(async () => {
const db = useDb()
await db.shutdown()
await shutdownServer()
})
beforeEach(async () => { beforeEach(async () => {
await createAdminUser(dbConnection, adminHeaders) await createAdminUser(dbConnection, adminHeaders, appContainer)
})
afterEach(async () => {
const db = useDb()
await db.teardown()
}) })
it("should batch delete customers from a group", async () => { it("should batch delete customers from a group", async () => {
const api = useApi() as any
const group = await customerModuleService.createCustomerGroup({ const group = await customerModuleService.createCustomerGroup({
name: "VIP", name: "VIP",
}) })
@@ -69,7 +48,10 @@ describe("DELETE /admin/customer-groups/:id/customers/remove", () => {
]) ])
await customerModuleService.addCustomerToGroup( await customerModuleService.addCustomerToGroup(
customers.map((c) => ({ customer_id: c.id, customer_group_id: group.id })) customers.map((c) => ({
customer_id: c.id,
customer_group_id: group.id,
}))
) )
const response = await api.post( const response = await api.post(
@@ -91,3 +73,5 @@ describe("DELETE /admin/customer-groups/:id/customers/remove", () => {
expect(updatedGroup.customers?.length).toEqual(0) expect(updatedGroup.customers?.length).toEqual(0)
}) })
}) })
},
})
@@ -1,13 +1,7 @@
import { initDb, useDb } from "../../../../environment-helpers/use-db"
import { ICustomerModuleService } from "@medusajs/types" import { ICustomerModuleService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { ModuleRegistrationName } from "@medusajs/modules-sdk"
import adminSeeder from "../../../../helpers/admin-seeder"
import { createAdminUser } from "../../../helpers/create-admin-user" import { createAdminUser } from "../../../helpers/create-admin-user"
import { getContainer } from "../../../../environment-helpers/use-container" import { medusaIntegrationTestRunner } from "medusa-test-utils"
import path from "path"
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
import { useApi } from "../../../../environment-helpers/use-api"
jest.setTimeout(50000) jest.setTimeout(50000)
@@ -16,40 +10,26 @@ const adminHeaders = {
headers: { "x-medusa-access-token": "test_token" }, headers: { "x-medusa-access-token": "test_token" },
} }
medusaIntegrationTestRunner({
env,
testSuite: ({ dbConnection, getContainer, api }) => {
describe("POST /admin/customer-groups", () => { describe("POST /admin/customer-groups", () => {
let dbConnection
let appContainer let appContainer
let shutdownServer
let customerModuleService: ICustomerModuleService let customerModuleService: ICustomerModuleService
beforeAll(async () => { beforeAll(async () => {
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
dbConnection = await initDb({ cwd, env } as any)
shutdownServer = await startBootstrapApp({ cwd, env })
appContainer = getContainer() appContainer = getContainer()
customerModuleService = appContainer.resolve( customerModuleService = appContainer.resolve(
ModuleRegistrationName.CUSTOMER ModuleRegistrationName.CUSTOMER
) )
}) })
afterAll(async () => {
const db = useDb()
await db.shutdown()
await shutdownServer()
})
beforeEach(async () => { beforeEach(async () => {
await createAdminUser(dbConnection, adminHeaders) await createAdminUser(dbConnection, adminHeaders, appContainer)
// await adminSeeder(dbConnection) // await adminSeeder(dbConnection)
}) })
afterEach(async () => {
const db = useDb()
await db.teardown()
})
it("should create a customer group", async () => { it("should create a customer group", async () => {
const api = useApi() as any
const response = await api.post( const response = await api.post(
`/admin/customer-groups`, `/admin/customer-groups`,
{ {
@@ -68,3 +48,5 @@ describe("POST /admin/customer-groups", () => {
) )
}) })
}) })
},
})
@@ -1,13 +1,7 @@
import { initDb, useDb } from "../../../../environment-helpers/use-db"
import { ICustomerModuleService } from "@medusajs/types" import { ICustomerModuleService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { ModuleRegistrationName } from "@medusajs/modules-sdk"
import adminSeeder from "../../../../helpers/admin-seeder"
import { createAdminUser } from "../../../helpers/create-admin-user" import { createAdminUser } from "../../../helpers/create-admin-user"
import { getContainer } from "../../../../environment-helpers/use-container" import { medusaIntegrationTestRunner } from "medusa-test-utils"
import path from "path"
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
import { useApi } from "../../../../environment-helpers/use-api"
jest.setTimeout(50000) jest.setTimeout(50000)
@@ -16,35 +10,22 @@ const adminHeaders = {
headers: { "x-medusa-access-token": "test_token" }, headers: { "x-medusa-access-token": "test_token" },
} }
medusaIntegrationTestRunner({
env,
testSuite: ({ dbConnection, getContainer, api }) => {
describe("DELETE /admin/customer-groups/:id", () => { describe("DELETE /admin/customer-groups/:id", () => {
let dbConnection
let appContainer let appContainer
let shutdownServer
let customerModuleService: ICustomerModuleService let customerModuleService: ICustomerModuleService
beforeAll(async () => { beforeAll(async () => {
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
dbConnection = await initDb({ cwd, env } as any)
shutdownServer = await startBootstrapApp({ cwd, env })
appContainer = getContainer() appContainer = getContainer()
customerModuleService = appContainer.resolve( customerModuleService = appContainer.resolve(
ModuleRegistrationName.CUSTOMER ModuleRegistrationName.CUSTOMER
) )
}) })
afterAll(async () => {
const db = useDb()
await db.shutdown()
await shutdownServer()
})
beforeEach(async () => { beforeEach(async () => {
await createAdminUser(dbConnection, adminHeaders) await createAdminUser(dbConnection, adminHeaders, appContainer)
})
afterEach(async () => {
const db = useDb()
await db.teardown()
}) })
it("should delete a group", async () => { it("should delete a group", async () => {
@@ -52,7 +33,6 @@ describe("DELETE /admin/customer-groups/:id", () => {
name: "VIP", name: "VIP",
}) })
const api = useApi() as any
const response = await api.delete( const response = await api.delete(
`/admin/customer-groups/${group.id}`, `/admin/customer-groups/${group.id}`,
adminHeaders adminHeaders
@@ -60,10 +40,12 @@ describe("DELETE /admin/customer-groups/:id", () => {
expect(response.status).toEqual(200) expect(response.status).toEqual(200)
const deletedCustomer = await customerModuleService.retrieveCustomerGroup( const deletedCustomer =
group.id, await customerModuleService.retrieveCustomerGroup(group.id, {
{ withDeleted: true } withDeleted: true,
) })
expect(deletedCustomer.deleted_at).toBeTruthy() expect(deletedCustomer.deleted_at).toBeTruthy()
}) })
}) })
},
})
@@ -1,13 +1,7 @@
import { initDb, useDb } from "../../../../environment-helpers/use-db"
import { ICustomerModuleService } from "@medusajs/types" import { ICustomerModuleService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { ModuleRegistrationName } from "@medusajs/modules-sdk"
import adminSeeder from "../../../../helpers/admin-seeder"
import { createAdminUser } from "../../../helpers/create-admin-user" import { createAdminUser } from "../../../helpers/create-admin-user"
import { getContainer } from "../../../../environment-helpers/use-container" import { medusaIntegrationTestRunner } from "medusa-test-utils"
import path from "path"
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
import { useApi } from "../../../../environment-helpers/use-api"
jest.setTimeout(50000) jest.setTimeout(50000)
@@ -16,35 +10,22 @@ const adminHeaders = {
headers: { "x-medusa-access-token": "test_token" }, headers: { "x-medusa-access-token": "test_token" },
} }
medusaIntegrationTestRunner({
env,
testSuite: ({ dbConnection, getContainer, api }) => {
describe("GET /admin/customer-groups/:id/customers", () => { describe("GET /admin/customer-groups/:id/customers", () => {
let dbConnection
let appContainer let appContainer
let shutdownServer
let customerModuleService: ICustomerModuleService let customerModuleService: ICustomerModuleService
beforeAll(async () => { beforeAll(async () => {
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
dbConnection = await initDb({ cwd, env } as any)
shutdownServer = await startBootstrapApp({ cwd, env })
appContainer = getContainer() appContainer = getContainer()
customerModuleService = appContainer.resolve( customerModuleService = appContainer.resolve(
ModuleRegistrationName.CUSTOMER ModuleRegistrationName.CUSTOMER
) )
}) })
afterAll(async () => {
const db = useDb()
await db.shutdown()
await shutdownServer()
})
beforeEach(async () => { beforeEach(async () => {
await createAdminUser(dbConnection, adminHeaders) await createAdminUser(dbConnection, adminHeaders, appContainer)
})
afterEach(async () => {
const db = useDb()
await db.teardown()
}) })
it("should get all customer groups and its count", async () => { it("should get all customer groups and its count", async () => {
@@ -66,11 +47,12 @@ describe("GET /admin/customer-groups/:id/customers", () => {
// add to group // add to group
await customerModuleService.addCustomerToGroup( await customerModuleService.addCustomerToGroup(
customers.map((c) => ({ customer_id: c.id, customer_group_id: group.id })) customers.map((c) => ({
customer_id: c.id,
customer_group_id: group.id,
}))
) )
const api = useApi() as any
const response = await api.get( const response = await api.get(
`/admin/customer-groups/${group.id}/customers`, `/admin/customer-groups/${group.id}/customers`,
adminHeaders adminHeaders
@@ -90,3 +72,5 @@ describe("GET /admin/customer-groups/:id/customers", () => {
) )
}) })
}) })
},
})
@@ -1,13 +1,7 @@
import { initDb, useDb } from "../../../../environment-helpers/use-db"
import { ICustomerModuleService } from "@medusajs/types" import { ICustomerModuleService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { ModuleRegistrationName } from "@medusajs/modules-sdk"
import adminSeeder from "../../../../helpers/admin-seeder"
import { createAdminUser } from "../../../helpers/create-admin-user" import { createAdminUser } from "../../../helpers/create-admin-user"
import { getContainer } from "../../../../environment-helpers/use-container" import { medusaIntegrationTestRunner } from "medusa-test-utils"
import path from "path"
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
import { useApi } from "../../../../environment-helpers/use-api"
jest.setTimeout(50000) jest.setTimeout(50000)
@@ -16,35 +10,22 @@ const adminHeaders = {
headers: { "x-medusa-access-token": "test_token" }, headers: { "x-medusa-access-token": "test_token" },
} }
medusaIntegrationTestRunner({
env,
testSuite: ({ dbConnection, getContainer, api }) => {
describe("GET /admin/customer-groups", () => { describe("GET /admin/customer-groups", () => {
let dbConnection
let appContainer let appContainer
let shutdownServer
let customerModuleService: ICustomerModuleService let customerModuleService: ICustomerModuleService
beforeAll(async () => { beforeAll(async () => {
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
dbConnection = await initDb({ cwd, env } as any)
shutdownServer = await startBootstrapApp({ cwd, env })
appContainer = getContainer() appContainer = getContainer()
customerModuleService = appContainer.resolve( customerModuleService = appContainer.resolve(
ModuleRegistrationName.CUSTOMER ModuleRegistrationName.CUSTOMER
) )
}) })
afterAll(async () => {
const db = useDb()
await db.shutdown()
await shutdownServer()
})
beforeEach(async () => { beforeEach(async () => {
await createAdminUser(dbConnection, adminHeaders) await createAdminUser(dbConnection, adminHeaders, appContainer)
})
afterEach(async () => {
const db = useDb()
await db.teardown()
}) })
it("should get all customer groups and its count", async () => { it("should get all customer groups and its count", async () => {
@@ -52,7 +33,6 @@ describe("GET /admin/customer-groups", () => {
name: "Test", name: "Test",
}) })
const api = useApi() as any
const response = await api.get(`/admin/customer-groups`, adminHeaders) const response = await api.get(`/admin/customer-groups`, adminHeaders)
expect(response.status).toEqual(200) expect(response.status).toEqual(200)
@@ -65,3 +45,5 @@ describe("GET /admin/customer-groups", () => {
]) ])
}) })
}) })
},
})
@@ -1,13 +1,7 @@
import { initDb, useDb } from "../../../../environment-helpers/use-db"
import { ICustomerModuleService } from "@medusajs/types" import { ICustomerModuleService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { ModuleRegistrationName } from "@medusajs/modules-sdk"
import adminSeeder from "../../../../helpers/admin-seeder"
import { createAdminUser } from "../../../helpers/create-admin-user" import { createAdminUser } from "../../../helpers/create-admin-user"
import { getContainer } from "../../../../environment-helpers/use-container" import { medusaIntegrationTestRunner } from "medusa-test-utils"
import path from "path"
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
import { useApi } from "../../../../environment-helpers/use-api"
jest.setTimeout(50000) jest.setTimeout(50000)
@@ -16,35 +10,22 @@ const adminHeaders = {
headers: { "x-medusa-access-token": "test_token" }, headers: { "x-medusa-access-token": "test_token" },
} }
medusaIntegrationTestRunner({
env,
testSuite: ({ dbConnection, getContainer, api }) => {
describe("GET /admin/customer-groups/:id", () => { describe("GET /admin/customer-groups/:id", () => {
let dbConnection
let appContainer let appContainer
let shutdownServer
let customerModuleService: ICustomerModuleService let customerModuleService: ICustomerModuleService
beforeAll(async () => { beforeAll(async () => {
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
dbConnection = await initDb({ cwd, env } as any)
shutdownServer = await startBootstrapApp({ cwd, env })
appContainer = getContainer() appContainer = getContainer()
customerModuleService = appContainer.resolve( customerModuleService = appContainer.resolve(
ModuleRegistrationName.CUSTOMER ModuleRegistrationName.CUSTOMER
) )
}) })
afterAll(async () => {
const db = useDb()
await db.shutdown()
await shutdownServer()
})
beforeEach(async () => { beforeEach(async () => {
await createAdminUser(dbConnection, adminHeaders) await createAdminUser(dbConnection, adminHeaders, appContainer)
})
afterEach(async () => {
const db = useDb()
await db.teardown()
}) })
it("should retrieve customer group", async () => { it("should retrieve customer group", async () => {
@@ -52,7 +33,6 @@ describe("GET /admin/customer-groups/:id", () => {
name: "Test", name: "Test",
}) })
const api = useApi() as any
const response = await api.get( const response = await api.get(
`/admin/customer-groups/${group.id}`, `/admin/customer-groups/${group.id}`,
adminHeaders adminHeaders
@@ -67,3 +47,5 @@ describe("GET /admin/customer-groups/:id", () => {
) )
}) })
}) })
},
})
@@ -1,13 +1,7 @@
import { initDb, useDb } from "../../../../environment-helpers/use-db"
import { ICustomerModuleService } from "@medusajs/types" import { ICustomerModuleService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { ModuleRegistrationName } from "@medusajs/modules-sdk"
import adminSeeder from "../../../../helpers/admin-seeder"
import { createAdminUser } from "../../../helpers/create-admin-user" import { createAdminUser } from "../../../helpers/create-admin-user"
import { getContainer } from "../../../../environment-helpers/use-container" import { medusaIntegrationTestRunner } from "medusa-test-utils"
import path from "path"
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
import { useApi } from "../../../../environment-helpers/use-api"
jest.setTimeout(50000) jest.setTimeout(50000)
@@ -16,35 +10,22 @@ const adminHeaders = {
headers: { "x-medusa-access-token": "test_token" }, headers: { "x-medusa-access-token": "test_token" },
} }
medusaIntegrationTestRunner({
env,
testSuite: ({ dbConnection, getContainer, api }) => {
describe("POST /admin/customer-groups/:id", () => { describe("POST /admin/customer-groups/:id", () => {
let dbConnection
let appContainer let appContainer
let shutdownServer
let customerModuleService: ICustomerModuleService let customerModuleService: ICustomerModuleService
beforeAll(async () => { beforeAll(async () => {
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
dbConnection = await initDb({ cwd, env } as any)
shutdownServer = await startBootstrapApp({ cwd, env })
appContainer = getContainer() appContainer = getContainer()
customerModuleService = appContainer.resolve( customerModuleService = appContainer.resolve(
ModuleRegistrationName.CUSTOMER ModuleRegistrationName.CUSTOMER
) )
}) })
afterAll(async () => {
const db = useDb()
await db.shutdown()
await shutdownServer()
})
beforeEach(async () => { beforeEach(async () => {
await createAdminUser(dbConnection, adminHeaders) await createAdminUser(dbConnection, adminHeaders, appContainer)
})
afterEach(async () => {
const db = useDb()
await db.teardown()
}) })
it("should update a customer group", async () => { it("should update a customer group", async () => {
@@ -52,7 +33,6 @@ describe("POST /admin/customer-groups/:id", () => {
name: "VIP", name: "VIP",
}) })
const api = useApi() as any
const response = await api.post( const response = await api.post(
`/admin/customer-groups/${customer.id}`, `/admin/customer-groups/${customer.id}`,
{ {
@@ -70,3 +50,5 @@ describe("POST /admin/customer-groups/:id", () => {
) )
}) })
}) })
},
})
@@ -1,13 +1,7 @@
import { initDb, useDb } from "../../../../environment-helpers/use-db"
import { ICustomerModuleService } from "@medusajs/types" import { ICustomerModuleService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { ModuleRegistrationName } from "@medusajs/modules-sdk"
import adminSeeder from "../../../../helpers/admin-seeder"
import { createAdminUser } from "../../../helpers/create-admin-user" import { createAdminUser } from "../../../helpers/create-admin-user"
import { getContainer } from "../../../../environment-helpers/use-container" import { medusaIntegrationTestRunner } from "medusa-test-utils"
import path from "path"
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
import { useApi } from "../../../../environment-helpers/use-api"
jest.setTimeout(50000) jest.setTimeout(50000)
@@ -16,37 +10,23 @@ const adminHeaders = {
headers: { "x-medusa-access-token": "test_token" }, headers: { "x-medusa-access-token": "test_token" },
} }
medusaIntegrationTestRunner({
env,
testSuite: ({ dbConnection, getContainer, api }) => {
describe("POST /admin/customers/:id/addresses", () => { describe("POST /admin/customers/:id/addresses", () => {
let dbConnection
let appContainer let appContainer
let shutdownServer
let customerModuleService: ICustomerModuleService let customerModuleService: ICustomerModuleService
beforeAll(async () => { beforeAll(async () => {
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
dbConnection = await initDb({ cwd, env } as any)
shutdownServer = await startBootstrapApp({ cwd, env })
appContainer = getContainer() appContainer = getContainer()
customerModuleService = appContainer.resolve( customerModuleService = appContainer.resolve(
ModuleRegistrationName.CUSTOMER ModuleRegistrationName.CUSTOMER
) )
}) })
afterAll(async () => {
const db = useDb()
await db.shutdown()
await shutdownServer()
})
beforeEach(async () => { beforeEach(async () => {
await createAdminUser(dbConnection, adminHeaders) await createAdminUser(dbConnection, adminHeaders, appContainer)
}) })
afterEach(async () => {
const db = useDb()
await db.teardown()
})
it("should create a customer address", async () => { it("should create a customer address", async () => {
// Create a customer // Create a customer
const customer = await customerModuleService.create({ const customer = await customerModuleService.create({
@@ -54,7 +34,6 @@ describe("POST /admin/customers/:id/addresses", () => {
last_name: "Doe", last_name: "Doe",
}) })
const api = useApi() as any
const response = await api.post( const response = await api.post(
`/admin/customers/${customer.id}/addresses`, `/admin/customers/${customer.id}/addresses`,
{ {
@@ -97,7 +76,6 @@ describe("POST /admin/customers/:id/addresses", () => {
], ],
}) })
const api = useApi() as any
const response = await api.post( const response = await api.post(
`/admin/customers/${customer.id}/addresses`, `/admin/customers/${customer.id}/addresses`,
{ {
@@ -133,7 +111,6 @@ describe("POST /admin/customers/:id/addresses", () => {
], ],
}) })
const api = useApi() as any
const response = await api.post( const response = await api.post(
`/admin/customers/${customer.id}/addresses`, `/admin/customers/${customer.id}/addresses`,
{ {
@@ -155,3 +132,5 @@ describe("POST /admin/customers/:id/addresses", () => {
expect(address.address_1).toEqual("Test street 2") expect(address.address_1).toEqual("Test street 2")
}) })
}) })
},
})
@@ -1,13 +1,7 @@
import { initDb, useDb } from "../../../../environment-helpers/use-db"
import { ICustomerModuleService } from "@medusajs/types" import { ICustomerModuleService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { ModuleRegistrationName } from "@medusajs/modules-sdk"
import adminSeeder from "../../../../helpers/admin-seeder"
import { createAdminUser } from "../../../helpers/create-admin-user" import { createAdminUser } from "../../../helpers/create-admin-user"
import { getContainer } from "../../../../environment-helpers/use-container" import { medusaIntegrationTestRunner } from "medusa-test-utils"
import path from "path"
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
import { useApi } from "../../../../environment-helpers/use-api"
jest.setTimeout(50000) jest.setTimeout(50000)
@@ -16,39 +10,25 @@ const adminHeaders = {
headers: { "x-medusa-access-token": "test_token" }, headers: { "x-medusa-access-token": "test_token" },
} }
medusaIntegrationTestRunner({
env,
testSuite: ({ dbConnection, getContainer, api }) => {
describe("POST /admin/customers", () => { describe("POST /admin/customers", () => {
let dbConnection
let appContainer let appContainer
let shutdownServer
let customerModuleService: ICustomerModuleService let customerModuleService: ICustomerModuleService
beforeAll(async () => { beforeAll(async () => {
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
dbConnection = await initDb({ cwd, env } as any)
shutdownServer = await startBootstrapApp({ cwd, env })
appContainer = getContainer() appContainer = getContainer()
customerModuleService = appContainer.resolve( customerModuleService = appContainer.resolve(
ModuleRegistrationName.CUSTOMER ModuleRegistrationName.CUSTOMER
) )
}) })
afterAll(async () => {
const db = useDb()
await db.shutdown()
await shutdownServer()
})
beforeEach(async () => { beforeEach(async () => {
await createAdminUser(dbConnection, adminHeaders) await createAdminUser(dbConnection, adminHeaders, appContainer)
})
afterEach(async () => {
const db = useDb()
await db.teardown()
}) })
it("should create a customer", async () => { it("should create a customer", async () => {
const api = useApi() as any
const response = await api.post( const response = await api.post(
`/admin/customers`, `/admin/customers`,
{ {
@@ -69,3 +49,5 @@ describe("POST /admin/customers", () => {
) )
}) })
}) })
},
})
@@ -1,13 +1,7 @@
import { initDb, useDb } from "../../../../environment-helpers/use-db"
import { ICustomerModuleService } from "@medusajs/types" import { ICustomerModuleService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { ModuleRegistrationName } from "@medusajs/modules-sdk"
import adminSeeder from "../../../../helpers/admin-seeder"
import { createAdminUser } from "../../../helpers/create-admin-user" import { createAdminUser } from "../../../helpers/create-admin-user"
import { getContainer } from "../../../../environment-helpers/use-container" import { medusaIntegrationTestRunner } from "medusa-test-utils"
import path from "path"
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
import { useApi } from "../../../../environment-helpers/use-api"
jest.setTimeout(50000) jest.setTimeout(50000)
@@ -16,35 +10,22 @@ const adminHeaders = {
headers: { "x-medusa-access-token": "test_token" }, headers: { "x-medusa-access-token": "test_token" },
} }
medusaIntegrationTestRunner({
env,
testSuite: ({ dbConnection, getContainer, api }) => {
describe("DELETE /admin/customers/:id/addresses/:address_id", () => { describe("DELETE /admin/customers/:id/addresses/:address_id", () => {
let dbConnection
let appContainer let appContainer
let shutdownServer
let customerModuleService: ICustomerModuleService let customerModuleService: ICustomerModuleService
beforeAll(async () => { beforeAll(async () => {
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
dbConnection = await initDb({ cwd, env } as any)
shutdownServer = await startBootstrapApp({ cwd, env })
appContainer = getContainer() appContainer = getContainer()
customerModuleService = appContainer.resolve( customerModuleService = appContainer.resolve(
ModuleRegistrationName.CUSTOMER ModuleRegistrationName.CUSTOMER
) )
}) })
afterAll(async () => {
const db = useDb()
await db.shutdown()
await shutdownServer()
})
beforeEach(async () => { beforeEach(async () => {
await createAdminUser(dbConnection, adminHeaders) await createAdminUser(dbConnection, adminHeaders, appContainer)
})
afterEach(async () => {
const db = useDb()
await db.teardown()
}) })
it("should update a customer address", async () => { it("should update a customer address", async () => {
@@ -60,7 +41,6 @@ describe("DELETE /admin/customers/:id/addresses/:address_id", () => {
address_1: "Test street 1", address_1: "Test street 1",
}) })
const api = useApi() as any
const response = await api.delete( const response = await api.delete(
`/admin/customers/${customer.id}/addresses/${address.id}`, `/admin/customers/${customer.id}/addresses/${address.id}`,
adminHeaders adminHeaders
@@ -68,10 +48,15 @@ describe("DELETE /admin/customers/:id/addresses/:address_id", () => {
expect(response.status).toEqual(200) expect(response.status).toEqual(200)
const updatedCustomer = await customerModuleService.retrieve(customer.id, { const updatedCustomer = await customerModuleService.retrieve(
customer.id,
{
relations: ["addresses"], relations: ["addresses"],
}) }
)
expect(updatedCustomer.addresses?.length).toEqual(0) expect(updatedCustomer.addresses?.length).toEqual(0)
}) })
}) })
},
})
@@ -1,13 +1,7 @@
import { initDb, useDb } from "../../../../environment-helpers/use-db"
import { ICustomerModuleService } from "@medusajs/types" import { ICustomerModuleService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { ModuleRegistrationName } from "@medusajs/modules-sdk"
import adminSeeder from "../../../../helpers/admin-seeder"
import { createAdminUser } from "../../../helpers/create-admin-user" import { createAdminUser } from "../../../helpers/create-admin-user"
import { getContainer } from "../../../../environment-helpers/use-container" import { medusaIntegrationTestRunner } from "medusa-test-utils"
import path from "path"
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
import { useApi } from "../../../../environment-helpers/use-api"
jest.setTimeout(50000) jest.setTimeout(50000)
@@ -16,35 +10,22 @@ const adminHeaders = {
headers: { "x-medusa-access-token": "test_token" }, headers: { "x-medusa-access-token": "test_token" },
} }
medusaIntegrationTestRunner({
env,
testSuite: ({ dbConnection, getContainer, api }) => {
describe("DELETE /admin/customers/:id", () => { describe("DELETE /admin/customers/:id", () => {
let dbConnection
let appContainer let appContainer
let shutdownServer
let customerModuleService: ICustomerModuleService let customerModuleService: ICustomerModuleService
beforeAll(async () => { beforeAll(async () => {
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
dbConnection = await initDb({ cwd, env } as any)
shutdownServer = await startBootstrapApp({ cwd, env })
appContainer = getContainer() appContainer = getContainer()
customerModuleService = appContainer.resolve( customerModuleService = appContainer.resolve(
ModuleRegistrationName.CUSTOMER ModuleRegistrationName.CUSTOMER
) )
}) })
afterAll(async () => {
const db = useDb()
await db.shutdown()
await shutdownServer()
})
beforeEach(async () => { beforeEach(async () => {
await createAdminUser(dbConnection, adminHeaders) await createAdminUser(dbConnection, adminHeaders, appContainer)
})
afterEach(async () => {
const db = useDb()
await db.teardown()
}) })
it("should delete a customer", async () => { it("should delete a customer", async () => {
@@ -53,7 +34,6 @@ describe("DELETE /admin/customers/:id", () => {
last_name: "Doe", last_name: "Doe",
}) })
const api = useApi() as any
const response = await api.delete( const response = await api.delete(
`/admin/customers/${customer.id}`, `/admin/customers/${customer.id}`,
adminHeaders adminHeaders
@@ -61,9 +41,14 @@ describe("DELETE /admin/customers/:id", () => {
expect(response.status).toEqual(200) expect(response.status).toEqual(200)
const deletedCustomer = await customerModuleService.retrieve(customer.id, { const deletedCustomer = await customerModuleService.retrieve(
customer.id,
{
withDeleted: true, withDeleted: true,
}) }
)
expect(deletedCustomer.deleted_at).toBeTruthy() expect(deletedCustomer.deleted_at).toBeTruthy()
}) })
}) })
},
})
@@ -1,13 +1,7 @@
import { initDb, useDb } from "../../../../environment-helpers/use-db"
import { ICustomerModuleService } from "@medusajs/types" import { ICustomerModuleService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { ModuleRegistrationName } from "@medusajs/modules-sdk"
import adminSeeder from "../../../../helpers/admin-seeder"
import { createAdminUser } from "../../../helpers/create-admin-user" import { createAdminUser } from "../../../helpers/create-admin-user"
import { getContainer } from "../../../../environment-helpers/use-container" import { medusaIntegrationTestRunner } from "medusa-test-utils"
import path from "path"
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
import { useApi } from "../../../../environment-helpers/use-api"
jest.setTimeout(50000) jest.setTimeout(50000)
@@ -16,35 +10,22 @@ const adminHeaders = {
headers: { "x-medusa-access-token": "test_token" }, headers: { "x-medusa-access-token": "test_token" },
} }
medusaIntegrationTestRunner({
env,
testSuite: ({ dbConnection, getContainer, api }) => {
describe("GET /admin/customers/:id/addresses", () => { describe("GET /admin/customers/:id/addresses", () => {
let dbConnection
let appContainer let appContainer
let shutdownServer
let customerModuleService: ICustomerModuleService let customerModuleService: ICustomerModuleService
beforeAll(async () => { beforeAll(async () => {
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
dbConnection = await initDb({ cwd, env } as any)
shutdownServer = await startBootstrapApp({ cwd, env })
appContainer = getContainer() appContainer = getContainer()
customerModuleService = appContainer.resolve( customerModuleService = appContainer.resolve(
ModuleRegistrationName.CUSTOMER ModuleRegistrationName.CUSTOMER
) )
}) })
afterAll(async () => {
const db = useDb()
await db.shutdown()
await shutdownServer()
})
beforeEach(async () => { beforeEach(async () => {
await createAdminUser(dbConnection, adminHeaders) await createAdminUser(dbConnection, adminHeaders, appContainer)
})
afterEach(async () => {
const db = useDb()
await db.teardown()
}) })
it("should get all customer addresses and its count", async () => { it("should get all customer addresses and its count", async () => {
@@ -84,7 +65,6 @@ describe("GET /admin/customers/:id/addresses", () => {
}, },
]) ])
const api = useApi() as any
const response = await api.get( const response = await api.get(
`/admin/customers/${customer.id}/addresses`, `/admin/customers/${customer.id}/addresses`,
adminHeaders adminHeaders
@@ -113,3 +93,5 @@ describe("GET /admin/customers/:id/addresses", () => {
) )
}) })
}) })
},
})
@@ -1,13 +1,7 @@
import { initDb, useDb } from "../../../../environment-helpers/use-db"
import { ICustomerModuleService } from "@medusajs/types" import { ICustomerModuleService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { ModuleRegistrationName } from "@medusajs/modules-sdk"
import adminSeeder from "../../../../helpers/admin-seeder"
import { createAdminUser } from "../../../helpers/create-admin-user" import { createAdminUser } from "../../../helpers/create-admin-user"
import { getContainer } from "../../../../environment-helpers/use-container" import { medusaIntegrationTestRunner } from "medusa-test-utils"
import path from "path"
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
import { useApi } from "../../../../environment-helpers/use-api"
jest.setTimeout(50000) jest.setTimeout(50000)
@@ -16,35 +10,23 @@ const adminHeaders = {
headers: { "x-medusa-access-token": "test_token" }, headers: { "x-medusa-access-token": "test_token" },
} }
medusaIntegrationTestRunner({
env,
testSuite: ({ dbConnection, getContainer, api }) => {
describe("GET /admin/customers", () => { describe("GET /admin/customers", () => {
let dbConnection
let appContainer let appContainer
let shutdownServer let shutdownServer
let customerModuleService: ICustomerModuleService let customerModuleService: ICustomerModuleService
beforeAll(async () => { beforeAll(async () => {
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
dbConnection = await initDb({ cwd, env } as any)
shutdownServer = await startBootstrapApp({ cwd, env })
appContainer = getContainer() appContainer = getContainer()
customerModuleService = appContainer.resolve( customerModuleService = appContainer.resolve(
ModuleRegistrationName.CUSTOMER ModuleRegistrationName.CUSTOMER
) )
}) })
afterAll(async () => {
const db = useDb()
await db.shutdown()
await shutdownServer()
})
beforeEach(async () => { beforeEach(async () => {
await createAdminUser(dbConnection, adminHeaders) await createAdminUser(dbConnection, adminHeaders, appContainer)
})
afterEach(async () => {
const db = useDb()
await db.teardown()
}) })
it("should get all customers and its count", async () => { it("should get all customers and its count", async () => {
@@ -56,7 +38,6 @@ describe("GET /admin/customers", () => {
}, },
]) ])
const api = useApi() as any
const response = await api.get(`/admin/customers`, adminHeaders) const response = await api.get(`/admin/customers`, adminHeaders)
expect(response.status).toEqual(200) expect(response.status).toEqual(200)
@@ -95,7 +76,6 @@ describe("GET /admin/customers", () => {
}, },
]) ])
const api = useApi() as any
const response = await api.get( const response = await api.get(
`/admin/customers?last_name=Doe`, `/admin/customers?last_name=Doe`,
adminHeaders adminHeaders
@@ -121,3 +101,5 @@ describe("GET /admin/customers", () => {
) )
}) })
}) })
},
})
@@ -1,13 +1,7 @@
import { initDb, useDb } from "../../../../environment-helpers/use-db"
import { ICustomerModuleService } from "@medusajs/types" import { ICustomerModuleService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { ModuleRegistrationName } from "@medusajs/modules-sdk"
import adminSeeder from "../../../../helpers/admin-seeder"
import { createAdminUser } from "../../../helpers/create-admin-user" import { createAdminUser } from "../../../helpers/create-admin-user"
import { getContainer } from "../../../../environment-helpers/use-container" import { medusaIntegrationTestRunner } from "medusa-test-utils"
import path from "path"
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
import { useApi } from "../../../../environment-helpers/use-api"
jest.setTimeout(50000) jest.setTimeout(50000)
@@ -16,35 +10,22 @@ const adminHeaders = {
headers: { "x-medusa-access-token": "test_token" }, headers: { "x-medusa-access-token": "test_token" },
} }
medusaIntegrationTestRunner({
env,
testSuite: ({ dbConnection, getContainer, api }) => {
describe("POST /admin/customers/:id/addresses/:address_id", () => { describe("POST /admin/customers/:id/addresses/:address_id", () => {
let dbConnection
let appContainer let appContainer
let shutdownServer
let customerModuleService: ICustomerModuleService let customerModuleService: ICustomerModuleService
beforeAll(async () => { beforeAll(async () => {
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
dbConnection = await initDb({ cwd, env } as any)
shutdownServer = await startBootstrapApp({ cwd, env })
appContainer = getContainer() appContainer = getContainer()
customerModuleService = appContainer.resolve( customerModuleService = appContainer.resolve(
ModuleRegistrationName.CUSTOMER ModuleRegistrationName.CUSTOMER
) )
}) })
afterAll(async () => {
const db = useDb()
await db.shutdown()
await shutdownServer()
})
beforeEach(async () => { beforeEach(async () => {
await createAdminUser(dbConnection, adminHeaders) await createAdminUser(dbConnection, adminHeaders, appContainer)
})
afterEach(async () => {
const db = useDb()
await db.teardown()
}) })
it("should update a customer address", async () => { it("should update a customer address", async () => {
@@ -60,7 +41,6 @@ describe("POST /admin/customers/:id/addresses/:address_id", () => {
address_1: "Test street 1", address_1: "Test street 1",
}) })
const api = useApi() as any
const response = await api.post( const response = await api.post(
`/admin/customers/${customer.id}/addresses/${address.id}`, `/admin/customers/${customer.id}/addresses/${address.id}`,
{ {
@@ -100,7 +80,6 @@ describe("POST /admin/customers/:id/addresses/:address_id", () => {
}, },
]) ])
const api = useApi() as any
const response = await api.post( const response = await api.post(
`/admin/customers/${customer.id}/addresses/${address.id}`, `/admin/customers/${customer.id}/addresses/${address.id}`,
{ {
@@ -143,7 +122,6 @@ describe("POST /admin/customers/:id/addresses/:address_id", () => {
}, },
]) ])
const api = useApi() as any
const response = await api.post( const response = await api.post(
`/admin/customers/${customer.id}/addresses/${address.id}`, `/admin/customers/${customer.id}/addresses/${address.id}`,
{ {
@@ -164,3 +142,5 @@ describe("POST /admin/customers/:id/addresses/:address_id", () => {
expect(defaultAddress.address_1).toEqual("Test street 2") expect(defaultAddress.address_1).toEqual("Test street 2")
}) })
}) })
},
})
@@ -1,13 +1,7 @@
import { initDb, useDb } from "../../../../environment-helpers/use-db"
import { ICustomerModuleService } from "@medusajs/types" import { ICustomerModuleService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { ModuleRegistrationName } from "@medusajs/modules-sdk"
import adminSeeder from "../../../../helpers/admin-seeder"
import { createAdminUser } from "../../../helpers/create-admin-user" import { createAdminUser } from "../../../helpers/create-admin-user"
import { getContainer } from "../../../../environment-helpers/use-container" import { medusaIntegrationTestRunner } from "medusa-test-utils"
import path from "path"
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
import { useApi } from "../../../../environment-helpers/use-api"
jest.setTimeout(50000) jest.setTimeout(50000)
@@ -16,35 +10,22 @@ const adminHeaders = {
headers: { "x-medusa-access-token": "test_token" }, headers: { "x-medusa-access-token": "test_token" },
} }
medusaIntegrationTestRunner({
env,
testSuite: ({ dbConnection, getContainer, api }) => {
describe("POST /admin/customers/:id", () => { describe("POST /admin/customers/:id", () => {
let dbConnection
let appContainer let appContainer
let shutdownServer
let customerModuleService: ICustomerModuleService let customerModuleService: ICustomerModuleService
beforeAll(async () => { beforeAll(async () => {
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
dbConnection = await initDb({ cwd, env } as any)
shutdownServer = await startBootstrapApp({ cwd, env })
appContainer = getContainer() appContainer = getContainer()
customerModuleService = appContainer.resolve( customerModuleService = appContainer.resolve(
ModuleRegistrationName.CUSTOMER ModuleRegistrationName.CUSTOMER
) )
}) })
afterAll(async () => {
const db = useDb()
await db.shutdown()
await shutdownServer()
})
beforeEach(async () => { beforeEach(async () => {
await createAdminUser(dbConnection, adminHeaders) await createAdminUser(dbConnection, adminHeaders, appContainer)
})
afterEach(async () => {
const db = useDb()
await db.teardown()
}) })
it("should update a customer", async () => { it("should update a customer", async () => {
@@ -53,7 +34,6 @@ describe("POST /admin/customers/:id", () => {
last_name: "Doe", last_name: "Doe",
}) })
const api = useApi() as any
const response = await api.post( const response = await api.post(
`/admin/customers/${customer.id}`, `/admin/customers/${customer.id}`,
{ {
@@ -72,3 +52,5 @@ describe("POST /admin/customers/:id", () => {
) )
}) })
}) })
},
})
@@ -1,48 +1,31 @@
import { initDb, useDb } from "../../../../environment-helpers/use-db"
import { ICustomerModuleService } from "@medusajs/types" import { ICustomerModuleService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { ModuleRegistrationName } from "@medusajs/modules-sdk"
import { createAuthenticatedCustomer } from "../../../helpers/create-authenticated-customer" import { createAuthenticatedCustomer } from "../../../helpers/create-authenticated-customer"
import { getContainer } from "../../../../environment-helpers/use-container" import { medusaIntegrationTestRunner } from "medusa-test-utils"
import path from "path"
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
import { useApi } from "../../../../environment-helpers/use-api"
jest.setTimeout(50000) jest.setTimeout(50000)
const env = { MEDUSA_FF_MEDUSA_V2: true } const env = { MEDUSA_FF_MEDUSA_V2: true }
medusaIntegrationTestRunner({
env,
testSuite: ({ dbConnection, getContainer, api }) => {
describe("POST /store/customers/me/addresses", () => { describe("POST /store/customers/me/addresses", () => {
let dbConnection
let appContainer let appContainer
let shutdownServer
let customerModuleService: ICustomerModuleService let customerModuleService: ICustomerModuleService
beforeAll(async () => { beforeAll(async () => {
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
dbConnection = await initDb({ cwd, env } as any)
shutdownServer = await startBootstrapApp({ cwd, env })
appContainer = getContainer() appContainer = getContainer()
customerModuleService = appContainer.resolve( customerModuleService = appContainer.resolve(
ModuleRegistrationName.CUSTOMER ModuleRegistrationName.CUSTOMER
) )
}) })
afterAll(async () => {
const db = useDb()
await db.shutdown()
await shutdownServer()
})
afterEach(async () => {
const db = useDb()
await db.teardown()
})
it("should create a customer address", async () => { it("should create a customer address", async () => {
const { customer, jwt } = await createAuthenticatedCustomer(appContainer) const { customer, jwt } = await createAuthenticatedCustomer(
appContainer
)
const api = useApi() as any
const response = await api.post( const response = await api.post(
`/store/customers/me/addresses`, `/store/customers/me/addresses`,
{ {
@@ -72,3 +55,5 @@ describe("POST /store/customers/me/addresses", () => {
expect(customerWithAddresses.addresses?.length).toEqual(1) expect(customerWithAddresses.addresses?.length).toEqual(1)
}) })
}) })
},
})
@@ -1,55 +1,38 @@
import { IAuthModuleService, ICustomerModuleService } from "@medusajs/types" import { IAuthModuleService, ICustomerModuleService } from "@medusajs/types"
import { initDb, useDb } from "../../../../environment-helpers/use-db"
import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { ModuleRegistrationName } from "@medusajs/modules-sdk"
import adminSeeder from "../../../../helpers/admin-seeder" import adminSeeder from "../../../../helpers/admin-seeder"
import { createAdminUser } from "../../../helpers/create-admin-user"
import { getContainer } from "../../../../environment-helpers/use-container"
import jwt from "jsonwebtoken" import jwt from "jsonwebtoken"
import path from "path" import { medusaIntegrationTestRunner } from "medusa-test-utils"
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
import { useApi } from "../../../../environment-helpers/use-api"
jest.setTimeout(50000) jest.setTimeout(50000)
const env = { MEDUSA_FF_MEDUSA_V2: true } const env = { MEDUSA_FF_MEDUSA_V2: true }
medusaIntegrationTestRunner({
env,
testSuite: ({ dbConnection, getContainer, api }) => {
describe("POST /store/customers", () => { describe("POST /store/customers", () => {
let dbConnection
let appContainer let appContainer
let shutdownServer
let customerModuleService: ICustomerModuleService let customerModuleService: ICustomerModuleService
beforeAll(async () => { beforeAll(async () => {
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
dbConnection = await initDb({ cwd, env } as any)
shutdownServer = await startBootstrapApp({ cwd, env })
appContainer = getContainer() appContainer = getContainer()
customerModuleService = appContainer.resolve( customerModuleService = appContainer.resolve(
ModuleRegistrationName.CUSTOMER ModuleRegistrationName.CUSTOMER
) )
}) })
afterAll(async () => {
const db = useDb()
await db.shutdown()
await shutdownServer()
})
beforeEach(async () => { beforeEach(async () => {
await adminSeeder(dbConnection) await adminSeeder(dbConnection)
}) })
afterEach(async () => {
const db = useDb()
await db.teardown()
})
it("should create a customer", async () => { it("should create a customer", async () => {
const authService: IAuthModuleService = appContainer.resolve( const authService: IAuthModuleService = appContainer.resolve(
ModuleRegistrationName.AUTH ModuleRegistrationName.AUTH
) )
const { jwt_secret } = appContainer.resolve("configModule").projectConfig const { jwt_secret } =
appContainer.resolve("configModule").projectConfig
const authUser = await authService.create({ const authUser = await authService.create({
entity_id: "store_user", entity_id: "store_user",
provider: "emailpass", provider: "emailpass",
@@ -58,7 +41,6 @@ describe("POST /store/customers", () => {
const token = jwt.sign(authUser, jwt_secret) const token = jwt.sign(authUser, jwt_secret)
const api = useApi() as any
const response = await api.post( const response = await api.post(
`/store/customers`, `/store/customers`,
{ {
@@ -80,3 +62,5 @@ describe("POST /store/customers", () => {
) )
}) })
}) })
},
})
@@ -1,46 +1,30 @@
import { initDb, useDb } from "../../../../environment-helpers/use-db"
import { ICustomerModuleService } from "@medusajs/types" import { ICustomerModuleService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { ModuleRegistrationName } from "@medusajs/modules-sdk"
import { createAuthenticatedCustomer } from "../../../helpers/create-authenticated-customer" import { createAuthenticatedCustomer } from "../../../helpers/create-authenticated-customer"
import { getContainer } from "../../../../environment-helpers/use-container" import { medusaIntegrationTestRunner } from "medusa-test-utils"
import path from "path"
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
import { useApi } from "../../../../environment-helpers/use-api"
const env = { MEDUSA_FF_MEDUSA_V2: true } const env = { MEDUSA_FF_MEDUSA_V2: true }
jest.setTimeout(50000) jest.setTimeout(50000)
medusaIntegrationTestRunner({
env,
testSuite: ({ dbConnection, getContainer, api }) => {
describe("DELETE /store/customers/me/addresses/:address_id", () => { describe("DELETE /store/customers/me/addresses/:address_id", () => {
let dbConnection
let appContainer let appContainer
let shutdownServer
let customerModuleService: ICustomerModuleService let customerModuleService: ICustomerModuleService
beforeAll(async () => { beforeAll(async () => {
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
dbConnection = await initDb({ cwd, env } as any)
shutdownServer = await startBootstrapApp({ cwd, env })
appContainer = getContainer() appContainer = getContainer()
customerModuleService = appContainer.resolve( customerModuleService = appContainer.resolve(
ModuleRegistrationName.CUSTOMER ModuleRegistrationName.CUSTOMER
) )
}) })
afterAll(async () => {
const db = useDb()
await db.shutdown()
await shutdownServer()
})
afterEach(async () => {
const db = useDb()
await db.teardown()
})
it("should delete a customer address", async () => { it("should delete a customer address", async () => {
const { customer, jwt } = await createAuthenticatedCustomer(appContainer) const { customer, jwt } = await createAuthenticatedCustomer(
appContainer
)
const address = await customerModuleService.addAddresses({ const address = await customerModuleService.addAddresses({
customer_id: customer.id, customer_id: customer.id,
@@ -49,7 +33,6 @@ describe("DELETE /store/customers/me/addresses/:address_id", () => {
address_1: "Test street 1", address_1: "Test street 1",
}) })
const api = useApi() as any
const response = await api.delete( const response = await api.delete(
`/store/customers/me/addresses/${address.id}`, `/store/customers/me/addresses/${address.id}`,
{ headers: { authorization: `Bearer ${jwt}` } } { headers: { authorization: `Bearer ${jwt}` } }
@@ -57,9 +40,12 @@ describe("DELETE /store/customers/me/addresses/:address_id", () => {
expect(response.status).toEqual(200) expect(response.status).toEqual(200)
const updatedCustomer = await customerModuleService.retrieve(customer.id, { const updatedCustomer = await customerModuleService.retrieve(
customer.id,
{
relations: ["addresses"], relations: ["addresses"],
}) }
)
expect(updatedCustomer.addresses?.length).toEqual(0) expect(updatedCustomer.addresses?.length).toEqual(0)
}) })
@@ -78,7 +64,6 @@ describe("DELETE /store/customers/me/addresses/:address_id", () => {
address_1: "Test street 1", address_1: "Test street 1",
}) })
const api = useApi() as any
const response = await api const response = await api
.delete(`/store/customers/me/addresses/${address.id}`, { .delete(`/store/customers/me/addresses/${address.id}`, {
headers: { authorization: `Bearer ${jwt}` }, headers: { authorization: `Bearer ${jwt}` },
@@ -88,3 +73,5 @@ describe("DELETE /store/customers/me/addresses/:address_id", () => {
expect(response.status).toEqual(404) expect(response.status).toEqual(404)
}) })
}) })
},
})
@@ -1,48 +1,31 @@
import { initDb, useDb } from "../../../../environment-helpers/use-db"
import { ICustomerModuleService } from "@medusajs/types" import { ICustomerModuleService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { ModuleRegistrationName } from "@medusajs/modules-sdk"
import { createAuthenticatedCustomer } from "../../../helpers/create-authenticated-customer" import { createAuthenticatedCustomer } from "../../../helpers/create-authenticated-customer"
import { getContainer } from "../../../../environment-helpers/use-container" import { medusaIntegrationTestRunner } from "medusa-test-utils"
import path from "path"
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
import { useApi } from "../../../../environment-helpers/use-api"
jest.setTimeout(50000) jest.setTimeout(50000)
const env = { MEDUSA_FF_MEDUSA_V2: true } const env = { MEDUSA_FF_MEDUSA_V2: true }
medusaIntegrationTestRunner({
env,
testSuite: ({ dbConnection, getContainer, api }) => {
describe("GET /store/customers", () => { describe("GET /store/customers", () => {
let dbConnection
let appContainer let appContainer
let shutdownServer
let customerModuleService: ICustomerModuleService let customerModuleService: ICustomerModuleService
beforeAll(async () => { beforeAll(async () => {
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
dbConnection = await initDb({ cwd, env } as any)
shutdownServer = await startBootstrapApp({ cwd, env })
appContainer = getContainer() appContainer = getContainer()
customerModuleService = appContainer.resolve( customerModuleService = appContainer.resolve(
ModuleRegistrationName.CUSTOMER ModuleRegistrationName.CUSTOMER
) )
}) })
afterAll(async () => {
const db = useDb()
await db.shutdown()
await shutdownServer()
})
afterEach(async () => {
const db = useDb()
await db.teardown()
})
it("should retrieve auth user's customer", async () => { it("should retrieve auth user's customer", async () => {
const { customer, jwt } = await createAuthenticatedCustomer(appContainer) const { customer, jwt } = await createAuthenticatedCustomer(
appContainer
)
const api = useApi() as any
const response = await api.get(`/store/customers/me`, { const response = await api.get(`/store/customers/me`, {
headers: { authorization: `Bearer ${jwt}` }, headers: { authorization: `Bearer ${jwt}` },
}) })
@@ -58,3 +41,5 @@ describe("GET /store/customers", () => {
) )
}) })
}) })
},
})
@@ -1,50 +1,30 @@
import { initDb, useDb } from "../../../../environment-helpers/use-db"
import { ICustomerModuleService } from "@medusajs/types" import { ICustomerModuleService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { ModuleRegistrationName } from "@medusajs/modules-sdk"
import { createAuthenticatedCustomer } from "../../../helpers/create-authenticated-customer" import { createAuthenticatedCustomer } from "../../../helpers/create-authenticated-customer"
import { getContainer } from "../../../../environment-helpers/use-container" import {medusaIntegrationTestRunner} from "medusa-test-utils";
import path from "path"
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
import { useApi } from "../../../../environment-helpers/use-api"
const env = { MEDUSA_FF_MEDUSA_V2: true } const env = { MEDUSA_FF_MEDUSA_V2: true }
jest.setTimeout(100000) jest.setTimeout(100000)
medusaIntegrationTestRunner({
env,
testSuite: ({ dbConnection, getContainer, api }) => {
describe("GET /store/customers/me/addresses", () => { describe("GET /store/customers/me/addresses", () => {
let dbConnection
let appContainer let appContainer
let shutdownServer
let customerModuleService: ICustomerModuleService let customerModuleService: ICustomerModuleService
beforeAll(async () => { beforeAll(async () => {
try {
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
dbConnection = await initDb({ cwd, env } as any)
shutdownServer = await startBootstrapApp({ cwd, env })
appContainer = getContainer() appContainer = getContainer()
customerModuleService = appContainer.resolve( customerModuleService = appContainer.resolve(
ModuleRegistrationName.CUSTOMER ModuleRegistrationName.CUSTOMER
) )
} catch (error) {
console.error(error)
}
})
afterAll(async () => {
const db = useDb()
await db.shutdown()
await shutdownServer()
})
afterEach(async () => {
const db = useDb()
await db.teardown()
}) })
it("should get all customer addresses and its count", async () => { it("should get all customer addresses and its count", async () => {
const { customer, jwt } = await createAuthenticatedCustomer(appContainer) const { customer, jwt } = await createAuthenticatedCustomer(
appContainer
)
await customerModuleService.addAddresses([ await customerModuleService.addAddresses([
{ {
@@ -79,7 +59,6 @@ describe("GET /store/customers/me/addresses", () => {
], ],
}) })
const api = useApi() as any
const response = await api.get(`/store/customers/me/addresses`, { const response = await api.get(`/store/customers/me/addresses`, {
headers: { authorization: `Bearer ${jwt}` }, headers: { authorization: `Bearer ${jwt}` },
}) })
@@ -107,3 +86,5 @@ describe("GET /store/customers/me/addresses", () => {
) )
}) })
}) })
},
})
@@ -1,46 +1,30 @@
import { initDb, useDb } from "../../../../environment-helpers/use-db"
import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { ModuleRegistrationName } from "@medusajs/modules-sdk"
import { ICustomerModuleService } from "@medusajs/types" import { ICustomerModuleService } from "@medusajs/types"
import path from "path"
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
import { useApi } from "../../../../environment-helpers/use-api"
import { getContainer } from "../../../../environment-helpers/use-container"
import { createAuthenticatedCustomer } from "../../../helpers/create-authenticated-customer" import { createAuthenticatedCustomer } from "../../../helpers/create-authenticated-customer"
import { medusaIntegrationTestRunner } from "medusa-test-utils"
jest.setTimeout(50000) jest.setTimeout(50000)
const env = { MEDUSA_FF_MEDUSA_V2: true } const env = { MEDUSA_FF_MEDUSA_V2: true }
medusaIntegrationTestRunner({
env,
testSuite: ({ dbConnection, getContainer, api }) => {
describe("POST /store/customers/:id/addresses/:address_id", () => { describe("POST /store/customers/:id/addresses/:address_id", () => {
let dbConnection
let appContainer let appContainer
let shutdownServer
let customerModuleService: ICustomerModuleService let customerModuleService: ICustomerModuleService
beforeAll(async () => { beforeAll(async () => {
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
dbConnection = await initDb({ cwd, env } as any)
shutdownServer = await startBootstrapApp({ cwd, env })
appContainer = getContainer() appContainer = getContainer()
customerModuleService = appContainer.resolve( customerModuleService = appContainer.resolve(
ModuleRegistrationName.CUSTOMER ModuleRegistrationName.CUSTOMER
) )
}) })
afterAll(async () => {
const db = useDb()
await db.shutdown()
await shutdownServer()
})
afterEach(async () => {
const db = useDb()
await db.teardown()
})
it("should update a customer address", async () => { it("should update a customer address", async () => {
const { customer, jwt } = await createAuthenticatedCustomer(appContainer) const { customer, jwt } = await createAuthenticatedCustomer(
appContainer
)
const address = await customerModuleService.addAddresses({ const address = await customerModuleService.addAddresses({
customer_id: customer.id, customer_id: customer.id,
@@ -49,7 +33,6 @@ describe("POST /store/customers/:id/addresses/:address_id", () => {
address_1: "Test street 1", address_1: "Test street 1",
}) })
const api = useApi() as any
const response = await api.post( const response = await api.post(
`/store/customers/me/addresses/${address.id}`, `/store/customers/me/addresses/${address.id}`,
{ {
@@ -83,7 +66,6 @@ describe("POST /store/customers/:id/addresses/:address_id", () => {
address_1: "Test street 1", address_1: "Test street 1",
}) })
const api = useApi() as any
const response = await api const response = await api
.post( .post(
`/store/customers/me/addresses/${address.id}`, `/store/customers/me/addresses/${address.id}`,
@@ -95,3 +77,5 @@ describe("POST /store/customers/:id/addresses/:address_id", () => {
expect(response.status).toEqual(404) expect(response.status).toEqual(404)
}) })
}) })
},
})
@@ -1,13 +1,7 @@
import { IAuthModuleService, IUserModuleService } from "@medusajs/types" import { IUserModuleService } from "@medusajs/types"
import { initDb, useDb } from "../../../environment-helpers/use-db"
import { AxiosInstance } from "axios"
import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { ModuleRegistrationName } from "@medusajs/modules-sdk"
import { createAdminUser } from "../../helpers/create-admin-user" import { createAdminUser } from "../../helpers/create-admin-user"
import { getContainer } from "../../../environment-helpers/use-container" import { medusaIntegrationTestRunner } from "medusa-test-utils"
import path from "path"
import { startBootstrapApp } from "../../../environment-helpers/bootstrap-app"
import { useApi } from "../../../environment-helpers/use-api"
jest.setTimeout(50000) jest.setTimeout(50000)
@@ -16,38 +10,23 @@ const adminHeaders = {
headers: { "x-medusa-access-token": "test_token" }, headers: { "x-medusa-access-token": "test_token" },
} }
medusaIntegrationTestRunner({
env,
testSuite: ({ dbConnection, getContainer, api }) => {
describe("GET /admin/invites/:id", () => { describe("GET /admin/invites/:id", () => {
let dbConnection
let appContainer let appContainer
let shutdownServer
let userModuleService: IUserModuleService let userModuleService: IUserModuleService
beforeAll(async () => { beforeAll(async () => {
const cwd = path.resolve(path.join(__dirname, "..", ".."))
dbConnection = await initDb({ cwd, env } as any)
shutdownServer = await startBootstrapApp({ cwd, env })
appContainer = getContainer() appContainer = getContainer()
userModuleService = appContainer.resolve(ModuleRegistrationName.USER) userModuleService = appContainer.resolve(ModuleRegistrationName.USER)
}) })
beforeEach(async () => { beforeEach(async () => {
await createAdminUser(dbConnection, adminHeaders) await createAdminUser(dbConnection, adminHeaders, appContainer)
})
afterAll(async () => {
const db = useDb()
await db.shutdown()
await shutdownServer()
})
afterEach(async () => {
const db = useDb()
await db.teardown()
}) })
it("should fail to accept an invite with an invalid invite token", async () => { it("should fail to accept an invite with an invalid invite token", async () => {
const api = useApi()! as AxiosInstance
const authResponse = await api.post(`/auth/admin/emailpass`, { const authResponse = await api.post(`/auth/admin/emailpass`, {
email: "potential_member@test.com", email: "potential_member@test.com",
password: "supersecret", password: "supersecret",
@@ -79,8 +58,6 @@ describe("GET /admin/invites/:id", () => {
email: "potential_member@test.com", email: "potential_member@test.com",
}) })
const api = useApi()! as AxiosInstance
const authResponse = await api.post(`/auth/admin/emailpass`, { const authResponse = await api.post(`/auth/admin/emailpass`, {
email: "potential_member@test.com", email: "potential_member@test.com",
password: "supersecret", password: "supersecret",
@@ -110,3 +87,5 @@ describe("GET /admin/invites/:id", () => {
) )
}) })
}) })
},
})
@@ -1,11 +1,5 @@
import { initDb, useDb } from "../../../environment-helpers/use-db"
import path from "path"
import { startBootstrapApp } from "../../../environment-helpers/bootstrap-app"
import { useApi } from "../../../environment-helpers/use-api"
import adminSeeder from "../../../helpers/admin-seeder"
import { AxiosInstance } from "axios"
import { createAdminUser } from "../../helpers/create-admin-user" import { createAdminUser } from "../../helpers/create-admin-user"
import { medusaIntegrationTestRunner } from "medusa-test-utils"
jest.setTimeout(50000) jest.setTimeout(50000)
@@ -14,34 +8,15 @@ const adminHeaders = {
headers: { "x-medusa-access-token": "test_token" }, headers: { "x-medusa-access-token": "test_token" },
} }
medusaIntegrationTestRunner({
env,
testSuite: ({ dbConnection, getContainer, api }) => {
describe("POST /admin/invites", () => { describe("POST /admin/invites", () => {
let dbConnection
let shutdownServer
beforeAll(async () => {
const cwd = path.resolve(path.join(__dirname, "..", ".."))
dbConnection = await initDb({ cwd, env } as any)
shutdownServer = await startBootstrapApp({ cwd, env })
})
beforeEach(async () => { beforeEach(async () => {
await createAdminUser(dbConnection, adminHeaders) await createAdminUser(dbConnection, adminHeaders, getContainer())
})
afterAll(async () => {
const db = useDb()
await db.shutdown()
await shutdownServer()
})
afterEach(async () => {
const db = useDb()
await db.teardown()
}) })
it("create an invite", async () => { it("create an invite", async () => {
const api = useApi()! as AxiosInstance
const body = { const body = {
email: "test_member@test.com", email: "test_member@test.com",
} }
@@ -54,3 +29,5 @@ describe("POST /admin/invites", () => {
}) })
}) })
}) })
},
})
@@ -1,14 +1,7 @@
import { initDb, useDb } from "../../../environment-helpers/use-db"
import { IUserModuleService } from "@medusajs/types" import { IUserModuleService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { ModuleRegistrationName } from "@medusajs/modules-sdk"
import { getContainer } from "../../../environment-helpers/use-container"
import path from "path"
import { startBootstrapApp } from "../../../environment-helpers/bootstrap-app"
import { useApi } from "../../../environment-helpers/use-api"
import adminSeeder from "../../../helpers/admin-seeder"
import { AxiosInstance } from "axios"
import { createAdminUser } from "../../helpers/create-admin-user" import { createAdminUser } from "../../helpers/create-admin-user"
import { medusaIntegrationTestRunner } from "medusa-test-utils"
jest.setTimeout(50000) jest.setTimeout(50000)
@@ -17,33 +10,20 @@ const adminHeaders = {
headers: { "x-medusa-access-token": "test_token" }, headers: { "x-medusa-access-token": "test_token" },
} }
medusaIntegrationTestRunner({
env,
testSuite: ({ dbConnection, getContainer, api }) => {
describe("DELETE /admin/invites/:id", () => { describe("DELETE /admin/invites/:id", () => {
let dbConnection
let appContainer let appContainer
let shutdownServer
let userModuleService: IUserModuleService let userModuleService: IUserModuleService
beforeAll(async () => { beforeAll(async () => {
const cwd = path.resolve(path.join(__dirname, "..", ".."))
dbConnection = await initDb({ cwd, env } as any)
shutdownServer = await startBootstrapApp({ cwd, env })
appContainer = getContainer() appContainer = getContainer()
userModuleService = appContainer.resolve(ModuleRegistrationName.USER) userModuleService = appContainer.resolve(ModuleRegistrationName.USER)
}) })
beforeEach(async () => { beforeEach(async () => {
await createAdminUser(dbConnection, adminHeaders) await createAdminUser(dbConnection, adminHeaders, appContainer)
})
afterAll(async () => {
const db = useDb()
await db.shutdown()
await shutdownServer()
})
afterEach(async () => {
const db = useDb()
await db.teardown()
}) })
it("should delete a single invite", async () => { it("should delete a single invite", async () => {
@@ -53,8 +33,6 @@ describe("DELETE /admin/invites/:id", () => {
expires_at: new Date(), expires_at: new Date(),
}) })
const api = useApi()! as AxiosInstance
const response = await api.delete( const response = await api.delete(
`/admin/invites/${invite.id}`, `/admin/invites/${invite.id}`,
adminHeaders adminHeaders
@@ -75,3 +53,5 @@ describe("DELETE /admin/invites/:id", () => {
expect(deletedResponse.data.type).toEqual("not_found") expect(deletedResponse.data.type).toEqual("not_found")
}) })
}) })
},
})
@@ -1,14 +1,7 @@
import { initDb, useDb } from "../../../environment-helpers/use-db"
import { IUserModuleService } from "@medusajs/types" import { IUserModuleService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { ModuleRegistrationName } from "@medusajs/modules-sdk"
import { getContainer } from "../../../environment-helpers/use-container"
import path from "path"
import { startBootstrapApp } from "../../../environment-helpers/bootstrap-app"
import { useApi } from "../../../environment-helpers/use-api"
import adminSeeder from "../../../helpers/admin-seeder"
import { AxiosInstance } from "axios"
import { createAdminUser } from "../../helpers/create-admin-user" import { createAdminUser } from "../../helpers/create-admin-user"
import { medusaIntegrationTestRunner } from "medusa-test-utils"
jest.setTimeout(50000) jest.setTimeout(50000)
@@ -17,33 +10,20 @@ const adminHeaders = {
headers: { "x-medusa-access-token": "test_token" }, headers: { "x-medusa-access-token": "test_token" },
} }
medusaIntegrationTestRunner({
env,
testSuite: ({ dbConnection, getContainer, api }) => {
describe("GET /admin/invites", () => { describe("GET /admin/invites", () => {
let dbConnection
let appContainer let appContainer
let shutdownServer
let userModuleService: IUserModuleService let userModuleService: IUserModuleService
beforeAll(async () => { beforeAll(async () => {
const cwd = path.resolve(path.join(__dirname, "..", ".."))
dbConnection = await initDb({ cwd, env } as any)
shutdownServer = await startBootstrapApp({ cwd, env })
appContainer = getContainer() appContainer = getContainer()
userModuleService = appContainer.resolve(ModuleRegistrationName.USER) userModuleService = appContainer.resolve(ModuleRegistrationName.USER)
}) })
beforeEach(async () => { beforeEach(async () => {
await createAdminUser(dbConnection, adminHeaders) await createAdminUser(dbConnection, adminHeaders, appContainer)
})
afterAll(async () => {
const db = useDb()
await db.shutdown()
await shutdownServer()
})
afterEach(async () => {
const db = useDb()
await db.teardown()
}) })
it("should list invites", async () => { it("should list invites", async () => {
@@ -53,8 +33,6 @@ describe("GET /admin/invites", () => {
expires_at: new Date(), expires_at: new Date(),
}) })
const api = useApi()! as AxiosInstance
const response = await api.get(`/admin/invites`, adminHeaders) const response = await api.get(`/admin/invites`, adminHeaders)
expect(response.status).toEqual(200) expect(response.status).toEqual(200)
@@ -68,3 +46,5 @@ describe("GET /admin/invites", () => {
}) })
}) })
}) })
},
})
@@ -1,13 +1,7 @@
import { IAuthModuleService, IUserModuleService } from "@medusajs/types" import { IUserModuleService } from "@medusajs/types"
import { initDb, useDb } from "../../../environment-helpers/use-db"
import { AxiosInstance } from "axios"
import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { ModuleRegistrationName } from "@medusajs/modules-sdk"
import { createAdminUser } from "../../helpers/create-admin-user" import { createAdminUser } from "../../helpers/create-admin-user"
import { getContainer } from "../../../environment-helpers/use-container" import { medusaIntegrationTestRunner } from "medusa-test-utils"
import path from "path"
import { startBootstrapApp } from "../../../environment-helpers/bootstrap-app"
import { useApi } from "../../../environment-helpers/use-api"
jest.setTimeout(50000) jest.setTimeout(50000)
@@ -16,33 +10,20 @@ const adminHeaders = {
headers: { "x-medusa-access-token": "test_token" }, headers: { "x-medusa-access-token": "test_token" },
} }
medusaIntegrationTestRunner({
env,
testSuite: ({ dbConnection, getContainer, api }) => {
describe("POST /admin/invites/:id/resend", () => { describe("POST /admin/invites/:id/resend", () => {
let dbConnection
let appContainer let appContainer
let shutdownServer
let userModuleService: IUserModuleService let userModuleService: IUserModuleService
beforeAll(async () => { beforeAll(async () => {
const cwd = path.resolve(path.join(__dirname, "..", ".."))
dbConnection = await initDb({ cwd, env } as any)
shutdownServer = await startBootstrapApp({ cwd, env })
appContainer = getContainer() appContainer = getContainer()
userModuleService = appContainer.resolve(ModuleRegistrationName.USER) userModuleService = appContainer.resolve(ModuleRegistrationName.USER)
}) })
beforeEach(async () => { beforeEach(async () => {
await createAdminUser(dbConnection, adminHeaders) await createAdminUser(dbConnection, adminHeaders, appContainer)
})
afterAll(async () => {
const db = useDb()
await db.shutdown()
await shutdownServer()
})
afterEach(async () => {
const db = useDb()
await db.teardown()
}) })
it("should resend a single invite", async () => { it("should resend a single invite", async () => {
@@ -50,8 +31,6 @@ describe("POST /admin/invites/:id/resend", () => {
email: "potential_member@test.com", email: "potential_member@test.com",
}) })
const api = useApi()! as AxiosInstance
const response = await api.post( const response = await api.post(
`/admin/invites/${invite.id}/resend`, `/admin/invites/${invite.id}/resend`,
{}, {},
@@ -65,3 +44,5 @@ describe("POST /admin/invites/:id/resend", () => {
) )
}) })
}) })
},
})
@@ -1,13 +1,7 @@
import { initDb, useDb } from "../../../environment-helpers/use-db" import { IUserModuleService } from "@medusajs/types"
import { IAuthModuleService, IUserModuleService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { ModuleRegistrationName } from "@medusajs/modules-sdk"
import { getContainer } from "../../../environment-helpers/use-container"
import path from "path"
import { startBootstrapApp } from "../../../environment-helpers/bootstrap-app"
import { useApi } from "../../../environment-helpers/use-api"
import { AxiosInstance } from "axios"
import { createAdminUser } from "../../helpers/create-admin-user" import { createAdminUser } from "../../helpers/create-admin-user"
import { medusaIntegrationTestRunner } from "medusa-test-utils"
jest.setTimeout(50000) jest.setTimeout(50000)
@@ -16,33 +10,20 @@ const adminHeaders = {
headers: { "x-medusa-access-token": "test_token" }, headers: { "x-medusa-access-token": "test_token" },
} }
medusaIntegrationTestRunner({
env,
testSuite: ({ dbConnection, getContainer, api }) => {
describe("GET /admin/invites/:id", () => { describe("GET /admin/invites/:id", () => {
let dbConnection
let appContainer let appContainer
let shutdownServer
let userModuleService: IUserModuleService let userModuleService: IUserModuleService
beforeAll(async () => { beforeAll(async () => {
const cwd = path.resolve(path.join(__dirname, "..", ".."))
dbConnection = await initDb({ cwd, env } as any)
shutdownServer = await startBootstrapApp({ cwd, env })
appContainer = getContainer() appContainer = getContainer()
userModuleService = appContainer.resolve(ModuleRegistrationName.USER) userModuleService = appContainer.resolve(ModuleRegistrationName.USER)
}) })
beforeEach(async () => { beforeEach(async () => {
await createAdminUser(dbConnection, adminHeaders) await createAdminUser(dbConnection, adminHeaders, appContainer)
})
afterAll(async () => {
const db = useDb()
await db.shutdown()
await shutdownServer()
})
afterEach(async () => {
const db = useDb()
await db.teardown()
}) })
it("should retrieve a single invite", async () => { it("should retrieve a single invite", async () => {
@@ -50,9 +31,10 @@ describe("GET /admin/invites/:id", () => {
email: "potential_member@test.com", email: "potential_member@test.com",
}) })
const api = useApi()! as AxiosInstance const response = await api.get(
`/admin/invites/${invite.id}`,
const response = await api.get(`/admin/invites/${invite.id}`, adminHeaders) adminHeaders
)
expect(response.status).toEqual(200) expect(response.status).toEqual(200)
expect(response.data.invite).toEqual( expect(response.data.invite).toEqual(
@@ -60,3 +42,5 @@ describe("GET /admin/invites/:id", () => {
) )
}) })
}) })
},
})
@@ -6,19 +6,17 @@ import {
IRegionModuleService, IRegionModuleService,
ISalesChannelModuleService, ISalesChannelModuleService,
} from "@medusajs/types" } from "@medusajs/types"
import path from "path" import { medusaIntegrationTestRunner } from "medusa-test-utils"
import { startBootstrapApp } from "../../../environment-helpers/bootstrap-app"
import { getContainer } from "../../../environment-helpers/use-container"
import { initDb, useDb } from "../../../environment-helpers/use-db"
jest.setTimeout(50000) jest.setTimeout(50000)
const env = { MEDUSA_FF_MEDUSA_V2: true } const env = { MEDUSA_FF_MEDUSA_V2: true }
medusaIntegrationTestRunner({
env,
testSuite: ({ dbConnection, getContainer, api }) => {
describe("Cart links", () => { describe("Cart links", () => {
let dbConnection
let appContainer let appContainer
let shutdownServer
let cartModuleService: ICartModuleService let cartModuleService: ICartModuleService
let regionModule: IRegionModuleService let regionModule: IRegionModuleService
let customerModule: ICustomerModuleService let customerModule: ICustomerModuleService
@@ -27,31 +25,21 @@ describe("Cart links", () => {
let remoteQuery, remoteLink let remoteQuery, remoteLink
beforeAll(async () => { beforeAll(async () => {
const cwd = path.resolve(path.join(__dirname, "..", ".."))
dbConnection = await initDb({ cwd, env } as any)
shutdownServer = await startBootstrapApp({ cwd, env })
appContainer = getContainer() appContainer = getContainer()
cartModuleService = appContainer.resolve(ModuleRegistrationName.CART) cartModuleService = appContainer.resolve(ModuleRegistrationName.CART)
regionModule = appContainer.resolve(ModuleRegistrationName.REGION) regionModule = appContainer.resolve(ModuleRegistrationName.REGION)
customerModule = appContainer.resolve(ModuleRegistrationName.CUSTOMER) customerModule = appContainer.resolve(ModuleRegistrationName.CUSTOMER)
scModuleService = appContainer.resolve(ModuleRegistrationName.SALES_CHANNEL) scModuleService = appContainer.resolve(
ModuleRegistrationName.SALES_CHANNEL
)
regionModule = appContainer.resolve(ModuleRegistrationName.REGION) regionModule = appContainer.resolve(ModuleRegistrationName.REGION)
paymentModuleService = appContainer.resolve(ModuleRegistrationName.PAYMENT) paymentModuleService = appContainer.resolve(
ModuleRegistrationName.PAYMENT
)
remoteQuery = appContainer.resolve("remoteQuery") remoteQuery = appContainer.resolve("remoteQuery")
remoteLink = appContainer.resolve("remoteLink") remoteLink = appContainer.resolve("remoteLink")
}) })
afterAll(async () => {
const db = useDb()
await db.shutdown()
await shutdownServer()
})
afterEach(async () => {
const db = useDb()
await db.teardown()
})
it("should query carts, sales channels, customers, regions with remote query", async () => { it("should query carts, sales channels, customers, regions with remote query", async () => {
const region = await regionModule.create({ const region = await regionModule.create({
name: "Region", name: "Region",
@@ -203,3 +191,5 @@ describe("Cart links", () => {
) )
}) })
}) })
},
})
@@ -1,43 +1,27 @@
import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { ModuleRegistrationName } from "@medusajs/modules-sdk"
import { ICartModuleService, IRegionModuleService } from "@medusajs/types" import { ICartModuleService, IRegionModuleService } from "@medusajs/types"
import path from "path" import { medusaIntegrationTestRunner } from "medusa-test-utils"
import { startBootstrapApp } from "../../../environment-helpers/bootstrap-app"
import { getContainer } from "../../../environment-helpers/use-container"
import { initDb, useDb } from "../../../environment-helpers/use-db"
jest.setTimeout(50000) jest.setTimeout(50000)
const env = { MEDUSA_FF_MEDUSA_V2: true } const env = { MEDUSA_FF_MEDUSA_V2: true }
medusaIntegrationTestRunner({
env,
testSuite: ({ dbConnection, getContainer, api }) => {
describe("Link: Cart Region", () => { describe("Link: Cart Region", () => {
let dbConnection
let appContainer let appContainer
let shutdownServer
let cartModuleService: ICartModuleService let cartModuleService: ICartModuleService
let regionModule: IRegionModuleService let regionModule: IRegionModuleService
let remoteQuery let remoteQuery
beforeAll(async () => { beforeAll(async () => {
const cwd = path.resolve(path.join(__dirname, "..", ".."))
dbConnection = await initDb({ cwd, env } as any)
shutdownServer = await startBootstrapApp({ cwd, env })
appContainer = getContainer() appContainer = getContainer()
cartModuleService = appContainer.resolve(ModuleRegistrationName.CART) cartModuleService = appContainer.resolve(ModuleRegistrationName.CART)
regionModule = appContainer.resolve(ModuleRegistrationName.REGION) regionModule = appContainer.resolve(ModuleRegistrationName.REGION)
remoteQuery = appContainer.resolve("remoteQuery") remoteQuery = appContainer.resolve("remoteQuery")
}) })
afterAll(async () => {
const db = useDb()
await db.shutdown()
await shutdownServer()
})
afterEach(async () => {
const db = useDb()
await db.teardown()
})
it("should query carts and regions with remote query", async () => { it("should query carts and regions with remote query", async () => {
const region = await regionModule.create({ const region = await regionModule.create({
name: "Region", name: "Region",
@@ -89,3 +73,5 @@ describe("Link: Cart Region", () => {
) )
}) })
}) })
},
})
@@ -3,47 +3,33 @@ import {
IApiKeyModuleService, IApiKeyModuleService,
ISalesChannelModuleService, ISalesChannelModuleService,
} from "@medusajs/types" } from "@medusajs/types"
import path from "path"
import { startBootstrapApp } from "../../../environment-helpers/bootstrap-app"
import { getContainer } from "../../../environment-helpers/use-container"
import { initDb, useDb } from "../../../environment-helpers/use-db"
import { remoteQueryObjectFromString } from "@medusajs/utils" import { remoteQueryObjectFromString } from "@medusajs/utils"
import { medusaIntegrationTestRunner } from "medusa-test-utils"
jest.setTimeout(50000) jest.setTimeout(50000)
const env = { MEDUSA_FF_MEDUSA_V2: true } const env = { MEDUSA_FF_MEDUSA_V2: true }
medusaIntegrationTestRunner({
env,
testSuite: ({ dbConnection, getContainer, api }) => {
describe("Publishable keys and sales channel link", () => { describe("Publishable keys and sales channel link", () => {
let dbConnection
let appContainer let appContainer
let shutdownServer
let apiKeyModule: IApiKeyModuleService let apiKeyModule: IApiKeyModuleService
let scModuleService: ISalesChannelModuleService let scModuleService: ISalesChannelModuleService
let remoteQuery let remoteQuery
let remoteLink let remoteLink
beforeAll(async () => { beforeAll(async () => {
const cwd = path.resolve(path.join(__dirname, "..", ".."))
dbConnection = await initDb({ cwd, env } as any)
shutdownServer = await startBootstrapApp({ cwd, env })
appContainer = getContainer() appContainer = getContainer()
apiKeyModule = appContainer.resolve(ModuleRegistrationName.API_KEY) apiKeyModule = appContainer.resolve(ModuleRegistrationName.API_KEY)
scModuleService = appContainer.resolve(ModuleRegistrationName.SALES_CHANNEL) scModuleService = appContainer.resolve(
ModuleRegistrationName.SALES_CHANNEL
)
remoteQuery = appContainer.resolve("remoteQuery") remoteQuery = appContainer.resolve("remoteQuery")
remoteLink = appContainer.resolve("remoteLink") remoteLink = appContainer.resolve("remoteLink")
}) })
afterAll(async () => {
const db = useDb()
await db.shutdown()
await shutdownServer()
})
afterEach(async () => {
const db = useDb()
await db.teardown()
})
it("should query api key and sales channels link with remote query", async () => { it("should query api key and sales channels link with remote query", async () => {
const salesChannel = await scModuleService.create({ const salesChannel = await scModuleService.create({
name: "Webshop", name: "Webshop",
@@ -103,3 +89,5 @@ describe("Publishable keys and sales channel link", () => {
) )
}) })
}) })
},
})
@@ -1,27 +1,22 @@
import { ModuleRegistrationName, Modules } from "@medusajs/modules-sdk" import { ModuleRegistrationName, Modules } from "@medusajs/modules-sdk"
import { IPaymentModuleService, IRegionModuleService } from "@medusajs/types" import { IPaymentModuleService, IRegionModuleService } from "@medusajs/types"
import path from "path" import { medusaIntegrationTestRunner } from "medusa-test-utils"
import { startBootstrapApp } from "../../../environment-helpers/bootstrap-app"
import { getContainer } from "../../../environment-helpers/use-container"
import { initDb, useDb } from "../../../environment-helpers/use-db"
jest.setTimeout(50000) jest.setTimeout(50000)
const env = { MEDUSA_FF_MEDUSA_V2: true } const env = { MEDUSA_FF_MEDUSA_V2: true }
medusaIntegrationTestRunner({
env,
testSuite: ({ dbConnection, getContainer, api }) => {
describe("Region and Payment Providers", () => { describe("Region and Payment Providers", () => {
let dbConnection
let appContainer let appContainer
let shutdownServer
let regionModule: IRegionModuleService let regionModule: IRegionModuleService
let paymentModule: IPaymentModuleService let paymentModule: IPaymentModuleService
let remoteQuery let remoteQuery
let remoteLink let remoteLink
beforeAll(async () => { beforeAll(async () => {
const cwd = path.resolve(path.join(__dirname, "..", ".."))
dbConnection = await initDb({ cwd, env } as any)
shutdownServer = await startBootstrapApp({ cwd, env })
appContainer = getContainer() appContainer = getContainer()
regionModule = appContainer.resolve(ModuleRegistrationName.REGION) regionModule = appContainer.resolve(ModuleRegistrationName.REGION)
paymentModule = appContainer.resolve(ModuleRegistrationName.PAYMENT) paymentModule = appContainer.resolve(ModuleRegistrationName.PAYMENT)
@@ -29,17 +24,6 @@ describe("Region and Payment Providers", () => {
remoteLink = appContainer.resolve("remoteLink") remoteLink = appContainer.resolve("remoteLink")
}) })
afterAll(async () => {
const db = useDb()
await db.shutdown()
await shutdownServer()
})
afterEach(async () => {
const db = useDb()
await db.teardown()
})
it("should query region and payment provider link with remote query", async () => { it("should query region and payment provider link with remote query", async () => {
const region = await regionModule.create({ const region = await regionModule.create({
name: "North America", name: "North America",
@@ -104,3 +88,5 @@ describe("Region and Payment Providers", () => {
) )
}) })
}) })
},
})
@@ -1,16 +1,12 @@
import dbFactory from "./../../../environment-helpers/use-template-db" import { medusaIntegrationTestRunner } from "medusa-test-utils"
jest.setTimeout(30000) jest.setTimeout(30000)
medusaIntegrationTestRunner({
testSuite: ({ dbConnection }) => {
describe("Standalone Modules", () => { describe("Standalone Modules", () => {
beforeAll(async () => { beforeAll(async () => {
const DB_HOST = process.env.DB_HOST process.env.POSTGRES_URL = dbConnection.manager.connection.options.url
const DB_USERNAME = process.env.DB_USERNAME
const DB_PASSWORD = process.env.DB_PASSWORD
const DB_NAME = process.env.DB_TEMP_NAME
process.env.POSTGRES_URL = `postgres://${DB_USERNAME}:${DB_PASSWORD}@${DB_HOST}/${DB_NAME}`
await dbFactory.createFromTemplate(DB_NAME)
}) })
afterAll(async () => { afterAll(async () => {
@@ -27,3 +23,5 @@ describe("Standalone Modules", () => {
expect(productList).toEqual(expect.arrayContaining([])) expect(productList).toEqual(expect.arrayContaining([]))
}) })
}) })
},
})
@@ -4,44 +4,28 @@ import {
} from "@medusajs/core-flows" } from "@medusajs/core-flows"
import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { ModuleRegistrationName } from "@medusajs/modules-sdk"
import { IPaymentModuleService, IRegionModuleService } from "@medusajs/types" import { IPaymentModuleService, IRegionModuleService } from "@medusajs/types"
import path from "path" import { medusaIntegrationTestRunner } from "medusa-test-utils/dist"
import { startBootstrapApp } from "../../../environment-helpers/bootstrap-app"
import { getContainer } from "../../../environment-helpers/use-container"
import { initDb, useDb } from "../../../environment-helpers/use-db"
jest.setTimeout(50000) jest.setTimeout(50000)
const env = { MEDUSA_FF_MEDUSA_V2: true } const env = { MEDUSA_FF_MEDUSA_V2: true }
medusaIntegrationTestRunner({
env,
testSuite: ({ dbConnection, getContainer, api }) => {
describe("Carts workflows", () => { describe("Carts workflows", () => {
let dbConnection
let appContainer let appContainer
let shutdownServer
let paymentModule: IPaymentModuleService let paymentModule: IPaymentModuleService
let regionModule: IRegionModuleService let regionModule: IRegionModuleService
let remoteLink let remoteLink
beforeAll(async () => { beforeAll(async () => {
const cwd = path.resolve(path.join(__dirname, "..", ".."))
dbConnection = await initDb({ cwd, env } as any)
shutdownServer = await startBootstrapApp({ cwd, env })
appContainer = getContainer() appContainer = getContainer()
paymentModule = appContainer.resolve(ModuleRegistrationName.PAYMENT) paymentModule = appContainer.resolve(ModuleRegistrationName.PAYMENT)
regionModule = appContainer.resolve(ModuleRegistrationName.REGION) regionModule = appContainer.resolve(ModuleRegistrationName.REGION)
remoteLink = appContainer.resolve("remoteLink") remoteLink = appContainer.resolve("remoteLink")
}) })
afterAll(async () => {
const db = useDb()
await db.shutdown()
await shutdownServer()
})
afterEach(async () => {
const db = useDb()
await db.teardown()
})
describe("createPaymentSessionWorkflow", () => { describe("createPaymentSessionWorkflow", () => {
it("should create payment sessions", async () => { it("should create payment sessions", async () => {
const region = await regionModule.create({ const region = await regionModule.create({
@@ -105,7 +89,8 @@ describe("Carts workflows", () => {
name: "US", name: "US",
}) })
let paymentCollection = await paymentModule.createPaymentCollections({ let paymentCollection =
await paymentModule.createPaymentCollections({
currency_code: "usd", currency_code: "usd",
amount: 1000, amount: 1000,
region_id: region.id, region_id: region.id,
@@ -140,3 +125,5 @@ describe("Carts workflows", () => {
}) })
}) })
}) })
},
})
@@ -1,49 +1,31 @@
import { ModuleRegistrationName, Modules } from "@medusajs/modules-sdk" import { ModuleRegistrationName, Modules } from "@medusajs/modules-sdk"
import { IRegionModuleService } from "@medusajs/types" import { IRegionModuleService } from "@medusajs/types"
import path from "path" import { medusaIntegrationTestRunner } from "medusa-test-utils/dist"
import { startBootstrapApp } from "../../../environment-helpers/bootstrap-app"
import { useApi } from "../../../environment-helpers/use-api"
import { getContainer } from "../../../environment-helpers/use-container"
import { initDb, useDb } from "../../../environment-helpers/use-db"
jest.setTimeout(50000) jest.setTimeout(50000)
const env = { MEDUSA_FF_MEDUSA_V2: true } const env = { MEDUSA_FF_MEDUSA_V2: true }
medusaIntegrationTestRunner({
env,
testSuite: ({ dbConnection, getContainer, api }) => {
describe("Payments", () => { describe("Payments", () => {
let dbConnection
let appContainer let appContainer
let shutdownServer
let regionService: IRegionModuleService let regionService: IRegionModuleService
let remoteLink let remoteLink
beforeAll(async () => { beforeAll(async () => {
const cwd = path.resolve(path.join(__dirname, "..", ".."))
dbConnection = await initDb({ cwd, env } as any)
shutdownServer = await startBootstrapApp({ cwd, env })
appContainer = getContainer() appContainer = getContainer()
regionService = appContainer.resolve(ModuleRegistrationName.REGION) regionService = appContainer.resolve(ModuleRegistrationName.REGION)
remoteLink = appContainer.resolve("remoteLink") remoteLink = appContainer.resolve("remoteLink")
}) })
afterAll(async () => {
const db = useDb()
await db.shutdown()
await shutdownServer()
})
afterEach(async () => {
const db = useDb()
await db.teardown()
})
it("should list payment providers", async () => { it("should list payment providers", async () => {
const region = await regionService.create({ const region = await regionService.create({
name: "Test Region", name: "Test Region",
currency_code: "usd", currency_code: "usd",
}) })
const api = useApi() as any
let response = await api.get( let response = await api.get(
`/store/regions/${region.id}/payment-providers` `/store/regions/${region.id}/payment-providers`
) )
@@ -62,7 +44,9 @@ describe("Payments", () => {
}, },
]) ])
response = await api.get(`/store/regions/${region.id}/payment-providers`) response = await api.get(
`/store/regions/${region.id}/payment-providers`
)
expect(response.status).toEqual(200) expect(response.status).toEqual(200)
expect(response.data.payment_providers).toEqual([ expect(response.data.payment_providers).toEqual([
@@ -72,3 +56,5 @@ describe("Payments", () => {
]) ])
}) })
}) })
},
})
@@ -1,6 +1,3 @@
import { useApi } from "../../../../environment-helpers/use-api"
import { getContainer } from "../../../../environment-helpers/use-container"
import { initDb, useDb } from "../../../../environment-helpers/use-db"
import { import {
simpleProductFactory, simpleProductFactory,
simpleRegionFactory, simpleRegionFactory,
@@ -11,11 +8,10 @@ import {
PriceListStatus, PriceListStatus,
PriceListType, PriceListType,
} from "@medusajs/types" } from "@medusajs/types"
import path from "path"
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
import adminSeeder from "../../../../helpers/admin-seeder" import adminSeeder from "../../../../helpers/admin-seeder"
import { createDefaultRuleTypes } from "../../../helpers/create-default-rule-types" import { createDefaultRuleTypes } from "../../../helpers/create-default-rule-types"
import { createVariantPriceSet } from "../../../helpers/create-variant-price-set" import { createVariantPriceSet } from "../../../helpers/create-variant-price-set"
import { medusaIntegrationTestRunner } from "medusa-test-utils"
jest.setTimeout(50000) jest.setTimeout(50000)
@@ -29,28 +25,20 @@ const env = {
MEDUSA_FF_MEDUSA_V2: true, MEDUSA_FF_MEDUSA_V2: true,
} }
medusaIntegrationTestRunner({
env,
testSuite: ({ dbConnection, getContainer, api }) => {
describe.skip("POST /admin/price-lists/:id/prices/batch", () => { describe.skip("POST /admin/price-lists/:id/prices/batch", () => {
let dbConnection
let appContainer let appContainer
let shutdownServer
let product let product
let variant let variant
let pricingModuleService: IPricingModuleService let pricingModuleService: IPricingModuleService
beforeAll(async () => { beforeAll(async () => {
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
dbConnection = await initDb({ cwd, env } as any)
shutdownServer = await startBootstrapApp({ cwd, env })
appContainer = getContainer() appContainer = getContainer()
pricingModuleService = appContainer.resolve("pricingModuleService") pricingModuleService = appContainer.resolve("pricingModuleService")
}) })
afterAll(async () => {
const db = useDb()
await db.shutdown()
await shutdownServer()
})
beforeEach(async () => { beforeEach(async () => {
await adminSeeder(dbConnection) await adminSeeder(dbConnection)
await createDefaultRuleTypes(appContainer) await createDefaultRuleTypes(appContainer)
@@ -80,11 +68,6 @@ describe.skip("POST /admin/price-lists/:id/prices/batch", () => {
variant = product.variants[0] variant = product.variants[0]
}) })
afterEach(async () => {
const db = useDb()
await db.teardown()
})
it("should update money amounts if variant id is present in prices", async () => { it("should update money amounts if variant id is present in prices", async () => {
const [priceList] = await pricingModuleService.createPriceLists([ const [priceList] = await pricingModuleService.createPriceLists([
{ {
@@ -108,7 +91,6 @@ describe.skip("POST /admin/price-lists/:id/prices/batch", () => {
], ],
}) })
const api = useApi() as any
const data = { const data = {
prices: [ prices: [
{ {
@@ -231,3 +213,5 @@ describe.skip("POST /admin/price-lists/:id/prices/batch", () => {
) )
}) })
}) })
},
})
@@ -1,6 +1,3 @@
import { useApi } from "../../../../environment-helpers/use-api"
import { getContainer } from "../../../../environment-helpers/use-container"
import { initDb, useDb } from "../../../../environment-helpers/use-db"
import { import {
simpleCustomerGroupFactory, simpleCustomerGroupFactory,
simpleProductFactory, simpleProductFactory,
@@ -8,11 +5,10 @@ import {
} from "../../../../factories" } from "../../../../factories"
import { IPricingModuleService } from "@medusajs/types" import { IPricingModuleService } from "@medusajs/types"
import path from "path"
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
import adminSeeder from "../../../../helpers/admin-seeder" import adminSeeder from "../../../../helpers/admin-seeder"
import { createDefaultRuleTypes } from "../../../helpers/create-default-rule-types" import { createDefaultRuleTypes } from "../../../helpers/create-default-rule-types"
import { createVariantPriceSet } from "../../../helpers/create-variant-price-set" import { createVariantPriceSet } from "../../../helpers/create-variant-price-set"
import { medusaIntegrationTestRunner } from "medusa-test-utils"
jest.setTimeout(50000) jest.setTimeout(50000)
@@ -26,28 +22,20 @@ const env = {
MEDUSA_FF_MEDUSA_V2: true, MEDUSA_FF_MEDUSA_V2: true,
} }
medusaIntegrationTestRunner({
env,
testSuite: ({ dbConnection, getContainer, api }) => {
describe.skip("POST /admin/price-lists", () => { describe.skip("POST /admin/price-lists", () => {
let dbConnection
let appContainer let appContainer
let shutdownServer
let product let product
let variant let variant
let pricingModuleService: IPricingModuleService let pricingModuleService: IPricingModuleService
beforeAll(async () => { beforeAll(async () => {
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
dbConnection = await initDb({ cwd, env } as any)
shutdownServer = await startBootstrapApp({ cwd, env })
appContainer = getContainer() appContainer = getContainer()
pricingModuleService = appContainer.resolve("pricingModuleService") pricingModuleService = appContainer.resolve("pricingModuleService")
}) })
afterAll(async () => {
const db = useDb()
await db.shutdown()
await shutdownServer()
})
beforeEach(async () => { beforeEach(async () => {
await adminSeeder(dbConnection) await adminSeeder(dbConnection)
await createDefaultRuleTypes(appContainer) await createDefaultRuleTypes(appContainer)
@@ -81,11 +69,6 @@ describe.skip("POST /admin/price-lists", () => {
variant = product.variants[0] variant = product.variants[0]
}) })
afterEach(async () => {
const db = useDb()
await db.teardown()
})
it("should create price list and money amounts", async () => { it("should create price list and money amounts", async () => {
await createVariantPriceSet({ await createVariantPriceSet({
container: appContainer, container: appContainer,
@@ -98,7 +81,6 @@ describe.skip("POST /admin/price-lists", () => {
], ],
}) })
const api = useApi() as any
const data = { const data = {
name: "test price list", name: "test price list",
description: "test", description: "test",
@@ -189,3 +171,5 @@ describe.skip("POST /admin/price-lists", () => {
) )
}) })
}) })
},
})
@@ -1,18 +1,13 @@
import { useApi } from "../../../../environment-helpers/use-api"
import { getContainer } from "../../../../environment-helpers/use-container"
import { initDb, useDb } from "../../../../environment-helpers/use-db"
import { import {
simpleProductFactory, simpleProductFactory,
simpleRegionFactory, simpleRegionFactory,
} from "../../../../factories" } from "../../../../factories"
import { IPricingModuleService } from "@medusajs/types" import { IPricingModuleService } from "@medusajs/types"
import path from "path"
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
import adminSeeder from "../../../../helpers/admin-seeder" import adminSeeder from "../../../../helpers/admin-seeder"
import { createDefaultRuleTypes } from "../../../helpers/create-default-rule-types" import { createDefaultRuleTypes } from "../../../helpers/create-default-rule-types"
import { createVariantPriceSet } from "../../../helpers/create-variant-price-set" import { createVariantPriceSet } from "../../../helpers/create-variant-price-set"
import { AxiosInstance } from "axios" import { medusaIntegrationTestRunner } from "medusa-test-utils"
jest.setTimeout(50000) jest.setTimeout(50000)
@@ -26,10 +21,11 @@ const env = {
MEDUSA_FF_MEDUSA_V2: true, MEDUSA_FF_MEDUSA_V2: true,
} }
medusaIntegrationTestRunner({
env,
testSuite: ({ dbConnection, getContainer, api }) => {
describe.skip("DELETE /admin/price-lists/:id/products/:productId/batch", () => { describe.skip("DELETE /admin/price-lists/:id/products/:productId/batch", () => {
let dbConnection
let appContainer let appContainer
let shutdownServer
let product let product
let variant1 let variant1
let priceSet let priceSet
@@ -37,22 +33,11 @@ describe.skip("DELETE /admin/price-lists/:id/products/:productId/batch", () => {
let pricingModuleService: IPricingModuleService let pricingModuleService: IPricingModuleService
beforeAll(async () => { beforeAll(async () => {
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
dbConnection = await initDb({ cwd, env } as any)
shutdownServer = await startBootstrapApp({ cwd, env })
appContainer = getContainer() appContainer = getContainer()
pricingModuleService = appContainer.resolve("pricingModuleService") pricingModuleService = appContainer.resolve("pricingModuleService")
}) })
afterAll(async () => {
const db = useDb()
await db.shutdown()
await shutdownServer()
})
beforeEach(async () => { beforeEach(async () => {
const api = useApi()! as AxiosInstance
await adminSeeder(dbConnection) await adminSeeder(dbConnection)
await createDefaultRuleTypes(appContainer) await createDefaultRuleTypes(appContainer)
@@ -114,14 +99,7 @@ describe.skip("DELETE /admin/price-lists/:id/products/:productId/batch", () => {
priceListId = priceListResult.data.price_list.id priceListId = priceListResult.data.price_list.id
}) })
afterEach(async () => {
const db = useDb()
await db.teardown()
})
it("should delete prices in batch based on product ids", async () => { it("should delete prices in batch based on product ids", async () => {
const api = useApi()! as AxiosInstance
let priceSetMoneyAmounts = let priceSetMoneyAmounts =
await pricingModuleService.listPriceSetMoneyAmounts({ await pricingModuleService.listPriceSetMoneyAmounts({
price_set_id: [priceSet.id], price_set_id: [priceSet.id],
@@ -139,7 +117,8 @@ describe.skip("DELETE /admin/price-lists/:id/products/:productId/batch", () => {
) )
expect(deleteRes.status).toEqual(200) expect(deleteRes.status).toEqual(200)
priceSetMoneyAmounts = await pricingModuleService.listPriceSetMoneyAmounts({ priceSetMoneyAmounts =
await pricingModuleService.listPriceSetMoneyAmounts({
price_set_id: [priceSet.id], price_set_id: [priceSet.id],
}) })
@@ -152,8 +131,6 @@ describe.skip("DELETE /admin/price-lists/:id/products/:productId/batch", () => {
}) })
it("should delete prices based on single product id", async () => { it("should delete prices based on single product id", async () => {
const api = useApi()! as AxiosInstance
let priceSetMoneyAmounts = let priceSetMoneyAmounts =
await pricingModuleService.listPriceSetMoneyAmounts({ await pricingModuleService.listPriceSetMoneyAmounts({
price_set_id: [priceSet.id], price_set_id: [priceSet.id],
@@ -166,7 +143,8 @@ describe.skip("DELETE /admin/price-lists/:id/products/:productId/batch", () => {
) )
expect(deleteRes.status).toEqual(200) expect(deleteRes.status).toEqual(200)
priceSetMoneyAmounts = await pricingModuleService.listPriceSetMoneyAmounts({ priceSetMoneyAmounts =
await pricingModuleService.listPriceSetMoneyAmounts({
price_set_id: [priceSet.id], price_set_id: [priceSet.id],
}) })
@@ -178,3 +156,5 @@ describe.skip("DELETE /admin/price-lists/:id/products/:productId/batch", () => {
]) ])
}) })
}) })
},
})
@@ -1,17 +1,13 @@
import { useApi } from "../../../../environment-helpers/use-api"
import { getContainer } from "../../../../environment-helpers/use-container"
import { initDb, useDb } from "../../../../environment-helpers/use-db"
import { import {
simpleProductFactory, simpleProductFactory,
simpleRegionFactory, simpleRegionFactory,
} from "../../../../factories" } from "../../../../factories"
import { IPricingModuleService } from "@medusajs/types" import { IPricingModuleService } from "@medusajs/types"
import path from "path"
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
import adminSeeder from "../../../../helpers/admin-seeder" import adminSeeder from "../../../../helpers/admin-seeder"
import { createDefaultRuleTypes } from "../../../helpers/create-default-rule-types" import { createDefaultRuleTypes } from "../../../helpers/create-default-rule-types"
import { createVariantPriceSet } from "../../../helpers/create-variant-price-set" import { createVariantPriceSet } from "../../../helpers/create-variant-price-set"
import { medusaIntegrationTestRunner } from "medusa-test-utils"
jest.setTimeout(50000) jest.setTimeout(50000)
@@ -25,28 +21,20 @@ const env = {
MEDUSA_FF_MEDUSA_V2: true, MEDUSA_FF_MEDUSA_V2: true,
} }
medusaIntegrationTestRunner({
env,
testSuite: ({ dbConnection, getContainer, api }) => {
describe.skip("DELETE /admin/price-lists/:id/variants/:variantId/prices", () => { describe.skip("DELETE /admin/price-lists/:id/variants/:variantId/prices", () => {
let dbConnection
let appContainer let appContainer
let shutdownServer
let product let product
let variant let variant
let pricingModuleService: IPricingModuleService let pricingModuleService: IPricingModuleService
beforeAll(async () => { beforeAll(async () => {
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
dbConnection = await initDb({ cwd, env } as any)
shutdownServer = await startBootstrapApp({ cwd, env })
appContainer = getContainer() appContainer = getContainer()
pricingModuleService = appContainer.resolve("pricingModuleService") pricingModuleService = appContainer.resolve("pricingModuleService")
}) })
afterAll(async () => {
const db = useDb()
await db.shutdown()
await shutdownServer()
})
beforeEach(async () => { beforeEach(async () => {
await adminSeeder(dbConnection) await adminSeeder(dbConnection)
await createDefaultRuleTypes(appContainer) await createDefaultRuleTypes(appContainer)
@@ -76,11 +64,6 @@ describe.skip("DELETE /admin/price-lists/:id/variants/:variantId/prices", () =>
variant = product.variants[0] variant = product.variants[0]
}) })
afterEach(async () => {
const db = useDb()
await db.teardown()
})
it("should delete all prices based on product variant ids", async () => { it("should delete all prices based on product variant ids", async () => {
const priceSet = await createVariantPriceSet({ const priceSet = await createVariantPriceSet({
container: appContainer, container: appContainer,
@@ -93,7 +76,6 @@ describe.skip("DELETE /admin/price-lists/:id/variants/:variantId/prices", () =>
], ],
}) })
const api = useApi() as any
const data = { const data = {
name: "test price list", name: "test price list",
description: "test", description: "test",
@@ -129,3 +111,5 @@ describe.skip("DELETE /admin/price-lists/:id/variants/:variantId/prices", () =>
expect(psmas.length).toEqual(0) expect(psmas.length).toEqual(0)
}) })
}) })
},
})
@@ -1,17 +1,13 @@
import { useApi } from "../../../../environment-helpers/use-api"
import { getContainer } from "../../../../environment-helpers/use-container"
import { initDb, useDb } from "../../../../environment-helpers/use-db"
import { import {
simpleProductFactory, simpleProductFactory,
simpleRegionFactory, simpleRegionFactory,
} from "../../../../factories" } from "../../../../factories"
import { IPricingModuleService } from "@medusajs/types" import { IPricingModuleService } from "@medusajs/types"
import path from "path"
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
import adminSeeder from "../../../../helpers/admin-seeder" import adminSeeder from "../../../../helpers/admin-seeder"
import { createDefaultRuleTypes } from "../../../helpers/create-default-rule-types" import { createDefaultRuleTypes } from "../../../helpers/create-default-rule-types"
import { createVariantPriceSet } from "../../../helpers/create-variant-price-set" import { createVariantPriceSet } from "../../../helpers/create-variant-price-set"
import { medusaIntegrationTestRunner } from "medusa-test-utils"
jest.setTimeout(50000) jest.setTimeout(50000)
@@ -25,28 +21,20 @@ const env = {
MEDUSA_FF_MEDUSA_V2: true, MEDUSA_FF_MEDUSA_V2: true,
} }
medusaIntegrationTestRunner({
env,
testSuite: ({ dbConnection, getContainer, api }) => {
describe.skip("DELETE /admin/price-lists/:id", () => { describe.skip("DELETE /admin/price-lists/:id", () => {
let dbConnection
let appContainer let appContainer
let shutdownServer
let product let product
let variant let variant
let pricingModuleService: IPricingModuleService let pricingModuleService: IPricingModuleService
beforeAll(async () => { beforeAll(async () => {
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
dbConnection = await initDb({ cwd, env } as any)
shutdownServer = await startBootstrapApp({ cwd, env })
appContainer = getContainer() appContainer = getContainer()
pricingModuleService = appContainer.resolve("pricingModuleService") pricingModuleService = appContainer.resolve("pricingModuleService")
}) })
afterAll(async () => {
const db = useDb()
await db.shutdown()
await shutdownServer()
})
beforeEach(async () => { beforeEach(async () => {
await adminSeeder(dbConnection) await adminSeeder(dbConnection)
await createDefaultRuleTypes(appContainer) await createDefaultRuleTypes(appContainer)
@@ -76,11 +64,6 @@ describe.skip("DELETE /admin/price-lists/:id", () => {
variant = product.variants[0] variant = product.variants[0]
}) })
afterEach(async () => {
const db = useDb()
await db.teardown()
})
it("should delete price list prices by money amount ids", async () => { it("should delete price list prices by money amount ids", async () => {
await createVariantPriceSet({ await createVariantPriceSet({
container: appContainer, container: appContainer,
@@ -93,7 +76,6 @@ describe.skip("DELETE /admin/price-lists/:id", () => {
], ],
}) })
const api = useApi() as any
const data = { const data = {
name: "test price list", name: "test price list",
description: "test", description: "test",
@@ -143,3 +125,5 @@ describe.skip("DELETE /admin/price-lists/:id", () => {
expect(psmas.length).toEqual(1) expect(psmas.length).toEqual(1)
}) })
}) })
},
})
@@ -1,17 +1,13 @@
import { useApi } from "../../../../environment-helpers/use-api"
import { getContainer } from "../../../../environment-helpers/use-container"
import { initDb, useDb } from "../../../../environment-helpers/use-db"
import { import {
simpleProductFactory, simpleProductFactory,
simpleRegionFactory, simpleRegionFactory,
} from "../../../../factories" } from "../../../../factories"
import { IPricingModuleService } from "@medusajs/types" import { IPricingModuleService } from "@medusajs/types"
import path from "path"
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
import adminSeeder from "../../../../helpers/admin-seeder" import adminSeeder from "../../../../helpers/admin-seeder"
import { createDefaultRuleTypes } from "../../../helpers/create-default-rule-types" import { createDefaultRuleTypes } from "../../../helpers/create-default-rule-types"
import { createVariantPriceSet } from "../../../helpers/create-variant-price-set" import { createVariantPriceSet } from "../../../helpers/create-variant-price-set"
import { medusaIntegrationTestRunner } from "medusa-test-utils"
jest.setTimeout(50000) jest.setTimeout(50000)
@@ -25,28 +21,20 @@ const env = {
MEDUSA_FF_MEDUSA_V2: true, MEDUSA_FF_MEDUSA_V2: true,
} }
medusaIntegrationTestRunner({
env,
testSuite: ({ dbConnection, getContainer, api }) => {
describe.skip("DELETE /admin/price-lists/:id", () => { describe.skip("DELETE /admin/price-lists/:id", () => {
let dbConnection
let appContainer let appContainer
let shutdownServer
let product let product
let variant let variant
let pricingModuleService: IPricingModuleService let pricingModuleService: IPricingModuleService
beforeAll(async () => { beforeAll(async () => {
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
dbConnection = await initDb({ cwd, env } as any)
shutdownServer = await startBootstrapApp({ cwd, env })
appContainer = getContainer() appContainer = getContainer()
pricingModuleService = appContainer.resolve("pricingModuleService") pricingModuleService = appContainer.resolve("pricingModuleService")
}) })
afterAll(async () => {
const db = useDb()
await db.shutdown()
await shutdownServer()
})
beforeEach(async () => { beforeEach(async () => {
await adminSeeder(dbConnection) await adminSeeder(dbConnection)
await createDefaultRuleTypes(appContainer) await createDefaultRuleTypes(appContainer)
@@ -76,11 +64,6 @@ describe.skip("DELETE /admin/price-lists/:id", () => {
variant = product.variants[0] variant = product.variants[0]
}) })
afterEach(async () => {
const db = useDb()
await db.teardown()
})
it("should delete price list and money amounts", async () => { it("should delete price list and money amounts", async () => {
const priceSet = await createVariantPriceSet({ const priceSet = await createVariantPriceSet({
container: appContainer, container: appContainer,
@@ -93,7 +76,6 @@ describe.skip("DELETE /admin/price-lists/:id", () => {
], ],
}) })
const api = useApi() as any
const data = { const data = {
name: "test price list", name: "test price list",
description: "test", description: "test",
@@ -142,3 +124,5 @@ describe.skip("DELETE /admin/price-lists/:id", () => {
expect(psmas.length).toEqual(0) expect(psmas.length).toEqual(0)
}) })
}) })
},
})
@@ -1,6 +1,3 @@
import { useApi } from "../../../../environment-helpers/use-api"
import { getContainer } from "../../../../environment-helpers/use-container"
import { initDb, useDb } from "../../../../environment-helpers/use-db"
import { simpleProductFactory } from "../../../../factories" import { simpleProductFactory } from "../../../../factories"
import { import {
@@ -8,10 +5,9 @@ import {
PriceListStatus, PriceListStatus,
PriceListType, PriceListType,
} from "@medusajs/types" } from "@medusajs/types"
import path from "path"
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
import adminSeeder from "../../../../helpers/admin-seeder" import adminSeeder from "../../../../helpers/admin-seeder"
import { createVariantPriceSet } from "../../../helpers/create-variant-price-set" import { createVariantPriceSet } from "../../../helpers/create-variant-price-set"
import { medusaIntegrationTestRunner } from "medusa-test-utils"
jest.setTimeout(50000) jest.setTimeout(50000)
@@ -25,28 +21,20 @@ const env = {
MEDUSA_FF_MEDUSA_V2: true, MEDUSA_FF_MEDUSA_V2: true,
} }
medusaIntegrationTestRunner({
env,
testSuite: ({ dbConnection, getContainer, api }) => {
describe.skip("GET /admin/price-lists/:id", () => { describe.skip("GET /admin/price-lists/:id", () => {
let dbConnection
let appContainer let appContainer
let shutdownServer
let product let product
let variant let variant
let pricingModuleService: IPricingModuleService let pricingModuleService: IPricingModuleService
beforeAll(async () => { beforeAll(async () => {
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
dbConnection = await initDb({ cwd, env } as any)
shutdownServer = await startBootstrapApp({ cwd, env })
appContainer = getContainer() appContainer = getContainer()
pricingModuleService = appContainer.resolve("pricingModuleService") pricingModuleService = appContainer.resolve("pricingModuleService")
}) })
afterAll(async () => {
const db = useDb()
await db.shutdown()
await shutdownServer()
})
beforeEach(async () => { beforeEach(async () => {
await adminSeeder(dbConnection) await adminSeeder(dbConnection)
@@ -68,11 +56,6 @@ describe.skip("GET /admin/price-lists/:id", () => {
variant = product.variants[0] variant = product.variants[0]
}) })
afterEach(async () => {
const db = useDb()
await db.teardown()
})
it("should get price list and its money amounts with variants", async () => { it("should get price list and its money amounts with variants", async () => {
const priceSet = await createVariantPriceSet({ const priceSet = await createVariantPriceSet({
container: appContainer, container: appContainer,
@@ -122,8 +105,6 @@ describe.skip("GET /admin/price-lists/:id", () => {
}, },
]) ])
const api = useApi() as any
const response = await api.get( const response = await api.get(
`/admin/price-lists/${priceList.id}`, `/admin/price-lists/${priceList.id}`,
adminHeaders adminHeaders
@@ -188,8 +169,6 @@ describe.skip("GET /admin/price-lists/:id", () => {
}) })
it("should throw an error when price list is not found", async () => { it("should throw an error when price list is not found", async () => {
const api = useApi() as any
const error = await api const error = await api
.get(`/admin/price-lists/does-not-exist`, adminHeaders) .get(`/admin/price-lists/does-not-exist`, adminHeaders)
.catch((e) => e) .catch((e) => e)
@@ -201,3 +180,5 @@ describe.skip("GET /admin/price-lists/:id", () => {
}) })
}) })
}) })
},
})
@@ -1,6 +1,3 @@
import { useApi } from "../../../../environment-helpers/use-api"
import { getContainer } from "../../../../environment-helpers/use-container"
import { initDb, useDb } from "../../../../environment-helpers/use-db"
import { simpleProductFactory } from "../../../../factories" import { simpleProductFactory } from "../../../../factories"
import { import {
@@ -8,10 +5,9 @@ import {
PriceListStatus, PriceListStatus,
PriceListType, PriceListType,
} from "@medusajs/types" } from "@medusajs/types"
import path from "path"
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
import adminSeeder from "../../../../helpers/admin-seeder" import adminSeeder from "../../../../helpers/admin-seeder"
import { createVariantPriceSet } from "../../../helpers/create-variant-price-set" import { createVariantPriceSet } from "../../../helpers/create-variant-price-set"
import { medusaIntegrationTestRunner } from "medusa-test-utils"
jest.setTimeout(50000) jest.setTimeout(50000)
@@ -25,29 +21,21 @@ const env = {
MEDUSA_FF_MEDUSA_V2: true, MEDUSA_FF_MEDUSA_V2: true,
} }
medusaIntegrationTestRunner({
env,
testSuite: ({ dbConnection, getContainer, api }) => {
describe.skip("GET /admin/price-lists/:id/products", () => { describe.skip("GET /admin/price-lists/:id/products", () => {
let dbConnection
let appContainer let appContainer
let shutdownServer
let product let product
let product2 let product2
let variant let variant
let pricingModuleService: IPricingModuleService let pricingModuleService: IPricingModuleService
beforeAll(async () => { beforeAll(async () => {
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
dbConnection = await initDb({ cwd, env } as any)
shutdownServer = await startBootstrapApp({ cwd, env })
appContainer = getContainer() appContainer = getContainer()
pricingModuleService = appContainer.resolve("pricingModuleService") pricingModuleService = appContainer.resolve("pricingModuleService")
}) })
afterAll(async () => {
const db = useDb()
await db.shutdown()
await shutdownServer()
})
beforeEach(async () => { beforeEach(async () => {
await adminSeeder(dbConnection) await adminSeeder(dbConnection)
@@ -74,7 +62,9 @@ describe.skip("GET /admin/price-lists/:id/products", () => {
title: "uniquely fun product 2", title: "uniquely fun product 2",
variants: [ variants: [
{ {
options: [{ option_id: "test-product-option-2", value: "test 2" }], options: [
{ option_id: "test-product-option-2", value: "test 2" },
],
}, },
], ],
options: [ options: [
@@ -86,11 +76,6 @@ describe.skip("GET /admin/price-lists/:id/products", () => {
}) })
}) })
afterEach(async () => {
const db = useDb()
await db.teardown()
})
it("should list all products in a price list", async () => { it("should list all products in a price list", async () => {
const priceSet = await createVariantPriceSet({ const priceSet = await createVariantPriceSet({
container: appContainer, container: appContainer,
@@ -122,8 +107,6 @@ describe.skip("GET /admin/price-lists/:id/products", () => {
}, },
]) ])
const api = useApi() as any
let response = await api.get( let response = await api.get(
`/admin/price-lists/${priceList.id}/products`, `/admin/price-lists/${priceList.id}/products`,
adminHeaders adminHeaders
@@ -232,8 +215,6 @@ describe.skip("GET /admin/price-lists/:id/products", () => {
}, },
]) ])
const api = useApi() as any
let response = await api.get( let response = await api.get(
`/admin/price-lists/${priceList.id}/products?q=shouldnotreturnanything`, `/admin/price-lists/${priceList.id}/products?q=shouldnotreturnanything`,
adminHeaders adminHeaders
@@ -270,3 +251,5 @@ describe.skip("GET /admin/price-lists/:id/products", () => {
]) ])
}) })
}) })
},
})
@@ -1,6 +1,3 @@
import { useApi } from "../../../../environment-helpers/use-api"
import { getContainer } from "../../../../environment-helpers/use-container"
import { initDb, useDb } from "../../../../environment-helpers/use-db"
import { simpleProductFactory } from "../../../../factories" import { simpleProductFactory } from "../../../../factories"
import { import {
@@ -8,10 +5,9 @@ import {
PriceListStatus, PriceListStatus,
PriceListType, PriceListType,
} from "@medusajs/types" } from "@medusajs/types"
import path from "path"
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
import adminSeeder from "../../../../helpers/admin-seeder" import adminSeeder from "../../../../helpers/admin-seeder"
import { createVariantPriceSet } from "../../../helpers/create-variant-price-set" import { createVariantPriceSet } from "../../../helpers/create-variant-price-set"
import { medusaIntegrationTestRunner } from "medusa-test-utils"
jest.setTimeout(50000) jest.setTimeout(50000)
@@ -25,28 +21,20 @@ const env = {
MEDUSA_FF_MEDUSA_V2: true, MEDUSA_FF_MEDUSA_V2: true,
} }
medusaIntegrationTestRunner({
env,
testSuite: ({ dbConnection, getContainer, api }) => {
describe.skip("GET /admin/price-lists", () => { describe.skip("GET /admin/price-lists", () => {
let dbConnection
let appContainer let appContainer
let shutdownServer
let product let product
let variant let variant
let pricingModuleService: IPricingModuleService let pricingModuleService: IPricingModuleService
beforeAll(async () => { beforeAll(async () => {
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
dbConnection = await initDb({ cwd, env } as any)
shutdownServer = await startBootstrapApp({ cwd, env })
appContainer = getContainer() appContainer = getContainer()
pricingModuleService = appContainer.resolve("pricingModuleService") pricingModuleService = appContainer.resolve("pricingModuleService")
}) })
afterAll(async () => {
const db = useDb()
await db.shutdown()
await shutdownServer()
})
beforeEach(async () => { beforeEach(async () => {
await adminSeeder(dbConnection) await adminSeeder(dbConnection)
@@ -68,11 +56,6 @@ describe.skip("GET /admin/price-lists", () => {
variant = product.variants[0] variant = product.variants[0]
}) })
afterEach(async () => {
const db = useDb()
await db.teardown()
})
it("should get price list and its money amounts with variants", async () => { it("should get price list and its money amounts with variants", async () => {
const priceSet = await createVariantPriceSet({ const priceSet = await createVariantPriceSet({
container: appContainer, container: appContainer,
@@ -104,8 +87,6 @@ describe.skip("GET /admin/price-lists", () => {
}, },
]) ])
const api = useApi() as any
const response = await api.get(`/admin/price-lists`, adminHeaders) const response = await api.get(`/admin/price-lists`, adminHeaders)
expect(response.status).toEqual(200) expect(response.status).toEqual(200)
@@ -167,3 +148,5 @@ describe.skip("GET /admin/price-lists", () => {
]) ])
}) })
}) })
},
})
@@ -1,6 +1,3 @@
import { useApi } from "../../../../environment-helpers/use-api"
import { getContainer } from "../../../../environment-helpers/use-container"
import { initDb, useDb } from "../../../../environment-helpers/use-db"
import { import {
simpleCustomerGroupFactory, simpleCustomerGroupFactory,
simpleProductFactory, simpleProductFactory,
@@ -12,11 +9,10 @@ import {
PriceListStatus, PriceListStatus,
PriceListType, PriceListType,
} from "@medusajs/types" } from "@medusajs/types"
import path from "path"
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
import adminSeeder from "../../../../helpers/admin-seeder" import adminSeeder from "../../../../helpers/admin-seeder"
import { createDefaultRuleTypes } from "../../../helpers/create-default-rule-types" import { createDefaultRuleTypes } from "../../../helpers/create-default-rule-types"
import { createVariantPriceSet } from "../../../helpers/create-variant-price-set" import { createVariantPriceSet } from "../../../helpers/create-variant-price-set"
import { medusaIntegrationTestRunner } from "medusa-test-utils"
jest.setTimeout(50000) jest.setTimeout(50000)
@@ -30,29 +26,21 @@ const env = {
MEDUSA_FF_MEDUSA_V2: true, MEDUSA_FF_MEDUSA_V2: true,
} }
medusaIntegrationTestRunner({
env,
testSuite: ({ dbConnection, getContainer, api }) => {
describe.skip("POST /admin/price-lists/:id", () => { describe.skip("POST /admin/price-lists/:id", () => {
let dbConnection
let appContainer let appContainer
let shutdownServer
let product let product
let variant let variant
let variant2 let variant2
let pricingModuleService: IPricingModuleService let pricingModuleService: IPricingModuleService
beforeAll(async () => { beforeAll(async () => {
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
dbConnection = await initDb({ cwd, env } as any)
shutdownServer = await startBootstrapApp({ cwd, env })
appContainer = getContainer() appContainer = getContainer()
pricingModuleService = appContainer.resolve("pricingModuleService") pricingModuleService = appContainer.resolve("pricingModuleService")
}) })
afterAll(async () => {
const db = useDb()
await db.shutdown()
await shutdownServer()
})
beforeEach(async () => { beforeEach(async () => {
await adminSeeder(dbConnection) await adminSeeder(dbConnection)
await createDefaultRuleTypes(appContainer) await createDefaultRuleTypes(appContainer)
@@ -75,7 +63,9 @@ describe.skip("POST /admin/price-lists/:id", () => {
options: [{ option_id: "test-product-option-1", value: "test" }], options: [{ option_id: "test-product-option-1", value: "test" }],
}, },
{ {
options: [{ option_id: "test-product-option-2", value: "test 2" }], options: [
{ option_id: "test-product-option-2", value: "test 2" },
],
}, },
], ],
options: [ options: [
@@ -94,11 +84,6 @@ describe.skip("POST /admin/price-lists/:id", () => {
variant2 = product.variants[1] variant2 = product.variants[1]
}) })
afterEach(async () => {
const db = useDb()
await db.teardown()
})
it("should update price lists successfully with prices", async () => { it("should update price lists successfully with prices", async () => {
const var2PriceSet = await createVariantPriceSet({ const var2PriceSet = await createVariantPriceSet({
container: appContainer, container: appContainer,
@@ -135,7 +120,6 @@ describe.skip("POST /admin/price-lists/:id", () => {
], ],
}) })
const api = useApi() as any
const data = { const data = {
name: "new price list name", name: "new price list name",
description: "new price list description", description: "new price list description",
@@ -248,7 +232,6 @@ describe.skip("POST /admin/price-lists/:id", () => {
prices: [], prices: [],
}) })
const api = useApi() as any
const data = { const data = {
status: PriceListStatus.ACTIVE, status: PriceListStatus.ACTIVE,
} }
@@ -278,3 +261,5 @@ describe.skip("POST /admin/price-lists/:id", () => {
) )
}) })
}) })
},
})
@@ -1,6 +1,3 @@
import { useApi } from "../../../../environment-helpers/use-api"
import { getContainer } from "../../../../environment-helpers/use-container"
import { initDb, useDb } from "../../../../environment-helpers/use-db"
import { import {
simpleCustomerFactory, simpleCustomerFactory,
simpleCustomerGroupFactory, simpleCustomerGroupFactory,
@@ -13,12 +10,10 @@ import {
PriceListStatus, PriceListStatus,
PriceListType, PriceListType,
} from "@medusajs/types" } from "@medusajs/types"
import { AxiosInstance } from "axios"
import path from "path"
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
import adminSeeder from "../../../../helpers/admin-seeder" import adminSeeder from "../../../../helpers/admin-seeder"
import { createDefaultRuleTypes } from "../../../helpers/create-default-rule-types" import { createDefaultRuleTypes } from "../../../helpers/create-default-rule-types"
import { createVariantPriceSet } from "../../../helpers/create-variant-price-set" import { createVariantPriceSet } from "../../../helpers/create-variant-price-set"
import { medusaIntegrationTestRunner } from "medusa-test-utils"
jest.setTimeout(50000) jest.setTimeout(50000)
@@ -32,29 +27,21 @@ const env = {
MEDUSA_FF_MEDUSA_V2: true, MEDUSA_FF_MEDUSA_V2: true,
} }
medusaIntegrationTestRunner({
env,
testSuite: ({ dbConnection, getContainer, api }) => {
describe.skip("GET /store/products/:id", () => { describe.skip("GET /store/products/:id", () => {
let dbConnection
let appContainer let appContainer
let shutdownServer
let product let product
let variant let variant
let priceSetId let priceSetId
let pricingModuleService: IPricingModuleService let pricingModuleService: IPricingModuleService
beforeAll(async () => { beforeAll(async () => {
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
dbConnection = await initDb({ cwd, env } as any)
shutdownServer = await startBootstrapApp({ cwd, env })
appContainer = getContainer() appContainer = getContainer()
pricingModuleService = appContainer.resolve("pricingModuleService") pricingModuleService = appContainer.resolve("pricingModuleService")
}) })
afterAll(async () => {
const db = useDb()
await db.shutdown()
await shutdownServer()
})
beforeEach(async () => { beforeEach(async () => {
await adminSeeder(dbConnection) await adminSeeder(dbConnection)
await createDefaultRuleTypes(appContainer) await createDefaultRuleTypes(appContainer)
@@ -103,14 +90,7 @@ describe.skip("GET /store/products/:id", () => {
priceSetId = priceSet.id priceSetId = priceSet.id
}) })
afterEach(async () => {
const db = useDb()
await db.teardown()
})
it("should get product and its prices from price-list created through the price list workflow", async () => { it("should get product and its prices from price-list created through the price list workflow", async () => {
const api = useApi()! as AxiosInstance
const priceListResponse = await api.post( const priceListResponse = await api.post(
`/admin/price-lists`, `/admin/price-lists`,
{ {
@@ -161,8 +141,6 @@ describe.skip("GET /store/products/:id", () => {
}) })
it("should not list prices from price-list with customer groups if not logged in", async () => { it("should not list prices from price-list with customer groups if not logged in", async () => {
const api = useApi()! as AxiosInstance
const { id: customerGroupId } = await simpleCustomerGroupFactory( const { id: customerGroupId } = await simpleCustomerGroupFactory(
dbConnection dbConnection
) )
@@ -210,8 +188,6 @@ describe.skip("GET /store/products/:id", () => {
}) })
it("should list prices from price-list with customer groups", async () => { it("should list prices from price-list with customer groups", async () => {
const api = useApi()! as AxiosInstance
await simpleCustomerFactory(dbConnection, { await simpleCustomerFactory(dbConnection, {
id: "test-customer-5-pl", id: "test-customer-5-pl",
email: "test5@email-pl.com", email: "test5@email-pl.com",
@@ -285,3 +261,5 @@ describe.skip("GET /store/products/:id", () => {
) )
}) })
}) })
},
})
@@ -1,14 +1,9 @@
import { useApi } from "../../../environment-helpers/use-api"
import { initDb, useDb } from "../../../environment-helpers/use-db"
import { simpleCartFactory, simpleRegionFactory } from "../../../factories" import { simpleCartFactory, simpleRegionFactory } from "../../../factories"
import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { ModuleRegistrationName } from "@medusajs/modules-sdk"
import { AxiosInstance } from "axios"
import path from "path"
import { startBootstrapApp } from "../../../environment-helpers/bootstrap-app"
import { getContainer } from "../../../environment-helpers/use-container"
import adminSeeder from "../../../helpers/admin-seeder" import adminSeeder from "../../../helpers/admin-seeder"
import { createDefaultRuleTypes } from "../../helpers/create-default-rule-types" import { createDefaultRuleTypes } from "../../helpers/create-default-rule-types"
import { medusaIntegrationTestRunner } from "medusa-test-utils"
jest.setTimeout(5000000) jest.setTimeout(5000000)
@@ -28,24 +23,15 @@ const env = {
MEDUSA_FF_MEDUSA_V2: true, MEDUSA_FF_MEDUSA_V2: true,
} }
medusaIntegrationTestRunner({
env,
testSuite: ({ dbConnection, getContainer, api }) => {
describe.skip("Link Modules", () => { describe.skip("Link Modules", () => {
let medusaContainer let medusaContainer
let dbConnection
let shutdownServer
beforeAll(async () => { beforeAll(async () => {
const cwd = path.resolve(path.join(__dirname, "..", ".."))
dbConnection = await initDb({ cwd, env } as any)
shutdownServer = await startBootstrapApp({ cwd, env })
medusaContainer = getContainer() medusaContainer = getContainer()
}) })
afterAll(async () => {
const db = useDb()
await db.shutdown()
await shutdownServer()
})
beforeEach(async () => { beforeEach(async () => {
await createDefaultRuleTypes(medusaContainer) await createDefaultRuleTypes(medusaContainer)
await adminSeeder(dbConnection) await adminSeeder(dbConnection)
@@ -64,9 +50,11 @@ describe.skip("Link Modules", () => {
const pricingModuleService = medusaContainer.resolve( const pricingModuleService = medusaContainer.resolve(
ModuleRegistrationName.PRICING ModuleRegistrationName.PRICING
) )
const api = useApi()! as AxiosInstance
await simpleCartFactory(dbConnection, { id: cartId, region: "region-1" }) await simpleCartFactory(dbConnection, {
id: cartId,
region: "region-1",
})
const payload = { const payload = {
title: "Test", title: "Test",
@@ -81,7 +69,11 @@ describe.skip("Link Modules", () => {
], ],
} }
const response = await api.post("/admin/products", payload, adminHeaders) const response = await api.post(
"/admin/products",
payload,
adminHeaders
)
productId = response.data.product.id productId = response.data.product.id
const variant = response.data.product.variants[0] const variant = response.data.product.variants[0]
@@ -119,8 +111,6 @@ describe.skip("Link Modules", () => {
}) })
it("Should get prices declared in pricing module", async () => { it("Should get prices declared in pricing module", async () => {
const api = useApi()! as AxiosInstance
const response = await api.get( const response = await api.get(
`/store/products/${productId}?cart_id=${cartId}` `/store/products/${productId}?cart_id=${cartId}`
) )
@@ -134,3 +124,5 @@ describe.skip("Link Modules", () => {
}) })
}) })
}) })
},
})
@@ -1,17 +1,12 @@
import { PricingModuleService } from "@medusajs/pricing" import { PricingModuleService } from "@medusajs/pricing"
import { ProductModuleService } from "@medusajs/product" import { ProductModuleService } from "@medusajs/product"
import { AxiosInstance } from "axios"
import path from "path"
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
import { useApi } from "../../../../environment-helpers/use-api"
import { getContainer } from "../../../../environment-helpers/use-container"
import { initDb, useDb } from "../../../../environment-helpers/use-db"
import { import {
simpleProductFactory, simpleProductFactory,
simpleRegionFactory, simpleRegionFactory,
} from "../../../../factories" } from "../../../../factories"
import adminSeeder from "../../../../helpers/admin-seeder" import adminSeeder from "../../../../helpers/admin-seeder"
import { createDefaultRuleTypes } from "../../../helpers/create-default-rule-types" import { createDefaultRuleTypes } from "../../../helpers/create-default-rule-types"
import { medusaIntegrationTestRunner } from "medusa-test-utils"
jest.setTimeout(50000) jest.setTimeout(50000)
@@ -25,26 +20,18 @@ const env = {
MEDUSA_FF_MEDUSA_V2: true, MEDUSA_FF_MEDUSA_V2: true,
} }
medusaIntegrationTestRunner({
env,
testSuite: ({ dbConnection, getContainer, api }) => {
describe.skip("POST /admin/products/:id/variants", () => { describe.skip("POST /admin/products/:id/variants", () => {
let dbConnection
let appContainer let appContainer
let shutdownServer
let product let product
let variant let variant
beforeAll(async () => { beforeAll(async () => {
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
dbConnection = await initDb({ cwd, env } as any)
shutdownServer = await startBootstrapApp({ cwd, env })
appContainer = getContainer() appContainer = getContainer()
}) })
afterAll(async () => {
const db = useDb()
await db.shutdown()
await shutdownServer()
})
beforeEach(async () => { beforeEach(async () => {
await adminSeeder(dbConnection) await adminSeeder(dbConnection)
await createDefaultRuleTypes(appContainer) await createDefaultRuleTypes(appContainer)
@@ -74,13 +61,7 @@ describe.skip("POST /admin/products/:id/variants", () => {
variant = product.variants[0] variant = product.variants[0]
}) })
afterEach(async () => {
const db = useDb()
await db.teardown()
})
it("should create a product variant with its price sets and prices through the workflow", async () => { it("should create a product variant with its price sets and prices through the workflow", async () => {
const api = useApi()! as AxiosInstance
const data = { const data = {
title: "test variant create", title: "test variant create",
prices: [ prices: [
@@ -110,7 +91,9 @@ describe.skip("POST /admin/products/:id/variants", () => {
height: 234, height: 234,
length: 234, length: 234,
metadata: { asdf: "asdf" }, metadata: { asdf: "asdf" },
options: [{ option_id: "test-product-option-1", value: "test option" }], options: [
{ option_id: "test-product-option-1", value: "test option" },
],
} }
let response = await api.post( let response = await api.post(
@@ -156,7 +139,6 @@ describe.skip("POST /admin/products/:id/variants", () => {
"deleteVariants" "deleteVariants"
) )
const api = useApi()! as AxiosInstance
const data = { const data = {
title: "test variant create", title: "test variant create",
prices: [ prices: [
@@ -186,7 +168,9 @@ describe.skip("POST /admin/products/:id/variants", () => {
height: 234, height: 234,
length: 234, length: 234,
metadata: { asdf: "asdf" }, metadata: { asdf: "asdf" },
options: [{ option_id: "test-product-option-1", value: "test option" }], options: [
{ option_id: "test-product-option-1", value: "test option" },
],
} }
await api await api
@@ -202,3 +186,5 @@ describe.skip("POST /admin/products/:id/variants", () => {
expect(getProductResponse.data.product.variants).toHaveLength(1) expect(getProductResponse.data.product.variants).toHaveLength(1)
}) })
}) })
},
})
@@ -1,18 +1,5 @@
import path from "path"
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
import { useApi } from "../../../../environment-helpers/use-api"
import { initDb, useDb } from "../../../../environment-helpers/use-db"
import productSeeder from "../../../../helpers/product-seeder"
import { AxiosInstance } from "axios"
import { getContainer } from "../../../../environment-helpers/use-container"
import {
simpleProductFactory,
simpleSalesChannelFactory,
} from "../../../../factories"
import { createDefaultRuleTypes } from "../../../helpers/create-default-rule-types"
import { createAdminUser } from "../../../helpers/create-admin-user" import { createAdminUser } from "../../../helpers/create-admin-user"
import { medusaIntegrationTestRunner } from "medusa-test-utils/dist"
jest.setTimeout(50000) jest.setTimeout(50000)
@@ -26,27 +13,18 @@ const env = {
MEDUSA_FF_MEDUSA_V2: true, MEDUSA_FF_MEDUSA_V2: true,
} }
medusaIntegrationTestRunner({
env,
testSuite: ({ dbConnection, getContainer, api }) => {
describe("/admin/products", () => { describe("/admin/products", () => {
let dbConnection
let shutdownServer
let medusaContainer let medusaContainer
beforeAll(async () => { beforeAll(async () => {
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
dbConnection = await initDb({ cwd, env })
shutdownServer = await startBootstrapApp({ cwd, env })
medusaContainer = getContainer() medusaContainer = getContainer()
}) })
afterAll(async () => {
const db = useDb()
await db.shutdown()
await shutdownServer()
})
describe("POST /admin/products", () => {
beforeEach(async () => { beforeEach(async () => {
await createAdminUser(dbConnection, adminHeaders) await createAdminUser(dbConnection, adminHeaders, medusaContainer)
// await productSeeder(dbConnection) // await productSeeder(dbConnection)
// await createDefaultRuleTypes(medusaContainer) // await createDefaultRuleTypes(medusaContainer)
@@ -57,14 +35,8 @@ describe("/admin/products", () => {
// }) // })
}) })
afterEach(async () => { describe("POST /admin/products", () => {
const db = useDb()
await db.teardown()
})
it("should create a product", async () => { it("should create a product", async () => {
const api = useApi()! as AxiosInstance
const payload = { const payload = {
title: "Test", title: "Test",
description: "test-product-description", description: "test-product-description",
@@ -243,8 +215,6 @@ describe("/admin/products", () => {
}) })
it("should create a product that is not discountable", async () => { it("should create a product that is not discountable", async () => {
const api = useApi()! as AxiosInstance
const payload = { const payload = {
title: "Test", title: "Test",
discountable: false, discountable: false,
@@ -279,8 +249,6 @@ describe("/admin/products", () => {
}) })
it("should sets the variant ranks when creating a product", async () => { it("should sets the variant ranks when creating a product", async () => {
const api = useApi()! as AxiosInstance
const payload = { const payload = {
title: "Test product - 1", title: "Test product - 1",
description: "test-product-description 1", description: "test-product-description 1",
@@ -340,8 +308,6 @@ describe("/admin/products", () => {
}) })
it("should create a giftcard", async () => { it("should create a giftcard", async () => {
const api = useApi()! as AxiosInstance
const payload = { const payload = {
title: "Test Giftcard", title: "Test Giftcard",
is_giftcard: true, is_giftcard: true,
@@ -373,8 +339,6 @@ describe("/admin/products", () => {
}) })
it("should create variants with inventory items", async () => { it("should create variants with inventory items", async () => {
const api = useApi()! as AxiosInstance
const response = await api.post( const response = await api.post(
`/admin/products`, `/admin/products`,
{ {
@@ -492,3 +456,5 @@ describe("/admin/products", () => {
// }) // })
}) })
}) })
},
})
@@ -24,6 +24,10 @@ const env: Record<any, any> = {
jest.setTimeout(180000) jest.setTimeout(180000)
// TODO SEE to use new test runner medusaIntegrationTestRunner({
// env,
// testSuite: ({ dbConnection, getContainer, api }) => {})
describe.skip("Batch job of product-export type", () => { describe.skip("Batch job of product-export type", () => {
let medusaProcess let medusaProcess
let dbConnection let dbConnection
@@ -56,6 +56,10 @@ const env: Record<any, any> = {
MEDUSA_FF_MEDUSA_V2: true, MEDUSA_FF_MEDUSA_V2: true,
} }
// TODO SEE to use new test runner medusaIntegrationTestRunner({
// env,
// testSuite: ({ dbConnection, getContainer, api }) => {})
describe.skip("Product import batch job", () => { describe.skip("Product import batch job", () => {
let dbConnection let dbConnection
let shutdownServer let shutdownServer
@@ -0,0 +1,659 @@
import path from "path"
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
import { useApi } from "../../../../environment-helpers/use-api"
import { initDb, useDb } from "../../../../environment-helpers/use-db"
import adminSeeder from "../../../../helpers/admin-seeder"
import productSeeder from "../../../../helpers/product-seeder"
import { Modules, ModulesDefinition } from "@medusajs/modules-sdk"
import { MedusaV2Flag } from "@medusajs/utils"
import { AxiosInstance } from "axios"
import { getContainer } from "../../../../environment-helpers/use-container"
import {
simpleProductFactory,
simpleSalesChannelFactory,
} from "../../../../factories"
import { createDefaultRuleTypes } from "../../../helpers/create-default-rule-types"
jest.setTimeout(50000)
const adminHeaders = {
headers: {
"x-medusa-access-token": "test_token",
},
}
const env = {
MEDUSA_FF_MEDUSA_V2: true,
}
// TODO SEE to use new test runner medusaIntegrationTestRunner({
// env,
// testSuite: ({ dbConnection, getContainer, api }) => {})
describe.skip("/admin/products", () => {
let dbConnection
let shutdownServer
let medusaContainer
beforeAll(async () => {
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
dbConnection = await initDb({ cwd, env })
shutdownServer = await startBootstrapApp({ cwd, env })
medusaContainer = getContainer()
})
afterAll(async () => {
const db = useDb()
await db.shutdown()
await shutdownServer()
})
it("Should have loaded the product module", function () {
const productRegistrationName =
ModulesDefinition[Modules.PRODUCT].registrationName
expect(
medusaContainer.hasRegistration(productRegistrationName)
).toBeTruthy()
})
it("Should have enabled workflows feature flag", function () {
const flagRouter = medusaContainer.resolve("featureFlagRouter")
const workflowsFlag = flagRouter.isFeatureEnabled(MedusaV2Flag.key)
expect(workflowsFlag).toBe(true)
})
describe("POST /admin/products", () => {
beforeEach(async () => {
await productSeeder(dbConnection)
await adminSeeder(dbConnection)
await createDefaultRuleTypes(medusaContainer)
await simpleSalesChannelFactory(dbConnection, {
name: "Default channel",
id: "default-channel",
is_default: true,
})
})
afterEach(async () => {
const db = useDb()
await db.teardown()
})
it("should create a product", async () => {
const api = useApi()! as AxiosInstance
const payload = {
title: "Test",
description: "test-product-description",
type: { value: "test-type" },
images: ["test-image.png", "test-image-2.png"],
collection_id: "test-collection",
tags: [{ value: "123" }, { value: "456" }],
options: [{ title: "size" }, { title: "color" }],
variants: [
{
title: "Test variant",
inventory_quantity: 10,
prices: [
{
currency_code: "usd",
amount: 100,
},
{
currency_code: "eur",
amount: 45,
},
{
currency_code: "dkk",
amount: 30,
},
],
options: [{ value: "large" }, { value: "green" }],
},
],
}
const response = await api
.post("/admin/products", payload, adminHeaders)
.catch((err) => {
console.log(err)
})
expect(response?.status).toEqual(200)
expect(response?.data.product).toEqual(
expect.objectContaining({
id: expect.stringMatching(/^prod_*/),
title: "Test",
discountable: true,
is_giftcard: false,
handle: "test",
status: "draft",
created_at: expect.any(String),
updated_at: expect.any(String),
profile_id: expect.stringMatching(/^sp_*/),
images: expect.arrayContaining([
expect.objectContaining({
id: expect.any(String),
url: "test-image.png",
created_at: expect.any(String),
updated_at: expect.any(String),
}),
expect.objectContaining({
id: expect.any(String),
url: "test-image-2.png",
created_at: expect.any(String),
updated_at: expect.any(String),
}),
]),
thumbnail: "test-image.png",
tags: expect.arrayContaining([
expect.objectContaining({
id: expect.any(String),
value: "123",
created_at: expect.any(String),
updated_at: expect.any(String),
}),
expect.objectContaining({
id: expect.any(String),
value: "456",
created_at: expect.any(String),
updated_at: expect.any(String),
}),
]),
type: expect.objectContaining({
value: "test-type",
created_at: expect.any(String),
updated_at: expect.any(String),
}),
collection: expect.objectContaining({
id: "test-collection",
title: "Test collection",
created_at: expect.any(String),
updated_at: expect.any(String),
}),
options: expect.arrayContaining([
expect.objectContaining({
id: expect.stringMatching(/^opt_*/),
product_id: expect.stringMatching(/^prod_*/),
title: "size",
created_at: expect.any(String),
updated_at: expect.any(String),
}),
expect.objectContaining({
id: expect.stringMatching(/^opt_*/),
product_id: expect.stringMatching(/^prod_*/),
title: "color",
created_at: expect.any(String),
updated_at: expect.any(String),
}),
]),
variants: expect.arrayContaining([
expect.objectContaining({
id: expect.stringMatching(/^variant_*/),
product_id: expect.stringMatching(/^prod_*/),
updated_at: expect.any(String),
created_at: expect.any(String),
title: "Test variant",
prices: expect.arrayContaining([
expect.objectContaining({
id: expect.stringMatching(/^ma_*/),
currency_code: "usd",
amount: 100,
// TODO: enable this in the Pricing Module PR
// created_at: expect.any(String),
// updated_at: expect.any(String),
// variant_id: expect.stringMatching(/^variant_*/),
}),
expect.objectContaining({
id: expect.stringMatching(/^ma_*/),
currency_code: "eur",
amount: 45,
// TODO: enable this in the Pricing Module PR
// created_at: expect.any(String),
// updated_at: expect.any(String),
// variant_id: expect.stringMatching(/^variant_*/),
}),
expect.objectContaining({
id: expect.stringMatching(/^ma_*/),
currency_code: "dkk",
amount: 30,
// TODO: enable this in the Pricing Module PR
// created_at: expect.any(String),
// updated_at: expect.any(String),
// variant_id: expect.stringMatching(/^variant_*/),
}),
]),
options: expect.arrayContaining([
expect.objectContaining({
value: "large",
created_at: expect.any(String),
updated_at: expect.any(String),
variant_id: expect.stringMatching(/^variant_*/),
option_id: expect.stringMatching(/^opt_*/),
id: expect.stringMatching(/^optval_*/),
}),
expect.objectContaining({
value: "green",
created_at: expect.any(String),
updated_at: expect.any(String),
variant_id: expect.stringMatching(/^variant_*/),
option_id: expect.stringMatching(/^opt_*/),
id: expect.stringMatching(/^optval_*/),
}),
]),
}),
]),
})
)
})
it("should create a product that is not discountable", async () => {
const api = useApi()! as AxiosInstance
const payload = {
title: "Test",
discountable: false,
description: "test-product-description",
type: { value: "test-type" },
images: ["test-image.png", "test-image-2.png"],
collection_id: "test-collection",
tags: [{ value: "123" }, { value: "456" }],
options: [{ title: "size" }, { title: "color" }],
variants: [
{
title: "Test variant",
inventory_quantity: 10,
prices: [{ currency_code: "usd", amount: 100 }],
options: [{ value: "large" }, { value: "green" }],
},
],
}
const response = await api
.post("/admin/products", payload, adminHeaders)
.catch((err) => {
console.log(err)
})
expect(response?.status).toEqual(200)
expect(response?.data.product).toEqual(
expect.objectContaining({
discountable: false,
})
)
})
it("should sets the variant ranks when creating a product", async () => {
const api = useApi()! as AxiosInstance
const payload = {
title: "Test product - 1",
description: "test-product-description 1",
type: { value: "test-type 1" },
images: ["test-image.png", "test-image-2.png"],
collection_id: "test-collection",
tags: [{ value: "123" }, { value: "456" }],
options: [{ title: "size" }, { title: "color" }],
variants: [
{
title: "Test variant 1",
inventory_quantity: 10,
prices: [{ currency_code: "usd", amount: 100 }],
options: [{ value: "large" }, { value: "green" }],
},
{
title: "Test variant 2",
inventory_quantity: 10,
prices: [{ currency_code: "usd", amount: 100 }],
options: [{ value: "large" }, { value: "green" }],
},
],
}
const creationResponse = await api
.post("/admin/products", payload, adminHeaders)
.catch((err) => {
console.log(err)
})
expect(creationResponse?.status).toEqual(200)
const productId = creationResponse?.data.product.id
const response = await api
.get(`/admin/products/${productId}`, adminHeaders)
.catch((err) => {
console.log(err)
})
expect(response?.data.product).toEqual(
expect.objectContaining({
title: "Test product - 1",
variants: [
expect.objectContaining({
title: "Test variant 1",
}),
expect.objectContaining({
title: "Test variant 2",
}),
],
})
)
})
it("should create a giftcard", async () => {
const api = useApi()! as AxiosInstance
const payload = {
title: "Test Giftcard",
is_giftcard: true,
description: "test-giftcard-description",
options: [{ title: "Denominations" }],
variants: [
{
title: "Test variant",
prices: [{ currency_code: "usd", amount: 100 }],
options: [{ value: "100" }],
},
],
}
const response = await api
.post("/admin/products", payload, adminHeaders)
.catch((err) => {
console.log(err)
})
expect(response?.status).toEqual(200)
expect(response?.data.product).toEqual(
expect.objectContaining({
title: "Test Giftcard",
discountable: false,
})
)
})
it("should create variants with inventory items", async () => {
const api = useApi()! as AxiosInstance
const response = await api.post(
`/admin/products`,
{
title: "Test product - 1",
description: "test-product-description 1",
type: { value: "test-type 1" },
images: ["test-image.png", "test-image-2.png"],
collection_id: "test-collection",
tags: [{ value: "123" }, { value: "456" }],
options: [{ title: "size" }, { title: "color" }],
variants: [
{
title: "Test variant 1",
inventory_quantity: 10,
prices: [{ currency_code: "usd", amount: 100 }],
options: [{ value: "large" }, { value: "green" }],
},
{
title: "Test variant 2",
inventory_quantity: 10,
prices: [{ currency_code: "usd", amount: 100 }],
options: [{ value: "large" }, { value: "green" }],
},
],
},
{ headers: { "x-medusa-access-token": "test_token" } }
)
expect(response.status).toEqual(200)
const variantIds = response.data.product.variants.map(
(v: { id: string }) => v.id
)
const variantInventoryService = medusaContainer.resolve(
"productVariantInventoryService"
)
const inventory = await variantInventoryService.listByVariant(variantIds)
expect(inventory).toHaveLength(2)
expect(inventory).toContainEqual(
expect.objectContaining({
variant_id: variantIds[0],
required_quantity: 1,
})
)
expect(inventory).toContainEqual(
expect.objectContaining({
variant_id: variantIds[1],
required_quantity: 1,
})
)
})
})
describe("POST /admin/products/:id", () => {
const toUpdateWithSalesChannels = "to-update-with-sales-channels"
const toUpdateWithVariants = "to-update-with-variants"
const toUpdate = "to-update"
beforeEach(async () => {
await productSeeder(dbConnection)
await adminSeeder(dbConnection)
await createDefaultRuleTypes(medusaContainer)
await simpleSalesChannelFactory(dbConnection, {
name: "Default channel",
id: "default-channel",
is_default: true,
})
await simpleSalesChannelFactory(dbConnection, {
name: "Channel 3",
id: "channel-3",
is_default: true,
})
await simpleProductFactory(dbConnection, {
title: "To update product",
id: toUpdate,
})
await simpleProductFactory(dbConnection, {
title: "To update product with channels",
id: toUpdateWithSalesChannels,
sales_channels: [
{ name: "channel 1", id: "channel-1" },
{ name: "channel 2", id: "channel-2" },
],
})
await simpleSalesChannelFactory(dbConnection, {
name: "To be added",
id: "to-be-added",
})
await simpleProductFactory(dbConnection, {
title: "To update product with variants",
id: toUpdateWithVariants,
variants: [
{
id: "variant-1",
title: "Variant 1",
},
{
id: "variant-2",
title: "Variant 2",
},
],
})
})
afterEach(async () => {
const db = useDb()
await db.teardown()
})
it("should do a basic product update", async () => {
const api = useApi()! as AxiosInstance
const payload = {
title: "New title",
description: "test-product-description",
}
const response = await api
.post(`/admin/products/${toUpdate}`, payload, adminHeaders)
.catch((err) => {
console.log(err)
})
expect(response?.status).toEqual(200)
expect(response?.data.product).toEqual(
expect.objectContaining({
id: toUpdate,
title: "New title",
description: "test-product-description",
})
)
})
it("should update product and also update a variant and create a variant", async () => {
const api = useApi()! as AxiosInstance
const payload = {
title: "New title",
description: "test-product-description",
variants: [
{
id: "variant-1",
title: "Variant 1 updated",
},
{
title: "Variant 3",
},
],
}
const response = await api
.post(`/admin/products/${toUpdateWithVariants}`, payload, adminHeaders)
.catch((err) => {
console.log(err)
})
expect(response?.status).toEqual(200)
expect(response?.data.product).toEqual(
expect.objectContaining({
id: toUpdateWithVariants,
title: "New title",
description: "test-product-description",
variants: expect.arrayContaining([
expect.objectContaining({
id: "variant-1",
title: "Variant 1 updated",
}),
expect.objectContaining({
title: "Variant 3",
}),
]),
})
)
})
it("should update product's sales channels", async () => {
const api = useApi()! as AxiosInstance
const payload = {
title: "New title",
description: "test-product-description",
sales_channels: [{ id: "channel-2" }, { id: "channel-3" }],
}
const response = await api
.post(
`/admin/products/${toUpdateWithSalesChannels}?expand=sales_channels`,
payload,
adminHeaders
)
.catch((err) => {
console.log(err)
})
expect(response?.status).toEqual(200)
expect(response?.data.product).toEqual(
expect.objectContaining({
id: toUpdateWithSalesChannels,
sales_channels: [
expect.objectContaining({ id: "channel-2" }),
expect.objectContaining({ id: "channel-3" }),
],
})
)
})
it("should update inventory when variants are updated", async () => {
const api = useApi()! as AxiosInstance
const variantInventoryService = medusaContainer.resolve(
"productVariantInventoryService"
)
const payload = {
title: "New title",
description: "test-product-description",
variants: [
{
id: "variant-1",
title: "Variant 1 updated",
},
{
title: "Variant 3",
},
],
}
const response = await api
.post(`/admin/products/${toUpdateWithVariants}`, payload, adminHeaders)
.catch((err) => {
console.log(err)
})
let inventory = await variantInventoryService.listInventoryItemsByVariant(
"variant-2"
)
expect(response?.status).toEqual(200)
expect(response?.data.product).toEqual(
expect.objectContaining({
id: toUpdateWithVariants,
title: "New title",
description: "test-product-description",
variants: expect.arrayContaining([
expect.objectContaining({
id: "variant-1",
title: "Variant 1 updated",
}),
expect.objectContaining({
title: "Variant 3",
}),
]),
})
)
expect(inventory).toEqual([]) // no inventory items for removed variant
inventory = await variantInventoryService.listInventoryItemsByVariant(
response?.data.product.variants.find((v) => v.title === "Variant 3").id
)
expect(inventory).toEqual([
expect.objectContaining({ id: expect.any(String) }),
])
})
})
})
@@ -1,12 +1,11 @@
import {initDb, useDb} from "../../../../environment-helpers/use-db" import {initDb, useDb} from "../../../../environment-helpers/use-db"
import { import {simpleProductFactory, simpleRegionFactory,} from "../../../../factories"
simpleProductFactory,
simpleRegionFactory,
} from "../../../../factories"
import {AxiosInstance} from "axios" import {AxiosInstance} from "axios"
import adminSeeder from "../../../../helpers/admin-seeder" import adminSeeder from "../../../../helpers/admin-seeder"
import { createDefaultRuleTypes } from "../../../helpers/create-default-rule-types" import {
createDefaultRuleTypes
} from "../../../helpers/create-default-rule-types"
import {createVariantPriceSet} from "../../../helpers/create-variant-price-set" import {createVariantPriceSet} from "../../../helpers/create-variant-price-set"
import {getContainer} from "../../../../environment-helpers/use-container" import {getContainer} from "../../../../environment-helpers/use-container"
import path from "path" import path from "path"
@@ -25,6 +24,10 @@ const env = {
MEDUSA_FF_MEDUSA_V2: true, MEDUSA_FF_MEDUSA_V2: true,
} }
// TODO SEE to use new test runner medusaIntegrationTestRunner({
// env,
// testSuite: ({ dbConnection, getContainer, api }) => {})
describe.skip("POST /admin/products/:id/variants/:id", () => { describe.skip("POST /admin/products/:id/variants/:id", () => {
let dbConnection let dbConnection
let appContainer let appContainer
@@ -23,6 +23,10 @@ const env = {
MEDUSA_FF_MEDUSA_V2: true, MEDUSA_FF_MEDUSA_V2: true,
} }
// TODO SEE to use new test runner medusaIntegrationTestRunner({
// env,
// testSuite: ({ dbConnection, getContainer, api }) => {})
describe.skip("POST /admin/products/:id", () => { describe.skip("POST /admin/products/:id", () => {
let dbConnection let dbConnection
let appContainer let appContainer
@@ -1,12 +1,7 @@
import { initDb, useDb } from "../../../../environment-helpers/use-db"
import { IPromotionModuleService } from "@medusajs/types" import { IPromotionModuleService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { ModuleRegistrationName } from "@medusajs/modules-sdk"
import { createAdminUser } from "../../../helpers/create-admin-user" import { createAdminUser } from "../../../helpers/create-admin-user"
import { getContainer } from "../../../../environment-helpers/use-container" import { medusaIntegrationTestRunner } from "medusa-test-utils"
import path from "path"
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
import { useApi } from "../../../../environment-helpers/use-api"
jest.setTimeout(50000) jest.setTimeout(50000)
@@ -15,39 +10,25 @@ const adminHeaders = {
headers: { "x-medusa-access-token": "test_token" }, headers: { "x-medusa-access-token": "test_token" },
} }
medusaIntegrationTestRunner({
env,
testSuite: ({ dbConnection, getContainer, api }) => {
describe("POST /admin/campaigns", () => { describe("POST /admin/campaigns", () => {
let dbConnection
let appContainer let appContainer
let shutdownServer
let promotionModuleService: IPromotionModuleService let promotionModuleService: IPromotionModuleService
beforeAll(async () => { beforeAll(async () => {
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
dbConnection = await initDb({ cwd, env } as any)
shutdownServer = await startBootstrapApp({ cwd, env })
appContainer = getContainer() appContainer = getContainer()
promotionModuleService = appContainer.resolve( promotionModuleService = appContainer.resolve(
ModuleRegistrationName.PROMOTION ModuleRegistrationName.PROMOTION
) )
}) })
afterAll(async () => {
const db = useDb()
await db.shutdown()
await shutdownServer()
})
beforeEach(async () => { beforeEach(async () => {
await createAdminUser(dbConnection, adminHeaders) await createAdminUser(dbConnection, adminHeaders, appContainer)
})
afterEach(async () => {
const db = useDb()
await db.teardown()
}) })
it("should throw an error if required params are not passed", async () => { it("should throw an error if required params are not passed", async () => {
const api = useApi() as any
const { response } = await api const { response } = await api
.post(`/admin/campaigns`, {}, adminHeaders) .post(`/admin/campaigns`, {}, adminHeaders)
.catch((e) => e) .catch((e) => e)
@@ -64,7 +45,6 @@ describe("POST /admin/campaigns", () => {
type: "standard", type: "standard",
}) })
const api = useApi() as any
const response = await api.post( const response = await api.post(
`/admin/campaigns`, `/admin/campaigns`,
{ {
@@ -113,8 +93,6 @@ describe("POST /admin/campaigns", () => {
"createCampaigns" "createCampaigns"
) )
const api = useApi() as any
const a = async () => { const a = async () => {
return await api.post( return await api.post(
`/admin/campaigns`, `/admin/campaigns`,
@@ -196,3 +174,5 @@ describe("POST /admin/campaigns", () => {
expect(distinctRequestId).toContain("my-custom-request-id") expect(distinctRequestId).toContain("my-custom-request-id")
}) })
}) })
},
})
@@ -1,13 +1,8 @@
import { initDb, useDb } from "../../../../environment-helpers/use-db"
import { IPromotionModuleService } from "@medusajs/types" import { IPromotionModuleService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { ModuleRegistrationName } from "@medusajs/modules-sdk"
import { PromotionType } from "@medusajs/utils" import { PromotionType } from "@medusajs/utils"
import { createAdminUser } from "../../../helpers/create-admin-user" import { createAdminUser } from "../../../helpers/create-admin-user"
import { getContainer } from "../../../../environment-helpers/use-container" import { medusaIntegrationTestRunner } from "medusa-test-utils"
import path from "path"
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
import { useApi } from "../../../../environment-helpers/use-api"
jest.setTimeout(50000) jest.setTimeout(50000)
@@ -16,39 +11,25 @@ const adminHeaders = {
headers: { "x-medusa-access-token": "test_token" }, headers: { "x-medusa-access-token": "test_token" },
} }
medusaIntegrationTestRunner({
env,
testSuite: ({ dbConnection, getContainer, api }) => {
describe("POST /admin/promotions", () => { describe("POST /admin/promotions", () => {
let dbConnection
let appContainer let appContainer
let shutdownServer
let promotionModuleService: IPromotionModuleService let promotionModuleService: IPromotionModuleService
beforeAll(async () => { beforeAll(async () => {
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
dbConnection = await initDb({ cwd, env } as any)
shutdownServer = await startBootstrapApp({ cwd, env })
appContainer = getContainer() appContainer = getContainer()
promotionModuleService = appContainer.resolve( promotionModuleService = appContainer.resolve(
ModuleRegistrationName.PROMOTION ModuleRegistrationName.PROMOTION
) )
}) })
afterAll(async () => {
const db = useDb()
await db.shutdown()
await shutdownServer()
})
beforeEach(async () => { beforeEach(async () => {
await createAdminUser(dbConnection, adminHeaders) await createAdminUser(dbConnection, adminHeaders, appContainer)
})
afterEach(async () => {
const db = useDb()
await db.teardown()
}) })
it("should throw an error if required params are not passed", async () => { it("should throw an error if required params are not passed", async () => {
const api = useApi() as any
const { response } = await api const { response } = await api
.post( .post(
`/admin/promotions`, `/admin/promotions`,
@@ -66,7 +47,6 @@ describe("POST /admin/promotions", () => {
}) })
it("should create a standard promotion successfully", async () => { it("should create a standard promotion successfully", async () => {
const api = useApi() as any
const response = await api.post( const response = await api.post(
`/admin/promotions`, `/admin/promotions`,
{ {
@@ -153,7 +133,6 @@ describe("POST /admin/promotions", () => {
}) })
it("should throw an error if buy_rules params are not passed", async () => { it("should throw an error if buy_rules params are not passed", async () => {
const api = useApi() as any
const { response } = await api const { response } = await api
.post( .post(
`/admin/promotions`, `/admin/promotions`,
@@ -194,7 +173,6 @@ describe("POST /admin/promotions", () => {
}) })
it("should throw an error if buy_rules params are not passed", async () => { it("should throw an error if buy_rules params are not passed", async () => {
const api = useApi() as any
const { response } = await api const { response } = await api
.post( .post(
`/admin/promotions`, `/admin/promotions`,
@@ -235,7 +213,6 @@ describe("POST /admin/promotions", () => {
}) })
it("should create a buyget promotion successfully", async () => { it("should create a buyget promotion successfully", async () => {
const api = useApi() as any
const response = await api.post( const response = await api.post(
`/admin/promotions`, `/admin/promotions`,
{ {
@@ -342,3 +319,5 @@ describe("POST /admin/promotions", () => {
) )
}) })
}) })
},
})
@@ -1,12 +1,7 @@
import { initDb, useDb } from "../../../../environment-helpers/use-db"
import { IPromotionModuleService } from "@medusajs/types" import { IPromotionModuleService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { ModuleRegistrationName } from "@medusajs/modules-sdk"
import { createAdminUser } from "../../../helpers/create-admin-user" import { createAdminUser } from "../../../helpers/create-admin-user"
import { getContainer } from "../../../../environment-helpers/use-container" import { medusaIntegrationTestRunner } from "medusa-test-utils"
import path from "path"
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
import { useApi } from "../../../../environment-helpers/use-api"
jest.setTimeout(50000) jest.setTimeout(50000)
@@ -15,35 +10,22 @@ const adminHeaders = {
headers: { "x-medusa-access-token": "test_token" }, headers: { "x-medusa-access-token": "test_token" },
} }
medusaIntegrationTestRunner({
env,
testSuite: ({ dbConnection, getContainer, api }) => {
describe("DELETE /admin/campaigns/:id", () => { describe("DELETE /admin/campaigns/:id", () => {
let dbConnection
let appContainer let appContainer
let shutdownServer
let promotionModuleService: IPromotionModuleService let promotionModuleService: IPromotionModuleService
beforeAll(async () => { beforeAll(async () => {
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
dbConnection = await initDb({ cwd, env } as any)
shutdownServer = await startBootstrapApp({ cwd, env })
appContainer = getContainer() appContainer = getContainer()
promotionModuleService = appContainer.resolve( promotionModuleService = appContainer.resolve(
ModuleRegistrationName.PROMOTION ModuleRegistrationName.PROMOTION
) )
}) })
afterAll(async () => {
const db = useDb()
await db.shutdown()
await shutdownServer()
})
beforeEach(async () => { beforeEach(async () => {
await createAdminUser(dbConnection, adminHeaders) await createAdminUser(dbConnection, adminHeaders, appContainer)
})
afterEach(async () => {
const db = useDb()
await db.teardown()
}) })
it("should delete campaign successfully", async () => { it("should delete campaign successfully", async () => {
@@ -56,7 +38,6 @@ describe("DELETE /admin/campaigns/:id", () => {
}, },
]) ])
const api = useApi() as any
const deleteRes = await api.delete( const deleteRes = await api.delete(
`/admin/campaigns/${createdCampaign.id}`, `/admin/campaigns/${createdCampaign.id}`,
adminHeaders adminHeaders
@@ -71,3 +52,5 @@ describe("DELETE /admin/campaigns/:id", () => {
expect(campaigns.length).toEqual(0) expect(campaigns.length).toEqual(0)
}) })
}) })
},
})
@@ -1,12 +1,7 @@
import { initDb, useDb } from "../../../../environment-helpers/use-db"
import { IPromotionModuleService } from "@medusajs/types" import { IPromotionModuleService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { ModuleRegistrationName } from "@medusajs/modules-sdk"
import { createAdminUser } from "../../../helpers/create-admin-user" import { createAdminUser } from "../../../helpers/create-admin-user"
import { getContainer } from "../../../../environment-helpers/use-container" import { medusaIntegrationTestRunner } from "medusa-test-utils"
import path from "path"
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
import { useApi } from "../../../../environment-helpers/use-api"
jest.setTimeout(50000) jest.setTimeout(50000)
@@ -15,35 +10,22 @@ const adminHeaders = {
headers: { "x-medusa-access-token": "test_token" }, headers: { "x-medusa-access-token": "test_token" },
} }
medusaIntegrationTestRunner({
env,
testSuite: ({ dbConnection, getContainer, api }) => {
describe("DELETE /admin/promotions/:id", () => { describe("DELETE /admin/promotions/:id", () => {
let dbConnection
let appContainer let appContainer
let shutdownServer
let promotionModuleService: IPromotionModuleService let promotionModuleService: IPromotionModuleService
beforeAll(async () => { beforeAll(async () => {
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
dbConnection = await initDb({ cwd, env } as any)
shutdownServer = await startBootstrapApp({ cwd, env })
appContainer = getContainer() appContainer = getContainer()
promotionModuleService = appContainer.resolve( promotionModuleService = appContainer.resolve(
ModuleRegistrationName.PROMOTION ModuleRegistrationName.PROMOTION
) )
}) })
afterAll(async () => {
const db = useDb()
await db.shutdown()
await shutdownServer()
})
beforeEach(async () => { beforeEach(async () => {
await createAdminUser(dbConnection, adminHeaders) await createAdminUser(dbConnection, adminHeaders, appContainer)
})
afterEach(async () => {
const db = useDb()
await db.teardown()
}) })
it("should delete promotion successfully", async () => { it("should delete promotion successfully", async () => {
@@ -57,7 +39,6 @@ describe("DELETE /admin/promotions/:id", () => {
}, },
}) })
const api = useApi() as any
const deleteRes = await api.delete( const deleteRes = await api.delete(
`/admin/promotions/${createdPromotion.id}`, `/admin/promotions/${createdPromotion.id}`,
adminHeaders adminHeaders
@@ -72,3 +53,5 @@ describe("DELETE /admin/promotions/:id", () => {
expect(promotions.length).toEqual(0) expect(promotions.length).toEqual(0)
}) })
}) })
},
})
@@ -1,13 +1,8 @@
import { initDb, useDb } from "../../../../environment-helpers/use-db"
import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { ModuleRegistrationName } from "@medusajs/modules-sdk"
import { IPromotionModuleService } from "@medusajs/types" import { IPromotionModuleService } from "@medusajs/types"
import { CampaignBudgetType } from "@medusajs/utils" import { CampaignBudgetType } from "@medusajs/utils"
import path from "path"
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
import { useApi } from "../../../../environment-helpers/use-api"
import { getContainer } from "../../../../environment-helpers/use-container"
import { createAdminUser } from "../../../helpers/create-admin-user" import { createAdminUser } from "../../../helpers/create-admin-user"
import { medusaIntegrationTestRunner } from "medusa-test-utils"
jest.setTimeout(50000) jest.setTimeout(50000)
@@ -47,40 +42,26 @@ const adminHeaders = {
headers: { "x-medusa-access-token": "test_token" }, headers: { "x-medusa-access-token": "test_token" },
} }
medusaIntegrationTestRunner({
env,
testSuite: ({ dbConnection, getContainer, api }) => {
describe("GET /admin/campaigns", () => { describe("GET /admin/campaigns", () => {
let dbConnection
let appContainer let appContainer
let shutdownServer
let promotionModuleService: IPromotionModuleService let promotionModuleService: IPromotionModuleService
beforeAll(async () => { beforeAll(async () => {
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
dbConnection = await initDb({ cwd, env } as any)
shutdownServer = await startBootstrapApp({ cwd, env })
appContainer = getContainer() appContainer = getContainer()
promotionModuleService = appContainer.resolve( promotionModuleService = appContainer.resolve(
ModuleRegistrationName.PROMOTION ModuleRegistrationName.PROMOTION
) )
}) })
afterAll(async () => {
const db = useDb()
await db.shutdown()
await shutdownServer()
})
beforeEach(async () => { beforeEach(async () => {
await createAdminUser(dbConnection, adminHeaders) await createAdminUser(dbConnection, adminHeaders, appContainer)
await promotionModuleService.createCampaigns(campaignsData) await promotionModuleService.createCampaigns(campaignsData)
}) })
afterEach(async () => {
const db = useDb()
await db.teardown()
})
it("should get all campaigns and its count", async () => { it("should get all campaigns and its count", async () => {
const api = useApi() as any
const response = await api.get(`/admin/campaigns`, adminHeaders) const response = await api.get(`/admin/campaigns`, adminHeaders)
expect(response.status).toEqual(200) expect(response.status).toEqual(200)
@@ -152,7 +133,6 @@ describe("GET /admin/campaigns", () => {
}) })
it("should get all campaigns and its count filtered", async () => { it("should get all campaigns and its count filtered", async () => {
const api = useApi() as any
const response = await api.get( const response = await api.get(
`/admin/campaigns?fields=name,created_at,budget.id`, `/admin/campaigns?fields=name,created_at,budget.id`,
adminHeaders adminHeaders
@@ -184,3 +164,5 @@ describe("GET /admin/campaigns", () => {
) )
}) })
}) })
},
})
@@ -1,13 +1,8 @@
import { initDb, useDb } from "../../../../environment-helpers/use-db"
import { IPromotionModuleService } from "@medusajs/types" import { IPromotionModuleService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { ModuleRegistrationName } from "@medusajs/modules-sdk"
import { PromotionType } from "@medusajs/utils" import { PromotionType } from "@medusajs/utils"
import { createAdminUser } from "../../../helpers/create-admin-user" import { createAdminUser } from "../../../helpers/create-admin-user"
import { getContainer } from "../../../../environment-helpers/use-container" import { medusaIntegrationTestRunner } from "medusa-test-utils"
import path from "path"
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
import { useApi } from "../../../../environment-helpers/use-api"
jest.setTimeout(50000) jest.setTimeout(50000)
@@ -16,35 +11,22 @@ const adminHeaders = {
headers: { "x-medusa-access-token": "test_token" }, headers: { "x-medusa-access-token": "test_token" },
} }
medusaIntegrationTestRunner({
env,
testSuite: ({ dbConnection, getContainer, api }) => {
describe("GET /admin/promotions", () => { describe("GET /admin/promotions", () => {
let dbConnection
let appContainer let appContainer
let shutdownServer
let promotionModuleService: IPromotionModuleService let promotionModuleService: IPromotionModuleService
beforeAll(async () => { beforeAll(async () => {
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
dbConnection = await initDb({ cwd, env } as any)
shutdownServer = await startBootstrapApp({ cwd, env })
appContainer = getContainer() appContainer = getContainer()
promotionModuleService = appContainer.resolve( promotionModuleService = appContainer.resolve(
ModuleRegistrationName.PROMOTION ModuleRegistrationName.PROMOTION
) )
}) })
afterAll(async () => {
const db = useDb()
await db.shutdown()
await shutdownServer()
})
beforeEach(async () => { beforeEach(async () => {
await createAdminUser(dbConnection, adminHeaders) await createAdminUser(dbConnection, adminHeaders, appContainer)
})
afterEach(async () => {
const db = useDb()
await db.teardown()
}) })
it("should get all promotions and its count", async () => { it("should get all promotions and its count", async () => {
@@ -60,7 +42,6 @@ describe("GET /admin/promotions", () => {
}, },
]) ])
const api = useApi() as any
const response = await api.get(`/admin/promotions`, adminHeaders) const response = await api.get(`/admin/promotions`, adminHeaders)
expect(response.status).toEqual(200) expect(response.status).toEqual(200)
@@ -102,7 +83,6 @@ describe("GET /admin/promotions", () => {
}, },
]) ])
const api = useApi() as any
const response = await api.get( const response = await api.get(
`/admin/promotions?fields=code,created_at,application_method.id`, `/admin/promotions?fields=code,created_at,application_method.id`,
adminHeaders adminHeaders
@@ -123,3 +103,5 @@ describe("GET /admin/promotions", () => {
]) ])
}) })
}) })
},
})
@@ -1,13 +1,8 @@
import { initDb, useDb } from "../../../../environment-helpers/use-db"
import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { ModuleRegistrationName } from "@medusajs/modules-sdk"
import { IPromotionModuleService } from "@medusajs/types" import { IPromotionModuleService } from "@medusajs/types"
import { CampaignBudgetType } from "@medusajs/utils" import { CampaignBudgetType } from "@medusajs/utils"
import path from "path"
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
import { useApi } from "../../../../environment-helpers/use-api"
import { getContainer } from "../../../../environment-helpers/use-container"
import { createAdminUser } from "../../../helpers/create-admin-user" import { createAdminUser } from "../../../helpers/create-admin-user"
import { medusaIntegrationTestRunner } from "medusa-test-utils"
jest.setTimeout(50000) jest.setTimeout(50000)
@@ -30,43 +25,25 @@ const adminHeaders = {
headers: { "x-medusa-access-token": "test_token" }, headers: { "x-medusa-access-token": "test_token" },
} }
medusaIntegrationTestRunner({
env,
testSuite: ({ dbConnection, getContainer, api }) => {
describe("GET /admin/campaigns", () => { describe("GET /admin/campaigns", () => {
let dbConnection
let appContainer let appContainer
let shutdownServer
let promotionModuleService: IPromotionModuleService let promotionModuleService: IPromotionModuleService
beforeAll(async () => { beforeAll(async () => {
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
dbConnection = await initDb({ cwd, env } as any)
shutdownServer = await startBootstrapApp({ cwd, env })
appContainer = getContainer() appContainer = getContainer()
promotionModuleService = appContainer.resolve( promotionModuleService = appContainer.resolve(
ModuleRegistrationName.PROMOTION ModuleRegistrationName.PROMOTION
) )
}) })
afterAll(async () => {
const db = useDb()
await db.shutdown()
await shutdownServer()
})
beforeEach(async () => { beforeEach(async () => {
await createAdminUser(dbConnection, adminHeaders) await createAdminUser(dbConnection, adminHeaders, appContainer)
}) })
afterEach(async () => {
const db = useDb()
await db.teardown()
})
let campaigns
beforeEach(async () => {})
it("should throw an error if id does not exist", async () => { it("should throw an error if id does not exist", async () => {
const api = useApi() as any
const { response } = await api const { response } = await api
.get(`/admin/campaigns/does-not-exist`, adminHeaders) .get(`/admin/campaigns/does-not-exist`, adminHeaders)
.catch((e) => e) .catch((e) => e)
@@ -82,7 +59,6 @@ describe("GET /admin/campaigns", () => {
campaignData campaignData
) )
const api = useApi() as any
const response = await api.get( const response = await api.get(
`/admin/campaigns/${createdCampaign.id}`, `/admin/campaigns/${createdCampaign.id}`,
adminHeaders adminHeaders
@@ -126,7 +102,6 @@ describe("GET /admin/campaigns", () => {
campaignData campaignData
) )
const api = useApi() as any
const response = await api.get( const response = await api.get(
`/admin/campaigns/${createdCampaign.id}?fields=name&expand=`, `/admin/campaigns/${createdCampaign.id}?fields=name&expand=`,
adminHeaders adminHeaders
@@ -139,3 +114,5 @@ describe("GET /admin/campaigns", () => {
}) })
}) })
}) })
},
})
@@ -1,13 +1,8 @@
import { initDb, useDb } from "../../../../environment-helpers/use-db"
import { IPromotionModuleService } from "@medusajs/types" import { IPromotionModuleService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { ModuleRegistrationName } from "@medusajs/modules-sdk"
import { PromotionType } from "@medusajs/utils" import { PromotionType } from "@medusajs/utils"
import { createAdminUser } from "../../../helpers/create-admin-user" import { createAdminUser } from "../../../helpers/create-admin-user"
import { getContainer } from "../../../../environment-helpers/use-container" import { medusaIntegrationTestRunner } from "medusa-test-utils"
import path from "path"
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
import { useApi } from "../../../../environment-helpers/use-api"
jest.setTimeout(50000) jest.setTimeout(50000)
@@ -16,39 +11,25 @@ const adminHeaders = {
headers: { "x-medusa-access-token": "test_token" }, headers: { "x-medusa-access-token": "test_token" },
} }
medusaIntegrationTestRunner({
env,
testSuite: ({ dbConnection, getContainer, api }) => {
describe("GET /admin/promotions", () => { describe("GET /admin/promotions", () => {
let dbConnection
let appContainer let appContainer
let shutdownServer
let promotionModuleService: IPromotionModuleService let promotionModuleService: IPromotionModuleService
beforeAll(async () => { beforeAll(async () => {
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
dbConnection = await initDb({ cwd, env } as any)
shutdownServer = await startBootstrapApp({ cwd, env })
appContainer = getContainer() appContainer = getContainer()
promotionModuleService = appContainer.resolve( promotionModuleService = appContainer.resolve(
ModuleRegistrationName.PROMOTION ModuleRegistrationName.PROMOTION
) )
}) })
afterAll(async () => {
const db = useDb()
await db.shutdown()
await shutdownServer()
})
beforeEach(async () => { beforeEach(async () => {
await createAdminUser(dbConnection, adminHeaders) await createAdminUser(dbConnection, adminHeaders, appContainer)
})
afterEach(async () => {
const db = useDb()
await db.teardown()
}) })
it("should throw an error if id does not exist", async () => { it("should throw an error if id does not exist", async () => {
const api = useApi() as any
const { response } = await api const { response } = await api
.get(`/admin/promotions/does-not-exist`, adminHeaders) .get(`/admin/promotions/does-not-exist`, adminHeaders)
.catch((e) => e) .catch((e) => e)
@@ -70,7 +51,6 @@ describe("GET /admin/promotions", () => {
}, },
}) })
const api = useApi() as any
const response = await api.get( const response = await api.get(
`/admin/promotions/${createdPromotion.id}`, `/admin/promotions/${createdPromotion.id}`,
adminHeaders adminHeaders
@@ -114,7 +94,6 @@ describe("GET /admin/promotions", () => {
}, },
}) })
const api = useApi() as any
const response = await api.get( const response = await api.get(
`/admin/promotions/${createdPromotion.id}?fields=id,code&expand=`, `/admin/promotions/${createdPromotion.id}?fields=id,code&expand=`,
adminHeaders adminHeaders
@@ -127,3 +106,5 @@ describe("GET /admin/promotions", () => {
}) })
}) })
}) })
},
})
@@ -1,12 +1,7 @@
import { initDb, useDb } from "../../../../environment-helpers/use-db"
import { IPromotionModuleService } from "@medusajs/types" import { IPromotionModuleService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { ModuleRegistrationName } from "@medusajs/modules-sdk"
import { createAdminUser } from "../../../helpers/create-admin-user" import { createAdminUser } from "../../../helpers/create-admin-user"
import { getContainer } from "../../../../environment-helpers/use-container" import { medusaIntegrationTestRunner } from "medusa-test-utils"
import path from "path"
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
import { useApi } from "../../../../environment-helpers/use-api"
jest.setTimeout(50000) jest.setTimeout(50000)
@@ -15,39 +10,25 @@ const adminHeaders = {
headers: { "x-medusa-access-token": "test_token" }, headers: { "x-medusa-access-token": "test_token" },
} }
medusaIntegrationTestRunner({
env,
testSuite: ({ dbConnection, getContainer, api }) => {
describe("POST /admin/campaigns/:id", () => { describe("POST /admin/campaigns/:id", () => {
let dbConnection
let appContainer let appContainer
let shutdownServer
let promotionModuleService: IPromotionModuleService let promotionModuleService: IPromotionModuleService
beforeAll(async () => { beforeAll(async () => {
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
dbConnection = await initDb({ cwd, env } as any)
shutdownServer = await startBootstrapApp({ cwd, env })
appContainer = getContainer() appContainer = getContainer()
promotionModuleService = appContainer.resolve( promotionModuleService = appContainer.resolve(
ModuleRegistrationName.PROMOTION ModuleRegistrationName.PROMOTION
) )
}) })
afterAll(async () => {
const db = useDb()
await db.shutdown()
await shutdownServer()
})
beforeEach(async () => { beforeEach(async () => {
await createAdminUser(dbConnection, adminHeaders) await createAdminUser(dbConnection, adminHeaders, appContainer)
})
afterEach(async () => {
const db = useDb()
await db.teardown()
}) })
it("should throw an error if id does not exist", async () => { it("should throw an error if id does not exist", async () => {
const api = useApi() as any
const { response } = await api const { response } = await api
.post(`/admin/campaigns/does-not-exist`, {}, adminHeaders) .post(`/admin/campaigns/does-not-exist`, {}, adminHeaders)
.catch((e) => e) .catch((e) => e)
@@ -82,7 +63,6 @@ describe("POST /admin/campaigns/:id", () => {
}, },
}) })
const api = useApi() as any
const response = await api.post( const response = await api.post(
`/admin/campaigns/${createdCampaign.id}`, `/admin/campaigns/${createdCampaign.id}`,
{ {
@@ -116,3 +96,5 @@ describe("POST /admin/campaigns/:id", () => {
) )
}) })
}) })
},
})
@@ -1,13 +1,8 @@
import { initDb, useDb } from "../../../../environment-helpers/use-db"
import { IPromotionModuleService } from "@medusajs/types" import { IPromotionModuleService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { ModuleRegistrationName } from "@medusajs/modules-sdk"
import { PromotionType } from "@medusajs/utils" import { PromotionType } from "@medusajs/utils"
import { createAdminUser } from "../../../helpers/create-admin-user" import { createAdminUser } from "../../../helpers/create-admin-user"
import { getContainer } from "../../../../environment-helpers/use-container" import { medusaIntegrationTestRunner } from "medusa-test-utils"
import path from "path"
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
import { useApi } from "../../../../environment-helpers/use-api"
jest.setTimeout(50000) jest.setTimeout(50000)
@@ -16,39 +11,25 @@ const adminHeaders = {
headers: { "x-medusa-access-token": "test_token" }, headers: { "x-medusa-access-token": "test_token" },
} }
medusaIntegrationTestRunner({
env,
testSuite: ({ dbConnection, getContainer, api }) => {
describe("POST /admin/promotions/:id", () => { describe("POST /admin/promotions/:id", () => {
let dbConnection
let appContainer let appContainer
let shutdownServer
let promotionModuleService: IPromotionModuleService let promotionModuleService: IPromotionModuleService
beforeAll(async () => { beforeAll(async () => {
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
dbConnection = await initDb({ cwd, env } as any)
shutdownServer = await startBootstrapApp({ cwd, env })
appContainer = getContainer() appContainer = getContainer()
promotionModuleService = appContainer.resolve( promotionModuleService = appContainer.resolve(
ModuleRegistrationName.PROMOTION ModuleRegistrationName.PROMOTION
) )
}) })
afterAll(async () => {
const db = useDb()
await db.shutdown()
await shutdownServer()
})
beforeEach(async () => { beforeEach(async () => {
await createAdminUser(dbConnection, adminHeaders) await createAdminUser(dbConnection, adminHeaders, appContainer)
})
afterEach(async () => {
const db = useDb()
await db.teardown()
}) })
it("should throw an error if id does not exist", async () => { it("should throw an error if id does not exist", async () => {
const api = useApi() as any
const { response } = await api const { response } = await api
.post( .post(
`/admin/promotions/does-not-exist`, `/admin/promotions/does-not-exist`,
@@ -77,8 +58,6 @@ describe("POST /admin/promotions/:id", () => {
}, },
}) })
const api = useApi() as any
const { response } = await api const { response } = await api
.post( .post(
`/admin/promotions/${createdPromotion.id}`, `/admin/promotions/${createdPromotion.id}`,
@@ -112,7 +91,6 @@ describe("POST /admin/promotions/:id", () => {
}, },
}) })
const api = useApi() as any
const response = await api.post( const response = await api.post(
`/admin/promotions/${createdPromotion.id}`, `/admin/promotions/${createdPromotion.id}`,
{ {
@@ -164,7 +142,6 @@ describe("POST /admin/promotions/:id", () => {
}, },
}) })
const api = useApi() as any
const response = await api.post( const response = await api.post(
`/admin/promotions/${createdPromotion.id}`, `/admin/promotions/${createdPromotion.id}`,
{ {
@@ -190,3 +167,5 @@ describe("POST /admin/promotions/:id", () => {
) )
}) })
}) })
},
})
@@ -1,11 +1,7 @@
import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { ModuleRegistrationName } from "@medusajs/modules-sdk"
import { IRegionModuleService } from "@medusajs/types" import { IRegionModuleService } from "@medusajs/types"
import path from "path"
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
import { useApi } from "../../../../environment-helpers/use-api"
import { getContainer } from "../../../../environment-helpers/use-container"
import { initDb, useDb } from "../../../../environment-helpers/use-db"
import { createAdminUser } from "../../../helpers/create-admin-user" import { createAdminUser } from "../../../helpers/create-admin-user"
import { medusaIntegrationTestRunner } from "medusa-test-utils"
jest.setTimeout(50000) jest.setTimeout(50000)
@@ -14,40 +10,29 @@ const adminHeaders = {
headers: { "x-medusa-access-token": "test_token" }, headers: { "x-medusa-access-token": "test_token" },
} }
medusaIntegrationTestRunner({
env,
testSuite: ({ dbConnection, getContainer, api }) => {
describe("Regions - Admin", () => { describe("Regions - Admin", () => {
let dbConnection
let appContainer let appContainer
let shutdownServer
let service: IRegionModuleService let service: IRegionModuleService
beforeAll(async () => { beforeAll(async () => {
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
dbConnection = await initDb({ cwd, env } as any)
shutdownServer = await startBootstrapApp({ cwd, env })
appContainer = getContainer() appContainer = getContainer()
service = appContainer.resolve(ModuleRegistrationName.REGION) service = appContainer.resolve(ModuleRegistrationName.REGION)
}) })
afterAll(async () => {
const db = useDb()
await db.shutdown()
await shutdownServer()
})
beforeEach(async () => { beforeEach(async () => {
await createAdminUser(dbConnection, adminHeaders) await createAdminUser(dbConnection, adminHeaders, appContainer)
}) })
afterEach(async () => { afterEach(async () => {
const db = useDb()
// TODO: Once teardown doesn't skip constraint checks and cascades, we can remove this // TODO: Once teardown doesn't skip constraint checks and cascades, we can remove this
const existingRegions = await service.list({}) const existingRegions = await service.list({})
await service.delete(existingRegions.map((r) => r.id)) await service.delete(existingRegions.map((r) => r.id))
await db.teardown()
}) })
it("should create, update, and delete a region", async () => { it("should create, update, and delete a region", async () => {
const api = useApi() as any
const created = await api.post( const created = await api.post(
`/admin/regions`, `/admin/regions`,
{ {
@@ -93,7 +78,9 @@ describe("Regions - Admin", () => {
metadata: { foo: "baz" }, metadata: { foo: "baz" },
}) })
) )
expect(updated.data.region.countries.map((c) => c.iso_2)).toEqual(["us"]) expect(updated.data.region.countries.map((c) => c.iso_2)).toEqual([
"us",
])
const deleted = await api.delete( const deleted = await api.delete(
`/admin/regions/${updated.data.region.id}`, `/admin/regions/${updated.data.region.id}`,
@@ -116,7 +103,6 @@ describe("Regions - Admin", () => {
}) })
it("should throw on missing required properties in create", async () => { it("should throw on missing required properties in create", async () => {
const api = useApi() as any
const err = await api const err = await api
.post(`/admin/regions`, {}, adminHeaders) .post(`/admin/regions`, {}, adminHeaders)
.catch((e) => e) .catch((e) => e)
@@ -128,7 +114,6 @@ describe("Regions - Admin", () => {
}) })
it("should throw on unknown properties in create", async () => { it("should throw on unknown properties in create", async () => {
const api = useApi() as any
const error = await api const error = await api
.post( .post(
`/admin/regions`, `/admin/regions`,
@@ -142,12 +127,12 @@ describe("Regions - Admin", () => {
.catch((e) => e) .catch((e) => e)
expect(error.response.status).toEqual(400) expect(error.response.status).toEqual(400)
expect(error.response.data.message).toEqual("property foo should not exist") expect(error.response.data.message).toEqual(
"property foo should not exist"
)
}) })
it("should throw on unknown properties in update", async () => { it("should throw on unknown properties in update", async () => {
const api = useApi() as any
const created = await service.create({ const created = await service.create({
name: "Test Region", name: "Test Region",
currency_code: "usd", currency_code: "usd",
@@ -166,7 +151,9 @@ describe("Regions - Admin", () => {
.catch((e) => e) .catch((e) => e)
expect(error.response.status).toEqual(400) expect(error.response.status).toEqual(400)
expect(error.response.data.message).toEqual("property foo should not exist") expect(error.response.data.message).toEqual(
"property foo should not exist"
)
}) })
it("should get all regions and count", async () => { it("should get all regions and count", async () => {
@@ -179,7 +166,6 @@ describe("Regions - Admin", () => {
}, },
]) ])
const api = useApi() as any
const response = await api.get(`/admin/regions`, adminHeaders) const response = await api.get(`/admin/regions`, adminHeaders)
expect(response.status).toEqual(200) expect(response.status).toEqual(200)
@@ -206,8 +192,10 @@ describe("Regions - Admin", () => {
}, },
]) ])
const api = useApi() as any const response = await api.get(
const response = await api.get(`/admin/regions/${region.id}`, adminHeaders) `/admin/regions/${region.id}`,
adminHeaders
)
expect(response.status).toEqual(200) expect(response.status).toEqual(200)
expect(response.data.region).toEqual( expect(response.data.region).toEqual(
@@ -218,6 +206,10 @@ describe("Regions - Admin", () => {
metadata: { foo: "bar" }, metadata: { foo: "bar" },
}) })
) )
expect(response.data.region.countries.map((c) => c.iso_2)).toEqual(["jp"]) expect(response.data.region.countries.map((c) => c.iso_2)).toEqual([
"jp",
])
}) })
}) })
},
})
@@ -1,12 +1,7 @@
import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { ModuleRegistrationName } from "@medusajs/modules-sdk"
import { IStoreModuleService } from "@medusajs/types" import { IStoreModuleService } from "@medusajs/types"
import path from "path"
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
import { useApi } from "../../../../environment-helpers/use-api"
import { getContainer } from "../../../../environment-helpers/use-container"
import { initDb, useDb } from "../../../../environment-helpers/use-db"
import { DataSource } from "typeorm"
import { createAdminUser } from "../../../helpers/create-admin-user" import { createAdminUser } from "../../../helpers/create-admin-user"
import { medusaIntegrationTestRunner } from "medusa-test-utils"
jest.setTimeout(50000) jest.setTimeout(50000)
@@ -15,37 +10,23 @@ const adminHeaders = {
headers: { "x-medusa-access-token": "test_token" }, headers: { "x-medusa-access-token": "test_token" },
} }
medusaIntegrationTestRunner({
env,
testSuite: ({ dbConnection, getContainer, api }) => {
describe("Store - Admin", () => { describe("Store - Admin", () => {
let dbConnection: DataSource
let appContainer let appContainer
let shutdownServer
let service: IStoreModuleService let service: IStoreModuleService
beforeAll(async () => { beforeAll(async () => {
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
dbConnection = await initDb({ cwd, env } as any)
shutdownServer = await startBootstrapApp({ cwd, env })
appContainer = getContainer() appContainer = getContainer()
service = appContainer.resolve(ModuleRegistrationName.STORE) service = appContainer.resolve(ModuleRegistrationName.STORE)
}) })
afterAll(async () => {
const db = useDb()
await db.shutdown()
await shutdownServer()
})
beforeEach(async () => { beforeEach(async () => {
await createAdminUser(dbConnection, adminHeaders) await createAdminUser(dbConnection, adminHeaders, appContainer)
})
afterEach(async () => {
const db = useDb()
await db.teardown()
}) })
it("should correctly implement the entire lifecycle of a store", async () => { it("should correctly implement the entire lifecycle of a store", async () => {
const api = useApi() as any
const createdStore = await service.create({ const createdStore = await service.create({
name: "Test store", name: "Test store",
supported_currency_codes: ["usd"], supported_currency_codes: ["usd"],
@@ -80,3 +61,5 @@ describe("Store - Admin", () => {
expect(listedStores.data.stores).toHaveLength(0) expect(listedStores.data.stores).toHaveLength(0)
}) })
}) })
},
})
@@ -1,12 +1,8 @@
import path from "path"
import { ITaxModuleService } from "@medusajs/types" import { ITaxModuleService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { ModuleRegistrationName } from "@medusajs/modules-sdk"
import { createAdminUser } from "../../../helpers/create-admin-user" import { createAdminUser } from "../../../helpers/create-admin-user"
import { initDb, useDb } from "../../../../environment-helpers/use-db" import { medusaIntegrationTestRunner } from "medusa-test-utils"
import { getContainer } from "../../../../environment-helpers/use-container"
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
import { useApi } from "../../../../environment-helpers/use-api"
jest.setTimeout(50000) jest.setTimeout(50000)
@@ -15,33 +11,20 @@ const adminHeaders = {
headers: { "x-medusa-access-token": "test_token" }, headers: { "x-medusa-access-token": "test_token" },
} }
medusaIntegrationTestRunner({
env,
testSuite: ({ dbConnection, getContainer, api }) => {
describe("Taxes - Admin", () => { describe("Taxes - Admin", () => {
let dbConnection
let appContainer let appContainer
let shutdownServer
let service: ITaxModuleService let service: ITaxModuleService
beforeAll(async () => { beforeAll(async () => {
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
dbConnection = await initDb({ cwd, env } as any)
shutdownServer = await startBootstrapApp({ cwd, env })
appContainer = getContainer() appContainer = getContainer()
service = appContainer.resolve(ModuleRegistrationName.TAX) service = appContainer.resolve(ModuleRegistrationName.TAX)
}) })
beforeEach(async () => { beforeEach(async () => {
await createAdminUser(dbConnection, adminHeaders) await createAdminUser(dbConnection, adminHeaders, appContainer)
})
afterAll(async () => {
const db = useDb()
await db.shutdown()
await shutdownServer()
})
afterEach(async () => {
const db = useDb()
await db.teardown()
}) })
it("can retrieve a tax rate", async () => { it("can retrieve a tax rate", async () => {
@@ -55,8 +38,10 @@ describe("Taxes - Admin", () => {
name: "Test Rate", name: "Test Rate",
}) })
const api = useApi() as any const response = await api.get(
const response = await api.get(`/admin/tax-rates/${rate.id}`, adminHeaders) `/admin/tax-rates/${rate.id}`,
adminHeaders
)
expect(response.status).toEqual(200) expect(response.status).toEqual(200)
expect(response.data).toEqual({ expect(response.data).toEqual({
@@ -78,7 +63,6 @@ describe("Taxes - Admin", () => {
}) })
it("can create a tax region with rates and rules", async () => { it("can create a tax region with rates and rules", async () => {
const api = useApi() as any
const regionRes = await api.post( const regionRes = await api.post(
`/admin/tax-regions`, `/admin/tax-regions`,
{ {
@@ -207,12 +191,15 @@ describe("Taxes - Admin", () => {
}) })
it("can create a tax rate and update it", async () => { it("can create a tax rate and update it", async () => {
const api = useApi() as any
const regionRes = await api.post( const regionRes = await api.post(
`/admin/tax-regions`, `/admin/tax-regions`,
{ {
country_code: "us", country_code: "us",
default_tax_rate: { code: "default", rate: 2, name: "default rate" }, default_tax_rate: {
code: "default",
rate: 2,
name: "default rate",
},
}, },
adminHeaders adminHeaders
) )
@@ -297,12 +284,15 @@ describe("Taxes - Admin", () => {
}) })
it("can create a tax rate and delete it", async () => { it("can create a tax rate and delete it", async () => {
const api = useApi() as any
const regionRes = await api.post( const regionRes = await api.post(
`/admin/tax-regions`, `/admin/tax-regions`,
{ {
country_code: "us", country_code: "us",
default_tax_rate: { code: "default", rate: 2, name: "default rate" }, default_tax_rate: {
code: "default",
rate: 2,
name: "default rate",
},
}, },
adminHeaders adminHeaders
) )
@@ -342,12 +332,15 @@ describe("Taxes - Admin", () => {
}) })
it("can create a tax region and delete it", async () => { it("can create a tax region and delete it", async () => {
const api = useApi() as any
const regionRes = await api.post( const regionRes = await api.post(
`/admin/tax-regions`, `/admin/tax-regions`,
{ {
country_code: "us", country_code: "us",
default_tax_rate: { code: "default", rate: 2, name: "default rate" }, default_tax_rate: {
code: "default",
rate: 2,
name: "default rate",
},
}, },
adminHeaders adminHeaders
) )
@@ -375,12 +368,15 @@ describe("Taxes - Admin", () => {
}) })
it("can create a tax rate add rules and remove them", async () => { it("can create a tax rate add rules and remove them", async () => {
const api = useApi() as any
const regionRes = await api.post( const regionRes = await api.post(
`/admin/tax-regions`, `/admin/tax-regions`,
{ {
country_code: "us", country_code: "us",
default_tax_rate: { code: "default", rate: 2, name: "default rate" }, default_tax_rate: {
code: "default",
rate: 2,
name: "default rate",
},
}, },
adminHeaders adminHeaders
) )
@@ -509,3 +505,5 @@ describe("Taxes - Admin", () => {
) )
}) })
}) })
},
})
@@ -1,18 +1,12 @@
import path from "path"
import { ITaxModuleService } from "@medusajs/types" import { ITaxModuleService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { ModuleRegistrationName } from "@medusajs/modules-sdk"
import { createAdminUser } from "../../../helpers/create-admin-user" import { createAdminUser } from "../../../helpers/create-admin-user"
import { initDb, useDb } from "../../../../environment-helpers/use-db"
import { getContainer } from "../../../../environment-helpers/use-container"
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
import { useApi } from "../../../../environment-helpers/use-api"
import { import {
createTaxRateRulesStepId, createTaxRateRulesStepId,
maybeSetTaxRateRulesStepId,
updateTaxRatesStepId,
updateTaxRatesWorkflow, updateTaxRatesWorkflow,
} from "@medusajs/core-flows" } from "@medusajs/core-flows"
import { medusaIntegrationTestRunner } from "medusa-test-utils/dist"
jest.setTimeout(50000) jest.setTimeout(50000)
@@ -21,16 +15,14 @@ const adminHeaders = {
headers: { "x-medusa-access-token": "test_token" }, headers: { "x-medusa-access-token": "test_token" },
} }
medusaIntegrationTestRunner({
env,
testSuite: ({ dbConnection, getContainer, api }) => {
describe("Taxes - Workflow", () => { describe("Taxes - Workflow", () => {
let dbConnection
let appContainer let appContainer
let shutdownServer
let service: ITaxModuleService let service: ITaxModuleService
beforeAll(async () => { beforeAll(async () => {
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
dbConnection = await initDb({ cwd, env } as any)
shutdownServer = await startBootstrapApp({ cwd, env })
appContainer = getContainer() appContainer = getContainer()
service = appContainer.resolve(ModuleRegistrationName.TAX) service = appContainer.resolve(ModuleRegistrationName.TAX)
}) })
@@ -39,17 +31,6 @@ describe("Taxes - Workflow", () => {
await createAdminUser(dbConnection, adminHeaders) await createAdminUser(dbConnection, adminHeaders)
}) })
afterAll(async () => {
const db = useDb()
await db.shutdown()
await shutdownServer()
})
afterEach(async () => {
const db = useDb()
await db.teardown()
})
it("compensates rules correctly", async () => { it("compensates rules correctly", async () => {
const taxRegion = await service.createTaxRegions({ const taxRegion = await service.createTaxRegions({
country_code: "us", country_code: "us",
@@ -207,3 +188,5 @@ describe("Taxes - Workflow", () => {
) )
}) })
}) })
},
})
@@ -1,10 +1,5 @@
import { initDb, useDb } from "../../../environment-helpers/use-db"
import { AxiosInstance } from "axios"
import { createAdminUser } from "../../helpers/create-admin-user" import { createAdminUser } from "../../helpers/create-admin-user"
import path from "path" import { medusaIntegrationTestRunner } from "medusa-test-utils"
import { startBootstrapApp } from "../../../environment-helpers/bootstrap-app"
import { useApi } from "../../../environment-helpers/use-api"
jest.setTimeout(50000) jest.setTimeout(50000)
@@ -13,34 +8,15 @@ const adminHeaders = {
headers: { "x-medusa-access-token": "test_token" }, headers: { "x-medusa-access-token": "test_token" },
} }
medusaIntegrationTestRunner({
env,
testSuite: ({ dbConnection, getContainer, api }) => {
describe("POST /admin/users", () => { describe("POST /admin/users", () => {
let dbConnection
let shutdownServer
beforeAll(async () => {
const cwd = path.resolve(path.join(__dirname, "..", ".."))
dbConnection = await initDb({ cwd, env } as any)
shutdownServer = await startBootstrapApp({ cwd, env })
})
beforeEach(async () => { beforeEach(async () => {
await createAdminUser(dbConnection, adminHeaders) await createAdminUser(dbConnection, adminHeaders, getContainer())
})
afterAll(async () => {
const db = useDb()
await db.shutdown()
await shutdownServer()
})
afterEach(async () => {
const db = useDb()
await db.teardown()
}) })
it("create a user", async () => { it("create a user", async () => {
const api = useApi()! as AxiosInstance
const body = { const body = {
email: "test_member@test.com", email: "test_member@test.com",
} }
@@ -53,3 +29,5 @@ describe("POST /admin/users", () => {
}) })
}) })
}) })
},
})
@@ -1,13 +1,7 @@
import { initDb, useDb } from "../../../environment-helpers/use-db"
import { AxiosInstance } from "axios"
import { IUserModuleService } from "@medusajs/types" import { IUserModuleService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { ModuleRegistrationName } from "@medusajs/modules-sdk"
import { createAdminUser } from "../../helpers/create-admin-user" import { createAdminUser } from "../../helpers/create-admin-user"
import { getContainer } from "../../../environment-helpers/use-container" import { medusaIntegrationTestRunner } from "medusa-test-utils"
import path from "path"
import { startBootstrapApp } from "../../../environment-helpers/bootstrap-app"
import { useApi } from "../../../environment-helpers/use-api"
jest.setTimeout(50000) jest.setTimeout(50000)
@@ -16,33 +10,20 @@ const adminHeaders = {
headers: { "x-medusa-access-token": "test_token" }, headers: { "x-medusa-access-token": "test_token" },
} }
medusaIntegrationTestRunner({
env,
testSuite: ({ dbConnection, getContainer, api }) => {
describe("DELETE /admin/users/:id", () => { describe("DELETE /admin/users/:id", () => {
let dbConnection
let appContainer let appContainer
let shutdownServer
let userModuleService: IUserModuleService let userModuleService: IUserModuleService
beforeAll(async () => { beforeAll(async () => {
const cwd = path.resolve(path.join(__dirname, "..", ".."))
dbConnection = await initDb({ cwd, env } as any)
shutdownServer = await startBootstrapApp({ cwd, env })
appContainer = getContainer() appContainer = getContainer()
userModuleService = appContainer.resolve(ModuleRegistrationName.USER) userModuleService = appContainer.resolve(ModuleRegistrationName.USER)
}) })
beforeEach(async () => { beforeEach(async () => {
await createAdminUser(dbConnection, adminHeaders) await createAdminUser(dbConnection, adminHeaders, appContainer)
})
afterAll(async () => {
const db = useDb()
await db.shutdown()
await shutdownServer()
})
afterEach(async () => {
const db = useDb()
await db.teardown()
}) })
it("should delete a single user", async () => { it("should delete a single user", async () => {
@@ -50,9 +31,10 @@ describe("DELETE /admin/users/:id", () => {
email: "member@test.com", email: "member@test.com",
}) })
const api = useApi()! as AxiosInstance const response = await api.delete(
`/admin/users/${user.id}`,
const response = await api.delete(`/admin/users/${user.id}`, adminHeaders) adminHeaders
)
expect(response.status).toEqual(200) expect(response.status).toEqual(200)
expect(response.data).toEqual({ expect(response.data).toEqual({
@@ -69,3 +51,5 @@ describe("DELETE /admin/users/:id", () => {
expect(deletedResponse.data.type).toEqual("not_found") expect(deletedResponse.data.type).toEqual("not_found")
}) })
}) })
},
})
@@ -1,10 +1,5 @@
import { initDb, useDb } from "../../../environment-helpers/use-db"
import { AxiosInstance } from "axios"
import path from "path"
import { startBootstrapApp } from "../../../environment-helpers/bootstrap-app"
import { useApi } from "../../../environment-helpers/use-api"
import { createAdminUser } from "../../helpers/create-admin-user" import { createAdminUser } from "../../helpers/create-admin-user"
import { medusaIntegrationTestRunner } from "medusa-test-utils/dist"
jest.setTimeout(50000) jest.setTimeout(50000)
@@ -13,34 +8,15 @@ const adminHeaders = {
headers: { "x-medusa-access-token": "test_token" }, headers: { "x-medusa-access-token": "test_token" },
} }
medusaIntegrationTestRunner({
env,
testSuite: ({ dbConnection, getContainer, api }) => {
describe("POST /admin/users/me", () => { describe("POST /admin/users/me", () => {
let dbConnection
let shutdownServer
beforeAll(async () => {
const cwd = path.resolve(path.join(__dirname, "..", ".."))
dbConnection = await initDb({ cwd, env } as any)
shutdownServer = await startBootstrapApp({ cwd, env })
})
beforeEach(async () => { beforeEach(async () => {
await createAdminUser(dbConnection, adminHeaders) await createAdminUser(dbConnection, adminHeaders)
}) })
afterAll(async () => {
const db = useDb()
await db.shutdown()
await shutdownServer()
})
afterEach(async () => {
const db = useDb()
await db.teardown()
})
it("gets the current user", async () => { it("gets the current user", async () => {
const api = useApi()! as AxiosInstance
const response = await api.get(`/admin/users/me`, adminHeaders) const response = await api.get(`/admin/users/me`, adminHeaders)
expect(response.status).toEqual(200) expect(response.status).toEqual(200)
@@ -49,3 +25,5 @@ describe("POST /admin/users/me", () => {
}) })
}) })
}) })
},
})
@@ -1,13 +1,7 @@
import { initDb, useDb } from "../../../environment-helpers/use-db"
import { AxiosInstance } from "axios"
import { IUserModuleService } from "@medusajs/types" import { IUserModuleService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { ModuleRegistrationName } from "@medusajs/modules-sdk"
import { createAdminUser } from "../../helpers/create-admin-user" import { createAdminUser } from "../../helpers/create-admin-user"
import { getContainer } from "../../../environment-helpers/use-container" import { medusaIntegrationTestRunner } from "medusa-test-utils"
import path from "path"
import { startBootstrapApp } from "../../../environment-helpers/bootstrap-app"
import { useApi } from "../../../environment-helpers/use-api"
jest.setTimeout(50000) jest.setTimeout(50000)
@@ -16,33 +10,20 @@ const adminHeaders = {
headers: { "x-medusa-access-token": "test_token" }, headers: { "x-medusa-access-token": "test_token" },
} }
medusaIntegrationTestRunner({
env,
testSuite: ({ dbConnection, getContainer, api }) => {
describe("GET /admin/users", () => { describe("GET /admin/users", () => {
let dbConnection
let appContainer let appContainer
let shutdownServer
let userModuleService: IUserModuleService let userModuleService: IUserModuleService
beforeAll(async () => { beforeAll(async () => {
const cwd = path.resolve(path.join(__dirname, "..", ".."))
dbConnection = await initDb({ cwd, env } as any)
shutdownServer = await startBootstrapApp({ cwd, env })
appContainer = getContainer() appContainer = getContainer()
userModuleService = appContainer.resolve(ModuleRegistrationName.USER) userModuleService = appContainer.resolve(ModuleRegistrationName.USER)
}) })
beforeEach(async () => { beforeEach(async () => {
await createAdminUser(dbConnection, adminHeaders) await createAdminUser(dbConnection, adminHeaders, appContainer)
})
afterAll(async () => {
const db = useDb()
await db.shutdown()
await shutdownServer()
})
afterEach(async () => {
const db = useDb()
await db.teardown()
}) })
it("should list users", async () => { it("should list users", async () => {
@@ -52,8 +33,6 @@ describe("GET /admin/users", () => {
}, },
]) ])
const api = useApi()! as AxiosInstance
const response = await api.get(`/admin/users`, adminHeaders) const response = await api.get(`/admin/users`, adminHeaders)
expect(response.status).toEqual(200) expect(response.status).toEqual(200)
@@ -70,3 +49,5 @@ describe("GET /admin/users", () => {
}) })
}) })
}) })
},
})
@@ -1,13 +1,7 @@
import { initDb, useDb } from "../../../environment-helpers/use-db"
import { AxiosInstance } from "axios"
import { IUserModuleService } from "@medusajs/types" import { IUserModuleService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { ModuleRegistrationName } from "@medusajs/modules-sdk"
import { createAdminUser } from "../../helpers/create-admin-user" import { createAdminUser } from "../../helpers/create-admin-user"
import { getContainer } from "../../../environment-helpers/use-container" import { medusaIntegrationTestRunner } from "medusa-test-utils"
import path from "path"
import { startBootstrapApp } from "../../../environment-helpers/bootstrap-app"
import { useApi } from "../../../environment-helpers/use-api"
jest.setTimeout(50000) jest.setTimeout(50000)
@@ -16,33 +10,20 @@ const adminHeaders = {
headers: { "x-medusa-access-token": "test_token" }, headers: { "x-medusa-access-token": "test_token" },
} }
medusaIntegrationTestRunner({
env,
testSuite: ({ dbConnection, getContainer, api }) => {
describe("GET /admin/users/:id", () => { describe("GET /admin/users/:id", () => {
let dbConnection
let appContainer let appContainer
let shutdownServer
let userModuleService: IUserModuleService let userModuleService: IUserModuleService
beforeAll(async () => { beforeAll(async () => {
const cwd = path.resolve(path.join(__dirname, "..", ".."))
dbConnection = await initDb({ cwd, env } as any)
shutdownServer = await startBootstrapApp({ cwd, env })
appContainer = getContainer() appContainer = getContainer()
userModuleService = appContainer.resolve(ModuleRegistrationName.USER) userModuleService = appContainer.resolve(ModuleRegistrationName.USER)
}) })
beforeEach(async () => { beforeEach(async () => {
await createAdminUser(dbConnection, adminHeaders) await createAdminUser(dbConnection, adminHeaders, appContainer)
})
afterAll(async () => {
const db = useDb()
await db.shutdown()
await shutdownServer()
})
afterEach(async () => {
const db = useDb()
await db.teardown()
}) })
it("should retrieve a single user", async () => { it("should retrieve a single user", async () => {
@@ -50,8 +31,6 @@ describe("GET /admin/users/:id", () => {
email: "member@test.com", email: "member@test.com",
}) })
const api = useApi()! as AxiosInstance
const response = await api.get(`/admin/users/${user.id}`, adminHeaders) const response = await api.get(`/admin/users/${user.id}`, adminHeaders)
expect(response.status).toEqual(200) expect(response.status).toEqual(200)
@@ -60,3 +39,5 @@ describe("GET /admin/users/:id", () => {
) )
}) })
}) })
},
})
@@ -1,13 +1,7 @@
import { initDb, useDb } from "../../../environment-helpers/use-db"
import { AxiosInstance } from "axios"
import { IUserModuleService } from "@medusajs/types" import { IUserModuleService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { ModuleRegistrationName } from "@medusajs/modules-sdk"
import { createAdminUser } from "../../helpers/create-admin-user" import { createAdminUser } from "../../helpers/create-admin-user"
import { getContainer } from "../../../environment-helpers/use-container" import { medusaIntegrationTestRunner } from "medusa-test-utils"
import path from "path"
import { startBootstrapApp } from "../../../environment-helpers/bootstrap-app"
import { useApi } from "../../../environment-helpers/use-api"
jest.setTimeout(50000) jest.setTimeout(50000)
@@ -16,33 +10,20 @@ const adminHeaders = {
headers: { "x-medusa-access-token": "test_token" }, headers: { "x-medusa-access-token": "test_token" },
} }
medusaIntegrationTestRunner({
env,
testSuite: ({ dbConnection, getContainer, api }) => {
describe("POST /admin/users/:id", () => { describe("POST /admin/users/:id", () => {
let dbConnection
let appContainer let appContainer
let shutdownServer
let userModuleService: IUserModuleService let userModuleService: IUserModuleService
beforeAll(async () => { beforeAll(async () => {
const cwd = path.resolve(path.join(__dirname, "..", ".."))
dbConnection = await initDb({ cwd, env } as any)
shutdownServer = await startBootstrapApp({ cwd, env })
appContainer = getContainer() appContainer = getContainer()
userModuleService = appContainer.resolve(ModuleRegistrationName.USER) userModuleService = appContainer.resolve(ModuleRegistrationName.USER)
}) })
beforeEach(async () => { beforeEach(async () => {
await createAdminUser(dbConnection, adminHeaders) await createAdminUser(dbConnection, adminHeaders, appContainer)
})
afterAll(async () => {
const db = useDb()
await db.shutdown()
await shutdownServer()
})
afterEach(async () => {
const db = useDb()
await db.teardown()
}) })
it("should update a single user", async () => { it("should update a single user", async () => {
@@ -50,8 +31,6 @@ describe("POST /admin/users/:id", () => {
email: "member@test.com", email: "member@test.com",
}) })
const api = useApi()! as AxiosInstance
const body = { const body = {
first_name: "John", first_name: "John",
last_name: "Doe", last_name: "Doe",
@@ -66,3 +45,5 @@ describe("POST /admin/users/:id", () => {
expect(response.data.user).toEqual(expect.objectContaining(body)) expect(response.data.user).toEqual(expect.objectContaining(body))
}) })
}) })
},
})
@@ -4,6 +4,7 @@ jest.setTimeout(5000000)
const env = { const env = {
MEDUSA_FF_MEDUSA_V2: false, MEDUSA_FF_MEDUSA_V2: false,
MEDUSA_FF_SALES_CHANNELS: true,
} }
workflowEngineTestSuite(env, { force_modules_migration: true }) workflowEngineTestSuite(env, { force_modules_migration: true })
@@ -4,41 +4,32 @@ import {
StepResponse, StepResponse,
WorkflowData, WorkflowData,
} from "@medusajs/workflows-sdk" } from "@medusajs/workflows-sdk"
import { initDb, useDb } from "../../../environment-helpers/use-db"
import { AxiosInstance } from "axios"
import adminSeeder from "../../../helpers/admin-seeder"
import { createAdminUser } from "../../helpers/create-admin-user" import { createAdminUser } from "../../helpers/create-admin-user"
import { getContainer } from "../../../environment-helpers/use-container" import { medusaIntegrationTestRunner } from "medusa-test-utils"
import path from "path"
import { startBootstrapApp } from "../../../environment-helpers/bootstrap-app"
import { useApi } from "../../../environment-helpers/use-api"
export const workflowEngineTestSuite = (env, extraParams = {}) => { export const workflowEngineTestSuite = (
env,
extraParams: { force_modules_migration?: boolean } = {}
) => {
const adminHeaders = { const adminHeaders = {
headers: { headers: {
"x-medusa-access-token": "test_token", "x-medusa-access-token": "test_token",
}, },
} }
return medusaIntegrationTestRunner({
env,
force_modules_migration: extraParams.force_modules_migration,
testSuite: ({ dbConnection, getContainer, api }) => {
describe("Workflow Engine API", () => { describe("Workflow Engine API", () => {
let medusaContainer let medusaContainer
let dbConnection
let shutdownServer
beforeAll(async () => { beforeAll(() => {
const cwd = path.resolve(path.join(__dirname, "..", ".."))
dbConnection = await initDb({ cwd, env, ...extraParams } as any)
shutdownServer = await startBootstrapApp({ cwd, env })
medusaContainer = getContainer() medusaContainer = getContainer()
await createAdminUser(dbConnection, adminHeaders)
}) })
afterAll(async () => { beforeEach(async () => {
const db = useDb() await createAdminUser(dbConnection, adminHeaders, medusaContainer)
await db.shutdown()
await shutdownServer()
}) })
describe("running workflows", () => { describe("running workflows", () => {
@@ -74,8 +65,6 @@ export const workflowEngineTestSuite = (env, extraParams = {}) => {
}) })
it("Should list all workflows in execution or completed and retrieve them by id", async () => { it("Should list all workflows in execution or completed and retrieve them by id", async () => {
const api = useApi()! as AxiosInstance
for (let i = 3; i--; ) { for (let i = 3; i--; ) {
await api.post( await api.post(
`/admin/workflows-executions/my-workflow-name/run`, `/admin/workflows-executions/my-workflow-name/run`,
@@ -116,8 +105,6 @@ export const workflowEngineTestSuite = (env, extraParams = {}) => {
}) })
it("Should list all workflows matching the filters", async () => { it("Should list all workflows matching the filters", async () => {
const api = useApi()! as AxiosInstance
for (let i = 3; i--; ) { for (let i = 3; i--; ) {
await api.post( await api.post(
`/admin/workflows-executions/my-workflow-name/run`, `/admin/workflows-executions/my-workflow-name/run`,
@@ -140,7 +127,9 @@ export const workflowEngineTestSuite = (env, extraParams = {}) => {
expect(executions.data.workflow_executions.length).toEqual(2) expect(executions.data.workflow_executions.length).toEqual(2)
expect(executions.data.workflow_executions[0]).toEqual({ expect(executions.data.workflow_executions[0]).toEqual({
workflow_id: "my-workflow-name", workflow_id: "my-workflow-name",
transaction_id: expect.stringMatching(/transaction_1|transaction_2/), transaction_id: expect.stringMatching(
/transaction_1|transaction_2/
),
id: expect.any(String), id: expect.any(String),
state: "invoking", state: "invoking",
created_at: expect.any(String), created_at: expect.any(String),
@@ -149,7 +138,9 @@ export const workflowEngineTestSuite = (env, extraParams = {}) => {
}) })
expect(executions.data.workflow_executions[1]).toEqual({ expect(executions.data.workflow_executions[1]).toEqual({
workflow_id: "my-workflow-name", workflow_id: "my-workflow-name",
transaction_id: expect.stringMatching(/transaction_1|transaction_2/), transaction_id: expect.stringMatching(
/transaction_1|transaction_2/
),
id: expect.any(String), id: expect.any(String),
state: "invoking", state: "invoking",
created_at: expect.any(String), created_at: expect.any(String),
@@ -159,8 +150,6 @@ export const workflowEngineTestSuite = (env, extraParams = {}) => {
}) })
it("Should execute a workflow and retrieve its execution while running and when it is completed", async () => { it("Should execute a workflow and retrieve its execution while running and when it is completed", async () => {
const api = useApi()! as AxiosInstance
const wf = await api.post( const wf = await api.post(
`/admin/workflows-executions/my-workflow-name/run`, `/admin/workflows-executions/my-workflow-name/run`,
{ {
@@ -265,6 +254,8 @@ export const workflowEngineTestSuite = (env, extraParams = {}) => {
}) })
}) })
}) })
},
})
} }
describe("Noop test", () => { describe("Noop test", () => {
@@ -4,9 +4,13 @@ import jwt from "jsonwebtoken"
import { getContainer } from "../../environment-helpers/use-container" import { getContainer } from "../../environment-helpers/use-container"
import adminSeeder from "../../helpers/admin-seeder" import adminSeeder from "../../helpers/admin-seeder"
export const createAdminUser = async (dbConnection, adminHeaders) => { export const createAdminUser = async (
dbConnection,
adminHeaders,
container?
) => {
await adminSeeder(dbConnection) await adminSeeder(dbConnection)
const appContainer = getContainer()! const appContainer = container ?? getContainer()!
const authModule: IAuthModuleService = appContainer.resolve( const authModule: IAuthModuleService = appContainer.resolve(
ModuleRegistrationName.AUTH ModuleRegistrationName.AUTH
+5 -3
View File
@@ -15,9 +15,11 @@ module.exports = {
`.cache`, `.cache`,
], ],
transformIgnorePatterns: [`/dist`], transformIgnorePatterns: [`/dist`],
transform: { "^.+\\.[jt]s$": `../../jest-transformer.js` }, transform: {
"^.+\\.[jt]s$": `../../jest-transformer.js`,
},
setupFiles: ["../setup-env.js"], setupFiles: ["../setup-env.js"],
setupFilesAfterEnv: ["../setup.js"], /*setupFilesAfterEnv: ["../setup.js"],
globalSetup: "../globalSetup.js", globalSetup: "../globalSetup.js",
globalTeardown: "../globalTeardown.js", globalTeardown: "../globalTeardown.js",*/
} }
+2 -1
View File
@@ -5,7 +5,7 @@
"license": "MIT", "license": "MIT",
"private": true, "private": true,
"scripts": { "scripts": {
"test:integration": "node --expose-gc ./../../node_modules/.bin/jest --silent=false --runInBand --bail --detectOpenHandles --logHeapUsage --clearMocks --forceExit", "test:integration": "node --expose-gc ./../../node_modules/.bin/jest --ci --silent=false -i --detectOpenHandles --logHeapUsage --forceExit",
"build": "babel src -d dist --extensions \".ts,.js\"" "build": "babel src -d dist --extensions \".ts,.js\""
}, },
"dependencies": { "dependencies": {
@@ -30,6 +30,7 @@
"medusa-fulfillment-webshipper": "workspace:*", "medusa-fulfillment-webshipper": "workspace:*",
"medusa-interfaces": "workspace:*", "medusa-interfaces": "workspace:*",
"medusa-plugin-sendgrid": "workspace:*", "medusa-plugin-sendgrid": "workspace:*",
"medusa-test-utils": "workspace:*",
"pg": "^8.11.0", "pg": "^8.11.0",
"typeorm": "^0.3.16" "typeorm": "^0.3.16"
}, },
+29 -1
View File
@@ -24,18 +24,46 @@
"author": "Sebastian Rindom", "author": "Sebastian Rindom",
"license": "MIT", "license": "MIT",
"devDependencies": { "devDependencies": {
"@medusajs/types": "^1.1.41",
"cross-env": "^5.2.1", "cross-env": "^5.2.1",
"jest": "^25.5.4", "jest": "^25.5.4",
"rimraf": "^3.0.2", "rimraf": "^3.0.2",
"typescript": "^5.1.6" "typescript": "^5.1.6"
}, },
"peerDependencies": {
"@medusajs/medusa": ">1.19",
"axios": "^0.28.0",
"express": "^4.18.3",
"get-port": "^5.1.0",
"pg-god": "^1.0.12",
"typeorm": "^0.2.43"
},
"peerDependenciesMeta": {
"@medusajs/medusa": {
"optional": true
},
"axios": {
"optional": true
},
"express": {
"optional": true
},
"get-port": {
"optional": true
},
"pg-god": {
"optional": true
},
"typeorm": {
"optional": true
}
},
"dependencies": { "dependencies": {
"@medusajs/modules-sdk": "^1.12.6", "@medusajs/modules-sdk": "^1.12.6",
"@medusajs/utils": "^1.1.41", "@medusajs/utils": "^1.1.41",
"@mikro-orm/migrations": "5.9.7", "@mikro-orm/migrations": "5.9.7",
"@mikro-orm/postgresql": "5.9.7", "@mikro-orm/postgresql": "5.9.7",
"medusa-core-utils": "^1.2.1", "medusa-core-utils": "^1.2.1",
"pg-god": "^1.0.12",
"randomatic": "^3.1.1" "randomatic": "^3.1.1"
}, },
"gitHead": "81a7ff73d012fda722f6e9ef0bd9ba0232d37808" "gitHead": "81a7ff73d012fda722f6e9ef0bd9ba0232d37808"
+1
View File
@@ -6,3 +6,4 @@ export { default as MockRepository } from "./mock-repository"
export * from "./init-modules" export * from "./init-modules"
export { default as MockEventBusService } from "./mock-event-bus-service" export { default as MockEventBusService } from "./mock-event-bus-service"
export * from "./module-test-runner" export * from "./module-test-runner"
export * from "./medusa-test-runner"
@@ -0,0 +1,79 @@
const path = require("path")
const express = require("express")
const getPort = require("get-port")
const { isObject } = require("@medusajs/utils")
async function bootstrapApp({ cwd, env = {} } = {}) {
const app = express()
if (isObject(env)) {
Object.entries(env).forEach(([k, v]) => (process.env[k] = v))
}
const loaders = require("@medusajs/medusa/dist/loaders").default
const { container, dbConnection, pgConnection, disposeResources } =
await loaders({
directory: path.resolve(cwd || process.cwd()),
expressApp: app,
isTest: false,
})
const PORT = await getPort()
return {
disposeResources,
container,
db: dbConnection,
pgConnection,
app,
port: PORT,
}
}
module.exports = {
startBootstrapApp: async ({
cwd,
env = {},
skipExpressListen = false,
} = {}) => {
const { app, port, container, db, pgConnection } = await bootstrapApp({
cwd,
env,
})
let expressServer
if (skipExpressListen) {
return
}
const shutdown = async () => {
await Promise.all([
container.dispose(),
expressServer.close(),
db?.destroy(),
pgConnection?.context?.destroy(),
container.dispose(),
])
if (typeof global !== "undefined" && global?.gc) {
global.gc()
}
}
return await new Promise((resolve, reject) => {
expressServer = app.listen(port, async (err) => {
if (err) {
await shutdown()
return reject(err)
}
process.send(port)
resolve({
shutdown,
container,
port,
})
})
})
},
}
@@ -0,0 +1,113 @@
const path = require("path")
const { getConfigFile } = require("medusa-core-utils")
const { asValue } = require("awilix")
const {
isObject,
createMedusaContainer,
MedusaV2Flag,
} = require("@medusajs/utils")
const { DataSource } = require("typeorm")
const { ContainerRegistrationKeys } = require("@medusajs/utils")
const { migrateMedusaApp } = require("@medusajs/medusa/dist/loaders/medusa-app")
const { logger } = require("@medusajs/medusa-cli/dist/reporter")
module.exports = {
initDb: async function ({
cwd,
database_extra,
env,
force_modules_migration,
dbUrl = DB_URL,
dbSchema = "public",
}) {
if (isObject(env)) {
Object.entries(env).forEach(([k, v]) => (process.env[k] = v))
}
const { configModule } = getConfigFile(cwd, `medusa-config`)
const featureFlagsLoader =
require("@medusajs/medusa/dist/loaders/feature-flags").default
const featureFlagRouter = featureFlagsLoader(configModule)
const modelsLoader = require("@medusajs/medusa/dist/loaders/models").default
const entities = modelsLoader({}, { register: false })
// get migrations with enabled featureflags
const migrationDir = path.resolve(
path.join(
cwd,
`../../`,
`node_modules`,
`@medusajs`,
`medusa`,
`dist`,
`migrations`,
`*.js`
)
)
const {
getEnabledMigrations,
getModuleSharedResources,
} = require("@medusajs/medusa/dist/commands/utils/get-migrations")
const { migrations: moduleMigrations, models: moduleModels } =
getModuleSharedResources(configModule, featureFlagRouter)
const enabledMigrations = getEnabledMigrations([migrationDir], (flag) =>
featureFlagRouter.isFeatureEnabled(flag)
)
const enabledEntities = entities.filter(
(e) => typeof e.isFeatureEnabled === "undefined" || e.isFeatureEnabled()
)
const dbDataSource = new DataSource({
type: "postgres",
url: dbUrl,
entities: enabledEntities.concat(moduleModels),
migrations: enabledMigrations.concat(moduleMigrations),
extra: database_extra ?? {},
//name: "integration-tests",
schema: dbSchema,
})
await dbDataSource.initialize()
await dbDataSource.runMigrations()
if (
force_modules_migration ||
featureFlagRouter.isFeatureEnabled(MedusaV2Flag.key)
) {
const pgConnectionLoader =
require("@medusajs/medusa/dist/loaders/pg-connection").default
const featureFlagLoader =
require("@medusajs/medusa/dist/loaders/feature-flags").default
const container = createMedusaContainer()
const featureFlagRouter = await featureFlagLoader(configModule)
const pgConnection = await pgConnectionLoader({ configModule, container })
container.register({
[ContainerRegistrationKeys.CONFIG_MODULE]: asValue(configModule),
[ContainerRegistrationKeys.LOGGER]: asValue(logger),
[ContainerRegistrationKeys.MANAGER]: asValue(dbDataSource.manager),
[ContainerRegistrationKeys.PG_CONNECTION]: asValue(pgConnection),
featureFlagRouter: asValue(featureFlagRouter),
})
await migrateMedusaApp(
{ configModule, container },
{ registerInContainer: false }
)
}
return { dbDataSource, pgConnection }
},
}
@@ -0,0 +1,238 @@
import { getDatabaseURL } from "./database"
import { initDb } from "./medusa-test-runner-utils/use-db"
import { startBootstrapApp } from "./medusa-test-runner-utils/bootstrap-app"
import { createDatabase, dropDatabase } from "pg-god"
import { ContainerLike } from "@medusajs/types"
const axios = require("axios").default
const keepTables = [
"store",
"staged_job",
"shipping_profile",
"fulfillment_provider",
"payment_provider",
"country",
"region_country",
"currency",
"migrations",
"mikro_orm_migrations",
]
const DB_HOST = process.env.DB_HOST
const DB_USERNAME = process.env.DB_USERNAME
const DB_PASSWORD = process.env.DB_PASSWORD
const pgGodCredentials = {
user: DB_USERNAME,
password: DB_PASSWORD,
host: DB_HOST,
}
const dbTestUtilFactory = (): any => ({
db_: null,
pgConnection_: null,
clear: async function () {
this.db_?.synchronize(true)
},
create: async function (dbName: string) {
await createDatabase({ databaseName: dbName }, pgGodCredentials)
},
teardown: async function ({
forceDelete,
schema,
}: { forceDelete?: string[]; schema?: string } = {}) {
forceDelete = forceDelete || []
const manager = this.db_.manager
await manager.query(`SET session_replication_role = 'replica';`)
const tableNames = await manager.query(`SELECT table_name
FROM information_schema.tables
WHERE table_schema = '${
schema ?? "public"
}';`)
for (const { table_name } of tableNames) {
if (
keepTables.includes(table_name) &&
!forceDelete.includes(table_name)
) {
continue
}
await manager.query(`DELETE
FROM "${table_name}";`)
}
await manager.query(`SET session_replication_role = 'origin';`)
},
shutdown: async function (dbName: string) {
await this.db_?.destroy()
await this.pgConnection_?.context?.destroy()
return await dropDatabase(
{ databaseName: dbName, errorIfNonExist: false },
pgGodCredentials
)
},
})
export interface MedusaSuiteOptions<TService = unknown> {
dbUtils: any
dbConnection: any // Legacy typeorm connection
getContainer: () => ContainerLike
api: any
dbConfig: {
dbName: string
schema: string
clientUrl: string
}
}
export function medusaIntegrationTestRunner({
moduleName,
dbName,
schema = "public",
env = {},
force_modules_migration = false,
debug = false,
testSuite,
}: {
moduleName?: string
env?: Record<string, string>
dbName?: string
schema?: string
debug?: boolean
force_modules_migration?: boolean
testSuite: <TService = unknown>(
options: MedusaSuiteOptions<TService>
) => () => void
}) {
const tempName = parseInt(process.env.JEST_WORKER_ID || "1")
moduleName = moduleName ?? Math.random().toString(36).substring(7)
dbName ??= `medusa-${moduleName.toLowerCase()}-integration-${tempName}`
let dbConfig = {
dbName,
clientUrl: getDatabaseURL(dbName),
schema,
debug,
}
// Intercept call to this utils to apply the unique client url for the current suite
const originalCreatePgConnection =
require("@medusajs/utils/dist/modules-sdk/create-pg-connection").createPgConnection
require("@medusajs/utils/dist/modules-sdk/create-pg-connection").createPgConnection =
(options: any) => {
return originalCreatePgConnection({
...options,
clientUrl: dbConfig.clientUrl,
})
}
const originalDatabaseLoader =
require("@medusajs/medusa/dist/loaders/database").default
require("@medusajs/medusa/dist/loaders/database").default = (
options: any
) => {
options.configModule.projectConfig.database_url
return originalDatabaseLoader({
...options,
configModule: {
...options.configModule,
projectConfig: {
database_logging: debug, // Will be used for the debug flag of the database options
...options.configModule.projectConfig,
database_url: dbConfig.clientUrl,
},
},
})
}
const cwd = process.cwd()
let shutdown: () => Promise<void>
let dbUtils = dbTestUtilFactory()
let container: ContainerLike
let apiUtils: any
let options = {
dbUtils,
api: new Proxy(
{},
{
get: (target, prop) => {
return apiUtils[prop]
},
}
),
dbConnection: new Proxy(
{},
{
get: (target, prop) => {
return dbUtils.db_[prop]
},
}
),
getContainer: () => container,
} as MedusaSuiteOptions
const beforeAll_ = async () => {
try {
await dbUtils.create(dbName)
const { dbDataSource, pgConnection } = await initDb({
cwd,
env,
force_modules_migration,
database_extra: {},
dbUrl: dbConfig.clientUrl,
dbSchema: dbConfig.schema,
})
dbUtils.db_ = dbDataSource
dbUtils.pgConnection_ = pgConnection
const {
shutdown: shutdown_,
container: container_,
port,
} = await startBootstrapApp({
cwd,
env,
})
apiUtils = axios.create({ baseURL: `http://localhost:${port}` })
container = container_
shutdown = shutdown_
} catch (error) {
console.error("Error setting up integration environment:", error)
}
}
const afterEach_ = async () => {
try {
await dbUtils.teardown({ forceDelete: [], schema })
} catch (error) {
console.error("Error tearing down database:", error)
}
}
return describe("", () => {
beforeAll(beforeAll_)
afterEach(afterEach_)
afterAll(async () => {
try {
await dbUtils.shutdown(dbName)
await shutdown()
} catch (error) {
console.error("Error shutting down integration environment:", error)
}
})
testSuite(options!)
})
}
@@ -39,6 +39,8 @@ export function moduleIntegrationTestRunner({
debug?: boolean debug?: boolean
testSuite: <TService = unknown>(options: SuiteOptions<TService>) => () => void testSuite: <TService = unknown>(options: SuiteOptions<TService>) => () => void
}) { }) {
process.env.LOG_LEVEL = "error"
moduleModels = Object.values(require(`${process.cwd()}/src/models`)) moduleModels = Object.values(require(`${process.cwd()}/src/models`))
// migrationPath ??= process.cwd() + "/src/migrations/!(*.d).{js,ts,cjs}" // migrationPath ??= process.cwd() + "/src/migrations/!(*.d).{js,ts,cjs}"
+7 -2
View File
@@ -66,8 +66,12 @@ export async function migrateMedusaApp(
const sharedResourcesConfig = { const sharedResourcesConfig = {
database: { database: {
clientUrl: configModule.projectConfig.database_url, clientUrl:
injectedDependencies[ContainerRegistrationKeys.PG_CONNECTION]?.client
?.config?.connection?.connectionString ??
configModule.projectConfig.database_url,
driverOptions: configModule.projectConfig.database_extra, driverOptions: configModule.projectConfig.database_extra,
debug: !!(configModule.projectConfig.database_logging ?? false),
}, },
} }
@@ -85,7 +89,7 @@ export async function migrateMedusaApp(
).options ??= { ).options ??= {
database: { database: {
type: "postgres", type: "postgres",
url: configModule.projectConfig.database_url, url: sharedResourcesConfig.database.clientUrl,
extra: configModule.projectConfig.database_extra, extra: configModule.projectConfig.database_extra,
schema: configModule.projectConfig.database_schema, schema: configModule.projectConfig.database_schema,
logging: configModule.projectConfig.database_logging, logging: configModule.projectConfig.database_logging,
@@ -132,6 +136,7 @@ export const loadMedusaApp = async (
database: { database: {
clientUrl: configModule.projectConfig.database_url, clientUrl: configModule.projectConfig.database_url,
driverOptions: configModule.projectConfig.database_extra, driverOptions: configModule.projectConfig.database_extra,
debug: !!(configModule.projectConfig.database_logging ?? false),
}, },
} }
+1 -1
View File
@@ -337,7 +337,7 @@ async function MedusaApp_({
) )
} }
const linkModuleOpt = { ...linkModuleOptions } const linkModuleOpt = { ...(linkModuleOptions ?? {}) }
linkModuleOpt.database ??= { linkModuleOpt.database ??= {
...(sharedResourcesConfig?.database ?? {}), ...(sharedResourcesConfig?.database ?? {}),
} }
+9 -3
View File
@@ -285,11 +285,14 @@ export class MedusaModule {
moduleDefinition moduleDefinition
) )
const logger_ =
container.resolve("logger", { allowUnregistered: true }) ?? logger
try { try {
await moduleLoader({ await moduleLoader({
container, container,
moduleResolutions, moduleResolutions,
logger, logger: logger_,
migrationOnly, migrationOnly,
}) })
} catch (err) { } catch (err) {
@@ -314,7 +317,7 @@ export class MedusaModule {
].__joinerConfig() ].__joinerConfig()
if (!joinerConfig.primaryKeys) { if (!joinerConfig.primaryKeys) {
logger.warn( logger_.warn(
`Primary keys are not defined by the module ${keyName}. Setting default primary key to 'id'${EOL}` `Primary keys are not defined by the module ${keyName}. Setting default primary key to 'id'${EOL}`
) )
@@ -407,11 +410,14 @@ export class MedusaModule {
moduleExports moduleExports
) )
const logger_ =
container.resolve("logger", { allowUnregistered: true }) ?? logger
try { try {
await moduleLoader({ await moduleLoader({
container, container,
moduleResolutions, moduleResolutions,
logger, logger: logger_,
}) })
} catch (err) { } catch (err) {
errorLoading(err) errorLoading(err)
+24 -3
View File
@@ -8914,7 +8914,7 @@ __metadata:
languageName: unknown languageName: unknown
linkType: soft linkType: soft
"@medusajs/types@^1.10.0, @medusajs/types@^1.11.11, @medusajs/types@^1.11.12, @medusajs/types@^1.11.13, @medusajs/types@^1.11.6, @medusajs/types@^1.11.8, @medusajs/types@^1.11.9, @medusajs/types@^1.8.10, @medusajs/types@workspace:^, @medusajs/types@workspace:packages/types": "@medusajs/types@^1.1.41, @medusajs/types@^1.10.0, @medusajs/types@^1.11.11, @medusajs/types@^1.11.12, @medusajs/types@^1.11.13, @medusajs/types@^1.11.6, @medusajs/types@^1.11.8, @medusajs/types@^1.11.9, @medusajs/types@^1.8.10, @medusajs/types@workspace:^, @medusajs/types@workspace:packages/types":
version: 0.0.0-use.local version: 0.0.0-use.local
resolution: "@medusajs/types@workspace:packages/types" resolution: "@medusajs/types@workspace:packages/types"
dependencies: dependencies:
@@ -31811,6 +31811,7 @@ __metadata:
medusa-fulfillment-webshipper: "workspace:*" medusa-fulfillment-webshipper: "workspace:*"
medusa-interfaces: "workspace:*" medusa-interfaces: "workspace:*"
medusa-plugin-sendgrid: "workspace:*" medusa-plugin-sendgrid: "workspace:*"
medusa-test-utils: "workspace:*"
pg: ^8.11.0 pg: ^8.11.0
typeorm: ^0.3.16 typeorm: ^0.3.16
languageName: unknown languageName: unknown
@@ -38296,21 +38297,41 @@ __metadata:
languageName: unknown languageName: unknown
linkType: soft linkType: soft
"medusa-test-utils@^1.1.40, medusa-test-utils@^1.1.41, medusa-test-utils@workspace:^, medusa-test-utils@workspace:packages/medusa-test-utils": "medusa-test-utils@^1.1.40, medusa-test-utils@^1.1.41, medusa-test-utils@workspace:*, medusa-test-utils@workspace:^, medusa-test-utils@workspace:packages/medusa-test-utils":
version: 0.0.0-use.local version: 0.0.0-use.local
resolution: "medusa-test-utils@workspace:packages/medusa-test-utils" resolution: "medusa-test-utils@workspace:packages/medusa-test-utils"
dependencies: dependencies:
"@medusajs/modules-sdk": ^1.12.6 "@medusajs/modules-sdk": ^1.12.6
"@medusajs/types": ^1.1.41
"@medusajs/utils": ^1.1.41 "@medusajs/utils": ^1.1.41
"@mikro-orm/migrations": 5.9.7 "@mikro-orm/migrations": 5.9.7
"@mikro-orm/postgresql": 5.9.7 "@mikro-orm/postgresql": 5.9.7
cross-env: ^5.2.1 cross-env: ^5.2.1
jest: ^25.5.4 jest: ^25.5.4
medusa-core-utils: ^1.2.1 medusa-core-utils: ^1.2.1
pg-god: ^1.0.12
randomatic: ^3.1.1 randomatic: ^3.1.1
rimraf: ^3.0.2 rimraf: ^3.0.2
typescript: ^5.1.6 typescript: ^5.1.6
peerDependencies:
"@medusajs/medusa": ">1.19"
axios: ^0.28.0
express: ^4.18.3
get-port: ^5.1.0
pg-god: ^1.0.12
typeorm: ^0.2.43
peerDependenciesMeta:
"@medusajs/medusa":
optional: true
axios:
optional: true
express:
optional: true
get-port:
optional: true
pg-god:
optional: true
typeorm:
optional: true
languageName: unknown languageName: unknown
linkType: soft linkType: soft