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:
committed by
GitHub
parent
a6736c7ee0
commit
51bb6f1e89
5
.changeset/tasty-glasses-cheat.md
Normal file
5
.changeset/tasty-glasses-cheat.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"medusa-test-utils": patch
|
||||
---
|
||||
|
||||
Chore/integration tests modules utils
|
||||
@@ -2,3 +2,4 @@
|
||||
DB_HOST=localhost
|
||||
DB_USERNAME=postgres
|
||||
DB_PASSWORD=''
|
||||
LOG_LEVEL=error
|
||||
@@ -1,13 +1,8 @@
|
||||
import { initDb, useDb } from "../../../../environment-helpers/use-db"
|
||||
|
||||
import { ApiKeyType } from "@medusajs/utils"
|
||||
import { IApiKeyModuleService, IRegionModuleService } from "@medusajs/types"
|
||||
import { IRegionModuleService } from "@medusajs/types"
|
||||
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||
import { createAdminUser } from "../../../helpers/create-admin-user"
|
||||
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 { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||
|
||||
jest.setTimeout(50000)
|
||||
|
||||
@@ -16,42 +11,31 @@ const adminHeaders = {
|
||||
headers: { "x-medusa-access-token": "test_token" },
|
||||
}
|
||||
|
||||
describe("API Keys - Admin", () => {
|
||||
let dbConnection
|
||||
let appContainer
|
||||
let shutdownServer
|
||||
let service: IApiKeyModuleService
|
||||
medusaIntegrationTestRunner({
|
||||
env,
|
||||
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||
describe("API Keys - Admin", () => {
|
||||
let regionService: IRegionModuleService
|
||||
let container
|
||||
|
||||
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.API_KEY)
|
||||
regionService = appContainer.resolve(ModuleRegistrationName.REGION)
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
const db = useDb()
|
||||
await db.shutdown()
|
||||
await shutdownServer()
|
||||
container = getContainer()
|
||||
regionService = container.resolve(
|
||||
ModuleRegistrationName.REGION
|
||||
) as IRegionModuleService
|
||||
})
|
||||
|
||||
beforeEach(async () => {
|
||||
await createAdminUser(dbConnection, adminHeaders)
|
||||
await createAdminUser(dbConnection, adminHeaders, container)
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
const db = useDb()
|
||||
// TODO: Once teardown doesn't skip constraint checks and cascades, we can remove this
|
||||
const existingRegions = await regionService.list({})
|
||||
await regionService.delete(existingRegions.map((r) => r.id))
|
||||
await db.teardown()
|
||||
})
|
||||
|
||||
it("should correctly implement the entire lifecycle of an api key", async () => {
|
||||
const api = useApi() as any
|
||||
const created = await api.post(
|
||||
`/admin/api-keys`,
|
||||
{
|
||||
@@ -114,7 +98,6 @@ describe("API Keys - Admin", () => {
|
||||
})
|
||||
|
||||
it("can use a secret api key for authentication", async () => {
|
||||
const api = useApi() as any
|
||||
const created = await api.post(
|
||||
`/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 () => {
|
||||
const api = useApi() as any
|
||||
const created = await api.post(
|
||||
`/admin/api-keys`,
|
||||
{
|
||||
@@ -194,4 +176,6 @@ describe("API Keys - Admin", () => {
|
||||
expect(createdRegion.status).toEqual(200)
|
||||
expect(createdRegion.data.region.name).toEqual("Test Region")
|
||||
})
|
||||
})
|
||||
},
|
||||
})
|
||||
|
||||
@@ -1,48 +1,31 @@
|
||||
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||
import { IAuthModuleService, ICustomerModuleService } from "@medusajs/types"
|
||||
import path from "path"
|
||||
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 { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||
|
||||
jest.setTimeout(50000)
|
||||
|
||||
const env = { MEDUSA_FF_MEDUSA_V2: true }
|
||||
|
||||
describe("POST /auth/emailpass", () => {
|
||||
let dbConnection
|
||||
medusaIntegrationTestRunner({
|
||||
env,
|
||||
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||
describe("POST /auth/emailpass", () => {
|
||||
let appContainer
|
||||
let shutdownServer
|
||||
let customerModuleService: ICustomerModuleService
|
||||
|
||||
beforeAll(async () => {
|
||||
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
|
||||
dbConnection = await initDb({ cwd, env } as any)
|
||||
shutdownServer = await startBootstrapApp({ cwd, env })
|
||||
appContainer = getContainer()
|
||||
customerModuleService = appContainer.resolve(
|
||||
ModuleRegistrationName.CUSTOMER
|
||||
)
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
const db = useDb()
|
||||
await db.shutdown()
|
||||
await shutdownServer()
|
||||
})
|
||||
|
||||
beforeEach(async () => {
|
||||
await adminSeeder(dbConnection)
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
const db = useDb()
|
||||
await db.teardown()
|
||||
})
|
||||
|
||||
const password = "supersecret"
|
||||
const email = "test@test.com"
|
||||
|
||||
@@ -63,7 +46,6 @@ describe("POST /auth/emailpass", () => {
|
||||
},
|
||||
})
|
||||
|
||||
const api = useApi() as any
|
||||
const response = await api
|
||||
.post(`/auth/admin/emailpass`, {
|
||||
email: email,
|
||||
@@ -96,7 +78,6 @@ describe("POST /auth/emailpass", () => {
|
||||
},
|
||||
})
|
||||
|
||||
const api = useApi() as any
|
||||
const error = await api
|
||||
.post(`/auth/admin/emailpass`, {
|
||||
email: email,
|
||||
@@ -116,7 +97,6 @@ describe("POST /auth/emailpass", () => {
|
||||
await Scrypt.kdf(password, { logN: 15, r: 8, p: 1 })
|
||||
).toString("base64")
|
||||
|
||||
const api = useApi() as any
|
||||
const error = await api
|
||||
.post(`/auth/admin/emailpass`, {
|
||||
email: "should-not-exist",
|
||||
@@ -132,4 +112,6 @@ describe("POST /auth/emailpass", () => {
|
||||
message: "Invalid email or password",
|
||||
})
|
||||
})
|
||||
})
|
||||
},
|
||||
})
|
||||
|
||||
@@ -6,29 +6,23 @@ import {
|
||||
} from "@medusajs/modules-sdk"
|
||||
import { ICartModuleService, IPromotionModuleService } from "@medusajs/types"
|
||||
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 { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||
|
||||
jest.setTimeout(50000)
|
||||
|
||||
const env = { MEDUSA_FF_MEDUSA_V2: true }
|
||||
|
||||
describe("Store Carts API: Add promotions to cart", () => {
|
||||
let dbConnection
|
||||
medusaIntegrationTestRunner({
|
||||
env,
|
||||
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||
describe("Store Carts API: Add promotions to cart", () => {
|
||||
let appContainer
|
||||
let shutdownServer
|
||||
let cartModuleService: ICartModuleService
|
||||
let promotionModuleService: IPromotionModuleService
|
||||
let remoteLinkService: RemoteLink
|
||||
|
||||
beforeAll(async () => {
|
||||
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
|
||||
dbConnection = await initDb({ cwd, env } as any)
|
||||
shutdownServer = await startBootstrapApp({ cwd, env })
|
||||
appContainer = getContainer()
|
||||
cartModuleService = appContainer.resolve(ModuleRegistrationName.CART)
|
||||
promotionModuleService = appContainer.resolve(
|
||||
@@ -37,21 +31,10 @@ describe("Store Carts API: Add promotions to cart", () => {
|
||||
remoteLinkService = appContainer.resolve(LinkModuleUtils.REMOTE_LINK)
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
const db = useDb()
|
||||
await db.shutdown()
|
||||
await shutdownServer()
|
||||
})
|
||||
|
||||
beforeEach(async () => {
|
||||
await adminSeeder(dbConnection)
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
const db = useDb()
|
||||
await db.teardown()
|
||||
})
|
||||
|
||||
describe("POST /store/carts/:id/promotions", () => {
|
||||
it("should add line item adjustments to a cart based on promotions", async () => {
|
||||
const appliedPromotion = await promotionModuleService.create({
|
||||
@@ -131,8 +114,6 @@ describe("Store Carts API: Add promotions to cart", () => {
|
||||
[Modules.PROMOTION]: { promotion_id: appliedPromotion.id },
|
||||
})
|
||||
|
||||
const api = useApi() as any
|
||||
|
||||
const created = await api.post(`/store/carts/${cart.id}/promotions`, {
|
||||
promo_codes: [createdPromotion.code],
|
||||
})
|
||||
@@ -245,9 +226,8 @@ describe("Store Carts API: Add promotions to cart", () => {
|
||||
],
|
||||
})
|
||||
|
||||
const [express, standard] = await cartModuleService.addShippingMethods(
|
||||
cart.id,
|
||||
[
|
||||
const [express, standard] =
|
||||
await cartModuleService.addShippingMethods(cart.id, [
|
||||
{
|
||||
amount: 500,
|
||||
name: "express",
|
||||
@@ -256,26 +236,21 @@ describe("Store Carts API: Add promotions to cart", () => {
|
||||
amount: 500,
|
||||
name: "standard",
|
||||
},
|
||||
]
|
||||
)
|
||||
])
|
||||
|
||||
await remoteLinkService.create({
|
||||
[Modules.CART]: { cart_id: cart.id },
|
||||
[Modules.PROMOTION]: { promotion_id: appliedPromotion.id },
|
||||
})
|
||||
|
||||
const [adjustment] = await cartModuleService.addShippingMethodAdjustments(
|
||||
cart.id,
|
||||
[
|
||||
const [adjustment] =
|
||||
await cartModuleService.addShippingMethodAdjustments(cart.id, [
|
||||
{
|
||||
shipping_method_id: express.id,
|
||||
amount: 100,
|
||||
code: appliedPromotion.code!,
|
||||
},
|
||||
]
|
||||
)
|
||||
|
||||
const api = useApi() as any
|
||||
])
|
||||
|
||||
const created = await api.post(`/store/carts/${cart.id}/promotions`, {
|
||||
promo_codes: [newPromotion.code],
|
||||
@@ -321,4 +296,6 @@ describe("Store Carts API: Add promotions to cart", () => {
|
||||
)
|
||||
})
|
||||
})
|
||||
})
|
||||
},
|
||||
})
|
||||
|
||||
@@ -19,21 +19,18 @@ import {
|
||||
IRegionModuleService,
|
||||
ISalesChannelModuleService,
|
||||
} 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 { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||
|
||||
jest.setTimeout(50000)
|
||||
|
||||
const env = { MEDUSA_FF_MEDUSA_V2: true }
|
||||
|
||||
describe("Carts workflows", () => {
|
||||
let dbConnection
|
||||
medusaIntegrationTestRunner({
|
||||
env,
|
||||
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||
describe("Carts workflows", () => {
|
||||
let appContainer
|
||||
let shutdownServer
|
||||
let cartModuleService: ICartModuleService
|
||||
let regionModuleService: IRegionModuleService
|
||||
let scModuleService: ISalesChannelModuleService
|
||||
@@ -46,13 +43,14 @@ describe("Carts workflows", () => {
|
||||
let defaultRegion
|
||||
|
||||
beforeAll(async () => {
|
||||
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
|
||||
dbConnection = await initDb({ cwd, env } as any)
|
||||
shutdownServer = await startBootstrapApp({ cwd, env })
|
||||
appContainer = getContainer()
|
||||
cartModuleService = appContainer.resolve(ModuleRegistrationName.CART)
|
||||
regionModuleService = appContainer.resolve(ModuleRegistrationName.REGION)
|
||||
scModuleService = appContainer.resolve(ModuleRegistrationName.SALES_CHANNEL)
|
||||
regionModuleService = appContainer.resolve(
|
||||
ModuleRegistrationName.REGION
|
||||
)
|
||||
scModuleService = appContainer.resolve(
|
||||
ModuleRegistrationName.SALES_CHANNEL
|
||||
)
|
||||
customerModule = appContainer.resolve(ModuleRegistrationName.CUSTOMER)
|
||||
productModule = appContainer.resolve(ModuleRegistrationName.PRODUCT)
|
||||
pricingModule = appContainer.resolve(ModuleRegistrationName.PRICING)
|
||||
@@ -61,12 +59,6 @@ describe("Carts workflows", () => {
|
||||
remoteQuery = appContainer.resolve("remoteQuery")
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
const db = useDb()
|
||||
await db.shutdown()
|
||||
await shutdownServer()
|
||||
})
|
||||
|
||||
beforeEach(async () => {
|
||||
await adminSeeder(dbConnection)
|
||||
|
||||
@@ -77,11 +69,6 @@ describe("Carts workflows", () => {
|
||||
})
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
const db = useDb()
|
||||
await db.teardown()
|
||||
})
|
||||
|
||||
describe("CreateCartWorkflow", () => {
|
||||
it("should create a cart", async () => {
|
||||
const region = await regionModuleService.create({
|
||||
@@ -181,8 +168,6 @@ describe("Carts workflows", () => {
|
||||
})
|
||||
|
||||
it("should throw if sales channel is disabled", async () => {
|
||||
const api = useApi() as any
|
||||
|
||||
const salesChannel = await scModuleService.create({
|
||||
name: "Webshop",
|
||||
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.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({
|
||||
input: {
|
||||
@@ -630,7 +619,9 @@ describe("Carts workflows", () => {
|
||||
|
||||
workflow.appendAction("throw", deleteLineItemsStepId, {
|
||||
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", () => {
|
||||
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() {
|
||||
throw new Error(
|
||||
`Failed to do something after linking cart and payment collection`
|
||||
)
|
||||
},
|
||||
})
|
||||
}
|
||||
)
|
||||
|
||||
const region = await regionModuleService.create({
|
||||
name: "US",
|
||||
@@ -812,4 +808,6 @@ describe("Carts workflows", () => {
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
},
|
||||
})
|
||||
|
||||
@@ -14,22 +14,19 @@ import {
|
||||
ISalesChannelModuleService,
|
||||
} from "@medusajs/types"
|
||||
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 { createAuthenticatedCustomer } from "../../../helpers/create-authenticated-customer"
|
||||
import { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||
|
||||
jest.setTimeout(50000)
|
||||
|
||||
const env = { MEDUSA_FF_MEDUSA_V2: true }
|
||||
|
||||
describe("Store Carts API", () => {
|
||||
let dbConnection
|
||||
medusaIntegrationTestRunner({
|
||||
env,
|
||||
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||
describe("Store Carts API", () => {
|
||||
let appContainer
|
||||
let shutdownServer
|
||||
let cartModuleService: ICartModuleService
|
||||
let regionModuleService: IRegionModuleService
|
||||
let scModuleService: ISalesChannelModuleService
|
||||
@@ -42,13 +39,14 @@ describe("Store Carts API", () => {
|
||||
let defaultRegion
|
||||
|
||||
beforeAll(async () => {
|
||||
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
|
||||
dbConnection = await initDb({ cwd, env } as any)
|
||||
shutdownServer = await startBootstrapApp({ cwd, env })
|
||||
appContainer = getContainer()
|
||||
cartModuleService = appContainer.resolve(ModuleRegistrationName.CART)
|
||||
regionModuleService = appContainer.resolve(ModuleRegistrationName.REGION)
|
||||
scModuleService = appContainer.resolve(ModuleRegistrationName.SALES_CHANNEL)
|
||||
regionModuleService = appContainer.resolve(
|
||||
ModuleRegistrationName.REGION
|
||||
)
|
||||
scModuleService = appContainer.resolve(
|
||||
ModuleRegistrationName.SALES_CHANNEL
|
||||
)
|
||||
customerModule = appContainer.resolve(ModuleRegistrationName.CUSTOMER)
|
||||
productModule = appContainer.resolve(ModuleRegistrationName.PRODUCT)
|
||||
pricingModule = appContainer.resolve(ModuleRegistrationName.PRICING)
|
||||
@@ -56,12 +54,6 @@ describe("Store Carts API", () => {
|
||||
promotionModule = appContainer.resolve(ModuleRegistrationName.PROMOTION)
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
const db = useDb()
|
||||
await db.shutdown()
|
||||
await shutdownServer()
|
||||
})
|
||||
|
||||
beforeEach(async () => {
|
||||
await adminSeeder(dbConnection)
|
||||
|
||||
@@ -72,11 +64,6 @@ describe("Store Carts API", () => {
|
||||
})
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
const db = useDb()
|
||||
await db.teardown()
|
||||
})
|
||||
|
||||
describe("POST /store/carts", () => {
|
||||
it("should create a cart", async () => {
|
||||
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`, {
|
||||
email: "tony@stark.com",
|
||||
currency_code: "usd",
|
||||
@@ -188,8 +173,6 @@ describe("Store Carts API", () => {
|
||||
})
|
||||
|
||||
it("should create cart with customer from email", async () => {
|
||||
const api = useApi() as any
|
||||
|
||||
const created = await api.post(`/store/carts`, {
|
||||
currency_code: "usd",
|
||||
email: "tony@stark-industries.com",
|
||||
@@ -215,7 +198,6 @@ describe("Store Carts API", () => {
|
||||
currency_code: "usd",
|
||||
})
|
||||
|
||||
const api = useApi() as any
|
||||
const response = await api.post(`/store/carts`, {
|
||||
email: "tony@stark.com",
|
||||
currency_code: "usd",
|
||||
@@ -240,7 +222,6 @@ describe("Store Carts API", () => {
|
||||
currency_code: "usd",
|
||||
})
|
||||
|
||||
const api = useApi() as any
|
||||
const response = await api.post(`/store/carts`, {
|
||||
email: "tony@stark.com",
|
||||
region_id: region.id,
|
||||
@@ -260,9 +241,10 @@ describe("Store Carts API", () => {
|
||||
})
|
||||
|
||||
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(
|
||||
`/store/carts`,
|
||||
{},
|
||||
@@ -286,8 +268,6 @@ describe("Store Carts API", () => {
|
||||
})
|
||||
|
||||
it("should respond 400 bad request on unknown props", async () => {
|
||||
const api = useApi() as any
|
||||
|
||||
await expect(
|
||||
api.post(`/store/carts`, {
|
||||
foo: "bar",
|
||||
@@ -361,8 +341,6 @@ describe("Store Carts API", () => {
|
||||
[Modules.PROMOTION]: { promotion_id: appliedPromotion.id },
|
||||
})
|
||||
|
||||
const api = useApi() as any
|
||||
|
||||
// Should remove earlier adjustments from other promocodes
|
||||
let updated = await api.post(`/store/carts/${cart.id}`, {
|
||||
promo_codes: [createdPromotion.code],
|
||||
@@ -419,8 +397,6 @@ describe("Store Carts API", () => {
|
||||
currency_code: "eur",
|
||||
})
|
||||
|
||||
const api = useApi() as any
|
||||
|
||||
let updated = await api.post(`/store/carts/${cart.id}`, {
|
||||
region_id: region.id,
|
||||
email: "tony@stark.com",
|
||||
@@ -477,8 +453,6 @@ describe("Store Carts API", () => {
|
||||
name: "Webshop",
|
||||
})
|
||||
|
||||
const api = useApi() as any
|
||||
|
||||
const created = await api.post(`/store/carts`, {
|
||||
email: "tony@stark.com",
|
||||
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",
|
||||
})
|
||||
}
|
||||
)
|
||||
|
||||
expect(updated.status).toEqual(200)
|
||||
expect(updated.data.cart).toEqual(
|
||||
@@ -539,7 +516,6 @@ describe("Store Carts API", () => {
|
||||
sales_channel_id: salesChannel.id,
|
||||
})
|
||||
|
||||
const api = useApi() as any
|
||||
const response = await api.get(`/store/carts/${cart.id}`)
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
@@ -644,11 +620,13 @@ describe("Store Carts API", () => {
|
||||
[Modules.PROMOTION]: { promotion_id: appliedPromotion.id },
|
||||
})
|
||||
|
||||
const api = useApi() as any
|
||||
const response = await api.post(`/store/carts/${cart.id}/line-items`, {
|
||||
const response = await api.post(
|
||||
`/store/carts/${cart.id}/line-items`,
|
||||
{
|
||||
variant_id: product.variants[0].id,
|
||||
quantity: 1,
|
||||
})
|
||||
}
|
||||
)
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data.cart).toEqual(
|
||||
@@ -697,7 +675,6 @@ describe("Store Carts API", () => {
|
||||
region_id: region.id,
|
||||
})
|
||||
|
||||
const api = useApi() as any
|
||||
const response = await api.post(
|
||||
`/store/carts/${cart.id}/payment-collections`
|
||||
)
|
||||
@@ -715,4 +692,6 @@ describe("Store Carts API", () => {
|
||||
)
|
||||
})
|
||||
})
|
||||
})
|
||||
},
|
||||
})
|
||||
|
||||
@@ -6,29 +6,23 @@ import {
|
||||
} from "@medusajs/modules-sdk"
|
||||
import { ICartModuleService, IPromotionModuleService } from "@medusajs/types"
|
||||
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 { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||
|
||||
jest.setTimeout(50000)
|
||||
|
||||
const env = { MEDUSA_FF_MEDUSA_V2: true }
|
||||
|
||||
describe("Store Carts API: Remove promotions from cart", () => {
|
||||
let dbConnection
|
||||
medusaIntegrationTestRunner({
|
||||
env,
|
||||
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||
describe("Store Carts API: Remove promotions from cart", () => {
|
||||
let appContainer
|
||||
let shutdownServer
|
||||
let cartModuleService: ICartModuleService
|
||||
let promotionModuleService: IPromotionModuleService
|
||||
let remoteLinkService: RemoteLink
|
||||
|
||||
beforeAll(async () => {
|
||||
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
|
||||
dbConnection = await initDb({ cwd, env } as any)
|
||||
shutdownServer = await startBootstrapApp({ cwd, env })
|
||||
appContainer = getContainer()
|
||||
cartModuleService = appContainer.resolve(ModuleRegistrationName.CART)
|
||||
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 () => {
|
||||
await adminSeeder(dbConnection)
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
const db = useDb()
|
||||
await db.teardown()
|
||||
})
|
||||
|
||||
describe("DELETE /store/carts/:id/promotions", () => {
|
||||
it("should remove line item adjustments from a cart based on promotions", async () => {
|
||||
const appliedPromotion = await promotionModuleService.create({
|
||||
@@ -143,17 +126,20 @@ describe("Store Carts API: Remove promotions from cart", () => {
|
||||
},
|
||||
{
|
||||
[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],
|
||||
},
|
||||
})
|
||||
}
|
||||
)
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data.cart).toEqual(
|
||||
@@ -254,9 +240,8 @@ describe("Store Carts API: Remove promotions from cart", () => {
|
||||
],
|
||||
})
|
||||
|
||||
const [express, standard] = await cartModuleService.addShippingMethods(
|
||||
cart.id,
|
||||
[
|
||||
const [express, standard] =
|
||||
await cartModuleService.addShippingMethods(cart.id, [
|
||||
{
|
||||
amount: 500,
|
||||
name: "express",
|
||||
@@ -265,8 +250,7 @@ describe("Store Carts API: Remove promotions from cart", () => {
|
||||
amount: 500,
|
||||
name: "standard",
|
||||
},
|
||||
]
|
||||
)
|
||||
])
|
||||
|
||||
await cartModuleService.addShippingMethodAdjustments(cart.id, [
|
||||
{
|
||||
@@ -288,15 +272,18 @@ describe("Store Carts API: Remove promotions from cart", () => {
|
||||
},
|
||||
{
|
||||
[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] },
|
||||
})
|
||||
}
|
||||
)
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data.cart).toEqual(
|
||||
@@ -326,4 +313,6 @@ 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 { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||
|
||||
jest.setTimeout(50000)
|
||||
|
||||
@@ -15,37 +8,18 @@ const adminHeaders = {
|
||||
headers: { "x-medusa-access-token": "test_token" },
|
||||
}
|
||||
|
||||
describe("Currency - Admin", () => {
|
||||
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()
|
||||
})
|
||||
medusaIntegrationTestRunner({
|
||||
env,
|
||||
testSuite: ({ dbConnection, api, getContainer }) => {
|
||||
describe("Currency - Admin", () => {
|
||||
let container
|
||||
|
||||
beforeEach(async () => {
|
||||
await createAdminUser(dbConnection, adminHeaders)
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
const db = useDb()
|
||||
await db.teardown()
|
||||
container = getContainer()
|
||||
await createAdminUser(dbConnection, adminHeaders, container)
|
||||
})
|
||||
|
||||
it("should correctly retrieve and list currencies", async () => {
|
||||
const api = useApi() as any
|
||||
const listResp = await api.get("/admin/currencies", adminHeaders)
|
||||
|
||||
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(
|
||||
listResp.data.currencies.find((c) => c.code === "aud")
|
||||
)
|
||||
})
|
||||
})
|
||||
},
|
||||
})
|
||||
|
||||
@@ -1,11 +1,4 @@
|
||||
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 { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||
|
||||
jest.setTimeout(50000)
|
||||
|
||||
@@ -14,33 +7,11 @@ const storeHeaders = {
|
||||
headers: {},
|
||||
}
|
||||
|
||||
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()
|
||||
})
|
||||
|
||||
medusaIntegrationTestRunner({
|
||||
env,
|
||||
testSuite: ({ api }) => {
|
||||
describe("Currency - Store", () => {
|
||||
it("should correctly retrieve and list currencies", async () => {
|
||||
const api = useApi() as any
|
||||
const listResp = await api.get("/store/currencies", storeHeaders)
|
||||
|
||||
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(
|
||||
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 { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||
import adminSeeder from "../../../../helpers/admin-seeder"
|
||||
import { createAdminUser } from "../../../helpers/create-admin-user"
|
||||
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 { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||
|
||||
jest.setTimeout(50000)
|
||||
|
||||
@@ -16,40 +10,25 @@ const adminHeaders = {
|
||||
headers: { "x-medusa-access-token": "test_token" },
|
||||
}
|
||||
|
||||
describe("POST /admin/customer-groups/:id/customers/batch", () => {
|
||||
let dbConnection
|
||||
medusaIntegrationTestRunner({
|
||||
env,
|
||||
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||
describe("POST /admin/customer-groups/:id/customers/batch", () => {
|
||||
let appContainer
|
||||
let shutdownServer
|
||||
let customerModuleService: ICustomerModuleService
|
||||
|
||||
beforeAll(async () => {
|
||||
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
|
||||
dbConnection = await initDb({ cwd, env } as any)
|
||||
shutdownServer = await startBootstrapApp({ cwd, env })
|
||||
appContainer = getContainer()
|
||||
customerModuleService = appContainer.resolve(
|
||||
ModuleRegistrationName.CUSTOMER
|
||||
)
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
const db = useDb()
|
||||
await db.shutdown()
|
||||
await shutdownServer()
|
||||
})
|
||||
|
||||
beforeEach(async () => {
|
||||
await createAdminUser(dbConnection, adminHeaders)
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
const db = useDb()
|
||||
await db.teardown()
|
||||
await createAdminUser(dbConnection, adminHeaders, appContainer)
|
||||
})
|
||||
|
||||
it("should batch add customers to a group", async () => {
|
||||
const api = useApi() as any
|
||||
|
||||
const group = await customerModuleService.createCustomerGroup({
|
||||
name: "VIP",
|
||||
})
|
||||
@@ -86,4 +65,6 @@ describe("POST /admin/customer-groups/:id/customers/batch", () => {
|
||||
)
|
||||
expect(updatedGroup.customers?.length).toEqual(3)
|
||||
})
|
||||
})
|
||||
},
|
||||
})
|
||||
|
||||
@@ -1,13 +1,7 @@
|
||||
import { initDb, useDb } from "../../../../environment-helpers/use-db"
|
||||
|
||||
import { ICustomerModuleService } from "@medusajs/types"
|
||||
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||
import adminSeeder from "../../../../helpers/admin-seeder"
|
||||
import { createAdminUser } from "../../../helpers/create-admin-user"
|
||||
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 { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||
|
||||
jest.setTimeout(50000)
|
||||
|
||||
@@ -16,40 +10,25 @@ const adminHeaders = {
|
||||
headers: { "x-medusa-access-token": "test_token" },
|
||||
}
|
||||
|
||||
describe("DELETE /admin/customer-groups/:id/customers/remove", () => {
|
||||
let dbConnection
|
||||
medusaIntegrationTestRunner({
|
||||
env,
|
||||
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||
describe("DELETE /admin/customer-groups/:id/customers/remove", () => {
|
||||
let appContainer
|
||||
let shutdownServer
|
||||
let customerModuleService: ICustomerModuleService
|
||||
|
||||
beforeAll(async () => {
|
||||
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
|
||||
dbConnection = await initDb({ cwd, env } as any)
|
||||
shutdownServer = await startBootstrapApp({ cwd, env })
|
||||
appContainer = getContainer()
|
||||
customerModuleService = appContainer.resolve(
|
||||
ModuleRegistrationName.CUSTOMER
|
||||
)
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
const db = useDb()
|
||||
await db.shutdown()
|
||||
await shutdownServer()
|
||||
})
|
||||
|
||||
beforeEach(async () => {
|
||||
await createAdminUser(dbConnection, adminHeaders)
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
const db = useDb()
|
||||
await db.teardown()
|
||||
await createAdminUser(dbConnection, adminHeaders, appContainer)
|
||||
})
|
||||
|
||||
it("should batch delete customers from a group", async () => {
|
||||
const api = useApi() as any
|
||||
|
||||
const group = await customerModuleService.createCustomerGroup({
|
||||
name: "VIP",
|
||||
})
|
||||
@@ -69,7 +48,10 @@ describe("DELETE /admin/customer-groups/:id/customers/remove", () => {
|
||||
])
|
||||
|
||||
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(
|
||||
@@ -90,4 +72,6 @@ describe("DELETE /admin/customer-groups/:id/customers/remove", () => {
|
||||
)
|
||||
expect(updatedGroup.customers?.length).toEqual(0)
|
||||
})
|
||||
})
|
||||
},
|
||||
})
|
||||
|
||||
@@ -1,13 +1,7 @@
|
||||
import { initDb, useDb } from "../../../../environment-helpers/use-db"
|
||||
|
||||
import { ICustomerModuleService } from "@medusajs/types"
|
||||
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||
import adminSeeder from "../../../../helpers/admin-seeder"
|
||||
import { createAdminUser } from "../../../helpers/create-admin-user"
|
||||
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 { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||
|
||||
jest.setTimeout(50000)
|
||||
|
||||
@@ -16,40 +10,26 @@ const adminHeaders = {
|
||||
headers: { "x-medusa-access-token": "test_token" },
|
||||
}
|
||||
|
||||
describe("POST /admin/customer-groups", () => {
|
||||
let dbConnection
|
||||
medusaIntegrationTestRunner({
|
||||
env,
|
||||
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||
describe("POST /admin/customer-groups", () => {
|
||||
let appContainer
|
||||
let shutdownServer
|
||||
let customerModuleService: ICustomerModuleService
|
||||
|
||||
beforeAll(async () => {
|
||||
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
|
||||
dbConnection = await initDb({ cwd, env } as any)
|
||||
shutdownServer = await startBootstrapApp({ cwd, env })
|
||||
appContainer = getContainer()
|
||||
customerModuleService = appContainer.resolve(
|
||||
ModuleRegistrationName.CUSTOMER
|
||||
)
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
const db = useDb()
|
||||
await db.shutdown()
|
||||
await shutdownServer()
|
||||
})
|
||||
|
||||
beforeEach(async () => {
|
||||
await createAdminUser(dbConnection, adminHeaders)
|
||||
await createAdminUser(dbConnection, adminHeaders, appContainer)
|
||||
// await adminSeeder(dbConnection)
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
const db = useDb()
|
||||
await db.teardown()
|
||||
})
|
||||
|
||||
it("should create a customer group", async () => {
|
||||
const api = useApi() as any
|
||||
const response = await api.post(
|
||||
`/admin/customer-groups`,
|
||||
{
|
||||
@@ -67,4 +47,6 @@ describe("POST /admin/customer-groups", () => {
|
||||
})
|
||||
)
|
||||
})
|
||||
})
|
||||
},
|
||||
})
|
||||
|
||||
@@ -1,13 +1,7 @@
|
||||
import { initDb, useDb } from "../../../../environment-helpers/use-db"
|
||||
|
||||
import { ICustomerModuleService } from "@medusajs/types"
|
||||
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||
import adminSeeder from "../../../../helpers/admin-seeder"
|
||||
import { createAdminUser } from "../../../helpers/create-admin-user"
|
||||
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 { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||
|
||||
jest.setTimeout(50000)
|
||||
|
||||
@@ -16,35 +10,22 @@ const adminHeaders = {
|
||||
headers: { "x-medusa-access-token": "test_token" },
|
||||
}
|
||||
|
||||
describe("DELETE /admin/customer-groups/:id", () => {
|
||||
let dbConnection
|
||||
medusaIntegrationTestRunner({
|
||||
env,
|
||||
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||
describe("DELETE /admin/customer-groups/:id", () => {
|
||||
let appContainer
|
||||
let shutdownServer
|
||||
let customerModuleService: ICustomerModuleService
|
||||
|
||||
beforeAll(async () => {
|
||||
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
|
||||
dbConnection = await initDb({ cwd, env } as any)
|
||||
shutdownServer = await startBootstrapApp({ cwd, env })
|
||||
appContainer = getContainer()
|
||||
customerModuleService = appContainer.resolve(
|
||||
ModuleRegistrationName.CUSTOMER
|
||||
)
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
const db = useDb()
|
||||
await db.shutdown()
|
||||
await shutdownServer()
|
||||
})
|
||||
|
||||
beforeEach(async () => {
|
||||
await createAdminUser(dbConnection, adminHeaders)
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
const db = useDb()
|
||||
await db.teardown()
|
||||
await createAdminUser(dbConnection, adminHeaders, appContainer)
|
||||
})
|
||||
|
||||
it("should delete a group", async () => {
|
||||
@@ -52,7 +33,6 @@ describe("DELETE /admin/customer-groups/:id", () => {
|
||||
name: "VIP",
|
||||
})
|
||||
|
||||
const api = useApi() as any
|
||||
const response = await api.delete(
|
||||
`/admin/customer-groups/${group.id}`,
|
||||
adminHeaders
|
||||
@@ -60,10 +40,12 @@ describe("DELETE /admin/customer-groups/:id", () => {
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
|
||||
const deletedCustomer = await customerModuleService.retrieveCustomerGroup(
|
||||
group.id,
|
||||
{ withDeleted: true }
|
||||
)
|
||||
const deletedCustomer =
|
||||
await customerModuleService.retrieveCustomerGroup(group.id, {
|
||||
withDeleted: true,
|
||||
})
|
||||
expect(deletedCustomer.deleted_at).toBeTruthy()
|
||||
})
|
||||
})
|
||||
},
|
||||
})
|
||||
|
||||
@@ -1,13 +1,7 @@
|
||||
import { initDb, useDb } from "../../../../environment-helpers/use-db"
|
||||
|
||||
import { ICustomerModuleService } from "@medusajs/types"
|
||||
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||
import adminSeeder from "../../../../helpers/admin-seeder"
|
||||
import { createAdminUser } from "../../../helpers/create-admin-user"
|
||||
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 { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||
|
||||
jest.setTimeout(50000)
|
||||
|
||||
@@ -16,35 +10,22 @@ const adminHeaders = {
|
||||
headers: { "x-medusa-access-token": "test_token" },
|
||||
}
|
||||
|
||||
describe("GET /admin/customer-groups/:id/customers", () => {
|
||||
let dbConnection
|
||||
medusaIntegrationTestRunner({
|
||||
env,
|
||||
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||
describe("GET /admin/customer-groups/:id/customers", () => {
|
||||
let appContainer
|
||||
let shutdownServer
|
||||
let customerModuleService: ICustomerModuleService
|
||||
|
||||
beforeAll(async () => {
|
||||
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
|
||||
dbConnection = await initDb({ cwd, env } as any)
|
||||
shutdownServer = await startBootstrapApp({ cwd, env })
|
||||
appContainer = getContainer()
|
||||
customerModuleService = appContainer.resolve(
|
||||
ModuleRegistrationName.CUSTOMER
|
||||
)
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
const db = useDb()
|
||||
await db.shutdown()
|
||||
await shutdownServer()
|
||||
})
|
||||
|
||||
beforeEach(async () => {
|
||||
await createAdminUser(dbConnection, adminHeaders)
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
const db = useDb()
|
||||
await db.teardown()
|
||||
await createAdminUser(dbConnection, adminHeaders, appContainer)
|
||||
})
|
||||
|
||||
it("should get all customer groups and its count", async () => {
|
||||
@@ -66,11 +47,12 @@ describe("GET /admin/customer-groups/:id/customers", () => {
|
||||
// add to group
|
||||
|
||||
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(
|
||||
`/admin/customer-groups/${group.id}/customers`,
|
||||
adminHeaders
|
||||
@@ -89,4 +71,6 @@ 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 { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||
import adminSeeder from "../../../../helpers/admin-seeder"
|
||||
import { createAdminUser } from "../../../helpers/create-admin-user"
|
||||
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 { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||
|
||||
jest.setTimeout(50000)
|
||||
|
||||
@@ -16,35 +10,22 @@ const adminHeaders = {
|
||||
headers: { "x-medusa-access-token": "test_token" },
|
||||
}
|
||||
|
||||
describe("GET /admin/customer-groups", () => {
|
||||
let dbConnection
|
||||
medusaIntegrationTestRunner({
|
||||
env,
|
||||
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||
describe("GET /admin/customer-groups", () => {
|
||||
let appContainer
|
||||
let shutdownServer
|
||||
let customerModuleService: ICustomerModuleService
|
||||
|
||||
beforeAll(async () => {
|
||||
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
|
||||
dbConnection = await initDb({ cwd, env } as any)
|
||||
shutdownServer = await startBootstrapApp({ cwd, env })
|
||||
appContainer = getContainer()
|
||||
customerModuleService = appContainer.resolve(
|
||||
ModuleRegistrationName.CUSTOMER
|
||||
)
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
const db = useDb()
|
||||
await db.shutdown()
|
||||
await shutdownServer()
|
||||
})
|
||||
|
||||
beforeEach(async () => {
|
||||
await createAdminUser(dbConnection, adminHeaders)
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
const db = useDb()
|
||||
await db.teardown()
|
||||
await createAdminUser(dbConnection, adminHeaders, appContainer)
|
||||
})
|
||||
|
||||
it("should get all customer groups and its count", async () => {
|
||||
@@ -52,7 +33,6 @@ describe("GET /admin/customer-groups", () => {
|
||||
name: "Test",
|
||||
})
|
||||
|
||||
const api = useApi() as any
|
||||
const response = await api.get(`/admin/customer-groups`, adminHeaders)
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
@@ -64,4 +44,6 @@ describe("GET /admin/customer-groups", () => {
|
||||
}),
|
||||
])
|
||||
})
|
||||
})
|
||||
},
|
||||
})
|
||||
|
||||
@@ -1,13 +1,7 @@
|
||||
import { initDb, useDb } from "../../../../environment-helpers/use-db"
|
||||
|
||||
import { ICustomerModuleService } from "@medusajs/types"
|
||||
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||
import adminSeeder from "../../../../helpers/admin-seeder"
|
||||
import { createAdminUser } from "../../../helpers/create-admin-user"
|
||||
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 { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||
|
||||
jest.setTimeout(50000)
|
||||
|
||||
@@ -16,35 +10,22 @@ const adminHeaders = {
|
||||
headers: { "x-medusa-access-token": "test_token" },
|
||||
}
|
||||
|
||||
describe("GET /admin/customer-groups/:id", () => {
|
||||
let dbConnection
|
||||
medusaIntegrationTestRunner({
|
||||
env,
|
||||
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||
describe("GET /admin/customer-groups/:id", () => {
|
||||
let appContainer
|
||||
let shutdownServer
|
||||
let customerModuleService: ICustomerModuleService
|
||||
|
||||
beforeAll(async () => {
|
||||
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
|
||||
dbConnection = await initDb({ cwd, env } as any)
|
||||
shutdownServer = await startBootstrapApp({ cwd, env })
|
||||
appContainer = getContainer()
|
||||
customerModuleService = appContainer.resolve(
|
||||
ModuleRegistrationName.CUSTOMER
|
||||
)
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
const db = useDb()
|
||||
await db.shutdown()
|
||||
await shutdownServer()
|
||||
})
|
||||
|
||||
beforeEach(async () => {
|
||||
await createAdminUser(dbConnection, adminHeaders)
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
const db = useDb()
|
||||
await db.teardown()
|
||||
await createAdminUser(dbConnection, adminHeaders, appContainer)
|
||||
})
|
||||
|
||||
it("should retrieve customer group", async () => {
|
||||
@@ -52,7 +33,6 @@ describe("GET /admin/customer-groups/:id", () => {
|
||||
name: "Test",
|
||||
})
|
||||
|
||||
const api = useApi() as any
|
||||
const response = await api.get(
|
||||
`/admin/customer-groups/${group.id}`,
|
||||
adminHeaders
|
||||
@@ -66,4 +46,6 @@ describe("GET /admin/customer-groups/:id", () => {
|
||||
})
|
||||
)
|
||||
})
|
||||
})
|
||||
},
|
||||
})
|
||||
|
||||
@@ -1,13 +1,7 @@
|
||||
import { initDb, useDb } from "../../../../environment-helpers/use-db"
|
||||
|
||||
import { ICustomerModuleService } from "@medusajs/types"
|
||||
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||
import adminSeeder from "../../../../helpers/admin-seeder"
|
||||
import { createAdminUser } from "../../../helpers/create-admin-user"
|
||||
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 { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||
|
||||
jest.setTimeout(50000)
|
||||
|
||||
@@ -16,35 +10,22 @@ const adminHeaders = {
|
||||
headers: { "x-medusa-access-token": "test_token" },
|
||||
}
|
||||
|
||||
describe("POST /admin/customer-groups/:id", () => {
|
||||
let dbConnection
|
||||
medusaIntegrationTestRunner({
|
||||
env,
|
||||
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||
describe("POST /admin/customer-groups/:id", () => {
|
||||
let appContainer
|
||||
let shutdownServer
|
||||
let customerModuleService: ICustomerModuleService
|
||||
|
||||
beforeAll(async () => {
|
||||
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
|
||||
dbConnection = await initDb({ cwd, env } as any)
|
||||
shutdownServer = await startBootstrapApp({ cwd, env })
|
||||
appContainer = getContainer()
|
||||
customerModuleService = appContainer.resolve(
|
||||
ModuleRegistrationName.CUSTOMER
|
||||
)
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
const db = useDb()
|
||||
await db.shutdown()
|
||||
await shutdownServer()
|
||||
})
|
||||
|
||||
beforeEach(async () => {
|
||||
await createAdminUser(dbConnection, adminHeaders)
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
const db = useDb()
|
||||
await db.teardown()
|
||||
await createAdminUser(dbConnection, adminHeaders, appContainer)
|
||||
})
|
||||
|
||||
it("should update a customer group", async () => {
|
||||
@@ -52,7 +33,6 @@ describe("POST /admin/customer-groups/:id", () => {
|
||||
name: "VIP",
|
||||
})
|
||||
|
||||
const api = useApi() as any
|
||||
const response = await api.post(
|
||||
`/admin/customer-groups/${customer.id}`,
|
||||
{
|
||||
@@ -69,4 +49,6 @@ describe("POST /admin/customer-groups/:id", () => {
|
||||
})
|
||||
)
|
||||
})
|
||||
})
|
||||
},
|
||||
})
|
||||
|
||||
@@ -1,13 +1,7 @@
|
||||
import { initDb, useDb } from "../../../../environment-helpers/use-db"
|
||||
|
||||
import { ICustomerModuleService } from "@medusajs/types"
|
||||
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||
import adminSeeder from "../../../../helpers/admin-seeder"
|
||||
import { createAdminUser } from "../../../helpers/create-admin-user"
|
||||
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 { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||
|
||||
jest.setTimeout(50000)
|
||||
|
||||
@@ -16,37 +10,23 @@ const adminHeaders = {
|
||||
headers: { "x-medusa-access-token": "test_token" },
|
||||
}
|
||||
|
||||
describe("POST /admin/customers/:id/addresses", () => {
|
||||
let dbConnection
|
||||
medusaIntegrationTestRunner({
|
||||
env,
|
||||
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||
describe("POST /admin/customers/:id/addresses", () => {
|
||||
let appContainer
|
||||
let shutdownServer
|
||||
let customerModuleService: ICustomerModuleService
|
||||
|
||||
beforeAll(async () => {
|
||||
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
|
||||
dbConnection = await initDb({ cwd, env } as any)
|
||||
shutdownServer = await startBootstrapApp({ cwd, env })
|
||||
appContainer = getContainer()
|
||||
customerModuleService = appContainer.resolve(
|
||||
ModuleRegistrationName.CUSTOMER
|
||||
)
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
const db = useDb()
|
||||
await db.shutdown()
|
||||
await shutdownServer()
|
||||
})
|
||||
|
||||
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 () => {
|
||||
// Create a customer
|
||||
const customer = await customerModuleService.create({
|
||||
@@ -54,7 +34,6 @@ describe("POST /admin/customers/:id/addresses", () => {
|
||||
last_name: "Doe",
|
||||
})
|
||||
|
||||
const api = useApi() as any
|
||||
const response = await api.post(
|
||||
`/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(
|
||||
`/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(
|
||||
`/admin/customers/${customer.id}/addresses`,
|
||||
{
|
||||
@@ -154,4 +131,6 @@ describe("POST /admin/customers/:id/addresses", () => {
|
||||
|
||||
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 { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||
import adminSeeder from "../../../../helpers/admin-seeder"
|
||||
import { createAdminUser } from "../../../helpers/create-admin-user"
|
||||
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 { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||
|
||||
jest.setTimeout(50000)
|
||||
|
||||
@@ -16,39 +10,25 @@ const adminHeaders = {
|
||||
headers: { "x-medusa-access-token": "test_token" },
|
||||
}
|
||||
|
||||
describe("POST /admin/customers", () => {
|
||||
let dbConnection
|
||||
medusaIntegrationTestRunner({
|
||||
env,
|
||||
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||
describe("POST /admin/customers", () => {
|
||||
let appContainer
|
||||
let shutdownServer
|
||||
let customerModuleService: ICustomerModuleService
|
||||
|
||||
beforeAll(async () => {
|
||||
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
|
||||
dbConnection = await initDb({ cwd, env } as any)
|
||||
shutdownServer = await startBootstrapApp({ cwd, env })
|
||||
appContainer = getContainer()
|
||||
customerModuleService = appContainer.resolve(
|
||||
ModuleRegistrationName.CUSTOMER
|
||||
)
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
const db = useDb()
|
||||
await db.shutdown()
|
||||
await shutdownServer()
|
||||
})
|
||||
|
||||
beforeEach(async () => {
|
||||
await createAdminUser(dbConnection, adminHeaders)
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
const db = useDb()
|
||||
await db.teardown()
|
||||
await createAdminUser(dbConnection, adminHeaders, appContainer)
|
||||
})
|
||||
|
||||
it("should create a customer", async () => {
|
||||
const api = useApi() as any
|
||||
const response = await api.post(
|
||||
`/admin/customers`,
|
||||
{
|
||||
@@ -68,4 +48,6 @@ describe("POST /admin/customers", () => {
|
||||
})
|
||||
)
|
||||
})
|
||||
})
|
||||
},
|
||||
})
|
||||
|
||||
@@ -1,13 +1,7 @@
|
||||
import { initDb, useDb } from "../../../../environment-helpers/use-db"
|
||||
|
||||
import { ICustomerModuleService } from "@medusajs/types"
|
||||
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||
import adminSeeder from "../../../../helpers/admin-seeder"
|
||||
import { createAdminUser } from "../../../helpers/create-admin-user"
|
||||
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 { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||
|
||||
jest.setTimeout(50000)
|
||||
|
||||
@@ -16,35 +10,22 @@ const adminHeaders = {
|
||||
headers: { "x-medusa-access-token": "test_token" },
|
||||
}
|
||||
|
||||
describe("DELETE /admin/customers/:id/addresses/:address_id", () => {
|
||||
let dbConnection
|
||||
medusaIntegrationTestRunner({
|
||||
env,
|
||||
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||
describe("DELETE /admin/customers/:id/addresses/:address_id", () => {
|
||||
let appContainer
|
||||
let shutdownServer
|
||||
let customerModuleService: ICustomerModuleService
|
||||
|
||||
beforeAll(async () => {
|
||||
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
|
||||
dbConnection = await initDb({ cwd, env } as any)
|
||||
shutdownServer = await startBootstrapApp({ cwd, env })
|
||||
appContainer = getContainer()
|
||||
customerModuleService = appContainer.resolve(
|
||||
ModuleRegistrationName.CUSTOMER
|
||||
)
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
const db = useDb()
|
||||
await db.shutdown()
|
||||
await shutdownServer()
|
||||
})
|
||||
|
||||
beforeEach(async () => {
|
||||
await createAdminUser(dbConnection, adminHeaders)
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
const db = useDb()
|
||||
await db.teardown()
|
||||
await createAdminUser(dbConnection, adminHeaders, appContainer)
|
||||
})
|
||||
|
||||
it("should update a customer address", async () => {
|
||||
@@ -60,7 +41,6 @@ describe("DELETE /admin/customers/:id/addresses/:address_id", () => {
|
||||
address_1: "Test street 1",
|
||||
})
|
||||
|
||||
const api = useApi() as any
|
||||
const response = await api.delete(
|
||||
`/admin/customers/${customer.id}/addresses/${address.id}`,
|
||||
adminHeaders
|
||||
@@ -68,10 +48,15 @@ describe("DELETE /admin/customers/:id/addresses/:address_id", () => {
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
|
||||
const updatedCustomer = await customerModuleService.retrieve(customer.id, {
|
||||
const updatedCustomer = await customerModuleService.retrieve(
|
||||
customer.id,
|
||||
{
|
||||
relations: ["addresses"],
|
||||
})
|
||||
}
|
||||
)
|
||||
|
||||
expect(updatedCustomer.addresses?.length).toEqual(0)
|
||||
})
|
||||
})
|
||||
},
|
||||
})
|
||||
|
||||
@@ -1,13 +1,7 @@
|
||||
import { initDb, useDb } from "../../../../environment-helpers/use-db"
|
||||
|
||||
import { ICustomerModuleService } from "@medusajs/types"
|
||||
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||
import adminSeeder from "../../../../helpers/admin-seeder"
|
||||
import { createAdminUser } from "../../../helpers/create-admin-user"
|
||||
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 { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||
|
||||
jest.setTimeout(50000)
|
||||
|
||||
@@ -16,35 +10,22 @@ const adminHeaders = {
|
||||
headers: { "x-medusa-access-token": "test_token" },
|
||||
}
|
||||
|
||||
describe("DELETE /admin/customers/:id", () => {
|
||||
let dbConnection
|
||||
medusaIntegrationTestRunner({
|
||||
env,
|
||||
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||
describe("DELETE /admin/customers/:id", () => {
|
||||
let appContainer
|
||||
let shutdownServer
|
||||
let customerModuleService: ICustomerModuleService
|
||||
|
||||
beforeAll(async () => {
|
||||
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
|
||||
dbConnection = await initDb({ cwd, env } as any)
|
||||
shutdownServer = await startBootstrapApp({ cwd, env })
|
||||
appContainer = getContainer()
|
||||
customerModuleService = appContainer.resolve(
|
||||
ModuleRegistrationName.CUSTOMER
|
||||
)
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
const db = useDb()
|
||||
await db.shutdown()
|
||||
await shutdownServer()
|
||||
})
|
||||
|
||||
beforeEach(async () => {
|
||||
await createAdminUser(dbConnection, adminHeaders)
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
const db = useDb()
|
||||
await db.teardown()
|
||||
await createAdminUser(dbConnection, adminHeaders, appContainer)
|
||||
})
|
||||
|
||||
it("should delete a customer", async () => {
|
||||
@@ -53,7 +34,6 @@ describe("DELETE /admin/customers/:id", () => {
|
||||
last_name: "Doe",
|
||||
})
|
||||
|
||||
const api = useApi() as any
|
||||
const response = await api.delete(
|
||||
`/admin/customers/${customer.id}`,
|
||||
adminHeaders
|
||||
@@ -61,9 +41,14 @@ describe("DELETE /admin/customers/:id", () => {
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
|
||||
const deletedCustomer = await customerModuleService.retrieve(customer.id, {
|
||||
const deletedCustomer = await customerModuleService.retrieve(
|
||||
customer.id,
|
||||
{
|
||||
withDeleted: true,
|
||||
})
|
||||
}
|
||||
)
|
||||
expect(deletedCustomer.deleted_at).toBeTruthy()
|
||||
})
|
||||
})
|
||||
},
|
||||
})
|
||||
|
||||
@@ -1,13 +1,7 @@
|
||||
import { initDb, useDb } from "../../../../environment-helpers/use-db"
|
||||
|
||||
import { ICustomerModuleService } from "@medusajs/types"
|
||||
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||
import adminSeeder from "../../../../helpers/admin-seeder"
|
||||
import { createAdminUser } from "../../../helpers/create-admin-user"
|
||||
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 { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||
|
||||
jest.setTimeout(50000)
|
||||
|
||||
@@ -16,35 +10,22 @@ const adminHeaders = {
|
||||
headers: { "x-medusa-access-token": "test_token" },
|
||||
}
|
||||
|
||||
describe("GET /admin/customers/:id/addresses", () => {
|
||||
let dbConnection
|
||||
medusaIntegrationTestRunner({
|
||||
env,
|
||||
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||
describe("GET /admin/customers/:id/addresses", () => {
|
||||
let appContainer
|
||||
let shutdownServer
|
||||
let customerModuleService: ICustomerModuleService
|
||||
|
||||
beforeAll(async () => {
|
||||
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
|
||||
dbConnection = await initDb({ cwd, env } as any)
|
||||
shutdownServer = await startBootstrapApp({ cwd, env })
|
||||
appContainer = getContainer()
|
||||
customerModuleService = appContainer.resolve(
|
||||
ModuleRegistrationName.CUSTOMER
|
||||
)
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
const db = useDb()
|
||||
await db.shutdown()
|
||||
await shutdownServer()
|
||||
})
|
||||
|
||||
beforeEach(async () => {
|
||||
await createAdminUser(dbConnection, adminHeaders)
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
const db = useDb()
|
||||
await db.teardown()
|
||||
await createAdminUser(dbConnection, adminHeaders, appContainer)
|
||||
})
|
||||
|
||||
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(
|
||||
`/admin/customers/${customer.id}/addresses`,
|
||||
adminHeaders
|
||||
@@ -112,4 +92,6 @@ describe("GET /admin/customers/:id/addresses", () => {
|
||||
])
|
||||
)
|
||||
})
|
||||
})
|
||||
},
|
||||
})
|
||||
|
||||
@@ -1,13 +1,7 @@
|
||||
import { initDb, useDb } from "../../../../environment-helpers/use-db"
|
||||
|
||||
import { ICustomerModuleService } from "@medusajs/types"
|
||||
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||
import adminSeeder from "../../../../helpers/admin-seeder"
|
||||
import { createAdminUser } from "../../../helpers/create-admin-user"
|
||||
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 { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||
|
||||
jest.setTimeout(50000)
|
||||
|
||||
@@ -16,35 +10,23 @@ const adminHeaders = {
|
||||
headers: { "x-medusa-access-token": "test_token" },
|
||||
}
|
||||
|
||||
describe("GET /admin/customers", () => {
|
||||
let dbConnection
|
||||
medusaIntegrationTestRunner({
|
||||
env,
|
||||
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||
describe("GET /admin/customers", () => {
|
||||
let appContainer
|
||||
let shutdownServer
|
||||
let customerModuleService: ICustomerModuleService
|
||||
|
||||
beforeAll(async () => {
|
||||
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
|
||||
dbConnection = await initDb({ cwd, env } as any)
|
||||
shutdownServer = await startBootstrapApp({ cwd, env })
|
||||
appContainer = getContainer()
|
||||
customerModuleService = appContainer.resolve(
|
||||
ModuleRegistrationName.CUSTOMER
|
||||
)
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
const db = useDb()
|
||||
await db.shutdown()
|
||||
await shutdownServer()
|
||||
})
|
||||
|
||||
beforeEach(async () => {
|
||||
await createAdminUser(dbConnection, adminHeaders)
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
const db = useDb()
|
||||
await db.teardown()
|
||||
await createAdminUser(dbConnection, adminHeaders, appContainer)
|
||||
})
|
||||
|
||||
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)
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
@@ -95,7 +76,6 @@ describe("GET /admin/customers", () => {
|
||||
},
|
||||
])
|
||||
|
||||
const api = useApi() as any
|
||||
const response = await api.get(
|
||||
`/admin/customers?last_name=Doe`,
|
||||
adminHeaders
|
||||
@@ -120,4 +100,6 @@ describe("GET /admin/customers", () => {
|
||||
})
|
||||
)
|
||||
})
|
||||
})
|
||||
},
|
||||
})
|
||||
|
||||
@@ -1,13 +1,7 @@
|
||||
import { initDb, useDb } from "../../../../environment-helpers/use-db"
|
||||
|
||||
import { ICustomerModuleService } from "@medusajs/types"
|
||||
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||
import adminSeeder from "../../../../helpers/admin-seeder"
|
||||
import { createAdminUser } from "../../../helpers/create-admin-user"
|
||||
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 { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||
|
||||
jest.setTimeout(50000)
|
||||
|
||||
@@ -16,35 +10,22 @@ const adminHeaders = {
|
||||
headers: { "x-medusa-access-token": "test_token" },
|
||||
}
|
||||
|
||||
describe("POST /admin/customers/:id/addresses/:address_id", () => {
|
||||
let dbConnection
|
||||
medusaIntegrationTestRunner({
|
||||
env,
|
||||
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||
describe("POST /admin/customers/:id/addresses/:address_id", () => {
|
||||
let appContainer
|
||||
let shutdownServer
|
||||
let customerModuleService: ICustomerModuleService
|
||||
|
||||
beforeAll(async () => {
|
||||
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
|
||||
dbConnection = await initDb({ cwd, env } as any)
|
||||
shutdownServer = await startBootstrapApp({ cwd, env })
|
||||
appContainer = getContainer()
|
||||
customerModuleService = appContainer.resolve(
|
||||
ModuleRegistrationName.CUSTOMER
|
||||
)
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
const db = useDb()
|
||||
await db.shutdown()
|
||||
await shutdownServer()
|
||||
})
|
||||
|
||||
beforeEach(async () => {
|
||||
await createAdminUser(dbConnection, adminHeaders)
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
const db = useDb()
|
||||
await db.teardown()
|
||||
await createAdminUser(dbConnection, adminHeaders, appContainer)
|
||||
})
|
||||
|
||||
it("should update a customer address", async () => {
|
||||
@@ -60,7 +41,6 @@ describe("POST /admin/customers/:id/addresses/:address_id", () => {
|
||||
address_1: "Test street 1",
|
||||
})
|
||||
|
||||
const api = useApi() as any
|
||||
const response = await api.post(
|
||||
`/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(
|
||||
`/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(
|
||||
`/admin/customers/${customer.id}/addresses/${address.id}`,
|
||||
{
|
||||
@@ -163,4 +141,6 @@ describe("POST /admin/customers/:id/addresses/:address_id", () => {
|
||||
expect(defaultAddress.first_name).toEqual("jane")
|
||||
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 { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||
import adminSeeder from "../../../../helpers/admin-seeder"
|
||||
import { createAdminUser } from "../../../helpers/create-admin-user"
|
||||
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 { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||
|
||||
jest.setTimeout(50000)
|
||||
|
||||
@@ -16,35 +10,22 @@ const adminHeaders = {
|
||||
headers: { "x-medusa-access-token": "test_token" },
|
||||
}
|
||||
|
||||
describe("POST /admin/customers/:id", () => {
|
||||
let dbConnection
|
||||
medusaIntegrationTestRunner({
|
||||
env,
|
||||
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||
describe("POST /admin/customers/:id", () => {
|
||||
let appContainer
|
||||
let shutdownServer
|
||||
let customerModuleService: ICustomerModuleService
|
||||
|
||||
beforeAll(async () => {
|
||||
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
|
||||
dbConnection = await initDb({ cwd, env } as any)
|
||||
shutdownServer = await startBootstrapApp({ cwd, env })
|
||||
appContainer = getContainer()
|
||||
customerModuleService = appContainer.resolve(
|
||||
ModuleRegistrationName.CUSTOMER
|
||||
)
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
const db = useDb()
|
||||
await db.shutdown()
|
||||
await shutdownServer()
|
||||
})
|
||||
|
||||
beforeEach(async () => {
|
||||
await createAdminUser(dbConnection, adminHeaders)
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
const db = useDb()
|
||||
await db.teardown()
|
||||
await createAdminUser(dbConnection, adminHeaders, appContainer)
|
||||
})
|
||||
|
||||
it("should update a customer", async () => {
|
||||
@@ -53,7 +34,6 @@ describe("POST /admin/customers/:id", () => {
|
||||
last_name: "Doe",
|
||||
})
|
||||
|
||||
const api = useApi() as any
|
||||
const response = await api.post(
|
||||
`/admin/customers/${customer.id}`,
|
||||
{
|
||||
@@ -71,4 +51,6 @@ describe("POST /admin/customers/:id", () => {
|
||||
})
|
||||
)
|
||||
})
|
||||
})
|
||||
},
|
||||
})
|
||||
|
||||
@@ -1,48 +1,31 @@
|
||||
import { initDb, useDb } from "../../../../environment-helpers/use-db"
|
||||
|
||||
import { ICustomerModuleService } from "@medusajs/types"
|
||||
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||
import { createAuthenticatedCustomer } from "../../../helpers/create-authenticated-customer"
|
||||
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 { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||
|
||||
jest.setTimeout(50000)
|
||||
|
||||
const env = { MEDUSA_FF_MEDUSA_V2: true }
|
||||
|
||||
describe("POST /store/customers/me/addresses", () => {
|
||||
let dbConnection
|
||||
medusaIntegrationTestRunner({
|
||||
env,
|
||||
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||
describe("POST /store/customers/me/addresses", () => {
|
||||
let appContainer
|
||||
let shutdownServer
|
||||
let customerModuleService: ICustomerModuleService
|
||||
|
||||
beforeAll(async () => {
|
||||
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
|
||||
dbConnection = await initDb({ cwd, env } as any)
|
||||
shutdownServer = await startBootstrapApp({ cwd, env })
|
||||
appContainer = getContainer()
|
||||
customerModuleService = appContainer.resolve(
|
||||
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 () => {
|
||||
const { customer, jwt } = await createAuthenticatedCustomer(appContainer)
|
||||
const { customer, jwt } = await createAuthenticatedCustomer(
|
||||
appContainer
|
||||
)
|
||||
|
||||
const api = useApi() as any
|
||||
const response = await api.post(
|
||||
`/store/customers/me/addresses`,
|
||||
{
|
||||
@@ -71,4 +54,6 @@ describe("POST /store/customers/me/addresses", () => {
|
||||
|
||||
expect(customerWithAddresses.addresses?.length).toEqual(1)
|
||||
})
|
||||
})
|
||||
},
|
||||
})
|
||||
|
||||
@@ -1,55 +1,38 @@
|
||||
import { IAuthModuleService, ICustomerModuleService } from "@medusajs/types"
|
||||
import { initDb, useDb } from "../../../../environment-helpers/use-db"
|
||||
|
||||
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||
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 path from "path"
|
||||
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
|
||||
import { useApi } from "../../../../environment-helpers/use-api"
|
||||
import { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||
|
||||
jest.setTimeout(50000)
|
||||
|
||||
const env = { MEDUSA_FF_MEDUSA_V2: true }
|
||||
|
||||
describe("POST /store/customers", () => {
|
||||
let dbConnection
|
||||
medusaIntegrationTestRunner({
|
||||
env,
|
||||
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||
describe("POST /store/customers", () => {
|
||||
let appContainer
|
||||
let shutdownServer
|
||||
let customerModuleService: ICustomerModuleService
|
||||
|
||||
beforeAll(async () => {
|
||||
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
|
||||
dbConnection = await initDb({ cwd, env } as any)
|
||||
shutdownServer = await startBootstrapApp({ cwd, env })
|
||||
appContainer = getContainer()
|
||||
customerModuleService = appContainer.resolve(
|
||||
ModuleRegistrationName.CUSTOMER
|
||||
)
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
const db = useDb()
|
||||
await db.shutdown()
|
||||
await shutdownServer()
|
||||
})
|
||||
|
||||
beforeEach(async () => {
|
||||
await adminSeeder(dbConnection)
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
const db = useDb()
|
||||
await db.teardown()
|
||||
})
|
||||
|
||||
it("should create a customer", async () => {
|
||||
const authService: IAuthModuleService = appContainer.resolve(
|
||||
ModuleRegistrationName.AUTH
|
||||
)
|
||||
const { jwt_secret } = appContainer.resolve("configModule").projectConfig
|
||||
const { jwt_secret } =
|
||||
appContainer.resolve("configModule").projectConfig
|
||||
const authUser = await authService.create({
|
||||
entity_id: "store_user",
|
||||
provider: "emailpass",
|
||||
@@ -58,7 +41,6 @@ describe("POST /store/customers", () => {
|
||||
|
||||
const token = jwt.sign(authUser, jwt_secret)
|
||||
|
||||
const api = useApi() as any
|
||||
const response = await api.post(
|
||||
`/store/customers`,
|
||||
{
|
||||
@@ -79,4 +61,6 @@ describe("POST /store/customers", () => {
|
||||
})
|
||||
)
|
||||
})
|
||||
})
|
||||
},
|
||||
})
|
||||
|
||||
@@ -1,46 +1,30 @@
|
||||
import { initDb, useDb } from "../../../../environment-helpers/use-db"
|
||||
|
||||
import { ICustomerModuleService } from "@medusajs/types"
|
||||
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||
import { createAuthenticatedCustomer } from "../../../helpers/create-authenticated-customer"
|
||||
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 { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||
|
||||
const env = { MEDUSA_FF_MEDUSA_V2: true }
|
||||
|
||||
jest.setTimeout(50000)
|
||||
|
||||
describe("DELETE /store/customers/me/addresses/:address_id", () => {
|
||||
let dbConnection
|
||||
medusaIntegrationTestRunner({
|
||||
env,
|
||||
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||
describe("DELETE /store/customers/me/addresses/:address_id", () => {
|
||||
let appContainer
|
||||
let shutdownServer
|
||||
let customerModuleService: ICustomerModuleService
|
||||
|
||||
beforeAll(async () => {
|
||||
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
|
||||
dbConnection = await initDb({ cwd, env } as any)
|
||||
shutdownServer = await startBootstrapApp({ cwd, env })
|
||||
appContainer = getContainer()
|
||||
customerModuleService = appContainer.resolve(
|
||||
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 () => {
|
||||
const { customer, jwt } = await createAuthenticatedCustomer(appContainer)
|
||||
const { customer, jwt } = await createAuthenticatedCustomer(
|
||||
appContainer
|
||||
)
|
||||
|
||||
const address = await customerModuleService.addAddresses({
|
||||
customer_id: customer.id,
|
||||
@@ -49,7 +33,6 @@ describe("DELETE /store/customers/me/addresses/:address_id", () => {
|
||||
address_1: "Test street 1",
|
||||
})
|
||||
|
||||
const api = useApi() as any
|
||||
const response = await api.delete(
|
||||
`/store/customers/me/addresses/${address.id}`,
|
||||
{ headers: { authorization: `Bearer ${jwt}` } }
|
||||
@@ -57,9 +40,12 @@ describe("DELETE /store/customers/me/addresses/:address_id", () => {
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
|
||||
const updatedCustomer = await customerModuleService.retrieve(customer.id, {
|
||||
const updatedCustomer = await customerModuleService.retrieve(
|
||||
customer.id,
|
||||
{
|
||||
relations: ["addresses"],
|
||||
})
|
||||
}
|
||||
)
|
||||
|
||||
expect(updatedCustomer.addresses?.length).toEqual(0)
|
||||
})
|
||||
@@ -78,7 +64,6 @@ describe("DELETE /store/customers/me/addresses/:address_id", () => {
|
||||
address_1: "Test street 1",
|
||||
})
|
||||
|
||||
const api = useApi() as any
|
||||
const response = await api
|
||||
.delete(`/store/customers/me/addresses/${address.id}`, {
|
||||
headers: { authorization: `Bearer ${jwt}` },
|
||||
@@ -87,4 +72,6 @@ describe("DELETE /store/customers/me/addresses/:address_id", () => {
|
||||
|
||||
expect(response.status).toEqual(404)
|
||||
})
|
||||
})
|
||||
},
|
||||
})
|
||||
|
||||
@@ -1,48 +1,31 @@
|
||||
import { initDb, useDb } from "../../../../environment-helpers/use-db"
|
||||
|
||||
import { ICustomerModuleService } from "@medusajs/types"
|
||||
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||
import { createAuthenticatedCustomer } from "../../../helpers/create-authenticated-customer"
|
||||
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 { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||
|
||||
jest.setTimeout(50000)
|
||||
|
||||
const env = { MEDUSA_FF_MEDUSA_V2: true }
|
||||
|
||||
describe("GET /store/customers", () => {
|
||||
let dbConnection
|
||||
medusaIntegrationTestRunner({
|
||||
env,
|
||||
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||
describe("GET /store/customers", () => {
|
||||
let appContainer
|
||||
let shutdownServer
|
||||
let customerModuleService: ICustomerModuleService
|
||||
|
||||
beforeAll(async () => {
|
||||
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
|
||||
dbConnection = await initDb({ cwd, env } as any)
|
||||
shutdownServer = await startBootstrapApp({ cwd, env })
|
||||
appContainer = getContainer()
|
||||
customerModuleService = appContainer.resolve(
|
||||
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 () => {
|
||||
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`, {
|
||||
headers: { authorization: `Bearer ${jwt}` },
|
||||
})
|
||||
@@ -57,4 +40,6 @@ describe("GET /store/customers", () => {
|
||||
})
|
||||
)
|
||||
})
|
||||
})
|
||||
},
|
||||
})
|
||||
|
||||
@@ -1,50 +1,30 @@
|
||||
import { initDb, useDb } from "../../../../environment-helpers/use-db"
|
||||
|
||||
import { ICustomerModuleService } from "@medusajs/types"
|
||||
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||
import { createAuthenticatedCustomer } from "../../../helpers/create-authenticated-customer"
|
||||
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 {medusaIntegrationTestRunner} from "medusa-test-utils";
|
||||
|
||||
const env = { MEDUSA_FF_MEDUSA_V2: true }
|
||||
|
||||
jest.setTimeout(100000)
|
||||
|
||||
describe("GET /store/customers/me/addresses", () => {
|
||||
let dbConnection
|
||||
medusaIntegrationTestRunner({
|
||||
env,
|
||||
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||
describe("GET /store/customers/me/addresses", () => {
|
||||
let appContainer
|
||||
let shutdownServer
|
||||
let customerModuleService: ICustomerModuleService
|
||||
|
||||
beforeAll(async () => {
|
||||
try {
|
||||
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
|
||||
dbConnection = await initDb({ cwd, env } as any)
|
||||
shutdownServer = await startBootstrapApp({ cwd, env })
|
||||
appContainer = getContainer()
|
||||
customerModuleService = appContainer.resolve(
|
||||
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 () => {
|
||||
const { customer, jwt } = await createAuthenticatedCustomer(appContainer)
|
||||
const { customer, jwt } = await createAuthenticatedCustomer(
|
||||
appContainer
|
||||
)
|
||||
|
||||
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`, {
|
||||
headers: { authorization: `Bearer ${jwt}` },
|
||||
})
|
||||
@@ -106,4 +85,6 @@ 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 { 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 { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||
|
||||
jest.setTimeout(50000)
|
||||
|
||||
const env = { MEDUSA_FF_MEDUSA_V2: true }
|
||||
|
||||
describe("POST /store/customers/:id/addresses/:address_id", () => {
|
||||
let dbConnection
|
||||
medusaIntegrationTestRunner({
|
||||
env,
|
||||
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||
describe("POST /store/customers/:id/addresses/:address_id", () => {
|
||||
let appContainer
|
||||
let shutdownServer
|
||||
let customerModuleService: ICustomerModuleService
|
||||
|
||||
beforeAll(async () => {
|
||||
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
|
||||
dbConnection = await initDb({ cwd, env } as any)
|
||||
shutdownServer = await startBootstrapApp({ cwd, env })
|
||||
appContainer = getContainer()
|
||||
customerModuleService = appContainer.resolve(
|
||||
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 () => {
|
||||
const { customer, jwt } = await createAuthenticatedCustomer(appContainer)
|
||||
const { customer, jwt } = await createAuthenticatedCustomer(
|
||||
appContainer
|
||||
)
|
||||
|
||||
const address = await customerModuleService.addAddresses({
|
||||
customer_id: customer.id,
|
||||
@@ -49,7 +33,6 @@ describe("POST /store/customers/:id/addresses/:address_id", () => {
|
||||
address_1: "Test street 1",
|
||||
})
|
||||
|
||||
const api = useApi() as any
|
||||
const response = await api.post(
|
||||
`/store/customers/me/addresses/${address.id}`,
|
||||
{
|
||||
@@ -83,7 +66,6 @@ describe("POST /store/customers/:id/addresses/:address_id", () => {
|
||||
address_1: "Test street 1",
|
||||
})
|
||||
|
||||
const api = useApi() as any
|
||||
const response = await api
|
||||
.post(
|
||||
`/store/customers/me/addresses/${address.id}`,
|
||||
@@ -94,4 +76,6 @@ describe("POST /store/customers/:id/addresses/:address_id", () => {
|
||||
|
||||
expect(response.status).toEqual(404)
|
||||
})
|
||||
})
|
||||
},
|
||||
})
|
||||
|
||||
@@ -1,13 +1,7 @@
|
||||
import { IAuthModuleService, IUserModuleService } from "@medusajs/types"
|
||||
import { initDb, useDb } from "../../../environment-helpers/use-db"
|
||||
|
||||
import { AxiosInstance } from "axios"
|
||||
import { IUserModuleService } from "@medusajs/types"
|
||||
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||
import { createAdminUser } from "../../helpers/create-admin-user"
|
||||
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 { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||
|
||||
jest.setTimeout(50000)
|
||||
|
||||
@@ -16,38 +10,23 @@ const adminHeaders = {
|
||||
headers: { "x-medusa-access-token": "test_token" },
|
||||
}
|
||||
|
||||
describe("GET /admin/invites/:id", () => {
|
||||
let dbConnection
|
||||
medusaIntegrationTestRunner({
|
||||
env,
|
||||
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||
describe("GET /admin/invites/:id", () => {
|
||||
let appContainer
|
||||
let shutdownServer
|
||||
let userModuleService: IUserModuleService
|
||||
|
||||
beforeAll(async () => {
|
||||
const cwd = path.resolve(path.join(__dirname, "..", ".."))
|
||||
dbConnection = await initDb({ cwd, env } as any)
|
||||
shutdownServer = await startBootstrapApp({ cwd, env })
|
||||
appContainer = getContainer()
|
||||
userModuleService = appContainer.resolve(ModuleRegistrationName.USER)
|
||||
})
|
||||
|
||||
beforeEach(async () => {
|
||||
await createAdminUser(dbConnection, adminHeaders)
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
const db = useDb()
|
||||
await db.shutdown()
|
||||
await shutdownServer()
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
const db = useDb()
|
||||
await db.teardown()
|
||||
await createAdminUser(dbConnection, adminHeaders, appContainer)
|
||||
})
|
||||
|
||||
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`, {
|
||||
email: "potential_member@test.com",
|
||||
password: "supersecret",
|
||||
@@ -79,8 +58,6 @@ describe("GET /admin/invites/:id", () => {
|
||||
email: "potential_member@test.com",
|
||||
})
|
||||
|
||||
const api = useApi()! as AxiosInstance
|
||||
|
||||
const authResponse = await api.post(`/auth/admin/emailpass`, {
|
||||
email: "potential_member@test.com",
|
||||
password: "supersecret",
|
||||
@@ -109,4 +86,6 @@ 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 { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||
|
||||
jest.setTimeout(50000)
|
||||
|
||||
@@ -14,34 +8,15 @@ const adminHeaders = {
|
||||
headers: { "x-medusa-access-token": "test_token" },
|
||||
}
|
||||
|
||||
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 })
|
||||
})
|
||||
|
||||
medusaIntegrationTestRunner({
|
||||
env,
|
||||
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||
describe("POST /admin/invites", () => {
|
||||
beforeEach(async () => {
|
||||
await createAdminUser(dbConnection, adminHeaders)
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
const db = useDb()
|
||||
await db.shutdown()
|
||||
await shutdownServer()
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
const db = useDb()
|
||||
await db.teardown()
|
||||
await createAdminUser(dbConnection, adminHeaders, getContainer())
|
||||
})
|
||||
|
||||
it("create an invite", async () => {
|
||||
const api = useApi()! as AxiosInstance
|
||||
|
||||
const body = {
|
||||
email: "test_member@test.com",
|
||||
}
|
||||
@@ -53,4 +28,6 @@ describe("POST /admin/invites", () => {
|
||||
invite: expect.objectContaining(body),
|
||||
})
|
||||
})
|
||||
})
|
||||
},
|
||||
})
|
||||
|
||||
@@ -1,14 +1,7 @@
|
||||
import { initDb, useDb } from "../../../environment-helpers/use-db"
|
||||
|
||||
import { IUserModuleService } from "@medusajs/types"
|
||||
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 { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||
|
||||
jest.setTimeout(50000)
|
||||
|
||||
@@ -17,33 +10,20 @@ const adminHeaders = {
|
||||
headers: { "x-medusa-access-token": "test_token" },
|
||||
}
|
||||
|
||||
describe("DELETE /admin/invites/:id", () => {
|
||||
let dbConnection
|
||||
medusaIntegrationTestRunner({
|
||||
env,
|
||||
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||
describe("DELETE /admin/invites/:id", () => {
|
||||
let appContainer
|
||||
let shutdownServer
|
||||
let userModuleService: IUserModuleService
|
||||
|
||||
beforeAll(async () => {
|
||||
const cwd = path.resolve(path.join(__dirname, "..", ".."))
|
||||
dbConnection = await initDb({ cwd, env } as any)
|
||||
shutdownServer = await startBootstrapApp({ cwd, env })
|
||||
appContainer = getContainer()
|
||||
userModuleService = appContainer.resolve(ModuleRegistrationName.USER)
|
||||
})
|
||||
|
||||
beforeEach(async () => {
|
||||
await createAdminUser(dbConnection, adminHeaders)
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
const db = useDb()
|
||||
await db.shutdown()
|
||||
await shutdownServer()
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
const db = useDb()
|
||||
await db.teardown()
|
||||
await createAdminUser(dbConnection, adminHeaders, appContainer)
|
||||
})
|
||||
|
||||
it("should delete a single invite", async () => {
|
||||
@@ -53,8 +33,6 @@ describe("DELETE /admin/invites/:id", () => {
|
||||
expires_at: new Date(),
|
||||
})
|
||||
|
||||
const api = useApi()! as AxiosInstance
|
||||
|
||||
const response = await api.delete(
|
||||
`/admin/invites/${invite.id}`,
|
||||
adminHeaders
|
||||
@@ -74,4 +52,6 @@ describe("DELETE /admin/invites/:id", () => {
|
||||
expect(deletedResponse.status).toEqual(404)
|
||||
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 { 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 { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||
|
||||
jest.setTimeout(50000)
|
||||
|
||||
@@ -17,33 +10,20 @@ const adminHeaders = {
|
||||
headers: { "x-medusa-access-token": "test_token" },
|
||||
}
|
||||
|
||||
describe("GET /admin/invites", () => {
|
||||
let dbConnection
|
||||
medusaIntegrationTestRunner({
|
||||
env,
|
||||
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||
describe("GET /admin/invites", () => {
|
||||
let appContainer
|
||||
let shutdownServer
|
||||
let userModuleService: IUserModuleService
|
||||
|
||||
beforeAll(async () => {
|
||||
const cwd = path.resolve(path.join(__dirname, "..", ".."))
|
||||
dbConnection = await initDb({ cwd, env } as any)
|
||||
shutdownServer = await startBootstrapApp({ cwd, env })
|
||||
appContainer = getContainer()
|
||||
userModuleService = appContainer.resolve(ModuleRegistrationName.USER)
|
||||
})
|
||||
|
||||
beforeEach(async () => {
|
||||
await createAdminUser(dbConnection, adminHeaders)
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
const db = useDb()
|
||||
await db.shutdown()
|
||||
await shutdownServer()
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
const db = useDb()
|
||||
await db.teardown()
|
||||
await createAdminUser(dbConnection, adminHeaders, appContainer)
|
||||
})
|
||||
|
||||
it("should list invites", async () => {
|
||||
@@ -53,8 +33,6 @@ describe("GET /admin/invites", () => {
|
||||
expires_at: new Date(),
|
||||
})
|
||||
|
||||
const api = useApi()! as AxiosInstance
|
||||
|
||||
const response = await api.get(`/admin/invites`, adminHeaders)
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
@@ -67,4 +45,6 @@ describe("GET /admin/invites", () => {
|
||||
limit: 50,
|
||||
})
|
||||
})
|
||||
})
|
||||
},
|
||||
})
|
||||
|
||||
@@ -1,13 +1,7 @@
|
||||
import { IAuthModuleService, IUserModuleService } from "@medusajs/types"
|
||||
import { initDb, useDb } from "../../../environment-helpers/use-db"
|
||||
|
||||
import { AxiosInstance } from "axios"
|
||||
import { IUserModuleService } from "@medusajs/types"
|
||||
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||
import { createAdminUser } from "../../helpers/create-admin-user"
|
||||
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 { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||
|
||||
jest.setTimeout(50000)
|
||||
|
||||
@@ -16,33 +10,20 @@ const adminHeaders = {
|
||||
headers: { "x-medusa-access-token": "test_token" },
|
||||
}
|
||||
|
||||
describe("POST /admin/invites/:id/resend", () => {
|
||||
let dbConnection
|
||||
medusaIntegrationTestRunner({
|
||||
env,
|
||||
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||
describe("POST /admin/invites/:id/resend", () => {
|
||||
let appContainer
|
||||
let shutdownServer
|
||||
let userModuleService: IUserModuleService
|
||||
|
||||
beforeAll(async () => {
|
||||
const cwd = path.resolve(path.join(__dirname, "..", ".."))
|
||||
dbConnection = await initDb({ cwd, env } as any)
|
||||
shutdownServer = await startBootstrapApp({ cwd, env })
|
||||
appContainer = getContainer()
|
||||
userModuleService = appContainer.resolve(ModuleRegistrationName.USER)
|
||||
})
|
||||
|
||||
beforeEach(async () => {
|
||||
await createAdminUser(dbConnection, adminHeaders)
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
const db = useDb()
|
||||
await db.shutdown()
|
||||
await shutdownServer()
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
const db = useDb()
|
||||
await db.teardown()
|
||||
await createAdminUser(dbConnection, adminHeaders, appContainer)
|
||||
})
|
||||
|
||||
it("should resend a single invite", async () => {
|
||||
@@ -50,8 +31,6 @@ describe("POST /admin/invites/:id/resend", () => {
|
||||
email: "potential_member@test.com",
|
||||
})
|
||||
|
||||
const api = useApi()! as AxiosInstance
|
||||
|
||||
const response = await api.post(
|
||||
`/admin/invites/${invite.id}/resend`,
|
||||
{},
|
||||
@@ -64,4 +43,6 @@ describe("POST /admin/invites/:id/resend", () => {
|
||||
expect.objectContaining({ email: "potential_member@test.com" })
|
||||
)
|
||||
})
|
||||
})
|
||||
},
|
||||
})
|
||||
|
||||
@@ -1,13 +1,7 @@
|
||||
import { initDb, useDb } from "../../../environment-helpers/use-db"
|
||||
|
||||
import { IAuthModuleService, IUserModuleService } from "@medusajs/types"
|
||||
import { IUserModuleService } from "@medusajs/types"
|
||||
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 { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||
|
||||
jest.setTimeout(50000)
|
||||
|
||||
@@ -16,33 +10,20 @@ const adminHeaders = {
|
||||
headers: { "x-medusa-access-token": "test_token" },
|
||||
}
|
||||
|
||||
describe("GET /admin/invites/:id", () => {
|
||||
let dbConnection
|
||||
medusaIntegrationTestRunner({
|
||||
env,
|
||||
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||
describe("GET /admin/invites/:id", () => {
|
||||
let appContainer
|
||||
let shutdownServer
|
||||
let userModuleService: IUserModuleService
|
||||
|
||||
beforeAll(async () => {
|
||||
const cwd = path.resolve(path.join(__dirname, "..", ".."))
|
||||
dbConnection = await initDb({ cwd, env } as any)
|
||||
shutdownServer = await startBootstrapApp({ cwd, env })
|
||||
appContainer = getContainer()
|
||||
userModuleService = appContainer.resolve(ModuleRegistrationName.USER)
|
||||
})
|
||||
|
||||
beforeEach(async () => {
|
||||
await createAdminUser(dbConnection, adminHeaders)
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
const db = useDb()
|
||||
await db.shutdown()
|
||||
await shutdownServer()
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
const db = useDb()
|
||||
await db.teardown()
|
||||
await createAdminUser(dbConnection, adminHeaders, appContainer)
|
||||
})
|
||||
|
||||
it("should retrieve a single invite", async () => {
|
||||
@@ -50,13 +31,16 @@ describe("GET /admin/invites/:id", () => {
|
||||
email: "potential_member@test.com",
|
||||
})
|
||||
|
||||
const api = useApi()! as AxiosInstance
|
||||
|
||||
const response = await api.get(`/admin/invites/${invite.id}`, adminHeaders)
|
||||
const response = await api.get(
|
||||
`/admin/invites/${invite.id}`,
|
||||
adminHeaders
|
||||
)
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data.invite).toEqual(
|
||||
expect.objectContaining({ email: "potential_member@test.com" })
|
||||
)
|
||||
})
|
||||
})
|
||||
},
|
||||
})
|
||||
|
||||
@@ -6,19 +6,17 @@ import {
|
||||
IRegionModuleService,
|
||||
ISalesChannelModuleService,
|
||||
} 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 { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||
|
||||
jest.setTimeout(50000)
|
||||
|
||||
const env = { MEDUSA_FF_MEDUSA_V2: true }
|
||||
|
||||
describe("Cart links", () => {
|
||||
let dbConnection
|
||||
medusaIntegrationTestRunner({
|
||||
env,
|
||||
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||
describe("Cart links", () => {
|
||||
let appContainer
|
||||
let shutdownServer
|
||||
let cartModuleService: ICartModuleService
|
||||
let regionModule: IRegionModuleService
|
||||
let customerModule: ICustomerModuleService
|
||||
@@ -27,31 +25,21 @@ describe("Cart links", () => {
|
||||
let remoteQuery, remoteLink
|
||||
|
||||
beforeAll(async () => {
|
||||
const cwd = path.resolve(path.join(__dirname, "..", ".."))
|
||||
dbConnection = await initDb({ cwd, env } as any)
|
||||
shutdownServer = await startBootstrapApp({ cwd, env })
|
||||
appContainer = getContainer()
|
||||
cartModuleService = appContainer.resolve(ModuleRegistrationName.CART)
|
||||
regionModule = appContainer.resolve(ModuleRegistrationName.REGION)
|
||||
customerModule = appContainer.resolve(ModuleRegistrationName.CUSTOMER)
|
||||
scModuleService = appContainer.resolve(ModuleRegistrationName.SALES_CHANNEL)
|
||||
scModuleService = appContainer.resolve(
|
||||
ModuleRegistrationName.SALES_CHANNEL
|
||||
)
|
||||
regionModule = appContainer.resolve(ModuleRegistrationName.REGION)
|
||||
paymentModuleService = appContainer.resolve(ModuleRegistrationName.PAYMENT)
|
||||
paymentModuleService = appContainer.resolve(
|
||||
ModuleRegistrationName.PAYMENT
|
||||
)
|
||||
remoteQuery = appContainer.resolve("remoteQuery")
|
||||
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 () => {
|
||||
const region = await regionModule.create({
|
||||
name: "Region",
|
||||
@@ -202,4 +190,6 @@ describe("Cart links", () => {
|
||||
])
|
||||
)
|
||||
})
|
||||
})
|
||||
},
|
||||
})
|
||||
|
||||
@@ -1,43 +1,27 @@
|
||||
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||
import { ICartModuleService, IRegionModuleService } 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 { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||
|
||||
jest.setTimeout(50000)
|
||||
|
||||
const env = { MEDUSA_FF_MEDUSA_V2: true }
|
||||
|
||||
describe("Link: Cart Region", () => {
|
||||
let dbConnection
|
||||
medusaIntegrationTestRunner({
|
||||
env,
|
||||
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||
describe("Link: Cart Region", () => {
|
||||
let appContainer
|
||||
let shutdownServer
|
||||
let cartModuleService: ICartModuleService
|
||||
let regionModule: IRegionModuleService
|
||||
let remoteQuery
|
||||
|
||||
beforeAll(async () => {
|
||||
const cwd = path.resolve(path.join(__dirname, "..", ".."))
|
||||
dbConnection = await initDb({ cwd, env } as any)
|
||||
shutdownServer = await startBootstrapApp({ cwd, env })
|
||||
appContainer = getContainer()
|
||||
cartModuleService = appContainer.resolve(ModuleRegistrationName.CART)
|
||||
regionModule = appContainer.resolve(ModuleRegistrationName.REGION)
|
||||
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 () => {
|
||||
const region = await regionModule.create({
|
||||
name: "Region",
|
||||
@@ -88,4 +72,6 @@ describe("Link: Cart Region", () => {
|
||||
])
|
||||
)
|
||||
})
|
||||
})
|
||||
},
|
||||
})
|
||||
|
||||
@@ -3,47 +3,33 @@ import {
|
||||
IApiKeyModuleService,
|
||||
ISalesChannelModuleService,
|
||||
} 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 { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||
|
||||
jest.setTimeout(50000)
|
||||
|
||||
const env = { MEDUSA_FF_MEDUSA_V2: true }
|
||||
|
||||
describe("Publishable keys and sales channel link", () => {
|
||||
let dbConnection
|
||||
medusaIntegrationTestRunner({
|
||||
env,
|
||||
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||
describe("Publishable keys and sales channel link", () => {
|
||||
let appContainer
|
||||
let shutdownServer
|
||||
let apiKeyModule: IApiKeyModuleService
|
||||
let scModuleService: ISalesChannelModuleService
|
||||
let remoteQuery
|
||||
let remoteLink
|
||||
|
||||
beforeAll(async () => {
|
||||
const cwd = path.resolve(path.join(__dirname, "..", ".."))
|
||||
dbConnection = await initDb({ cwd, env } as any)
|
||||
shutdownServer = await startBootstrapApp({ cwd, env })
|
||||
appContainer = getContainer()
|
||||
apiKeyModule = appContainer.resolve(ModuleRegistrationName.API_KEY)
|
||||
scModuleService = appContainer.resolve(ModuleRegistrationName.SALES_CHANNEL)
|
||||
scModuleService = appContainer.resolve(
|
||||
ModuleRegistrationName.SALES_CHANNEL
|
||||
)
|
||||
remoteQuery = appContainer.resolve("remoteQuery")
|
||||
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 () => {
|
||||
const salesChannel = await scModuleService.create({
|
||||
name: "Webshop",
|
||||
@@ -102,4 +88,6 @@ describe("Publishable keys and sales channel link", () => {
|
||||
])
|
||||
)
|
||||
})
|
||||
})
|
||||
},
|
||||
})
|
||||
|
||||
@@ -1,27 +1,22 @@
|
||||
import { ModuleRegistrationName, Modules } from "@medusajs/modules-sdk"
|
||||
import { IPaymentModuleService, IRegionModuleService } 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 { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||
|
||||
jest.setTimeout(50000)
|
||||
|
||||
const env = { MEDUSA_FF_MEDUSA_V2: true }
|
||||
|
||||
describe("Region and Payment Providers", () => {
|
||||
let dbConnection
|
||||
medusaIntegrationTestRunner({
|
||||
env,
|
||||
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||
describe("Region and Payment Providers", () => {
|
||||
let appContainer
|
||||
let shutdownServer
|
||||
let regionModule: IRegionModuleService
|
||||
let paymentModule: IPaymentModuleService
|
||||
let remoteQuery
|
||||
let remoteLink
|
||||
|
||||
beforeAll(async () => {
|
||||
const cwd = path.resolve(path.join(__dirname, "..", ".."))
|
||||
dbConnection = await initDb({ cwd, env } as any)
|
||||
shutdownServer = await startBootstrapApp({ cwd, env })
|
||||
appContainer = getContainer()
|
||||
regionModule = appContainer.resolve(ModuleRegistrationName.REGION)
|
||||
paymentModule = appContainer.resolve(ModuleRegistrationName.PAYMENT)
|
||||
@@ -29,17 +24,6 @@ describe("Region and Payment Providers", () => {
|
||||
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 () => {
|
||||
const region = await regionModule.create({
|
||||
name: "North America",
|
||||
@@ -103,4 +87,6 @@ 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)
|
||||
|
||||
describe("Standalone Modules", () => {
|
||||
medusaIntegrationTestRunner({
|
||||
testSuite: ({ dbConnection }) => {
|
||||
describe("Standalone Modules", () => {
|
||||
beforeAll(async () => {
|
||||
const DB_HOST = process.env.DB_HOST
|
||||
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)
|
||||
process.env.POSTGRES_URL = dbConnection.manager.connection.options.url
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
@@ -26,4 +22,6 @@ describe("Standalone Modules", () => {
|
||||
|
||||
expect(productList).toEqual(expect.arrayContaining([]))
|
||||
})
|
||||
})
|
||||
},
|
||||
})
|
||||
|
||||
@@ -4,44 +4,28 @@ import {
|
||||
} from "@medusajs/core-flows"
|
||||
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||
import { IPaymentModuleService, IRegionModuleService } 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 { medusaIntegrationTestRunner } from "medusa-test-utils/dist"
|
||||
|
||||
jest.setTimeout(50000)
|
||||
|
||||
const env = { MEDUSA_FF_MEDUSA_V2: true }
|
||||
|
||||
describe("Carts workflows", () => {
|
||||
let dbConnection
|
||||
medusaIntegrationTestRunner({
|
||||
env,
|
||||
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||
describe("Carts workflows", () => {
|
||||
let appContainer
|
||||
let shutdownServer
|
||||
let paymentModule: IPaymentModuleService
|
||||
let regionModule: IRegionModuleService
|
||||
let remoteLink
|
||||
|
||||
beforeAll(async () => {
|
||||
const cwd = path.resolve(path.join(__dirname, "..", ".."))
|
||||
dbConnection = await initDb({ cwd, env } as any)
|
||||
shutdownServer = await startBootstrapApp({ cwd, env })
|
||||
appContainer = getContainer()
|
||||
paymentModule = appContainer.resolve(ModuleRegistrationName.PAYMENT)
|
||||
regionModule = appContainer.resolve(ModuleRegistrationName.REGION)
|
||||
remoteLink = appContainer.resolve("remoteLink")
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
const db = useDb()
|
||||
await db.shutdown()
|
||||
await shutdownServer()
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
const db = useDb()
|
||||
await db.teardown()
|
||||
})
|
||||
|
||||
describe("createPaymentSessionWorkflow", () => {
|
||||
it("should create payment sessions", async () => {
|
||||
const region = await regionModule.create({
|
||||
@@ -105,7 +89,8 @@ describe("Carts workflows", () => {
|
||||
name: "US",
|
||||
})
|
||||
|
||||
let paymentCollection = await paymentModule.createPaymentCollections({
|
||||
let paymentCollection =
|
||||
await paymentModule.createPaymentCollections({
|
||||
currency_code: "usd",
|
||||
amount: 1000,
|
||||
region_id: region.id,
|
||||
@@ -139,4 +124,6 @@ describe("Carts workflows", () => {
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
},
|
||||
})
|
||||
|
||||
@@ -1,49 +1,31 @@
|
||||
import { ModuleRegistrationName, Modules } from "@medusajs/modules-sdk"
|
||||
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 { medusaIntegrationTestRunner } from "medusa-test-utils/dist"
|
||||
|
||||
jest.setTimeout(50000)
|
||||
|
||||
const env = { MEDUSA_FF_MEDUSA_V2: true }
|
||||
|
||||
describe("Payments", () => {
|
||||
let dbConnection
|
||||
medusaIntegrationTestRunner({
|
||||
env,
|
||||
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||
describe("Payments", () => {
|
||||
let appContainer
|
||||
let shutdownServer
|
||||
let regionService: IRegionModuleService
|
||||
let remoteLink
|
||||
|
||||
beforeAll(async () => {
|
||||
const cwd = path.resolve(path.join(__dirname, "..", ".."))
|
||||
dbConnection = await initDb({ cwd, env } as any)
|
||||
shutdownServer = await startBootstrapApp({ cwd, env })
|
||||
appContainer = getContainer()
|
||||
regionService = appContainer.resolve(ModuleRegistrationName.REGION)
|
||||
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 () => {
|
||||
const region = await regionService.create({
|
||||
name: "Test Region",
|
||||
currency_code: "usd",
|
||||
})
|
||||
|
||||
const api = useApi() as any
|
||||
let response = await api.get(
|
||||
`/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.data.payment_providers).toEqual([
|
||||
@@ -71,4 +55,6 @@ 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 {
|
||||
simpleProductFactory,
|
||||
simpleRegionFactory,
|
||||
@@ -11,11 +8,10 @@ import {
|
||||
PriceListStatus,
|
||||
PriceListType,
|
||||
} from "@medusajs/types"
|
||||
import path from "path"
|
||||
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
|
||||
import adminSeeder from "../../../../helpers/admin-seeder"
|
||||
import { createDefaultRuleTypes } from "../../../helpers/create-default-rule-types"
|
||||
import { createVariantPriceSet } from "../../../helpers/create-variant-price-set"
|
||||
import { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||
|
||||
jest.setTimeout(50000)
|
||||
|
||||
@@ -29,28 +25,20 @@ const env = {
|
||||
MEDUSA_FF_MEDUSA_V2: true,
|
||||
}
|
||||
|
||||
describe.skip("POST /admin/price-lists/:id/prices/batch", () => {
|
||||
let dbConnection
|
||||
medusaIntegrationTestRunner({
|
||||
env,
|
||||
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||
describe.skip("POST /admin/price-lists/:id/prices/batch", () => {
|
||||
let appContainer
|
||||
let shutdownServer
|
||||
let product
|
||||
let variant
|
||||
let pricingModuleService: IPricingModuleService
|
||||
|
||||
beforeAll(async () => {
|
||||
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
|
||||
dbConnection = await initDb({ cwd, env } as any)
|
||||
shutdownServer = await startBootstrapApp({ cwd, env })
|
||||
appContainer = getContainer()
|
||||
pricingModuleService = appContainer.resolve("pricingModuleService")
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
const db = useDb()
|
||||
await db.shutdown()
|
||||
await shutdownServer()
|
||||
})
|
||||
|
||||
beforeEach(async () => {
|
||||
await adminSeeder(dbConnection)
|
||||
await createDefaultRuleTypes(appContainer)
|
||||
@@ -80,11 +68,6 @@ describe.skip("POST /admin/price-lists/:id/prices/batch", () => {
|
||||
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 () => {
|
||||
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 = {
|
||||
prices: [
|
||||
{
|
||||
@@ -230,4 +212,6 @@ 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 {
|
||||
simpleCustomerGroupFactory,
|
||||
simpleProductFactory,
|
||||
@@ -8,11 +5,10 @@ import {
|
||||
} from "../../../../factories"
|
||||
|
||||
import { IPricingModuleService } from "@medusajs/types"
|
||||
import path from "path"
|
||||
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
|
||||
import adminSeeder from "../../../../helpers/admin-seeder"
|
||||
import { createDefaultRuleTypes } from "../../../helpers/create-default-rule-types"
|
||||
import { createVariantPriceSet } from "../../../helpers/create-variant-price-set"
|
||||
import { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||
|
||||
jest.setTimeout(50000)
|
||||
|
||||
@@ -26,28 +22,20 @@ const env = {
|
||||
MEDUSA_FF_MEDUSA_V2: true,
|
||||
}
|
||||
|
||||
describe.skip("POST /admin/price-lists", () => {
|
||||
let dbConnection
|
||||
medusaIntegrationTestRunner({
|
||||
env,
|
||||
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||
describe.skip("POST /admin/price-lists", () => {
|
||||
let appContainer
|
||||
let shutdownServer
|
||||
let product
|
||||
let variant
|
||||
let pricingModuleService: IPricingModuleService
|
||||
|
||||
beforeAll(async () => {
|
||||
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
|
||||
dbConnection = await initDb({ cwd, env } as any)
|
||||
shutdownServer = await startBootstrapApp({ cwd, env })
|
||||
appContainer = getContainer()
|
||||
pricingModuleService = appContainer.resolve("pricingModuleService")
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
const db = useDb()
|
||||
await db.shutdown()
|
||||
await shutdownServer()
|
||||
})
|
||||
|
||||
beforeEach(async () => {
|
||||
await adminSeeder(dbConnection)
|
||||
await createDefaultRuleTypes(appContainer)
|
||||
@@ -81,11 +69,6 @@ describe.skip("POST /admin/price-lists", () => {
|
||||
variant = product.variants[0]
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
const db = useDb()
|
||||
await db.teardown()
|
||||
})
|
||||
|
||||
it("should create price list and money amounts", async () => {
|
||||
await createVariantPriceSet({
|
||||
container: appContainer,
|
||||
@@ -98,7 +81,6 @@ describe.skip("POST /admin/price-lists", () => {
|
||||
],
|
||||
})
|
||||
|
||||
const api = useApi() as any
|
||||
const data = {
|
||||
name: "test price list",
|
||||
description: "test",
|
||||
@@ -188,4 +170,6 @@ 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 {
|
||||
simpleProductFactory,
|
||||
simpleRegionFactory,
|
||||
} from "../../../../factories"
|
||||
|
||||
import { IPricingModuleService } from "@medusajs/types"
|
||||
import path from "path"
|
||||
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
|
||||
import adminSeeder from "../../../../helpers/admin-seeder"
|
||||
import { createDefaultRuleTypes } from "../../../helpers/create-default-rule-types"
|
||||
import { createVariantPriceSet } from "../../../helpers/create-variant-price-set"
|
||||
import { AxiosInstance } from "axios"
|
||||
import { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||
|
||||
jest.setTimeout(50000)
|
||||
|
||||
@@ -26,10 +21,11 @@ const env = {
|
||||
MEDUSA_FF_MEDUSA_V2: true,
|
||||
}
|
||||
|
||||
describe.skip("DELETE /admin/price-lists/:id/products/:productId/batch", () => {
|
||||
let dbConnection
|
||||
medusaIntegrationTestRunner({
|
||||
env,
|
||||
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||
describe.skip("DELETE /admin/price-lists/:id/products/:productId/batch", () => {
|
||||
let appContainer
|
||||
let shutdownServer
|
||||
let product
|
||||
let variant1
|
||||
let priceSet
|
||||
@@ -37,22 +33,11 @@ describe.skip("DELETE /admin/price-lists/:id/products/:productId/batch", () => {
|
||||
let pricingModuleService: IPricingModuleService
|
||||
|
||||
beforeAll(async () => {
|
||||
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
|
||||
dbConnection = await initDb({ cwd, env } as any)
|
||||
shutdownServer = await startBootstrapApp({ cwd, env })
|
||||
appContainer = getContainer()
|
||||
pricingModuleService = appContainer.resolve("pricingModuleService")
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
const db = useDb()
|
||||
await db.shutdown()
|
||||
await shutdownServer()
|
||||
})
|
||||
|
||||
beforeEach(async () => {
|
||||
const api = useApi()! as AxiosInstance
|
||||
|
||||
await adminSeeder(dbConnection)
|
||||
await createDefaultRuleTypes(appContainer)
|
||||
|
||||
@@ -114,14 +99,7 @@ describe.skip("DELETE /admin/price-lists/:id/products/:productId/batch", () => {
|
||||
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 () => {
|
||||
const api = useApi()! as AxiosInstance
|
||||
|
||||
let priceSetMoneyAmounts =
|
||||
await pricingModuleService.listPriceSetMoneyAmounts({
|
||||
price_set_id: [priceSet.id],
|
||||
@@ -139,7 +117,8 @@ describe.skip("DELETE /admin/price-lists/:id/products/:productId/batch", () => {
|
||||
)
|
||||
expect(deleteRes.status).toEqual(200)
|
||||
|
||||
priceSetMoneyAmounts = await pricingModuleService.listPriceSetMoneyAmounts({
|
||||
priceSetMoneyAmounts =
|
||||
await pricingModuleService.listPriceSetMoneyAmounts({
|
||||
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 () => {
|
||||
const api = useApi()! as AxiosInstance
|
||||
|
||||
let priceSetMoneyAmounts =
|
||||
await pricingModuleService.listPriceSetMoneyAmounts({
|
||||
price_set_id: [priceSet.id],
|
||||
@@ -166,7 +143,8 @@ describe.skip("DELETE /admin/price-lists/:id/products/:productId/batch", () => {
|
||||
)
|
||||
expect(deleteRes.status).toEqual(200)
|
||||
|
||||
priceSetMoneyAmounts = await pricingModuleService.listPriceSetMoneyAmounts({
|
||||
priceSetMoneyAmounts =
|
||||
await pricingModuleService.listPriceSetMoneyAmounts({
|
||||
price_set_id: [priceSet.id],
|
||||
})
|
||||
|
||||
@@ -177,4 +155,6 @@ 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 {
|
||||
simpleProductFactory,
|
||||
simpleRegionFactory,
|
||||
} from "../../../../factories"
|
||||
|
||||
import { IPricingModuleService } from "@medusajs/types"
|
||||
import path from "path"
|
||||
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
|
||||
import adminSeeder from "../../../../helpers/admin-seeder"
|
||||
import { createDefaultRuleTypes } from "../../../helpers/create-default-rule-types"
|
||||
import { createVariantPriceSet } from "../../../helpers/create-variant-price-set"
|
||||
import { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||
|
||||
jest.setTimeout(50000)
|
||||
|
||||
@@ -25,28 +21,20 @@ const env = {
|
||||
MEDUSA_FF_MEDUSA_V2: true,
|
||||
}
|
||||
|
||||
describe.skip("DELETE /admin/price-lists/:id/variants/:variantId/prices", () => {
|
||||
let dbConnection
|
||||
medusaIntegrationTestRunner({
|
||||
env,
|
||||
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||
describe.skip("DELETE /admin/price-lists/:id/variants/:variantId/prices", () => {
|
||||
let appContainer
|
||||
let shutdownServer
|
||||
let product
|
||||
let variant
|
||||
let pricingModuleService: IPricingModuleService
|
||||
|
||||
beforeAll(async () => {
|
||||
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
|
||||
dbConnection = await initDb({ cwd, env } as any)
|
||||
shutdownServer = await startBootstrapApp({ cwd, env })
|
||||
appContainer = getContainer()
|
||||
pricingModuleService = appContainer.resolve("pricingModuleService")
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
const db = useDb()
|
||||
await db.shutdown()
|
||||
await shutdownServer()
|
||||
})
|
||||
|
||||
beforeEach(async () => {
|
||||
await adminSeeder(dbConnection)
|
||||
await createDefaultRuleTypes(appContainer)
|
||||
@@ -76,11 +64,6 @@ describe.skip("DELETE /admin/price-lists/:id/variants/:variantId/prices", () =>
|
||||
variant = product.variants[0]
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
const db = useDb()
|
||||
await db.teardown()
|
||||
})
|
||||
|
||||
it("should delete all prices based on product variant ids", async () => {
|
||||
const priceSet = await createVariantPriceSet({
|
||||
container: appContainer,
|
||||
@@ -93,7 +76,6 @@ describe.skip("DELETE /admin/price-lists/:id/variants/:variantId/prices", () =>
|
||||
],
|
||||
})
|
||||
|
||||
const api = useApi() as any
|
||||
const data = {
|
||||
name: "test price list",
|
||||
description: "test",
|
||||
@@ -128,4 +110,6 @@ describe.skip("DELETE /admin/price-lists/:id/variants/:variantId/prices", () =>
|
||||
})
|
||||
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 {
|
||||
simpleProductFactory,
|
||||
simpleRegionFactory,
|
||||
} from "../../../../factories"
|
||||
|
||||
import { IPricingModuleService } from "@medusajs/types"
|
||||
import path from "path"
|
||||
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
|
||||
import adminSeeder from "../../../../helpers/admin-seeder"
|
||||
import { createDefaultRuleTypes } from "../../../helpers/create-default-rule-types"
|
||||
import { createVariantPriceSet } from "../../../helpers/create-variant-price-set"
|
||||
import { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||
|
||||
jest.setTimeout(50000)
|
||||
|
||||
@@ -25,28 +21,20 @@ const env = {
|
||||
MEDUSA_FF_MEDUSA_V2: true,
|
||||
}
|
||||
|
||||
describe.skip("DELETE /admin/price-lists/:id", () => {
|
||||
let dbConnection
|
||||
medusaIntegrationTestRunner({
|
||||
env,
|
||||
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||
describe.skip("DELETE /admin/price-lists/:id", () => {
|
||||
let appContainer
|
||||
let shutdownServer
|
||||
let product
|
||||
let variant
|
||||
let pricingModuleService: IPricingModuleService
|
||||
|
||||
beforeAll(async () => {
|
||||
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
|
||||
dbConnection = await initDb({ cwd, env } as any)
|
||||
shutdownServer = await startBootstrapApp({ cwd, env })
|
||||
appContainer = getContainer()
|
||||
pricingModuleService = appContainer.resolve("pricingModuleService")
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
const db = useDb()
|
||||
await db.shutdown()
|
||||
await shutdownServer()
|
||||
})
|
||||
|
||||
beforeEach(async () => {
|
||||
await adminSeeder(dbConnection)
|
||||
await createDefaultRuleTypes(appContainer)
|
||||
@@ -76,11 +64,6 @@ describe.skip("DELETE /admin/price-lists/:id", () => {
|
||||
variant = product.variants[0]
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
const db = useDb()
|
||||
await db.teardown()
|
||||
})
|
||||
|
||||
it("should delete price list prices by money amount ids", async () => {
|
||||
await createVariantPriceSet({
|
||||
container: appContainer,
|
||||
@@ -93,7 +76,6 @@ describe.skip("DELETE /admin/price-lists/:id", () => {
|
||||
],
|
||||
})
|
||||
|
||||
const api = useApi() as any
|
||||
const data = {
|
||||
name: "test price list",
|
||||
description: "test",
|
||||
@@ -142,4 +124,6 @@ describe.skip("DELETE /admin/price-lists/:id", () => {
|
||||
})
|
||||
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 {
|
||||
simpleProductFactory,
|
||||
simpleRegionFactory,
|
||||
} from "../../../../factories"
|
||||
|
||||
import { IPricingModuleService } from "@medusajs/types"
|
||||
import path from "path"
|
||||
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
|
||||
import adminSeeder from "../../../../helpers/admin-seeder"
|
||||
import { createDefaultRuleTypes } from "../../../helpers/create-default-rule-types"
|
||||
import { createVariantPriceSet } from "../../../helpers/create-variant-price-set"
|
||||
import { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||
|
||||
jest.setTimeout(50000)
|
||||
|
||||
@@ -25,28 +21,20 @@ const env = {
|
||||
MEDUSA_FF_MEDUSA_V2: true,
|
||||
}
|
||||
|
||||
describe.skip("DELETE /admin/price-lists/:id", () => {
|
||||
let dbConnection
|
||||
medusaIntegrationTestRunner({
|
||||
env,
|
||||
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||
describe.skip("DELETE /admin/price-lists/:id", () => {
|
||||
let appContainer
|
||||
let shutdownServer
|
||||
let product
|
||||
let variant
|
||||
let pricingModuleService: IPricingModuleService
|
||||
|
||||
beforeAll(async () => {
|
||||
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
|
||||
dbConnection = await initDb({ cwd, env } as any)
|
||||
shutdownServer = await startBootstrapApp({ cwd, env })
|
||||
appContainer = getContainer()
|
||||
pricingModuleService = appContainer.resolve("pricingModuleService")
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
const db = useDb()
|
||||
await db.shutdown()
|
||||
await shutdownServer()
|
||||
})
|
||||
|
||||
beforeEach(async () => {
|
||||
await adminSeeder(dbConnection)
|
||||
await createDefaultRuleTypes(appContainer)
|
||||
@@ -76,11 +64,6 @@ describe.skip("DELETE /admin/price-lists/:id", () => {
|
||||
variant = product.variants[0]
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
const db = useDb()
|
||||
await db.teardown()
|
||||
})
|
||||
|
||||
it("should delete price list and money amounts", async () => {
|
||||
const priceSet = await createVariantPriceSet({
|
||||
container: appContainer,
|
||||
@@ -93,7 +76,6 @@ describe.skip("DELETE /admin/price-lists/:id", () => {
|
||||
],
|
||||
})
|
||||
|
||||
const api = useApi() as any
|
||||
const data = {
|
||||
name: "test price list",
|
||||
description: "test",
|
||||
@@ -141,4 +123,6 @@ describe.skip("DELETE /admin/price-lists/:id", () => {
|
||||
})
|
||||
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 {
|
||||
@@ -8,10 +5,9 @@ import {
|
||||
PriceListStatus,
|
||||
PriceListType,
|
||||
} from "@medusajs/types"
|
||||
import path from "path"
|
||||
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
|
||||
import adminSeeder from "../../../../helpers/admin-seeder"
|
||||
import { createVariantPriceSet } from "../../../helpers/create-variant-price-set"
|
||||
import { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||
|
||||
jest.setTimeout(50000)
|
||||
|
||||
@@ -25,28 +21,20 @@ const env = {
|
||||
MEDUSA_FF_MEDUSA_V2: true,
|
||||
}
|
||||
|
||||
describe.skip("GET /admin/price-lists/:id", () => {
|
||||
let dbConnection
|
||||
medusaIntegrationTestRunner({
|
||||
env,
|
||||
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||
describe.skip("GET /admin/price-lists/:id", () => {
|
||||
let appContainer
|
||||
let shutdownServer
|
||||
let product
|
||||
let variant
|
||||
let pricingModuleService: IPricingModuleService
|
||||
|
||||
beforeAll(async () => {
|
||||
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
|
||||
dbConnection = await initDb({ cwd, env } as any)
|
||||
shutdownServer = await startBootstrapApp({ cwd, env })
|
||||
appContainer = getContainer()
|
||||
pricingModuleService = appContainer.resolve("pricingModuleService")
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
const db = useDb()
|
||||
await db.shutdown()
|
||||
await shutdownServer()
|
||||
})
|
||||
|
||||
beforeEach(async () => {
|
||||
await adminSeeder(dbConnection)
|
||||
|
||||
@@ -68,11 +56,6 @@ describe.skip("GET /admin/price-lists/:id", () => {
|
||||
variant = product.variants[0]
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
const db = useDb()
|
||||
await db.teardown()
|
||||
})
|
||||
|
||||
it("should get price list and its money amounts with variants", async () => {
|
||||
const priceSet = await createVariantPriceSet({
|
||||
container: appContainer,
|
||||
@@ -122,8 +105,6 @@ describe.skip("GET /admin/price-lists/:id", () => {
|
||||
},
|
||||
])
|
||||
|
||||
const api = useApi() as any
|
||||
|
||||
const response = await api.get(
|
||||
`/admin/price-lists/${priceList.id}`,
|
||||
adminHeaders
|
||||
@@ -188,8 +169,6 @@ describe.skip("GET /admin/price-lists/:id", () => {
|
||||
})
|
||||
|
||||
it("should throw an error when price list is not found", async () => {
|
||||
const api = useApi() as any
|
||||
|
||||
const error = await api
|
||||
.get(`/admin/price-lists/does-not-exist`, adminHeaders)
|
||||
.catch((e) => e)
|
||||
@@ -200,4 +179,6 @@ describe.skip("GET /admin/price-lists/:id", () => {
|
||||
message: "Price list with id: does-not-exist was not found",
|
||||
})
|
||||
})
|
||||
})
|
||||
},
|
||||
})
|
||||
|
||||
@@ -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 {
|
||||
@@ -8,10 +5,9 @@ import {
|
||||
PriceListStatus,
|
||||
PriceListType,
|
||||
} from "@medusajs/types"
|
||||
import path from "path"
|
||||
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
|
||||
import adminSeeder from "../../../../helpers/admin-seeder"
|
||||
import { createVariantPriceSet } from "../../../helpers/create-variant-price-set"
|
||||
import { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||
|
||||
jest.setTimeout(50000)
|
||||
|
||||
@@ -25,29 +21,21 @@ const env = {
|
||||
MEDUSA_FF_MEDUSA_V2: true,
|
||||
}
|
||||
|
||||
describe.skip("GET /admin/price-lists/:id/products", () => {
|
||||
let dbConnection
|
||||
medusaIntegrationTestRunner({
|
||||
env,
|
||||
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||
describe.skip("GET /admin/price-lists/:id/products", () => {
|
||||
let appContainer
|
||||
let shutdownServer
|
||||
let product
|
||||
let product2
|
||||
let variant
|
||||
let pricingModuleService: IPricingModuleService
|
||||
|
||||
beforeAll(async () => {
|
||||
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
|
||||
dbConnection = await initDb({ cwd, env } as any)
|
||||
shutdownServer = await startBootstrapApp({ cwd, env })
|
||||
appContainer = getContainer()
|
||||
pricingModuleService = appContainer.resolve("pricingModuleService")
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
const db = useDb()
|
||||
await db.shutdown()
|
||||
await shutdownServer()
|
||||
})
|
||||
|
||||
beforeEach(async () => {
|
||||
await adminSeeder(dbConnection)
|
||||
|
||||
@@ -74,7 +62,9 @@ describe.skip("GET /admin/price-lists/:id/products", () => {
|
||||
title: "uniquely fun product 2",
|
||||
variants: [
|
||||
{
|
||||
options: [{ option_id: "test-product-option-2", value: "test 2" }],
|
||||
options: [
|
||||
{ option_id: "test-product-option-2", value: "test 2" },
|
||||
],
|
||||
},
|
||||
],
|
||||
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 () => {
|
||||
const priceSet = await createVariantPriceSet({
|
||||
container: appContainer,
|
||||
@@ -122,8 +107,6 @@ describe.skip("GET /admin/price-lists/:id/products", () => {
|
||||
},
|
||||
])
|
||||
|
||||
const api = useApi() as any
|
||||
|
||||
let response = await api.get(
|
||||
`/admin/price-lists/${priceList.id}/products`,
|
||||
adminHeaders
|
||||
@@ -232,8 +215,6 @@ describe.skip("GET /admin/price-lists/:id/products", () => {
|
||||
},
|
||||
])
|
||||
|
||||
const api = useApi() as any
|
||||
|
||||
let response = await api.get(
|
||||
`/admin/price-lists/${priceList.id}/products?q=shouldnotreturnanything`,
|
||||
adminHeaders
|
||||
@@ -269,4 +250,6 @@ 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 {
|
||||
@@ -8,10 +5,9 @@ import {
|
||||
PriceListStatus,
|
||||
PriceListType,
|
||||
} from "@medusajs/types"
|
||||
import path from "path"
|
||||
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
|
||||
import adminSeeder from "../../../../helpers/admin-seeder"
|
||||
import { createVariantPriceSet } from "../../../helpers/create-variant-price-set"
|
||||
import { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||
|
||||
jest.setTimeout(50000)
|
||||
|
||||
@@ -25,28 +21,20 @@ const env = {
|
||||
MEDUSA_FF_MEDUSA_V2: true,
|
||||
}
|
||||
|
||||
describe.skip("GET /admin/price-lists", () => {
|
||||
let dbConnection
|
||||
medusaIntegrationTestRunner({
|
||||
env,
|
||||
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||
describe.skip("GET /admin/price-lists", () => {
|
||||
let appContainer
|
||||
let shutdownServer
|
||||
let product
|
||||
let variant
|
||||
let pricingModuleService: IPricingModuleService
|
||||
|
||||
beforeAll(async () => {
|
||||
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
|
||||
dbConnection = await initDb({ cwd, env } as any)
|
||||
shutdownServer = await startBootstrapApp({ cwd, env })
|
||||
appContainer = getContainer()
|
||||
pricingModuleService = appContainer.resolve("pricingModuleService")
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
const db = useDb()
|
||||
await db.shutdown()
|
||||
await shutdownServer()
|
||||
})
|
||||
|
||||
beforeEach(async () => {
|
||||
await adminSeeder(dbConnection)
|
||||
|
||||
@@ -68,11 +56,6 @@ describe.skip("GET /admin/price-lists", () => {
|
||||
variant = product.variants[0]
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
const db = useDb()
|
||||
await db.teardown()
|
||||
})
|
||||
|
||||
it("should get price list and its money amounts with variants", async () => {
|
||||
const priceSet = await createVariantPriceSet({
|
||||
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)
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
@@ -166,4 +147,6 @@ 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 {
|
||||
simpleCustomerGroupFactory,
|
||||
simpleProductFactory,
|
||||
@@ -12,11 +9,10 @@ import {
|
||||
PriceListStatus,
|
||||
PriceListType,
|
||||
} from "@medusajs/types"
|
||||
import path from "path"
|
||||
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
|
||||
import adminSeeder from "../../../../helpers/admin-seeder"
|
||||
import { createDefaultRuleTypes } from "../../../helpers/create-default-rule-types"
|
||||
import { createVariantPriceSet } from "../../../helpers/create-variant-price-set"
|
||||
import { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||
|
||||
jest.setTimeout(50000)
|
||||
|
||||
@@ -30,29 +26,21 @@ const env = {
|
||||
MEDUSA_FF_MEDUSA_V2: true,
|
||||
}
|
||||
|
||||
describe.skip("POST /admin/price-lists/:id", () => {
|
||||
let dbConnection
|
||||
medusaIntegrationTestRunner({
|
||||
env,
|
||||
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||
describe.skip("POST /admin/price-lists/:id", () => {
|
||||
let appContainer
|
||||
let shutdownServer
|
||||
let product
|
||||
let variant
|
||||
let variant2
|
||||
let pricingModuleService: IPricingModuleService
|
||||
|
||||
beforeAll(async () => {
|
||||
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
|
||||
dbConnection = await initDb({ cwd, env } as any)
|
||||
shutdownServer = await startBootstrapApp({ cwd, env })
|
||||
appContainer = getContainer()
|
||||
pricingModuleService = appContainer.resolve("pricingModuleService")
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
const db = useDb()
|
||||
await db.shutdown()
|
||||
await shutdownServer()
|
||||
})
|
||||
|
||||
beforeEach(async () => {
|
||||
await adminSeeder(dbConnection)
|
||||
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-2", value: "test 2" }],
|
||||
options: [
|
||||
{ option_id: "test-product-option-2", value: "test 2" },
|
||||
],
|
||||
},
|
||||
],
|
||||
options: [
|
||||
@@ -94,11 +84,6 @@ describe.skip("POST /admin/price-lists/:id", () => {
|
||||
variant2 = product.variants[1]
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
const db = useDb()
|
||||
await db.teardown()
|
||||
})
|
||||
|
||||
it("should update price lists successfully with prices", async () => {
|
||||
const var2PriceSet = await createVariantPriceSet({
|
||||
container: appContainer,
|
||||
@@ -135,7 +120,6 @@ describe.skip("POST /admin/price-lists/:id", () => {
|
||||
],
|
||||
})
|
||||
|
||||
const api = useApi() as any
|
||||
const data = {
|
||||
name: "new price list name",
|
||||
description: "new price list description",
|
||||
@@ -248,7 +232,6 @@ describe.skip("POST /admin/price-lists/:id", () => {
|
||||
prices: [],
|
||||
})
|
||||
|
||||
const api = useApi() as any
|
||||
const data = {
|
||||
status: PriceListStatus.ACTIVE,
|
||||
}
|
||||
@@ -277,4 +260,6 @@ 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 {
|
||||
simpleCustomerFactory,
|
||||
simpleCustomerGroupFactory,
|
||||
@@ -13,12 +10,10 @@ import {
|
||||
PriceListStatus,
|
||||
PriceListType,
|
||||
} 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 { createDefaultRuleTypes } from "../../../helpers/create-default-rule-types"
|
||||
import { createVariantPriceSet } from "../../../helpers/create-variant-price-set"
|
||||
import { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||
|
||||
jest.setTimeout(50000)
|
||||
|
||||
@@ -32,29 +27,21 @@ const env = {
|
||||
MEDUSA_FF_MEDUSA_V2: true,
|
||||
}
|
||||
|
||||
describe.skip("GET /store/products/:id", () => {
|
||||
let dbConnection
|
||||
medusaIntegrationTestRunner({
|
||||
env,
|
||||
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||
describe.skip("GET /store/products/:id", () => {
|
||||
let appContainer
|
||||
let shutdownServer
|
||||
let product
|
||||
let variant
|
||||
let priceSetId
|
||||
let pricingModuleService: IPricingModuleService
|
||||
|
||||
beforeAll(async () => {
|
||||
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
|
||||
dbConnection = await initDb({ cwd, env } as any)
|
||||
shutdownServer = await startBootstrapApp({ cwd, env })
|
||||
appContainer = getContainer()
|
||||
pricingModuleService = appContainer.resolve("pricingModuleService")
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
const db = useDb()
|
||||
await db.shutdown()
|
||||
await shutdownServer()
|
||||
})
|
||||
|
||||
beforeEach(async () => {
|
||||
await adminSeeder(dbConnection)
|
||||
await createDefaultRuleTypes(appContainer)
|
||||
@@ -103,14 +90,7 @@ describe.skip("GET /store/products/: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 () => {
|
||||
const api = useApi()! as AxiosInstance
|
||||
|
||||
const priceListResponse = await api.post(
|
||||
`/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 () => {
|
||||
const api = useApi()! as AxiosInstance
|
||||
|
||||
const { id: customerGroupId } = await simpleCustomerGroupFactory(
|
||||
dbConnection
|
||||
)
|
||||
@@ -210,8 +188,6 @@ describe.skip("GET /store/products/:id", () => {
|
||||
})
|
||||
|
||||
it("should list prices from price-list with customer groups", async () => {
|
||||
const api = useApi()! as AxiosInstance
|
||||
|
||||
await simpleCustomerFactory(dbConnection, {
|
||||
id: "test-customer-5-pl",
|
||||
email: "test5@email-pl.com",
|
||||
@@ -284,4 +260,6 @@ 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 { 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 { createDefaultRuleTypes } from "../../helpers/create-default-rule-types"
|
||||
import { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||
|
||||
jest.setTimeout(5000000)
|
||||
|
||||
@@ -28,24 +23,15 @@ const env = {
|
||||
MEDUSA_FF_MEDUSA_V2: true,
|
||||
}
|
||||
|
||||
describe.skip("Link Modules", () => {
|
||||
medusaIntegrationTestRunner({
|
||||
env,
|
||||
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||
describe.skip("Link Modules", () => {
|
||||
let medusaContainer
|
||||
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 })
|
||||
medusaContainer = getContainer()
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
const db = useDb()
|
||||
await db.shutdown()
|
||||
await shutdownServer()
|
||||
})
|
||||
|
||||
beforeEach(async () => {
|
||||
await createDefaultRuleTypes(medusaContainer)
|
||||
await adminSeeder(dbConnection)
|
||||
@@ -64,9 +50,11 @@ describe.skip("Link Modules", () => {
|
||||
const pricingModuleService = medusaContainer.resolve(
|
||||
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 = {
|
||||
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
|
||||
const variant = response.data.product.variants[0]
|
||||
@@ -119,8 +111,6 @@ describe.skip("Link Modules", () => {
|
||||
})
|
||||
|
||||
it("Should get prices declared in pricing module", async () => {
|
||||
const api = useApi()! as AxiosInstance
|
||||
|
||||
const response = await api.get(
|
||||
`/store/products/${productId}?cart_id=${cartId}`
|
||||
)
|
||||
@@ -133,4 +123,6 @@ describe.skip("Link Modules", () => {
|
||||
])
|
||||
})
|
||||
})
|
||||
})
|
||||
},
|
||||
})
|
||||
|
||||
@@ -1,17 +1,12 @@
|
||||
import { PricingModuleService } from "@medusajs/pricing"
|
||||
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 {
|
||||
simpleProductFactory,
|
||||
simpleRegionFactory,
|
||||
} from "../../../../factories"
|
||||
import adminSeeder from "../../../../helpers/admin-seeder"
|
||||
import { createDefaultRuleTypes } from "../../../helpers/create-default-rule-types"
|
||||
import { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||
|
||||
jest.setTimeout(50000)
|
||||
|
||||
@@ -25,26 +20,18 @@ const env = {
|
||||
MEDUSA_FF_MEDUSA_V2: true,
|
||||
}
|
||||
|
||||
describe.skip("POST /admin/products/:id/variants", () => {
|
||||
let dbConnection
|
||||
medusaIntegrationTestRunner({
|
||||
env,
|
||||
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||
describe.skip("POST /admin/products/:id/variants", () => {
|
||||
let appContainer
|
||||
let shutdownServer
|
||||
let product
|
||||
let variant
|
||||
|
||||
beforeAll(async () => {
|
||||
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
|
||||
dbConnection = await initDb({ cwd, env } as any)
|
||||
shutdownServer = await startBootstrapApp({ cwd, env })
|
||||
appContainer = getContainer()
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
const db = useDb()
|
||||
await db.shutdown()
|
||||
await shutdownServer()
|
||||
})
|
||||
|
||||
beforeEach(async () => {
|
||||
await adminSeeder(dbConnection)
|
||||
await createDefaultRuleTypes(appContainer)
|
||||
@@ -74,13 +61,7 @@ describe.skip("POST /admin/products/:id/variants", () => {
|
||||
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 () => {
|
||||
const api = useApi()! as AxiosInstance
|
||||
const data = {
|
||||
title: "test variant create",
|
||||
prices: [
|
||||
@@ -110,7 +91,9 @@ describe.skip("POST /admin/products/:id/variants", () => {
|
||||
height: 234,
|
||||
length: 234,
|
||||
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(
|
||||
@@ -156,7 +139,6 @@ describe.skip("POST /admin/products/:id/variants", () => {
|
||||
"deleteVariants"
|
||||
)
|
||||
|
||||
const api = useApi()! as AxiosInstance
|
||||
const data = {
|
||||
title: "test variant create",
|
||||
prices: [
|
||||
@@ -186,7 +168,9 @@ describe.skip("POST /admin/products/:id/variants", () => {
|
||||
height: 234,
|
||||
length: 234,
|
||||
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
|
||||
@@ -201,4 +185,6 @@ describe.skip("POST /admin/products/:id/variants", () => {
|
||||
)
|
||||
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 { medusaIntegrationTestRunner } from "medusa-test-utils/dist"
|
||||
|
||||
jest.setTimeout(50000)
|
||||
|
||||
@@ -26,27 +13,18 @@ const env = {
|
||||
MEDUSA_FF_MEDUSA_V2: true,
|
||||
}
|
||||
|
||||
describe("/admin/products", () => {
|
||||
let dbConnection
|
||||
let shutdownServer
|
||||
medusaIntegrationTestRunner({
|
||||
env,
|
||||
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||
describe("/admin/products", () => {
|
||||
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()
|
||||
})
|
||||
|
||||
describe("POST /admin/products", () => {
|
||||
beforeEach(async () => {
|
||||
await createAdminUser(dbConnection, adminHeaders)
|
||||
await createAdminUser(dbConnection, adminHeaders, medusaContainer)
|
||||
|
||||
// await productSeeder(dbConnection)
|
||||
// await createDefaultRuleTypes(medusaContainer)
|
||||
@@ -57,14 +35,8 @@ describe("/admin/products", () => {
|
||||
// })
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
const db = useDb()
|
||||
await db.teardown()
|
||||
})
|
||||
|
||||
describe("POST /admin/products", () => {
|
||||
it("should create a product", async () => {
|
||||
const api = useApi()! as AxiosInstance
|
||||
|
||||
const payload = {
|
||||
title: "Test",
|
||||
description: "test-product-description",
|
||||
@@ -243,8 +215,6 @@ describe("/admin/products", () => {
|
||||
})
|
||||
|
||||
it("should create a product that is not discountable", async () => {
|
||||
const api = useApi()! as AxiosInstance
|
||||
|
||||
const payload = {
|
||||
title: "Test",
|
||||
discountable: false,
|
||||
@@ -279,8 +249,6 @@ describe("/admin/products", () => {
|
||||
})
|
||||
|
||||
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",
|
||||
@@ -340,8 +308,6 @@ describe("/admin/products", () => {
|
||||
})
|
||||
|
||||
it("should create a giftcard", async () => {
|
||||
const api = useApi()! as AxiosInstance
|
||||
|
||||
const payload = {
|
||||
title: "Test Giftcard",
|
||||
is_giftcard: true,
|
||||
@@ -373,8 +339,6 @@ describe("/admin/products", () => {
|
||||
})
|
||||
|
||||
it("should create variants with inventory items", async () => {
|
||||
const api = useApi()! as AxiosInstance
|
||||
|
||||
const response = await api.post(
|
||||
`/admin/products`,
|
||||
{
|
||||
@@ -491,4 +455,6 @@ describe("/admin/products", () => {
|
||||
// expect(count).toEqual(1)
|
||||
// })
|
||||
})
|
||||
})
|
||||
},
|
||||
})
|
||||
|
||||
@@ -24,6 +24,10 @@ const env: Record<any, any> = {
|
||||
|
||||
jest.setTimeout(180000)
|
||||
|
||||
// TODO SEE to use new test runner medusaIntegrationTestRunner({
|
||||
// env,
|
||||
// testSuite: ({ dbConnection, getContainer, api }) => {})
|
||||
|
||||
describe.skip("Batch job of product-export type", () => {
|
||||
let medusaProcess
|
||||
let dbConnection
|
||||
|
||||
@@ -56,6 +56,10 @@ const env: Record<any, any> = {
|
||||
MEDUSA_FF_MEDUSA_V2: true,
|
||||
}
|
||||
|
||||
// TODO SEE to use new test runner medusaIntegrationTestRunner({
|
||||
// env,
|
||||
// testSuite: ({ dbConnection, getContainer, api }) => {})
|
||||
|
||||
describe.skip("Product import batch job", () => {
|
||||
let dbConnection
|
||||
let shutdownServer
|
||||
|
||||
659
integration-tests/modules/__tests__/product/admin/index.ts
Normal file
659
integration-tests/modules/__tests__/product/admin/index.ts
Normal file
@@ -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,17 +1,16 @@
|
||||
import { initDb, useDb } from "../../../../environment-helpers/use-db"
|
||||
import {
|
||||
simpleProductFactory,
|
||||
simpleRegionFactory,
|
||||
} from "../../../../factories"
|
||||
import {initDb, useDb} from "../../../../environment-helpers/use-db"
|
||||
import {simpleProductFactory, simpleRegionFactory,} from "../../../../factories"
|
||||
|
||||
import { AxiosInstance } from "axios"
|
||||
import {AxiosInstance} from "axios"
|
||||
import adminSeeder from "../../../../helpers/admin-seeder"
|
||||
import { createDefaultRuleTypes } from "../../../helpers/create-default-rule-types"
|
||||
import { createVariantPriceSet } from "../../../helpers/create-variant-price-set"
|
||||
import { getContainer } from "../../../../environment-helpers/use-container"
|
||||
import {
|
||||
createDefaultRuleTypes
|
||||
} from "../../../helpers/create-default-rule-types"
|
||||
import {createVariantPriceSet} from "../../../helpers/create-variant-price-set"
|
||||
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 {startBootstrapApp} from "../../../../environment-helpers/bootstrap-app"
|
||||
import {useApi} from "../../../../environment-helpers/use-api"
|
||||
|
||||
jest.setTimeout(50000)
|
||||
|
||||
@@ -25,6 +24,10 @@ const env = {
|
||||
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", () => {
|
||||
let dbConnection
|
||||
let appContainer
|
||||
|
||||
@@ -23,6 +23,10 @@ const env = {
|
||||
MEDUSA_FF_MEDUSA_V2: true,
|
||||
}
|
||||
|
||||
// TODO SEE to use new test runner medusaIntegrationTestRunner({
|
||||
// env,
|
||||
// testSuite: ({ dbConnection, getContainer, api }) => {})
|
||||
|
||||
describe.skip("POST /admin/products/:id", () => {
|
||||
let dbConnection
|
||||
let appContainer
|
||||
|
||||
@@ -1,12 +1,7 @@
|
||||
import { initDb, useDb } from "../../../../environment-helpers/use-db"
|
||||
|
||||
import { IPromotionModuleService } from "@medusajs/types"
|
||||
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||
import { createAdminUser } from "../../../helpers/create-admin-user"
|
||||
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 { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||
|
||||
jest.setTimeout(50000)
|
||||
|
||||
@@ -15,39 +10,25 @@ const adminHeaders = {
|
||||
headers: { "x-medusa-access-token": "test_token" },
|
||||
}
|
||||
|
||||
describe("POST /admin/campaigns", () => {
|
||||
let dbConnection
|
||||
medusaIntegrationTestRunner({
|
||||
env,
|
||||
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||
describe("POST /admin/campaigns", () => {
|
||||
let appContainer
|
||||
let shutdownServer
|
||||
let promotionModuleService: IPromotionModuleService
|
||||
|
||||
beforeAll(async () => {
|
||||
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
|
||||
dbConnection = await initDb({ cwd, env } as any)
|
||||
shutdownServer = await startBootstrapApp({ cwd, env })
|
||||
appContainer = getContainer()
|
||||
promotionModuleService = appContainer.resolve(
|
||||
ModuleRegistrationName.PROMOTION
|
||||
)
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
const db = useDb()
|
||||
await db.shutdown()
|
||||
await shutdownServer()
|
||||
})
|
||||
|
||||
beforeEach(async () => {
|
||||
await createAdminUser(dbConnection, adminHeaders)
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
const db = useDb()
|
||||
await db.teardown()
|
||||
await createAdminUser(dbConnection, adminHeaders, appContainer)
|
||||
})
|
||||
|
||||
it("should throw an error if required params are not passed", async () => {
|
||||
const api = useApi() as any
|
||||
const { response } = await api
|
||||
.post(`/admin/campaigns`, {}, adminHeaders)
|
||||
.catch((e) => e)
|
||||
@@ -64,7 +45,6 @@ describe("POST /admin/campaigns", () => {
|
||||
type: "standard",
|
||||
})
|
||||
|
||||
const api = useApi() as any
|
||||
const response = await api.post(
|
||||
`/admin/campaigns`,
|
||||
{
|
||||
@@ -113,8 +93,6 @@ describe("POST /admin/campaigns", () => {
|
||||
"createCampaigns"
|
||||
)
|
||||
|
||||
const api = useApi() as any
|
||||
|
||||
const a = async () => {
|
||||
return await api.post(
|
||||
`/admin/campaigns`,
|
||||
@@ -195,4 +173,6 @@ describe("POST /admin/campaigns", () => {
|
||||
expect(distinctRequestId).toHaveLength(3)
|
||||
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 { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||
import { PromotionType } from "@medusajs/utils"
|
||||
import { createAdminUser } from "../../../helpers/create-admin-user"
|
||||
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 { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||
|
||||
jest.setTimeout(50000)
|
||||
|
||||
@@ -16,39 +11,25 @@ const adminHeaders = {
|
||||
headers: { "x-medusa-access-token": "test_token" },
|
||||
}
|
||||
|
||||
describe("POST /admin/promotions", () => {
|
||||
let dbConnection
|
||||
medusaIntegrationTestRunner({
|
||||
env,
|
||||
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||
describe("POST /admin/promotions", () => {
|
||||
let appContainer
|
||||
let shutdownServer
|
||||
let promotionModuleService: IPromotionModuleService
|
||||
|
||||
beforeAll(async () => {
|
||||
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
|
||||
dbConnection = await initDb({ cwd, env } as any)
|
||||
shutdownServer = await startBootstrapApp({ cwd, env })
|
||||
appContainer = getContainer()
|
||||
promotionModuleService = appContainer.resolve(
|
||||
ModuleRegistrationName.PROMOTION
|
||||
)
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
const db = useDb()
|
||||
await db.shutdown()
|
||||
await shutdownServer()
|
||||
})
|
||||
|
||||
beforeEach(async () => {
|
||||
await createAdminUser(dbConnection, adminHeaders)
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
const db = useDb()
|
||||
await db.teardown()
|
||||
await createAdminUser(dbConnection, adminHeaders, appContainer)
|
||||
})
|
||||
|
||||
it("should throw an error if required params are not passed", async () => {
|
||||
const api = useApi() as any
|
||||
const { response } = await api
|
||||
.post(
|
||||
`/admin/promotions`,
|
||||
@@ -66,7 +47,6 @@ describe("POST /admin/promotions", () => {
|
||||
})
|
||||
|
||||
it("should create a standard promotion successfully", async () => {
|
||||
const api = useApi() as any
|
||||
const response = await api.post(
|
||||
`/admin/promotions`,
|
||||
{
|
||||
@@ -153,7 +133,6 @@ describe("POST /admin/promotions", () => {
|
||||
})
|
||||
|
||||
it("should throw an error if buy_rules params are not passed", async () => {
|
||||
const api = useApi() as any
|
||||
const { response } = await api
|
||||
.post(
|
||||
`/admin/promotions`,
|
||||
@@ -194,7 +173,6 @@ describe("POST /admin/promotions", () => {
|
||||
})
|
||||
|
||||
it("should throw an error if buy_rules params are not passed", async () => {
|
||||
const api = useApi() as any
|
||||
const { response } = await api
|
||||
.post(
|
||||
`/admin/promotions`,
|
||||
@@ -235,7 +213,6 @@ describe("POST /admin/promotions", () => {
|
||||
})
|
||||
|
||||
it("should create a buyget promotion successfully", async () => {
|
||||
const api = useApi() as any
|
||||
const response = await api.post(
|
||||
`/admin/promotions`,
|
||||
{
|
||||
@@ -341,4 +318,6 @@ describe("POST /admin/promotions", () => {
|
||||
})
|
||||
)
|
||||
})
|
||||
})
|
||||
},
|
||||
})
|
||||
|
||||
@@ -1,12 +1,7 @@
|
||||
import { initDb, useDb } from "../../../../environment-helpers/use-db"
|
||||
|
||||
import { IPromotionModuleService } from "@medusajs/types"
|
||||
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||
import { createAdminUser } from "../../../helpers/create-admin-user"
|
||||
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 { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||
|
||||
jest.setTimeout(50000)
|
||||
|
||||
@@ -15,35 +10,22 @@ const adminHeaders = {
|
||||
headers: { "x-medusa-access-token": "test_token" },
|
||||
}
|
||||
|
||||
describe("DELETE /admin/campaigns/:id", () => {
|
||||
let dbConnection
|
||||
medusaIntegrationTestRunner({
|
||||
env,
|
||||
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||
describe("DELETE /admin/campaigns/:id", () => {
|
||||
let appContainer
|
||||
let shutdownServer
|
||||
let promotionModuleService: IPromotionModuleService
|
||||
|
||||
beforeAll(async () => {
|
||||
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
|
||||
dbConnection = await initDb({ cwd, env } as any)
|
||||
shutdownServer = await startBootstrapApp({ cwd, env })
|
||||
appContainer = getContainer()
|
||||
promotionModuleService = appContainer.resolve(
|
||||
ModuleRegistrationName.PROMOTION
|
||||
)
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
const db = useDb()
|
||||
await db.shutdown()
|
||||
await shutdownServer()
|
||||
})
|
||||
|
||||
beforeEach(async () => {
|
||||
await createAdminUser(dbConnection, adminHeaders)
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
const db = useDb()
|
||||
await db.teardown()
|
||||
await createAdminUser(dbConnection, adminHeaders, appContainer)
|
||||
})
|
||||
|
||||
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(
|
||||
`/admin/campaigns/${createdCampaign.id}`,
|
||||
adminHeaders
|
||||
@@ -70,4 +51,6 @@ describe("DELETE /admin/campaigns/:id", () => {
|
||||
|
||||
expect(campaigns.length).toEqual(0)
|
||||
})
|
||||
})
|
||||
},
|
||||
})
|
||||
|
||||
@@ -1,12 +1,7 @@
|
||||
import { initDb, useDb } from "../../../../environment-helpers/use-db"
|
||||
|
||||
import { IPromotionModuleService } from "@medusajs/types"
|
||||
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||
import { createAdminUser } from "../../../helpers/create-admin-user"
|
||||
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 { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||
|
||||
jest.setTimeout(50000)
|
||||
|
||||
@@ -15,35 +10,22 @@ const adminHeaders = {
|
||||
headers: { "x-medusa-access-token": "test_token" },
|
||||
}
|
||||
|
||||
describe("DELETE /admin/promotions/:id", () => {
|
||||
let dbConnection
|
||||
medusaIntegrationTestRunner({
|
||||
env,
|
||||
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||
describe("DELETE /admin/promotions/:id", () => {
|
||||
let appContainer
|
||||
let shutdownServer
|
||||
let promotionModuleService: IPromotionModuleService
|
||||
|
||||
beforeAll(async () => {
|
||||
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
|
||||
dbConnection = await initDb({ cwd, env } as any)
|
||||
shutdownServer = await startBootstrapApp({ cwd, env })
|
||||
appContainer = getContainer()
|
||||
promotionModuleService = appContainer.resolve(
|
||||
ModuleRegistrationName.PROMOTION
|
||||
)
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
const db = useDb()
|
||||
await db.shutdown()
|
||||
await shutdownServer()
|
||||
})
|
||||
|
||||
beforeEach(async () => {
|
||||
await createAdminUser(dbConnection, adminHeaders)
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
const db = useDb()
|
||||
await db.teardown()
|
||||
await createAdminUser(dbConnection, adminHeaders, appContainer)
|
||||
})
|
||||
|
||||
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(
|
||||
`/admin/promotions/${createdPromotion.id}`,
|
||||
adminHeaders
|
||||
@@ -71,4 +52,6 @@ describe("DELETE /admin/promotions/:id", () => {
|
||||
|
||||
expect(promotions.length).toEqual(0)
|
||||
})
|
||||
})
|
||||
},
|
||||
})
|
||||
|
||||
@@ -1,13 +1,8 @@
|
||||
import { initDb, useDb } from "../../../../environment-helpers/use-db"
|
||||
|
||||
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||
import { IPromotionModuleService } from "@medusajs/types"
|
||||
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 { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||
|
||||
jest.setTimeout(50000)
|
||||
|
||||
@@ -47,40 +42,26 @@ const adminHeaders = {
|
||||
headers: { "x-medusa-access-token": "test_token" },
|
||||
}
|
||||
|
||||
describe("GET /admin/campaigns", () => {
|
||||
let dbConnection
|
||||
medusaIntegrationTestRunner({
|
||||
env,
|
||||
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||
describe("GET /admin/campaigns", () => {
|
||||
let appContainer
|
||||
let shutdownServer
|
||||
let promotionModuleService: IPromotionModuleService
|
||||
|
||||
beforeAll(async () => {
|
||||
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
|
||||
dbConnection = await initDb({ cwd, env } as any)
|
||||
shutdownServer = await startBootstrapApp({ cwd, env })
|
||||
appContainer = getContainer()
|
||||
promotionModuleService = appContainer.resolve(
|
||||
ModuleRegistrationName.PROMOTION
|
||||
)
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
const db = useDb()
|
||||
await db.shutdown()
|
||||
await shutdownServer()
|
||||
})
|
||||
|
||||
beforeEach(async () => {
|
||||
await createAdminUser(dbConnection, adminHeaders)
|
||||
await createAdminUser(dbConnection, adminHeaders, appContainer)
|
||||
await promotionModuleService.createCampaigns(campaignsData)
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
const db = useDb()
|
||||
await db.teardown()
|
||||
})
|
||||
|
||||
it("should get all campaigns and its count", async () => {
|
||||
const api = useApi() as any
|
||||
const response = await api.get(`/admin/campaigns`, adminHeaders)
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
@@ -152,7 +133,6 @@ describe("GET /admin/campaigns", () => {
|
||||
})
|
||||
|
||||
it("should get all campaigns and its count filtered", async () => {
|
||||
const api = useApi() as any
|
||||
const response = await api.get(
|
||||
`/admin/campaigns?fields=name,created_at,budget.id`,
|
||||
adminHeaders
|
||||
@@ -183,4 +163,6 @@ describe("GET /admin/campaigns", () => {
|
||||
])
|
||||
)
|
||||
})
|
||||
})
|
||||
},
|
||||
})
|
||||
|
||||
@@ -1,13 +1,8 @@
|
||||
import { initDb, useDb } from "../../../../environment-helpers/use-db"
|
||||
|
||||
import { IPromotionModuleService } from "@medusajs/types"
|
||||
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||
import { PromotionType } from "@medusajs/utils"
|
||||
import { createAdminUser } from "../../../helpers/create-admin-user"
|
||||
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 { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||
|
||||
jest.setTimeout(50000)
|
||||
|
||||
@@ -16,35 +11,22 @@ const adminHeaders = {
|
||||
headers: { "x-medusa-access-token": "test_token" },
|
||||
}
|
||||
|
||||
describe("GET /admin/promotions", () => {
|
||||
let dbConnection
|
||||
medusaIntegrationTestRunner({
|
||||
env,
|
||||
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||
describe("GET /admin/promotions", () => {
|
||||
let appContainer
|
||||
let shutdownServer
|
||||
let promotionModuleService: IPromotionModuleService
|
||||
|
||||
beforeAll(async () => {
|
||||
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
|
||||
dbConnection = await initDb({ cwd, env } as any)
|
||||
shutdownServer = await startBootstrapApp({ cwd, env })
|
||||
appContainer = getContainer()
|
||||
promotionModuleService = appContainer.resolve(
|
||||
ModuleRegistrationName.PROMOTION
|
||||
)
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
const db = useDb()
|
||||
await db.shutdown()
|
||||
await shutdownServer()
|
||||
})
|
||||
|
||||
beforeEach(async () => {
|
||||
await createAdminUser(dbConnection, adminHeaders)
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
const db = useDb()
|
||||
await db.teardown()
|
||||
await createAdminUser(dbConnection, adminHeaders, appContainer)
|
||||
})
|
||||
|
||||
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)
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
@@ -102,7 +83,6 @@ describe("GET /admin/promotions", () => {
|
||||
},
|
||||
])
|
||||
|
||||
const api = useApi() as any
|
||||
const response = await api.get(
|
||||
`/admin/promotions?fields=code,created_at,application_method.id`,
|
||||
adminHeaders
|
||||
@@ -122,4 +102,6 @@ describe("GET /admin/promotions", () => {
|
||||
},
|
||||
])
|
||||
})
|
||||
})
|
||||
},
|
||||
})
|
||||
|
||||
@@ -1,13 +1,8 @@
|
||||
import { initDb, useDb } from "../../../../environment-helpers/use-db"
|
||||
|
||||
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||
import { IPromotionModuleService } from "@medusajs/types"
|
||||
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 { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||
|
||||
jest.setTimeout(50000)
|
||||
|
||||
@@ -30,43 +25,25 @@ const adminHeaders = {
|
||||
headers: { "x-medusa-access-token": "test_token" },
|
||||
}
|
||||
|
||||
describe("GET /admin/campaigns", () => {
|
||||
let dbConnection
|
||||
medusaIntegrationTestRunner({
|
||||
env,
|
||||
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||
describe("GET /admin/campaigns", () => {
|
||||
let appContainer
|
||||
let shutdownServer
|
||||
let promotionModuleService: IPromotionModuleService
|
||||
|
||||
beforeAll(async () => {
|
||||
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
|
||||
dbConnection = await initDb({ cwd, env } as any)
|
||||
shutdownServer = await startBootstrapApp({ cwd, env })
|
||||
appContainer = getContainer()
|
||||
promotionModuleService = appContainer.resolve(
|
||||
ModuleRegistrationName.PROMOTION
|
||||
)
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
const db = useDb()
|
||||
await db.shutdown()
|
||||
await shutdownServer()
|
||||
})
|
||||
|
||||
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 () => {
|
||||
const api = useApi() as any
|
||||
const { response } = await api
|
||||
.get(`/admin/campaigns/does-not-exist`, adminHeaders)
|
||||
.catch((e) => e)
|
||||
@@ -82,7 +59,6 @@ describe("GET /admin/campaigns", () => {
|
||||
campaignData
|
||||
)
|
||||
|
||||
const api = useApi() as any
|
||||
const response = await api.get(
|
||||
`/admin/campaigns/${createdCampaign.id}`,
|
||||
adminHeaders
|
||||
@@ -126,7 +102,6 @@ describe("GET /admin/campaigns", () => {
|
||||
campaignData
|
||||
)
|
||||
|
||||
const api = useApi() as any
|
||||
const response = await api.get(
|
||||
`/admin/campaigns/${createdCampaign.id}?fields=name&expand=`,
|
||||
adminHeaders
|
||||
@@ -138,4 +113,6 @@ describe("GET /admin/campaigns", () => {
|
||||
name: "campaign 1",
|
||||
})
|
||||
})
|
||||
})
|
||||
},
|
||||
})
|
||||
|
||||
@@ -1,13 +1,8 @@
|
||||
import { initDb, useDb } from "../../../../environment-helpers/use-db"
|
||||
|
||||
import { IPromotionModuleService } from "@medusajs/types"
|
||||
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||
import { PromotionType } from "@medusajs/utils"
|
||||
import { createAdminUser } from "../../../helpers/create-admin-user"
|
||||
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 { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||
|
||||
jest.setTimeout(50000)
|
||||
|
||||
@@ -16,39 +11,25 @@ const adminHeaders = {
|
||||
headers: { "x-medusa-access-token": "test_token" },
|
||||
}
|
||||
|
||||
describe("GET /admin/promotions", () => {
|
||||
let dbConnection
|
||||
medusaIntegrationTestRunner({
|
||||
env,
|
||||
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||
describe("GET /admin/promotions", () => {
|
||||
let appContainer
|
||||
let shutdownServer
|
||||
let promotionModuleService: IPromotionModuleService
|
||||
|
||||
beforeAll(async () => {
|
||||
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
|
||||
dbConnection = await initDb({ cwd, env } as any)
|
||||
shutdownServer = await startBootstrapApp({ cwd, env })
|
||||
appContainer = getContainer()
|
||||
promotionModuleService = appContainer.resolve(
|
||||
ModuleRegistrationName.PROMOTION
|
||||
)
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
const db = useDb()
|
||||
await db.shutdown()
|
||||
await shutdownServer()
|
||||
})
|
||||
|
||||
beforeEach(async () => {
|
||||
await createAdminUser(dbConnection, adminHeaders)
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
const db = useDb()
|
||||
await db.teardown()
|
||||
await createAdminUser(dbConnection, adminHeaders, appContainer)
|
||||
})
|
||||
|
||||
it("should throw an error if id does not exist", async () => {
|
||||
const api = useApi() as any
|
||||
const { response } = await api
|
||||
.get(`/admin/promotions/does-not-exist`, adminHeaders)
|
||||
.catch((e) => e)
|
||||
@@ -70,7 +51,6 @@ describe("GET /admin/promotions", () => {
|
||||
},
|
||||
})
|
||||
|
||||
const api = useApi() as any
|
||||
const response = await api.get(
|
||||
`/admin/promotions/${createdPromotion.id}`,
|
||||
adminHeaders
|
||||
@@ -114,7 +94,6 @@ describe("GET /admin/promotions", () => {
|
||||
},
|
||||
})
|
||||
|
||||
const api = useApi() as any
|
||||
const response = await api.get(
|
||||
`/admin/promotions/${createdPromotion.id}?fields=id,code&expand=`,
|
||||
adminHeaders
|
||||
@@ -126,4 +105,6 @@ describe("GET /admin/promotions", () => {
|
||||
code: "TEST",
|
||||
})
|
||||
})
|
||||
})
|
||||
},
|
||||
})
|
||||
|
||||
@@ -1,12 +1,7 @@
|
||||
import { initDb, useDb } from "../../../../environment-helpers/use-db"
|
||||
|
||||
import { IPromotionModuleService } from "@medusajs/types"
|
||||
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||
import { createAdminUser } from "../../../helpers/create-admin-user"
|
||||
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 { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||
|
||||
jest.setTimeout(50000)
|
||||
|
||||
@@ -15,39 +10,25 @@ const adminHeaders = {
|
||||
headers: { "x-medusa-access-token": "test_token" },
|
||||
}
|
||||
|
||||
describe("POST /admin/campaigns/:id", () => {
|
||||
let dbConnection
|
||||
medusaIntegrationTestRunner({
|
||||
env,
|
||||
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||
describe("POST /admin/campaigns/:id", () => {
|
||||
let appContainer
|
||||
let shutdownServer
|
||||
let promotionModuleService: IPromotionModuleService
|
||||
|
||||
beforeAll(async () => {
|
||||
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
|
||||
dbConnection = await initDb({ cwd, env } as any)
|
||||
shutdownServer = await startBootstrapApp({ cwd, env })
|
||||
appContainer = getContainer()
|
||||
promotionModuleService = appContainer.resolve(
|
||||
ModuleRegistrationName.PROMOTION
|
||||
)
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
const db = useDb()
|
||||
await db.shutdown()
|
||||
await shutdownServer()
|
||||
})
|
||||
|
||||
beforeEach(async () => {
|
||||
await createAdminUser(dbConnection, adminHeaders)
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
const db = useDb()
|
||||
await db.teardown()
|
||||
await createAdminUser(dbConnection, adminHeaders, appContainer)
|
||||
})
|
||||
|
||||
it("should throw an error if id does not exist", async () => {
|
||||
const api = useApi() as any
|
||||
const { response } = await api
|
||||
.post(`/admin/campaigns/does-not-exist`, {}, adminHeaders)
|
||||
.catch((e) => e)
|
||||
@@ -82,7 +63,6 @@ describe("POST /admin/campaigns/:id", () => {
|
||||
},
|
||||
})
|
||||
|
||||
const api = useApi() as any
|
||||
const response = await api.post(
|
||||
`/admin/campaigns/${createdCampaign.id}`,
|
||||
{
|
||||
@@ -115,4 +95,6 @@ describe("POST /admin/campaigns/:id", () => {
|
||||
})
|
||||
)
|
||||
})
|
||||
})
|
||||
},
|
||||
})
|
||||
|
||||
@@ -1,13 +1,8 @@
|
||||
import { initDb, useDb } from "../../../../environment-helpers/use-db"
|
||||
|
||||
import { IPromotionModuleService } from "@medusajs/types"
|
||||
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||
import { PromotionType } from "@medusajs/utils"
|
||||
import { createAdminUser } from "../../../helpers/create-admin-user"
|
||||
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 { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||
|
||||
jest.setTimeout(50000)
|
||||
|
||||
@@ -16,39 +11,25 @@ const adminHeaders = {
|
||||
headers: { "x-medusa-access-token": "test_token" },
|
||||
}
|
||||
|
||||
describe("POST /admin/promotions/:id", () => {
|
||||
let dbConnection
|
||||
medusaIntegrationTestRunner({
|
||||
env,
|
||||
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||
describe("POST /admin/promotions/:id", () => {
|
||||
let appContainer
|
||||
let shutdownServer
|
||||
let promotionModuleService: IPromotionModuleService
|
||||
|
||||
beforeAll(async () => {
|
||||
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
|
||||
dbConnection = await initDb({ cwd, env } as any)
|
||||
shutdownServer = await startBootstrapApp({ cwd, env })
|
||||
appContainer = getContainer()
|
||||
promotionModuleService = appContainer.resolve(
|
||||
ModuleRegistrationName.PROMOTION
|
||||
)
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
const db = useDb()
|
||||
await db.shutdown()
|
||||
await shutdownServer()
|
||||
})
|
||||
|
||||
beforeEach(async () => {
|
||||
await createAdminUser(dbConnection, adminHeaders)
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
const db = useDb()
|
||||
await db.teardown()
|
||||
await createAdminUser(dbConnection, adminHeaders, appContainer)
|
||||
})
|
||||
|
||||
it("should throw an error if id does not exist", async () => {
|
||||
const api = useApi() as any
|
||||
const { response } = await api
|
||||
.post(
|
||||
`/admin/promotions/does-not-exist`,
|
||||
@@ -77,8 +58,6 @@ describe("POST /admin/promotions/:id", () => {
|
||||
},
|
||||
})
|
||||
|
||||
const api = useApi() as any
|
||||
|
||||
const { response } = await api
|
||||
.post(
|
||||
`/admin/promotions/${createdPromotion.id}`,
|
||||
@@ -112,7 +91,6 @@ describe("POST /admin/promotions/:id", () => {
|
||||
},
|
||||
})
|
||||
|
||||
const api = useApi() as any
|
||||
const response = await api.post(
|
||||
`/admin/promotions/${createdPromotion.id}`,
|
||||
{
|
||||
@@ -164,7 +142,6 @@ describe("POST /admin/promotions/:id", () => {
|
||||
},
|
||||
})
|
||||
|
||||
const api = useApi() as any
|
||||
const response = await api.post(
|
||||
`/admin/promotions/${createdPromotion.id}`,
|
||||
{
|
||||
@@ -189,4 +166,6 @@ describe("POST /admin/promotions/:id", () => {
|
||||
})
|
||||
)
|
||||
})
|
||||
})
|
||||
},
|
||||
})
|
||||
|
||||
@@ -1,11 +1,7 @@
|
||||
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||
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 { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||
|
||||
jest.setTimeout(50000)
|
||||
|
||||
@@ -14,40 +10,29 @@ const adminHeaders = {
|
||||
headers: { "x-medusa-access-token": "test_token" },
|
||||
}
|
||||
|
||||
describe("Regions - Admin", () => {
|
||||
let dbConnection
|
||||
medusaIntegrationTestRunner({
|
||||
env,
|
||||
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||
describe("Regions - Admin", () => {
|
||||
let appContainer
|
||||
let shutdownServer
|
||||
let service: IRegionModuleService
|
||||
|
||||
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.REGION)
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
const db = useDb()
|
||||
await db.shutdown()
|
||||
await shutdownServer()
|
||||
})
|
||||
|
||||
beforeEach(async () => {
|
||||
await createAdminUser(dbConnection, adminHeaders)
|
||||
await createAdminUser(dbConnection, adminHeaders, appContainer)
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
const db = useDb()
|
||||
// TODO: Once teardown doesn't skip constraint checks and cascades, we can remove this
|
||||
const existingRegions = await service.list({})
|
||||
await service.delete(existingRegions.map((r) => r.id))
|
||||
await db.teardown()
|
||||
})
|
||||
|
||||
it("should create, update, and delete a region", async () => {
|
||||
const api = useApi() as any
|
||||
const created = await api.post(
|
||||
`/admin/regions`,
|
||||
{
|
||||
@@ -93,7 +78,9 @@ describe("Regions - Admin", () => {
|
||||
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(
|
||||
`/admin/regions/${updated.data.region.id}`,
|
||||
@@ -116,7 +103,6 @@ describe("Regions - Admin", () => {
|
||||
})
|
||||
|
||||
it("should throw on missing required properties in create", async () => {
|
||||
const api = useApi() as any
|
||||
const err = await api
|
||||
.post(`/admin/regions`, {}, adminHeaders)
|
||||
.catch((e) => e)
|
||||
@@ -128,7 +114,6 @@ describe("Regions - Admin", () => {
|
||||
})
|
||||
|
||||
it("should throw on unknown properties in create", async () => {
|
||||
const api = useApi() as any
|
||||
const error = await api
|
||||
.post(
|
||||
`/admin/regions`,
|
||||
@@ -142,12 +127,12 @@ describe("Regions - Admin", () => {
|
||||
.catch((e) => e)
|
||||
|
||||
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 () => {
|
||||
const api = useApi() as any
|
||||
|
||||
const created = await service.create({
|
||||
name: "Test Region",
|
||||
currency_code: "usd",
|
||||
@@ -166,7 +151,9 @@ describe("Regions - Admin", () => {
|
||||
.catch((e) => e)
|
||||
|
||||
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 () => {
|
||||
@@ -179,7 +166,6 @@ describe("Regions - Admin", () => {
|
||||
},
|
||||
])
|
||||
|
||||
const api = useApi() as any
|
||||
const response = await api.get(`/admin/regions`, adminHeaders)
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
@@ -206,8 +192,10 @@ describe("Regions - Admin", () => {
|
||||
},
|
||||
])
|
||||
|
||||
const api = useApi() as any
|
||||
const response = await api.get(`/admin/regions/${region.id}`, adminHeaders)
|
||||
const response = await api.get(
|
||||
`/admin/regions/${region.id}`,
|
||||
adminHeaders
|
||||
)
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data.region).toEqual(
|
||||
@@ -218,6 +206,10 @@ describe("Regions - Admin", () => {
|
||||
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 { 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 { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||
|
||||
jest.setTimeout(50000)
|
||||
|
||||
@@ -15,37 +10,23 @@ const adminHeaders = {
|
||||
headers: { "x-medusa-access-token": "test_token" },
|
||||
}
|
||||
|
||||
describe("Store - Admin", () => {
|
||||
let dbConnection: DataSource
|
||||
medusaIntegrationTestRunner({
|
||||
env,
|
||||
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||
describe("Store - Admin", () => {
|
||||
let appContainer
|
||||
let shutdownServer
|
||||
let service: IStoreModuleService
|
||||
|
||||
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.STORE)
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
const db = useDb()
|
||||
await db.shutdown()
|
||||
await shutdownServer()
|
||||
})
|
||||
|
||||
beforeEach(async () => {
|
||||
await createAdminUser(dbConnection, adminHeaders)
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
const db = useDb()
|
||||
await db.teardown()
|
||||
await createAdminUser(dbConnection, adminHeaders, appContainer)
|
||||
})
|
||||
|
||||
it("should correctly implement the entire lifecycle of a store", async () => {
|
||||
const api = useApi() as any
|
||||
const createdStore = await service.create({
|
||||
name: "Test store",
|
||||
supported_currency_codes: ["usd"],
|
||||
@@ -79,4 +60,6 @@ describe("Store - Admin", () => {
|
||||
const listedStores = await api.get(`/admin/stores`, adminHeaders)
|
||||
expect(listedStores.data.stores).toHaveLength(0)
|
||||
})
|
||||
})
|
||||
},
|
||||
})
|
||||
|
||||
@@ -1,12 +1,8 @@
|
||||
import path from "path"
|
||||
import { ITaxModuleService } from "@medusajs/types"
|
||||
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||
|
||||
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 { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||
|
||||
jest.setTimeout(50000)
|
||||
|
||||
@@ -15,33 +11,20 @@ const adminHeaders = {
|
||||
headers: { "x-medusa-access-token": "test_token" },
|
||||
}
|
||||
|
||||
describe("Taxes - Admin", () => {
|
||||
let dbConnection
|
||||
medusaIntegrationTestRunner({
|
||||
env,
|
||||
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||
describe("Taxes - Admin", () => {
|
||||
let appContainer
|
||||
let shutdownServer
|
||||
let service: ITaxModuleService
|
||||
|
||||
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.TAX)
|
||||
})
|
||||
|
||||
beforeEach(async () => {
|
||||
await createAdminUser(dbConnection, adminHeaders)
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
const db = useDb()
|
||||
await db.shutdown()
|
||||
await shutdownServer()
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
const db = useDb()
|
||||
await db.teardown()
|
||||
await createAdminUser(dbConnection, adminHeaders, appContainer)
|
||||
})
|
||||
|
||||
it("can retrieve a tax rate", async () => {
|
||||
@@ -55,8 +38,10 @@ describe("Taxes - Admin", () => {
|
||||
name: "Test Rate",
|
||||
})
|
||||
|
||||
const api = useApi() as any
|
||||
const response = await api.get(`/admin/tax-rates/${rate.id}`, adminHeaders)
|
||||
const response = await api.get(
|
||||
`/admin/tax-rates/${rate.id}`,
|
||||
adminHeaders
|
||||
)
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data).toEqual({
|
||||
@@ -78,7 +63,6 @@ describe("Taxes - Admin", () => {
|
||||
})
|
||||
|
||||
it("can create a tax region with rates and rules", async () => {
|
||||
const api = useApi() as any
|
||||
const regionRes = await api.post(
|
||||
`/admin/tax-regions`,
|
||||
{
|
||||
@@ -207,12 +191,15 @@ describe("Taxes - Admin", () => {
|
||||
})
|
||||
|
||||
it("can create a tax rate and update it", async () => {
|
||||
const api = useApi() as any
|
||||
const regionRes = await api.post(
|
||||
`/admin/tax-regions`,
|
||||
{
|
||||
country_code: "us",
|
||||
default_tax_rate: { code: "default", rate: 2, name: "default rate" },
|
||||
default_tax_rate: {
|
||||
code: "default",
|
||||
rate: 2,
|
||||
name: "default rate",
|
||||
},
|
||||
},
|
||||
adminHeaders
|
||||
)
|
||||
@@ -297,12 +284,15 @@ describe("Taxes - Admin", () => {
|
||||
})
|
||||
|
||||
it("can create a tax rate and delete it", async () => {
|
||||
const api = useApi() as any
|
||||
const regionRes = await api.post(
|
||||
`/admin/tax-regions`,
|
||||
{
|
||||
country_code: "us",
|
||||
default_tax_rate: { code: "default", rate: 2, name: "default rate" },
|
||||
default_tax_rate: {
|
||||
code: "default",
|
||||
rate: 2,
|
||||
name: "default rate",
|
||||
},
|
||||
},
|
||||
adminHeaders
|
||||
)
|
||||
@@ -342,12 +332,15 @@ describe("Taxes - Admin", () => {
|
||||
})
|
||||
|
||||
it("can create a tax region and delete it", async () => {
|
||||
const api = useApi() as any
|
||||
const regionRes = await api.post(
|
||||
`/admin/tax-regions`,
|
||||
{
|
||||
country_code: "us",
|
||||
default_tax_rate: { code: "default", rate: 2, name: "default rate" },
|
||||
default_tax_rate: {
|
||||
code: "default",
|
||||
rate: 2,
|
||||
name: "default rate",
|
||||
},
|
||||
},
|
||||
adminHeaders
|
||||
)
|
||||
@@ -375,12 +368,15 @@ describe("Taxes - Admin", () => {
|
||||
})
|
||||
|
||||
it("can create a tax rate add rules and remove them", async () => {
|
||||
const api = useApi() as any
|
||||
const regionRes = await api.post(
|
||||
`/admin/tax-regions`,
|
||||
{
|
||||
country_code: "us",
|
||||
default_tax_rate: { code: "default", rate: 2, name: "default rate" },
|
||||
default_tax_rate: {
|
||||
code: "default",
|
||||
rate: 2,
|
||||
name: "default rate",
|
||||
},
|
||||
},
|
||||
adminHeaders
|
||||
)
|
||||
@@ -508,4 +504,6 @@ describe("Taxes - Admin", () => {
|
||||
])
|
||||
)
|
||||
})
|
||||
})
|
||||
},
|
||||
})
|
||||
|
||||
@@ -1,18 +1,12 @@
|
||||
import path from "path"
|
||||
import { ITaxModuleService } from "@medusajs/types"
|
||||
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||
|
||||
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 {
|
||||
createTaxRateRulesStepId,
|
||||
maybeSetTaxRateRulesStepId,
|
||||
updateTaxRatesStepId,
|
||||
updateTaxRatesWorkflow,
|
||||
} from "@medusajs/core-flows"
|
||||
import { medusaIntegrationTestRunner } from "medusa-test-utils/dist"
|
||||
|
||||
jest.setTimeout(50000)
|
||||
|
||||
@@ -21,16 +15,14 @@ const adminHeaders = {
|
||||
headers: { "x-medusa-access-token": "test_token" },
|
||||
}
|
||||
|
||||
describe("Taxes - Workflow", () => {
|
||||
let dbConnection
|
||||
medusaIntegrationTestRunner({
|
||||
env,
|
||||
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||
describe("Taxes - Workflow", () => {
|
||||
let appContainer
|
||||
let shutdownServer
|
||||
let service: ITaxModuleService
|
||||
|
||||
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.TAX)
|
||||
})
|
||||
@@ -39,17 +31,6 @@ describe("Taxes - Workflow", () => {
|
||||
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 () => {
|
||||
const taxRegion = await service.createTaxRegions({
|
||||
country_code: "us",
|
||||
@@ -206,4 +187,6 @@ 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 path from "path"
|
||||
import { startBootstrapApp } from "../../../environment-helpers/bootstrap-app"
|
||||
import { useApi } from "../../../environment-helpers/use-api"
|
||||
import { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||
|
||||
jest.setTimeout(50000)
|
||||
|
||||
@@ -13,34 +8,15 @@ const adminHeaders = {
|
||||
headers: { "x-medusa-access-token": "test_token" },
|
||||
}
|
||||
|
||||
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 })
|
||||
})
|
||||
|
||||
medusaIntegrationTestRunner({
|
||||
env,
|
||||
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||
describe("POST /admin/users", () => {
|
||||
beforeEach(async () => {
|
||||
await createAdminUser(dbConnection, adminHeaders)
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
const db = useDb()
|
||||
await db.shutdown()
|
||||
await shutdownServer()
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
const db = useDb()
|
||||
await db.teardown()
|
||||
await createAdminUser(dbConnection, adminHeaders, getContainer())
|
||||
})
|
||||
|
||||
it("create a user", async () => {
|
||||
const api = useApi()! as AxiosInstance
|
||||
|
||||
const body = {
|
||||
email: "test_member@test.com",
|
||||
}
|
||||
@@ -52,4 +28,6 @@ describe("POST /admin/users", () => {
|
||||
user: expect.objectContaining(body),
|
||||
})
|
||||
})
|
||||
})
|
||||
},
|
||||
})
|
||||
|
||||
@@ -1,13 +1,7 @@
|
||||
import { initDb, useDb } from "../../../environment-helpers/use-db"
|
||||
|
||||
import { AxiosInstance } from "axios"
|
||||
import { IUserModuleService } from "@medusajs/types"
|
||||
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||
import { createAdminUser } from "../../helpers/create-admin-user"
|
||||
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 { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||
|
||||
jest.setTimeout(50000)
|
||||
|
||||
@@ -16,33 +10,20 @@ const adminHeaders = {
|
||||
headers: { "x-medusa-access-token": "test_token" },
|
||||
}
|
||||
|
||||
describe("DELETE /admin/users/:id", () => {
|
||||
let dbConnection
|
||||
medusaIntegrationTestRunner({
|
||||
env,
|
||||
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||
describe("DELETE /admin/users/:id", () => {
|
||||
let appContainer
|
||||
let shutdownServer
|
||||
let userModuleService: IUserModuleService
|
||||
|
||||
beforeAll(async () => {
|
||||
const cwd = path.resolve(path.join(__dirname, "..", ".."))
|
||||
dbConnection = await initDb({ cwd, env } as any)
|
||||
shutdownServer = await startBootstrapApp({ cwd, env })
|
||||
appContainer = getContainer()
|
||||
userModuleService = appContainer.resolve(ModuleRegistrationName.USER)
|
||||
})
|
||||
|
||||
beforeEach(async () => {
|
||||
await createAdminUser(dbConnection, adminHeaders)
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
const db = useDb()
|
||||
await db.shutdown()
|
||||
await shutdownServer()
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
const db = useDb()
|
||||
await db.teardown()
|
||||
await createAdminUser(dbConnection, adminHeaders, appContainer)
|
||||
})
|
||||
|
||||
it("should delete a single user", async () => {
|
||||
@@ -50,9 +31,10 @@ describe("DELETE /admin/users/:id", () => {
|
||||
email: "member@test.com",
|
||||
})
|
||||
|
||||
const api = useApi()! as AxiosInstance
|
||||
|
||||
const response = await api.delete(`/admin/users/${user.id}`, adminHeaders)
|
||||
const response = await api.delete(
|
||||
`/admin/users/${user.id}`,
|
||||
adminHeaders
|
||||
)
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data).toEqual({
|
||||
@@ -68,4 +50,6 @@ describe("DELETE /admin/users/:id", () => {
|
||||
expect(deletedResponse.status).toEqual(404)
|
||||
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 { medusaIntegrationTestRunner } from "medusa-test-utils/dist"
|
||||
|
||||
jest.setTimeout(50000)
|
||||
|
||||
@@ -13,34 +8,15 @@ const adminHeaders = {
|
||||
headers: { "x-medusa-access-token": "test_token" },
|
||||
}
|
||||
|
||||
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 })
|
||||
})
|
||||
|
||||
medusaIntegrationTestRunner({
|
||||
env,
|
||||
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||
describe("POST /admin/users/me", () => {
|
||||
beforeEach(async () => {
|
||||
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 () => {
|
||||
const api = useApi()! as AxiosInstance
|
||||
|
||||
const response = await api.get(`/admin/users/me`, adminHeaders)
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
@@ -48,4 +24,6 @@ describe("POST /admin/users/me", () => {
|
||||
user: expect.objectContaining({ id: "admin_user" }),
|
||||
})
|
||||
})
|
||||
})
|
||||
},
|
||||
})
|
||||
|
||||
@@ -1,13 +1,7 @@
|
||||
import { initDb, useDb } from "../../../environment-helpers/use-db"
|
||||
|
||||
import { AxiosInstance } from "axios"
|
||||
import { IUserModuleService } from "@medusajs/types"
|
||||
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||
import { createAdminUser } from "../../helpers/create-admin-user"
|
||||
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 { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||
|
||||
jest.setTimeout(50000)
|
||||
|
||||
@@ -16,33 +10,20 @@ const adminHeaders = {
|
||||
headers: { "x-medusa-access-token": "test_token" },
|
||||
}
|
||||
|
||||
describe("GET /admin/users", () => {
|
||||
let dbConnection
|
||||
medusaIntegrationTestRunner({
|
||||
env,
|
||||
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||
describe("GET /admin/users", () => {
|
||||
let appContainer
|
||||
let shutdownServer
|
||||
let userModuleService: IUserModuleService
|
||||
|
||||
beforeAll(async () => {
|
||||
const cwd = path.resolve(path.join(__dirname, "..", ".."))
|
||||
dbConnection = await initDb({ cwd, env } as any)
|
||||
shutdownServer = await startBootstrapApp({ cwd, env })
|
||||
appContainer = getContainer()
|
||||
userModuleService = appContainer.resolve(ModuleRegistrationName.USER)
|
||||
})
|
||||
|
||||
beforeEach(async () => {
|
||||
await createAdminUser(dbConnection, adminHeaders)
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
const db = useDb()
|
||||
await db.shutdown()
|
||||
await shutdownServer()
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
const db = useDb()
|
||||
await db.teardown()
|
||||
await createAdminUser(dbConnection, adminHeaders, appContainer)
|
||||
})
|
||||
|
||||
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)
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
@@ -69,4 +48,6 @@ describe("GET /admin/users", () => {
|
||||
limit: 50,
|
||||
})
|
||||
})
|
||||
})
|
||||
},
|
||||
})
|
||||
|
||||
@@ -1,13 +1,7 @@
|
||||
import { initDb, useDb } from "../../../environment-helpers/use-db"
|
||||
|
||||
import { AxiosInstance } from "axios"
|
||||
import { IUserModuleService } from "@medusajs/types"
|
||||
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||
import { createAdminUser } from "../../helpers/create-admin-user"
|
||||
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 { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||
|
||||
jest.setTimeout(50000)
|
||||
|
||||
@@ -16,33 +10,20 @@ const adminHeaders = {
|
||||
headers: { "x-medusa-access-token": "test_token" },
|
||||
}
|
||||
|
||||
describe("GET /admin/users/:id", () => {
|
||||
let dbConnection
|
||||
medusaIntegrationTestRunner({
|
||||
env,
|
||||
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||
describe("GET /admin/users/:id", () => {
|
||||
let appContainer
|
||||
let shutdownServer
|
||||
let userModuleService: IUserModuleService
|
||||
|
||||
beforeAll(async () => {
|
||||
const cwd = path.resolve(path.join(__dirname, "..", ".."))
|
||||
dbConnection = await initDb({ cwd, env } as any)
|
||||
shutdownServer = await startBootstrapApp({ cwd, env })
|
||||
appContainer = getContainer()
|
||||
userModuleService = appContainer.resolve(ModuleRegistrationName.USER)
|
||||
})
|
||||
|
||||
beforeEach(async () => {
|
||||
await createAdminUser(dbConnection, adminHeaders)
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
const db = useDb()
|
||||
await db.shutdown()
|
||||
await shutdownServer()
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
const db = useDb()
|
||||
await db.teardown()
|
||||
await createAdminUser(dbConnection, adminHeaders, appContainer)
|
||||
})
|
||||
|
||||
it("should retrieve a single user", async () => {
|
||||
@@ -50,8 +31,6 @@ describe("GET /admin/users/:id", () => {
|
||||
email: "member@test.com",
|
||||
})
|
||||
|
||||
const api = useApi()! as AxiosInstance
|
||||
|
||||
const response = await api.get(`/admin/users/${user.id}`, adminHeaders)
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
@@ -59,4 +38,6 @@ describe("GET /admin/users/:id", () => {
|
||||
expect.objectContaining({ email: "member@test.com" })
|
||||
)
|
||||
})
|
||||
})
|
||||
},
|
||||
})
|
||||
|
||||
@@ -1,13 +1,7 @@
|
||||
import { initDb, useDb } from "../../../environment-helpers/use-db"
|
||||
|
||||
import { AxiosInstance } from "axios"
|
||||
import { IUserModuleService } from "@medusajs/types"
|
||||
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||
import { createAdminUser } from "../../helpers/create-admin-user"
|
||||
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 { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||
|
||||
jest.setTimeout(50000)
|
||||
|
||||
@@ -16,33 +10,20 @@ const adminHeaders = {
|
||||
headers: { "x-medusa-access-token": "test_token" },
|
||||
}
|
||||
|
||||
describe("POST /admin/users/:id", () => {
|
||||
let dbConnection
|
||||
medusaIntegrationTestRunner({
|
||||
env,
|
||||
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||
describe("POST /admin/users/:id", () => {
|
||||
let appContainer
|
||||
let shutdownServer
|
||||
let userModuleService: IUserModuleService
|
||||
|
||||
beforeAll(async () => {
|
||||
const cwd = path.resolve(path.join(__dirname, "..", ".."))
|
||||
dbConnection = await initDb({ cwd, env } as any)
|
||||
shutdownServer = await startBootstrapApp({ cwd, env })
|
||||
appContainer = getContainer()
|
||||
userModuleService = appContainer.resolve(ModuleRegistrationName.USER)
|
||||
})
|
||||
|
||||
beforeEach(async () => {
|
||||
await createAdminUser(dbConnection, adminHeaders)
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
const db = useDb()
|
||||
await db.shutdown()
|
||||
await shutdownServer()
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
const db = useDb()
|
||||
await db.teardown()
|
||||
await createAdminUser(dbConnection, adminHeaders, appContainer)
|
||||
})
|
||||
|
||||
it("should update a single user", async () => {
|
||||
@@ -50,8 +31,6 @@ describe("POST /admin/users/:id", () => {
|
||||
email: "member@test.com",
|
||||
})
|
||||
|
||||
const api = useApi()! as AxiosInstance
|
||||
|
||||
const body = {
|
||||
first_name: "John",
|
||||
last_name: "Doe",
|
||||
@@ -65,4 +44,6 @@ describe("POST /admin/users/:id", () => {
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data.user).toEqual(expect.objectContaining(body))
|
||||
})
|
||||
})
|
||||
},
|
||||
})
|
||||
|
||||
@@ -4,6 +4,7 @@ jest.setTimeout(5000000)
|
||||
|
||||
const env = {
|
||||
MEDUSA_FF_MEDUSA_V2: false,
|
||||
MEDUSA_FF_SALES_CHANNELS: true,
|
||||
}
|
||||
|
||||
workflowEngineTestSuite(env, { force_modules_migration: true })
|
||||
|
||||
@@ -4,41 +4,32 @@ import {
|
||||
StepResponse,
|
||||
WorkflowData,
|
||||
} 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 { 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 { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||
|
||||
export const workflowEngineTestSuite = (env, extraParams = {}) => {
|
||||
export const workflowEngineTestSuite = (
|
||||
env,
|
||||
extraParams: { force_modules_migration?: boolean } = {}
|
||||
) => {
|
||||
const adminHeaders = {
|
||||
headers: {
|
||||
"x-medusa-access-token": "test_token",
|
||||
},
|
||||
}
|
||||
|
||||
return medusaIntegrationTestRunner({
|
||||
env,
|
||||
force_modules_migration: extraParams.force_modules_migration,
|
||||
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||
describe("Workflow Engine API", () => {
|
||||
let medusaContainer
|
||||
let dbConnection
|
||||
let shutdownServer
|
||||
|
||||
beforeAll(async () => {
|
||||
const cwd = path.resolve(path.join(__dirname, "..", ".."))
|
||||
dbConnection = await initDb({ cwd, env, ...extraParams } as any)
|
||||
shutdownServer = await startBootstrapApp({ cwd, env })
|
||||
beforeAll(() => {
|
||||
medusaContainer = getContainer()
|
||||
|
||||
await createAdminUser(dbConnection, adminHeaders)
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
const db = useDb()
|
||||
await db.shutdown()
|
||||
await shutdownServer()
|
||||
beforeEach(async () => {
|
||||
await createAdminUser(dbConnection, adminHeaders, medusaContainer)
|
||||
})
|
||||
|
||||
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 () => {
|
||||
const api = useApi()! as AxiosInstance
|
||||
|
||||
for (let i = 3; i--; ) {
|
||||
await api.post(
|
||||
`/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 () => {
|
||||
const api = useApi()! as AxiosInstance
|
||||
|
||||
for (let i = 3; i--; ) {
|
||||
await api.post(
|
||||
`/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[0]).toEqual({
|
||||
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),
|
||||
state: "invoking",
|
||||
created_at: expect.any(String),
|
||||
@@ -149,7 +138,9 @@ export const workflowEngineTestSuite = (env, extraParams = {}) => {
|
||||
})
|
||||
expect(executions.data.workflow_executions[1]).toEqual({
|
||||
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),
|
||||
state: "invoking",
|
||||
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 () => {
|
||||
const api = useApi()! as AxiosInstance
|
||||
|
||||
const wf = await api.post(
|
||||
`/admin/workflows-executions/my-workflow-name/run`,
|
||||
{
|
||||
@@ -265,6 +254,8 @@ export const workflowEngineTestSuite = (env, extraParams = {}) => {
|
||||
})
|
||||
})
|
||||
})
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
describe("Noop test", () => {
|
||||
|
||||
@@ -4,9 +4,13 @@ import jwt from "jsonwebtoken"
|
||||
import { getContainer } from "../../environment-helpers/use-container"
|
||||
import adminSeeder from "../../helpers/admin-seeder"
|
||||
|
||||
export const createAdminUser = async (dbConnection, adminHeaders) => {
|
||||
export const createAdminUser = async (
|
||||
dbConnection,
|
||||
adminHeaders,
|
||||
container?
|
||||
) => {
|
||||
await adminSeeder(dbConnection)
|
||||
const appContainer = getContainer()!
|
||||
const appContainer = container ?? getContainer()!
|
||||
|
||||
const authModule: IAuthModuleService = appContainer.resolve(
|
||||
ModuleRegistrationName.AUTH
|
||||
|
||||
@@ -15,9 +15,11 @@ module.exports = {
|
||||
`.cache`,
|
||||
],
|
||||
transformIgnorePatterns: [`/dist`],
|
||||
transform: { "^.+\\.[jt]s$": `../../jest-transformer.js` },
|
||||
transform: {
|
||||
"^.+\\.[jt]s$": `../../jest-transformer.js`,
|
||||
},
|
||||
setupFiles: ["../setup-env.js"],
|
||||
setupFilesAfterEnv: ["../setup.js"],
|
||||
/*setupFilesAfterEnv: ["../setup.js"],
|
||||
globalSetup: "../globalSetup.js",
|
||||
globalTeardown: "../globalTeardown.js",
|
||||
globalTeardown: "../globalTeardown.js",*/
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
"license": "MIT",
|
||||
"private": true,
|
||||
"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\""
|
||||
},
|
||||
"dependencies": {
|
||||
@@ -30,6 +30,7 @@
|
||||
"medusa-fulfillment-webshipper": "workspace:*",
|
||||
"medusa-interfaces": "workspace:*",
|
||||
"medusa-plugin-sendgrid": "workspace:*",
|
||||
"medusa-test-utils": "workspace:*",
|
||||
"pg": "^8.11.0",
|
||||
"typeorm": "^0.3.16"
|
||||
},
|
||||
|
||||
@@ -24,18 +24,46 @@
|
||||
"author": "Sebastian Rindom",
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"@medusajs/types": "^1.1.41",
|
||||
"cross-env": "^5.2.1",
|
||||
"jest": "^25.5.4",
|
||||
"rimraf": "^3.0.2",
|
||||
"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": {
|
||||
"@medusajs/modules-sdk": "^1.12.6",
|
||||
"@medusajs/utils": "^1.1.41",
|
||||
"@mikro-orm/migrations": "5.9.7",
|
||||
"@mikro-orm/postgresql": "5.9.7",
|
||||
"medusa-core-utils": "^1.2.1",
|
||||
"pg-god": "^1.0.12",
|
||||
"randomatic": "^3.1.1"
|
||||
},
|
||||
"gitHead": "81a7ff73d012fda722f6e9ef0bd9ba0232d37808"
|
||||
|
||||
@@ -6,3 +6,4 @@ export { default as MockRepository } from "./mock-repository"
|
||||
export * from "./init-modules"
|
||||
export { default as MockEventBusService } from "./mock-event-bus-service"
|
||||
export * from "./module-test-runner"
|
||||
export * from "./medusa-test-runner"
|
||||
|
||||
79
packages/medusa-test-utils/src/medusa-test-runner-utils/bootstrap-app.js
vendored
Normal file
79
packages/medusa-test-utils/src/medusa-test-runner-utils/bootstrap-app.js
vendored
Normal file
@@ -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 }
|
||||
},
|
||||
}
|
||||
238
packages/medusa-test-utils/src/medusa-test-runner.ts
Normal file
238
packages/medusa-test-utils/src/medusa-test-runner.ts
Normal file
@@ -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
|
||||
testSuite: <TService = unknown>(options: SuiteOptions<TService>) => () => void
|
||||
}) {
|
||||
process.env.LOG_LEVEL = "error"
|
||||
|
||||
moduleModels = Object.values(require(`${process.cwd()}/src/models`))
|
||||
// migrationPath ??= process.cwd() + "/src/migrations/!(*.d).{js,ts,cjs}"
|
||||
|
||||
|
||||
@@ -66,8 +66,12 @@ export async function migrateMedusaApp(
|
||||
|
||||
const sharedResourcesConfig = {
|
||||
database: {
|
||||
clientUrl: configModule.projectConfig.database_url,
|
||||
clientUrl:
|
||||
injectedDependencies[ContainerRegistrationKeys.PG_CONNECTION]?.client
|
||||
?.config?.connection?.connectionString ??
|
||||
configModule.projectConfig.database_url,
|
||||
driverOptions: configModule.projectConfig.database_extra,
|
||||
debug: !!(configModule.projectConfig.database_logging ?? false),
|
||||
},
|
||||
}
|
||||
|
||||
@@ -85,7 +89,7 @@ export async function migrateMedusaApp(
|
||||
).options ??= {
|
||||
database: {
|
||||
type: "postgres",
|
||||
url: configModule.projectConfig.database_url,
|
||||
url: sharedResourcesConfig.database.clientUrl,
|
||||
extra: configModule.projectConfig.database_extra,
|
||||
schema: configModule.projectConfig.database_schema,
|
||||
logging: configModule.projectConfig.database_logging,
|
||||
@@ -132,6 +136,7 @@ export const loadMedusaApp = async (
|
||||
database: {
|
||||
clientUrl: configModule.projectConfig.database_url,
|
||||
driverOptions: configModule.projectConfig.database_extra,
|
||||
debug: !!(configModule.projectConfig.database_logging ?? false),
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@@ -337,7 +337,7 @@ async function MedusaApp_({
|
||||
)
|
||||
}
|
||||
|
||||
const linkModuleOpt = { ...linkModuleOptions }
|
||||
const linkModuleOpt = { ...(linkModuleOptions ?? {}) }
|
||||
linkModuleOpt.database ??= {
|
||||
...(sharedResourcesConfig?.database ?? {}),
|
||||
}
|
||||
|
||||
@@ -285,11 +285,14 @@ export class MedusaModule {
|
||||
moduleDefinition
|
||||
)
|
||||
|
||||
const logger_ =
|
||||
container.resolve("logger", { allowUnregistered: true }) ?? logger
|
||||
|
||||
try {
|
||||
await moduleLoader({
|
||||
container,
|
||||
moduleResolutions,
|
||||
logger,
|
||||
logger: logger_,
|
||||
migrationOnly,
|
||||
})
|
||||
} catch (err) {
|
||||
@@ -314,7 +317,7 @@ export class MedusaModule {
|
||||
].__joinerConfig()
|
||||
|
||||
if (!joinerConfig.primaryKeys) {
|
||||
logger.warn(
|
||||
logger_.warn(
|
||||
`Primary keys are not defined by the module ${keyName}. Setting default primary key to 'id'${EOL}`
|
||||
)
|
||||
|
||||
@@ -407,11 +410,14 @@ export class MedusaModule {
|
||||
moduleExports
|
||||
)
|
||||
|
||||
const logger_ =
|
||||
container.resolve("logger", { allowUnregistered: true }) ?? logger
|
||||
|
||||
try {
|
||||
await moduleLoader({
|
||||
container,
|
||||
moduleResolutions,
|
||||
logger,
|
||||
logger: logger_,
|
||||
})
|
||||
} catch (err) {
|
||||
errorLoading(err)
|
||||
|
||||
27
yarn.lock
27
yarn.lock
@@ -8914,7 +8914,7 @@ __metadata:
|
||||
languageName: unknown
|
||||
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
|
||||
resolution: "@medusajs/types@workspace:packages/types"
|
||||
dependencies:
|
||||
@@ -31811,6 +31811,7 @@ __metadata:
|
||||
medusa-fulfillment-webshipper: "workspace:*"
|
||||
medusa-interfaces: "workspace:*"
|
||||
medusa-plugin-sendgrid: "workspace:*"
|
||||
medusa-test-utils: "workspace:*"
|
||||
pg: ^8.11.0
|
||||
typeorm: ^0.3.16
|
||||
languageName: unknown
|
||||
@@ -38296,21 +38297,41 @@ __metadata:
|
||||
languageName: unknown
|
||||
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
|
||||
resolution: "medusa-test-utils@workspace:packages/medusa-test-utils"
|
||||
dependencies:
|
||||
"@medusajs/modules-sdk": ^1.12.6
|
||||
"@medusajs/types": ^1.1.41
|
||||
"@medusajs/utils": ^1.1.41
|
||||
"@mikro-orm/migrations": 5.9.7
|
||||
"@mikro-orm/postgresql": 5.9.7
|
||||
cross-env: ^5.2.1
|
||||
jest: ^25.5.4
|
||||
medusa-core-utils: ^1.2.1
|
||||
pg-god: ^1.0.12
|
||||
randomatic: ^3.1.1
|
||||
rimraf: ^3.0.2
|
||||
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
|
||||
linkType: soft
|
||||
|
||||
|
||||
Reference in New Issue
Block a user