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:
1 parent
a6736c7ee0
commit
51bb6f1e89
99 files changed
+10164
-10303
No files matched your search
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"medusa-test-utils": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Chore/integration tests modules utils
|
||||||
@@ -2,3 +2,4 @@
|
|||||||
DB_HOST=localhost
|
DB_HOST=localhost
|
||||||
DB_USERNAME=postgres
|
DB_USERNAME=postgres
|
||||||
DB_PASSWORD=''
|
DB_PASSWORD=''
|
||||||
|
LOG_LEVEL=error
|
||||||
@@ -1,13 +1,8 @@
|
|||||||
import { initDb, useDb } from "../../../../environment-helpers/use-db"
|
|
||||||
|
|
||||||
import { ApiKeyType } from "@medusajs/utils"
|
import { ApiKeyType } from "@medusajs/utils"
|
||||||
import { IApiKeyModuleService, IRegionModuleService } from "@medusajs/types"
|
import { IRegionModuleService } from "@medusajs/types"
|
||||||
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||||
import { createAdminUser } from "../../../helpers/create-admin-user"
|
import { createAdminUser } from "../../../helpers/create-admin-user"
|
||||||
import { getContainer } from "../../../../environment-helpers/use-container"
|
import { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||||
import path from "path"
|
|
||||||
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
|
|
||||||
import { useApi } from "../../../../environment-helpers/use-api"
|
|
||||||
|
|
||||||
jest.setTimeout(50000)
|
jest.setTimeout(50000)
|
||||||
|
|
||||||
@@ -16,182 +11,171 @@ const adminHeaders = {
|
|||||||
headers: { "x-medusa-access-token": "test_token" },
|
headers: { "x-medusa-access-token": "test_token" },
|
||||||
}
|
}
|
||||||
|
|
||||||
describe("API Keys - Admin", () => {
|
medusaIntegrationTestRunner({
|
||||||
let dbConnection
|
env,
|
||||||
let appContainer
|
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||||
let shutdownServer
|
describe("API Keys - Admin", () => {
|
||||||
let service: IApiKeyModuleService
|
let regionService: IRegionModuleService
|
||||||
let regionService: IRegionModuleService
|
let container
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
|
container = getContainer()
|
||||||
dbConnection = await initDb({ cwd, env } as any)
|
regionService = container.resolve(
|
||||||
shutdownServer = await startBootstrapApp({ cwd, env })
|
ModuleRegistrationName.REGION
|
||||||
appContainer = getContainer()
|
) as IRegionModuleService
|
||||||
service = appContainer.resolve(ModuleRegistrationName.API_KEY)
|
|
||||||
regionService = appContainer.resolve(ModuleRegistrationName.REGION)
|
|
||||||
})
|
|
||||||
|
|
||||||
afterAll(async () => {
|
|
||||||
const db = useDb()
|
|
||||||
await db.shutdown()
|
|
||||||
await shutdownServer()
|
|
||||||
})
|
|
||||||
|
|
||||||
beforeEach(async () => {
|
|
||||||
await createAdminUser(dbConnection, adminHeaders)
|
|
||||||
})
|
|
||||||
|
|
||||||
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`,
|
|
||||||
{
|
|
||||||
title: "Test Secret Key",
|
|
||||||
type: ApiKeyType.SECRET,
|
|
||||||
},
|
|
||||||
adminHeaders
|
|
||||||
)
|
|
||||||
|
|
||||||
expect(created.status).toEqual(200)
|
|
||||||
expect(created.data.apiKey).toEqual(
|
|
||||||
expect.objectContaining({
|
|
||||||
id: created.data.apiKey.id,
|
|
||||||
title: "Test Secret Key",
|
|
||||||
created_by: "admin_user",
|
|
||||||
})
|
})
|
||||||
)
|
|
||||||
// On create we get the token in raw form so we can store it.
|
|
||||||
expect(created.data.apiKey.token).toContain("sk_")
|
|
||||||
|
|
||||||
const updated = await api.post(
|
beforeEach(async () => {
|
||||||
`/admin/api-keys/${created.data.apiKey.id}`,
|
await createAdminUser(dbConnection, adminHeaders, container)
|
||||||
{
|
|
||||||
title: "Updated Secret Key",
|
|
||||||
},
|
|
||||||
adminHeaders
|
|
||||||
)
|
|
||||||
|
|
||||||
expect(updated.status).toEqual(200)
|
|
||||||
expect(updated.data.apiKey).toEqual(
|
|
||||||
expect.objectContaining({
|
|
||||||
id: created.data.apiKey.id,
|
|
||||||
title: "Updated Secret Key",
|
|
||||||
})
|
})
|
||||||
)
|
|
||||||
|
|
||||||
const revoked = await api.post(
|
afterEach(async () => {
|
||||||
`/admin/api-keys/${created.data.apiKey.id}/revoke`,
|
// TODO: Once teardown doesn't skip constraint checks and cascades, we can remove this
|
||||||
{},
|
const existingRegions = await regionService.list({})
|
||||||
adminHeaders
|
await regionService.delete(existingRegions.map((r) => r.id))
|
||||||
)
|
|
||||||
|
|
||||||
expect(revoked.status).toEqual(200)
|
|
||||||
expect(revoked.data.apiKey).toEqual(
|
|
||||||
expect.objectContaining({
|
|
||||||
id: created.data.apiKey.id,
|
|
||||||
revoked_by: "admin_user",
|
|
||||||
})
|
})
|
||||||
)
|
|
||||||
expect(revoked.data.apiKey.revoked_at).toBeTruthy()
|
|
||||||
|
|
||||||
const deleted = await api.delete(
|
it("should correctly implement the entire lifecycle of an api key", async () => {
|
||||||
`/admin/api-keys/${created.data.apiKey.id}`,
|
const created = await api.post(
|
||||||
adminHeaders
|
`/admin/api-keys`,
|
||||||
)
|
{
|
||||||
const listedApiKeys = await api.get(`/admin/api-keys`, adminHeaders)
|
title: "Test Secret Key",
|
||||||
|
type: ApiKeyType.SECRET,
|
||||||
expect(deleted.status).toEqual(200)
|
|
||||||
expect(listedApiKeys.data.apiKeys).toHaveLength(0)
|
|
||||||
})
|
|
||||||
|
|
||||||
it("can use a secret api key for authentication", async () => {
|
|
||||||
const api = useApi() as any
|
|
||||||
const created = await api.post(
|
|
||||||
`/admin/api-keys`,
|
|
||||||
{
|
|
||||||
title: "Test Secret Key",
|
|
||||||
type: ApiKeyType.SECRET,
|
|
||||||
},
|
|
||||||
adminHeaders
|
|
||||||
)
|
|
||||||
|
|
||||||
const createdRegion = await api.post(
|
|
||||||
`/admin/regions`,
|
|
||||||
{
|
|
||||||
name: "Test Region",
|
|
||||||
currency_code: "usd",
|
|
||||||
countries: ["us", "ca"],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
auth: {
|
|
||||||
username: created.data.apiKey.token,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
expect(createdRegion.status).toEqual(200)
|
|
||||||
expect(createdRegion.data.region.name).toEqual("Test Region")
|
|
||||||
})
|
|
||||||
|
|
||||||
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`,
|
|
||||||
{
|
|
||||||
title: "Test Secret Key",
|
|
||||||
type: ApiKeyType.SECRET,
|
|
||||||
},
|
|
||||||
adminHeaders
|
|
||||||
)
|
|
||||||
|
|
||||||
await api.post(
|
|
||||||
`/admin/api-keys/${created.data.apiKey.id}/revoke`,
|
|
||||||
{},
|
|
||||||
adminHeaders
|
|
||||||
)
|
|
||||||
|
|
||||||
const err = await api
|
|
||||||
.post(
|
|
||||||
`/admin/regions`,
|
|
||||||
{
|
|
||||||
name: "Test Region",
|
|
||||||
currency_code: "usd",
|
|
||||||
countries: ["us", "ca"],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
auth: {
|
|
||||||
username: created.data.apiKey.token,
|
|
||||||
},
|
},
|
||||||
}
|
adminHeaders
|
||||||
)
|
)
|
||||||
.catch((e) => e.message)
|
|
||||||
|
|
||||||
const createdRegion = await api.post(
|
expect(created.status).toEqual(200)
|
||||||
`/admin/regions`,
|
expect(created.data.apiKey).toEqual(
|
||||||
{
|
expect.objectContaining({
|
||||||
name: "Test Region",
|
id: created.data.apiKey.id,
|
||||||
currency_code: "usd",
|
title: "Test Secret Key",
|
||||||
countries: ["us", "ca"],
|
created_by: "admin_user",
|
||||||
},
|
})
|
||||||
{
|
)
|
||||||
auth: {
|
// On create we get the token in raw form so we can store it.
|
||||||
username: created.data.apiKey.token,
|
expect(created.data.apiKey.token).toContain("sk_")
|
||||||
},
|
|
||||||
...adminHeaders,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
expect(err).toEqual("Request failed with status code 401")
|
const updated = await api.post(
|
||||||
expect(createdRegion.status).toEqual(200)
|
`/admin/api-keys/${created.data.apiKey.id}`,
|
||||||
expect(createdRegion.data.region.name).toEqual("Test Region")
|
{
|
||||||
})
|
title: "Updated Secret Key",
|
||||||
|
},
|
||||||
|
adminHeaders
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(updated.status).toEqual(200)
|
||||||
|
expect(updated.data.apiKey).toEqual(
|
||||||
|
expect.objectContaining({
|
||||||
|
id: created.data.apiKey.id,
|
||||||
|
title: "Updated Secret Key",
|
||||||
|
})
|
||||||
|
)
|
||||||
|
|
||||||
|
const revoked = await api.post(
|
||||||
|
`/admin/api-keys/${created.data.apiKey.id}/revoke`,
|
||||||
|
{},
|
||||||
|
adminHeaders
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(revoked.status).toEqual(200)
|
||||||
|
expect(revoked.data.apiKey).toEqual(
|
||||||
|
expect.objectContaining({
|
||||||
|
id: created.data.apiKey.id,
|
||||||
|
revoked_by: "admin_user",
|
||||||
|
})
|
||||||
|
)
|
||||||
|
expect(revoked.data.apiKey.revoked_at).toBeTruthy()
|
||||||
|
|
||||||
|
const deleted = await api.delete(
|
||||||
|
`/admin/api-keys/${created.data.apiKey.id}`,
|
||||||
|
adminHeaders
|
||||||
|
)
|
||||||
|
const listedApiKeys = await api.get(`/admin/api-keys`, adminHeaders)
|
||||||
|
|
||||||
|
expect(deleted.status).toEqual(200)
|
||||||
|
expect(listedApiKeys.data.apiKeys).toHaveLength(0)
|
||||||
|
})
|
||||||
|
|
||||||
|
it("can use a secret api key for authentication", async () => {
|
||||||
|
const created = await api.post(
|
||||||
|
`/admin/api-keys`,
|
||||||
|
{
|
||||||
|
title: "Test Secret Key",
|
||||||
|
type: ApiKeyType.SECRET,
|
||||||
|
},
|
||||||
|
adminHeaders
|
||||||
|
)
|
||||||
|
|
||||||
|
const createdRegion = await api.post(
|
||||||
|
`/admin/regions`,
|
||||||
|
{
|
||||||
|
name: "Test Region",
|
||||||
|
currency_code: "usd",
|
||||||
|
countries: ["us", "ca"],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
auth: {
|
||||||
|
username: created.data.apiKey.token,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(createdRegion.status).toEqual(200)
|
||||||
|
expect(createdRegion.data.region.name).toEqual("Test Region")
|
||||||
|
})
|
||||||
|
|
||||||
|
it("falls back to other mode of authentication when an api key is not valid", async () => {
|
||||||
|
const created = await api.post(
|
||||||
|
`/admin/api-keys`,
|
||||||
|
{
|
||||||
|
title: "Test Secret Key",
|
||||||
|
type: ApiKeyType.SECRET,
|
||||||
|
},
|
||||||
|
adminHeaders
|
||||||
|
)
|
||||||
|
|
||||||
|
await api.post(
|
||||||
|
`/admin/api-keys/${created.data.apiKey.id}/revoke`,
|
||||||
|
{},
|
||||||
|
adminHeaders
|
||||||
|
)
|
||||||
|
|
||||||
|
const err = await api
|
||||||
|
.post(
|
||||||
|
`/admin/regions`,
|
||||||
|
{
|
||||||
|
name: "Test Region",
|
||||||
|
currency_code: "usd",
|
||||||
|
countries: ["us", "ca"],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
auth: {
|
||||||
|
username: created.data.apiKey.token,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
)
|
||||||
|
.catch((e) => e.message)
|
||||||
|
|
||||||
|
const createdRegion = await api.post(
|
||||||
|
`/admin/regions`,
|
||||||
|
{
|
||||||
|
name: "Test Region",
|
||||||
|
currency_code: "usd",
|
||||||
|
countries: ["us", "ca"],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
auth: {
|
||||||
|
username: created.data.apiKey.token,
|
||||||
|
},
|
||||||
|
...adminHeaders,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(err).toEqual("Request failed with status code 401")
|
||||||
|
expect(createdRegion.status).toEqual(200)
|
||||||
|
expect(createdRegion.data.region.name).toEqual("Test Region")
|
||||||
|
})
|
||||||
|
})
|
||||||
|
},
|
||||||
})
|
})
|
||||||
@@ -1,135 +1,117 @@
|
|||||||
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||||
import { IAuthModuleService, ICustomerModuleService } from "@medusajs/types"
|
import { IAuthModuleService, ICustomerModuleService } from "@medusajs/types"
|
||||||
import path from "path"
|
|
||||||
import Scrypt from "scrypt-kdf"
|
import Scrypt from "scrypt-kdf"
|
||||||
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
|
|
||||||
import { useApi } from "../../../../environment-helpers/use-api"
|
|
||||||
import { getContainer } from "../../../../environment-helpers/use-container"
|
|
||||||
import { initDb, useDb } from "../../../../environment-helpers/use-db"
|
|
||||||
import adminSeeder from "../../../../helpers/admin-seeder"
|
import adminSeeder from "../../../../helpers/admin-seeder"
|
||||||
|
import { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||||
|
|
||||||
jest.setTimeout(50000)
|
jest.setTimeout(50000)
|
||||||
|
|
||||||
const env = { MEDUSA_FF_MEDUSA_V2: true }
|
const env = { MEDUSA_FF_MEDUSA_V2: true }
|
||||||
|
|
||||||
describe("POST /auth/emailpass", () => {
|
medusaIntegrationTestRunner({
|
||||||
let dbConnection
|
env,
|
||||||
let appContainer
|
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||||
let shutdownServer
|
describe("POST /auth/emailpass", () => {
|
||||||
let customerModuleService: ICustomerModuleService
|
let appContainer
|
||||||
|
let customerModuleService: ICustomerModuleService
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
|
appContainer = getContainer()
|
||||||
dbConnection = await initDb({ cwd, env } as any)
|
customerModuleService = appContainer.resolve(
|
||||||
shutdownServer = await startBootstrapApp({ cwd, env })
|
ModuleRegistrationName.CUSTOMER
|
||||||
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"
|
|
||||||
|
|
||||||
it("should return a token on successful login", async () => {
|
|
||||||
const passwordHash = (
|
|
||||||
await Scrypt.kdf(password, { logN: 15, r: 8, p: 1 })
|
|
||||||
).toString("base64")
|
|
||||||
const authService: IAuthModuleService = appContainer.resolve(
|
|
||||||
ModuleRegistrationName.AUTH
|
|
||||||
)
|
|
||||||
|
|
||||||
await authService.create({
|
|
||||||
provider: "emailpass",
|
|
||||||
entity_id: email,
|
|
||||||
scope: "admin",
|
|
||||||
provider_metadata: {
|
|
||||||
password: passwordHash,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
const api = useApi() as any
|
|
||||||
const response = await api
|
|
||||||
.post(`/auth/admin/emailpass`, {
|
|
||||||
email: email,
|
|
||||||
password: password,
|
|
||||||
})
|
})
|
||||||
.catch((e) => e)
|
|
||||||
|
|
||||||
expect(response.status).toEqual(200)
|
beforeEach(async () => {
|
||||||
expect(response.data).toEqual(
|
await adminSeeder(dbConnection)
|
||||||
expect.objectContaining({
|
|
||||||
token: expect.any(String),
|
|
||||||
})
|
})
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
it("should throw an error upon incorrect password", async () => {
|
const password = "supersecret"
|
||||||
const passwordHash = (
|
const email = "test@test.com"
|
||||||
await Scrypt.kdf(password, { logN: 15, r: 8, p: 1 })
|
|
||||||
).toString("base64")
|
|
||||||
const authService: IAuthModuleService = appContainer.resolve(
|
|
||||||
ModuleRegistrationName.AUTH
|
|
||||||
)
|
|
||||||
|
|
||||||
await authService.create({
|
it("should return a token on successful login", async () => {
|
||||||
provider: "emailpass",
|
const passwordHash = (
|
||||||
entity_id: email,
|
await Scrypt.kdf(password, { logN: 15, r: 8, p: 1 })
|
||||||
scope: "admin",
|
).toString("base64")
|
||||||
provider_metadata: {
|
const authService: IAuthModuleService = appContainer.resolve(
|
||||||
password: passwordHash,
|
ModuleRegistrationName.AUTH
|
||||||
},
|
)
|
||||||
})
|
|
||||||
|
|
||||||
const api = useApi() as any
|
await authService.create({
|
||||||
const error = await api
|
provider: "emailpass",
|
||||||
.post(`/auth/admin/emailpass`, {
|
entity_id: email,
|
||||||
email: email,
|
scope: "admin",
|
||||||
password: "incorrect-password",
|
provider_metadata: {
|
||||||
|
password: passwordHash,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
const response = await api
|
||||||
|
.post(`/auth/admin/emailpass`, {
|
||||||
|
email: email,
|
||||||
|
password: password,
|
||||||
|
})
|
||||||
|
.catch((e) => e)
|
||||||
|
|
||||||
|
expect(response.status).toEqual(200)
|
||||||
|
expect(response.data).toEqual(
|
||||||
|
expect.objectContaining({
|
||||||
|
token: expect.any(String),
|
||||||
|
})
|
||||||
|
)
|
||||||
})
|
})
|
||||||
.catch((e) => e)
|
|
||||||
|
|
||||||
expect(error.response.status).toEqual(401)
|
it("should throw an error upon incorrect password", async () => {
|
||||||
expect(error.response.data).toEqual({
|
const passwordHash = (
|
||||||
type: "unauthorized",
|
await Scrypt.kdf(password, { logN: 15, r: 8, p: 1 })
|
||||||
message: "Invalid email or password",
|
).toString("base64")
|
||||||
})
|
const authService: IAuthModuleService = appContainer.resolve(
|
||||||
})
|
ModuleRegistrationName.AUTH
|
||||||
|
)
|
||||||
|
|
||||||
it.skip("should throw an error upon logging in with a non existing auth user", async () => {
|
await authService.create({
|
||||||
const passwordHash = (
|
provider: "emailpass",
|
||||||
await Scrypt.kdf(password, { logN: 15, r: 8, p: 1 })
|
entity_id: email,
|
||||||
).toString("base64")
|
scope: "admin",
|
||||||
|
provider_metadata: {
|
||||||
|
password: passwordHash,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
const api = useApi() as any
|
const error = await api
|
||||||
const error = await api
|
.post(`/auth/admin/emailpass`, {
|
||||||
.post(`/auth/admin/emailpass`, {
|
email: email,
|
||||||
email: "should-not-exist",
|
password: "incorrect-password",
|
||||||
password: "should-not-exist",
|
})
|
||||||
|
.catch((e) => e)
|
||||||
|
|
||||||
|
expect(error.response.status).toEqual(401)
|
||||||
|
expect(error.response.data).toEqual({
|
||||||
|
type: "unauthorized",
|
||||||
|
message: "Invalid email or password",
|
||||||
|
})
|
||||||
})
|
})
|
||||||
.catch((e) => e)
|
|
||||||
|
|
||||||
// TODO: This is creating a user with a scope of admin. The client consuming the auth service
|
it.skip("should throw an error upon logging in with a non existing auth user", async () => {
|
||||||
// should reject this if its not being created by an admin user
|
const passwordHash = (
|
||||||
expect(error.response.status).toEqual(401)
|
await Scrypt.kdf(password, { logN: 15, r: 8, p: 1 })
|
||||||
expect(error.response.data).toEqual({
|
).toString("base64")
|
||||||
type: "unauthorized",
|
|
||||||
message: "Invalid email or password",
|
const error = await api
|
||||||
|
.post(`/auth/admin/emailpass`, {
|
||||||
|
email: "should-not-exist",
|
||||||
|
password: "should-not-exist",
|
||||||
|
})
|
||||||
|
.catch((e) => e)
|
||||||
|
|
||||||
|
// TODO: This is creating a user with a scope of admin. The client consuming the auth service
|
||||||
|
// should reject this if its not being created by an admin user
|
||||||
|
expect(error.response.status).toEqual(401)
|
||||||
|
expect(error.response.data).toEqual({
|
||||||
|
type: "unauthorized",
|
||||||
|
message: "Invalid email or password",
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
},
|
||||||
})
|
})
|
||||||
@@ -6,319 +6,296 @@ import {
|
|||||||
} from "@medusajs/modules-sdk"
|
} from "@medusajs/modules-sdk"
|
||||||
import { ICartModuleService, IPromotionModuleService } from "@medusajs/types"
|
import { ICartModuleService, IPromotionModuleService } from "@medusajs/types"
|
||||||
import { PromotionType } from "@medusajs/utils"
|
import { PromotionType } from "@medusajs/utils"
|
||||||
import path from "path"
|
|
||||||
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
|
|
||||||
import { useApi } from "../../../../environment-helpers/use-api"
|
|
||||||
import { getContainer } from "../../../../environment-helpers/use-container"
|
|
||||||
import { initDb, useDb } from "../../../../environment-helpers/use-db"
|
|
||||||
import adminSeeder from "../../../../helpers/admin-seeder"
|
import adminSeeder from "../../../../helpers/admin-seeder"
|
||||||
|
import { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||||
|
|
||||||
jest.setTimeout(50000)
|
jest.setTimeout(50000)
|
||||||
|
|
||||||
const env = { MEDUSA_FF_MEDUSA_V2: true }
|
const env = { MEDUSA_FF_MEDUSA_V2: true }
|
||||||
|
|
||||||
describe("Store Carts API: Add promotions to cart", () => {
|
medusaIntegrationTestRunner({
|
||||||
let dbConnection
|
env,
|
||||||
let appContainer
|
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||||
let shutdownServer
|
describe("Store Carts API: Add promotions to cart", () => {
|
||||||
let cartModuleService: ICartModuleService
|
let appContainer
|
||||||
let promotionModuleService: IPromotionModuleService
|
let cartModuleService: ICartModuleService
|
||||||
let remoteLinkService: RemoteLink
|
let promotionModuleService: IPromotionModuleService
|
||||||
|
let remoteLinkService: RemoteLink
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
|
appContainer = getContainer()
|
||||||
dbConnection = await initDb({ cwd, env } as any)
|
cartModuleService = appContainer.resolve(ModuleRegistrationName.CART)
|
||||||
shutdownServer = await startBootstrapApp({ cwd, env })
|
promotionModuleService = appContainer.resolve(
|
||||||
appContainer = getContainer()
|
ModuleRegistrationName.PROMOTION
|
||||||
cartModuleService = appContainer.resolve(ModuleRegistrationName.CART)
|
)
|
||||||
promotionModuleService = appContainer.resolve(
|
remoteLinkService = appContainer.resolve(LinkModuleUtils.REMOTE_LINK)
|
||||||
ModuleRegistrationName.PROMOTION
|
})
|
||||||
)
|
|
||||||
remoteLinkService = appContainer.resolve(LinkModuleUtils.REMOTE_LINK)
|
|
||||||
})
|
|
||||||
|
|
||||||
afterAll(async () => {
|
beforeEach(async () => {
|
||||||
const db = useDb()
|
await adminSeeder(dbConnection)
|
||||||
await db.shutdown()
|
})
|
||||||
await shutdownServer()
|
|
||||||
})
|
|
||||||
|
|
||||||
beforeEach(async () => {
|
describe("POST /store/carts/:id/promotions", () => {
|
||||||
await adminSeeder(dbConnection)
|
it("should add line item adjustments to a cart based on promotions", async () => {
|
||||||
})
|
const appliedPromotion = await promotionModuleService.create({
|
||||||
|
code: "PROMOTION_APPLIED",
|
||||||
afterEach(async () => {
|
type: PromotionType.STANDARD,
|
||||||
const db = useDb()
|
application_method: {
|
||||||
await db.teardown()
|
type: "fixed",
|
||||||
})
|
target_type: "items",
|
||||||
|
allocation: "each",
|
||||||
describe("POST /store/carts/:id/promotions", () => {
|
value: "300",
|
||||||
it("should add line item adjustments to a cart based on promotions", async () => {
|
apply_to_quantity: 1,
|
||||||
const appliedPromotion = await promotionModuleService.create({
|
max_quantity: 1,
|
||||||
code: "PROMOTION_APPLIED",
|
target_rules: [
|
||||||
type: PromotionType.STANDARD,
|
{
|
||||||
application_method: {
|
attribute: "product_id",
|
||||||
type: "fixed",
|
operator: "eq",
|
||||||
target_type: "items",
|
values: "prod_tshirt",
|
||||||
allocation: "each",
|
},
|
||||||
value: "300",
|
],
|
||||||
apply_to_quantity: 1,
|
|
||||||
max_quantity: 1,
|
|
||||||
target_rules: [
|
|
||||||
{
|
|
||||||
attribute: "product_id",
|
|
||||||
operator: "eq",
|
|
||||||
values: "prod_tshirt",
|
|
||||||
},
|
},
|
||||||
],
|
})
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
const createdPromotion = await promotionModuleService.create({
|
const createdPromotion = await promotionModuleService.create({
|
||||||
code: "PROMOTION_TEST",
|
code: "PROMOTION_TEST",
|
||||||
type: PromotionType.STANDARD,
|
type: PromotionType.STANDARD,
|
||||||
application_method: {
|
application_method: {
|
||||||
type: "fixed",
|
type: "fixed",
|
||||||
target_type: "items",
|
target_type: "items",
|
||||||
allocation: "across",
|
allocation: "across",
|
||||||
value: "1000",
|
value: "1000",
|
||||||
apply_to_quantity: 1,
|
apply_to_quantity: 1,
|
||||||
target_rules: [
|
target_rules: [
|
||||||
{
|
{
|
||||||
attribute: "product_id",
|
attribute: "product_id",
|
||||||
operator: "eq",
|
operator: "eq",
|
||||||
values: "prod_mat",
|
values: "prod_mat",
|
||||||
|
},
|
||||||
|
],
|
||||||
},
|
},
|
||||||
],
|
})
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
const cart = await cartModuleService.create({
|
const cart = await cartModuleService.create({
|
||||||
currency_code: "usd",
|
currency_code: "usd",
|
||||||
items: [
|
items: [
|
||||||
// Adjustment to add
|
// Adjustment to add
|
||||||
{
|
|
||||||
id: "item-1",
|
|
||||||
unit_price: 2000,
|
|
||||||
quantity: 1,
|
|
||||||
title: "Test item",
|
|
||||||
product_id: "prod_mat",
|
|
||||||
} as any,
|
|
||||||
// This adjustment will be removed and recreated
|
|
||||||
{
|
|
||||||
id: "item-2",
|
|
||||||
unit_price: 1000,
|
|
||||||
quantity: 1,
|
|
||||||
title: "Test item",
|
|
||||||
product_id: "prod_tshirt",
|
|
||||||
} as any,
|
|
||||||
],
|
|
||||||
})
|
|
||||||
|
|
||||||
// Adjustment to keep
|
|
||||||
const [lineItemAdjustment] =
|
|
||||||
await cartModuleService.addLineItemAdjustments([
|
|
||||||
{
|
|
||||||
code: appliedPromotion.code!,
|
|
||||||
amount: 300,
|
|
||||||
item_id: "item-2",
|
|
||||||
promotion_id: appliedPromotion.id,
|
|
||||||
},
|
|
||||||
])
|
|
||||||
|
|
||||||
await remoteLinkService.create({
|
|
||||||
[Modules.CART]: { cart_id: cart.id },
|
|
||||||
[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],
|
|
||||||
})
|
|
||||||
|
|
||||||
expect(created.status).toEqual(200)
|
|
||||||
expect(created.data.cart).toEqual(
|
|
||||||
expect.objectContaining({
|
|
||||||
id: expect.any(String),
|
|
||||||
items: expect.arrayContaining([
|
|
||||||
expect.objectContaining({
|
|
||||||
id: "item-1",
|
|
||||||
adjustments: expect.arrayContaining([
|
|
||||||
expect.objectContaining({
|
|
||||||
code: createdPromotion.code,
|
|
||||||
amount: 1000,
|
|
||||||
}),
|
|
||||||
]),
|
|
||||||
}),
|
|
||||||
expect.objectContaining({
|
|
||||||
adjustments: expect.arrayContaining([
|
|
||||||
expect.objectContaining({
|
|
||||||
id: expect.not.stringContaining(lineItemAdjustment.id),
|
|
||||||
code: appliedPromotion.code,
|
|
||||||
amount: 300,
|
|
||||||
}),
|
|
||||||
]),
|
|
||||||
}),
|
|
||||||
]),
|
|
||||||
})
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
it("should add shipping method adjustments to a cart based on promotions", async () => {
|
|
||||||
const [appliedPromotion] = await promotionModuleService.create([
|
|
||||||
{
|
|
||||||
code: "PROMOTION_APPLIED",
|
|
||||||
type: PromotionType.STANDARD,
|
|
||||||
rules: [
|
|
||||||
{
|
|
||||||
attribute: "customer_id",
|
|
||||||
operator: "in",
|
|
||||||
values: ["cus_test"],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
attribute: "currency_code",
|
|
||||||
operator: "in",
|
|
||||||
values: ["eur"],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
application_method: {
|
|
||||||
type: "fixed",
|
|
||||||
target_type: "shipping_methods",
|
|
||||||
allocation: "each",
|
|
||||||
value: "100",
|
|
||||||
max_quantity: 1,
|
|
||||||
target_rules: [
|
|
||||||
{
|
{
|
||||||
attribute: "name",
|
id: "item-1",
|
||||||
operator: "in",
|
unit_price: 2000,
|
||||||
values: ["express"],
|
quantity: 1,
|
||||||
},
|
title: "Test item",
|
||||||
],
|
product_id: "prod_mat",
|
||||||
},
|
} as any,
|
||||||
},
|
// This adjustment will be removed and recreated
|
||||||
])
|
|
||||||
|
|
||||||
const [newPromotion] = await promotionModuleService.create([
|
|
||||||
{
|
|
||||||
code: "PROMOTION_NEW",
|
|
||||||
type: PromotionType.STANDARD,
|
|
||||||
rules: [
|
|
||||||
{
|
|
||||||
attribute: "customer_id",
|
|
||||||
operator: "in",
|
|
||||||
values: ["cus_test"],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
attribute: "currency_code",
|
|
||||||
operator: "in",
|
|
||||||
values: ["eur"],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
application_method: {
|
|
||||||
type: "fixed",
|
|
||||||
target_type: "shipping_methods",
|
|
||||||
allocation: "each",
|
|
||||||
value: "200",
|
|
||||||
max_quantity: 1,
|
|
||||||
target_rules: [
|
|
||||||
{
|
{
|
||||||
attribute: "name",
|
id: "item-2",
|
||||||
operator: "in",
|
unit_price: 1000,
|
||||||
values: ["express", "standard"],
|
quantity: 1,
|
||||||
},
|
title: "Test item",
|
||||||
|
product_id: "prod_tshirt",
|
||||||
|
} as any,
|
||||||
],
|
],
|
||||||
},
|
})
|
||||||
},
|
|
||||||
])
|
|
||||||
|
|
||||||
const cart = await cartModuleService.create({
|
// Adjustment to keep
|
||||||
currency_code: "eur",
|
const [lineItemAdjustment] =
|
||||||
customer_id: "cus_test",
|
await cartModuleService.addLineItemAdjustments([
|
||||||
items: [
|
{
|
||||||
{
|
code: appliedPromotion.code!,
|
||||||
unit_price: 2000,
|
amount: 300,
|
||||||
quantity: 1,
|
item_id: "item-2",
|
||||||
title: "Test item",
|
promotion_id: appliedPromotion.id,
|
||||||
product_id: "prod_mat",
|
},
|
||||||
} as any,
|
])
|
||||||
],
|
|
||||||
})
|
|
||||||
|
|
||||||
const [express, standard] = await cartModuleService.addShippingMethods(
|
await remoteLinkService.create({
|
||||||
cart.id,
|
[Modules.CART]: { cart_id: cart.id },
|
||||||
[
|
[Modules.PROMOTION]: { promotion_id: appliedPromotion.id },
|
||||||
{
|
})
|
||||||
amount: 500,
|
|
||||||
name: "express",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
amount: 500,
|
|
||||||
name: "standard",
|
|
||||||
},
|
|
||||||
]
|
|
||||||
)
|
|
||||||
|
|
||||||
await remoteLinkService.create({
|
const created = await api.post(`/store/carts/${cart.id}/promotions`, {
|
||||||
[Modules.CART]: { cart_id: cart.id },
|
promo_codes: [createdPromotion.code],
|
||||||
[Modules.PROMOTION]: { promotion_id: appliedPromotion.id },
|
})
|
||||||
})
|
|
||||||
|
|
||||||
const [adjustment] = await cartModuleService.addShippingMethodAdjustments(
|
expect(created.status).toEqual(200)
|
||||||
cart.id,
|
expect(created.data.cart).toEqual(
|
||||||
[
|
|
||||||
{
|
|
||||||
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],
|
|
||||||
})
|
|
||||||
|
|
||||||
expect(created.status).toEqual(200)
|
|
||||||
expect(created.data.cart).toEqual(
|
|
||||||
expect.objectContaining({
|
|
||||||
id: expect.any(String),
|
|
||||||
items: expect.arrayContaining([
|
|
||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
id: expect.any(String),
|
id: expect.any(String),
|
||||||
}),
|
items: expect.arrayContaining([
|
||||||
]),
|
|
||||||
shipping_methods: expect.arrayContaining([
|
|
||||||
expect.objectContaining({
|
|
||||||
id: express.id,
|
|
||||||
adjustments: expect.arrayContaining([
|
|
||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
id: expect.any(String),
|
id: "item-1",
|
||||||
amount: 200,
|
adjustments: expect.arrayContaining([
|
||||||
code: newPromotion.code,
|
expect.objectContaining({
|
||||||
|
code: createdPromotion.code,
|
||||||
|
amount: 1000,
|
||||||
|
}),
|
||||||
|
]),
|
||||||
}),
|
}),
|
||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
id: expect.not.stringContaining(adjustment.id),
|
adjustments: expect.arrayContaining([
|
||||||
amount: 100,
|
expect.objectContaining({
|
||||||
code: appliedPromotion.code,
|
id: expect.not.stringContaining(lineItemAdjustment.id),
|
||||||
|
code: appliedPromotion.code,
|
||||||
|
amount: 300,
|
||||||
|
}),
|
||||||
|
]),
|
||||||
}),
|
}),
|
||||||
]),
|
]),
|
||||||
}),
|
})
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should add shipping method adjustments to a cart based on promotions", async () => {
|
||||||
|
const [appliedPromotion] = await promotionModuleService.create([
|
||||||
|
{
|
||||||
|
code: "PROMOTION_APPLIED",
|
||||||
|
type: PromotionType.STANDARD,
|
||||||
|
rules: [
|
||||||
|
{
|
||||||
|
attribute: "customer_id",
|
||||||
|
operator: "in",
|
||||||
|
values: ["cus_test"],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
attribute: "currency_code",
|
||||||
|
operator: "in",
|
||||||
|
values: ["eur"],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
application_method: {
|
||||||
|
type: "fixed",
|
||||||
|
target_type: "shipping_methods",
|
||||||
|
allocation: "each",
|
||||||
|
value: "100",
|
||||||
|
max_quantity: 1,
|
||||||
|
target_rules: [
|
||||||
|
{
|
||||||
|
attribute: "name",
|
||||||
|
operator: "in",
|
||||||
|
values: ["express"],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
])
|
||||||
|
|
||||||
|
const [newPromotion] = await promotionModuleService.create([
|
||||||
|
{
|
||||||
|
code: "PROMOTION_NEW",
|
||||||
|
type: PromotionType.STANDARD,
|
||||||
|
rules: [
|
||||||
|
{
|
||||||
|
attribute: "customer_id",
|
||||||
|
operator: "in",
|
||||||
|
values: ["cus_test"],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
attribute: "currency_code",
|
||||||
|
operator: "in",
|
||||||
|
values: ["eur"],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
application_method: {
|
||||||
|
type: "fixed",
|
||||||
|
target_type: "shipping_methods",
|
||||||
|
allocation: "each",
|
||||||
|
value: "200",
|
||||||
|
max_quantity: 1,
|
||||||
|
target_rules: [
|
||||||
|
{
|
||||||
|
attribute: "name",
|
||||||
|
operator: "in",
|
||||||
|
values: ["express", "standard"],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
])
|
||||||
|
|
||||||
|
const cart = await cartModuleService.create({
|
||||||
|
currency_code: "eur",
|
||||||
|
customer_id: "cus_test",
|
||||||
|
items: [
|
||||||
|
{
|
||||||
|
unit_price: 2000,
|
||||||
|
quantity: 1,
|
||||||
|
title: "Test item",
|
||||||
|
product_id: "prod_mat",
|
||||||
|
} as any,
|
||||||
|
],
|
||||||
|
})
|
||||||
|
|
||||||
|
const [express, standard] =
|
||||||
|
await cartModuleService.addShippingMethods(cart.id, [
|
||||||
|
{
|
||||||
|
amount: 500,
|
||||||
|
name: "express",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
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, [
|
||||||
|
{
|
||||||
|
shipping_method_id: express.id,
|
||||||
|
amount: 100,
|
||||||
|
code: appliedPromotion.code!,
|
||||||
|
},
|
||||||
|
])
|
||||||
|
|
||||||
|
const created = await api.post(`/store/carts/${cart.id}/promotions`, {
|
||||||
|
promo_codes: [newPromotion.code],
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(created.status).toEqual(200)
|
||||||
|
expect(created.data.cart).toEqual(
|
||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
id: standard.id,
|
id: expect.any(String),
|
||||||
adjustments: [
|
items: expect.arrayContaining([
|
||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
id: expect.any(String),
|
id: expect.any(String),
|
||||||
amount: 200,
|
|
||||||
code: newPromotion.code,
|
|
||||||
}),
|
}),
|
||||||
],
|
]),
|
||||||
}),
|
shipping_methods: expect.arrayContaining([
|
||||||
]),
|
expect.objectContaining({
|
||||||
|
id: express.id,
|
||||||
|
adjustments: expect.arrayContaining([
|
||||||
|
expect.objectContaining({
|
||||||
|
id: expect.any(String),
|
||||||
|
amount: 200,
|
||||||
|
code: newPromotion.code,
|
||||||
|
}),
|
||||||
|
expect.objectContaining({
|
||||||
|
id: expect.not.stringContaining(adjustment.id),
|
||||||
|
amount: 100,
|
||||||
|
code: appliedPromotion.code,
|
||||||
|
}),
|
||||||
|
]),
|
||||||
|
}),
|
||||||
|
expect.objectContaining({
|
||||||
|
id: standard.id,
|
||||||
|
adjustments: [
|
||||||
|
expect.objectContaining({
|
||||||
|
id: expect.any(String),
|
||||||
|
amount: 200,
|
||||||
|
code: newPromotion.code,
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
]),
|
||||||
|
})
|
||||||
|
)
|
||||||
})
|
})
|
||||||
)
|
})
|
||||||
})
|
})
|
||||||
})
|
},
|
||||||
})
|
})
|
||||||
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
+283
-294
@@ -6,324 +6,313 @@ import {
|
|||||||
} from "@medusajs/modules-sdk"
|
} from "@medusajs/modules-sdk"
|
||||||
import { ICartModuleService, IPromotionModuleService } from "@medusajs/types"
|
import { ICartModuleService, IPromotionModuleService } from "@medusajs/types"
|
||||||
import { PromotionType } from "@medusajs/utils"
|
import { PromotionType } from "@medusajs/utils"
|
||||||
import path from "path"
|
|
||||||
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
|
|
||||||
import { useApi } from "../../../../environment-helpers/use-api"
|
|
||||||
import { getContainer } from "../../../../environment-helpers/use-container"
|
|
||||||
import { initDb, useDb } from "../../../../environment-helpers/use-db"
|
|
||||||
import adminSeeder from "../../../../helpers/admin-seeder"
|
import adminSeeder from "../../../../helpers/admin-seeder"
|
||||||
|
import { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||||
|
|
||||||
jest.setTimeout(50000)
|
jest.setTimeout(50000)
|
||||||
|
|
||||||
const env = { MEDUSA_FF_MEDUSA_V2: true }
|
const env = { MEDUSA_FF_MEDUSA_V2: true }
|
||||||
|
|
||||||
describe("Store Carts API: Remove promotions from cart", () => {
|
medusaIntegrationTestRunner({
|
||||||
let dbConnection
|
env,
|
||||||
let appContainer
|
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||||
let shutdownServer
|
describe("Store Carts API: Remove promotions from cart", () => {
|
||||||
let cartModuleService: ICartModuleService
|
let appContainer
|
||||||
let promotionModuleService: IPromotionModuleService
|
let cartModuleService: ICartModuleService
|
||||||
let remoteLinkService: RemoteLink
|
let promotionModuleService: IPromotionModuleService
|
||||||
|
let remoteLinkService: RemoteLink
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
|
appContainer = getContainer()
|
||||||
dbConnection = await initDb({ cwd, env } as any)
|
cartModuleService = appContainer.resolve(ModuleRegistrationName.CART)
|
||||||
shutdownServer = await startBootstrapApp({ cwd, env })
|
remoteLinkService = appContainer.resolve(LinkModuleUtils.REMOTE_LINK)
|
||||||
appContainer = getContainer()
|
promotionModuleService = appContainer.resolve(
|
||||||
cartModuleService = appContainer.resolve(ModuleRegistrationName.CART)
|
ModuleRegistrationName.PROMOTION
|
||||||
remoteLinkService = appContainer.resolve(LinkModuleUtils.REMOTE_LINK)
|
)
|
||||||
promotionModuleService = appContainer.resolve(
|
|
||||||
ModuleRegistrationName.PROMOTION
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
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({
|
|
||||||
code: "PROMOTION_APPLIED",
|
|
||||||
type: PromotionType.STANDARD,
|
|
||||||
application_method: {
|
|
||||||
type: "fixed",
|
|
||||||
target_type: "items",
|
|
||||||
allocation: "each",
|
|
||||||
value: "300",
|
|
||||||
apply_to_quantity: 1,
|
|
||||||
max_quantity: 1,
|
|
||||||
target_rules: [
|
|
||||||
{
|
|
||||||
attribute: "product_id",
|
|
||||||
operator: "eq",
|
|
||||||
values: "prod_tshirt",
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
})
|
})
|
||||||
|
|
||||||
const appliedPromotionToRemove = await promotionModuleService.create({
|
beforeEach(async () => {
|
||||||
code: "PROMOTION_APPLIED_TO_REMOVE",
|
await adminSeeder(dbConnection)
|
||||||
type: PromotionType.STANDARD,
|
|
||||||
application_method: {
|
|
||||||
type: "fixed",
|
|
||||||
target_type: "items",
|
|
||||||
allocation: "each",
|
|
||||||
value: "300",
|
|
||||||
apply_to_quantity: 1,
|
|
||||||
max_quantity: 1,
|
|
||||||
target_rules: [
|
|
||||||
{
|
|
||||||
attribute: "product_id",
|
|
||||||
operator: "eq",
|
|
||||||
values: "prod_tshirt",
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
})
|
})
|
||||||
|
|
||||||
const cart = await cartModuleService.create({
|
describe("DELETE /store/carts/:id/promotions", () => {
|
||||||
currency_code: "usd",
|
it("should remove line item adjustments from a cart based on promotions", async () => {
|
||||||
items: [
|
const appliedPromotion = await promotionModuleService.create({
|
||||||
{
|
code: "PROMOTION_APPLIED",
|
||||||
id: "item-1",
|
type: PromotionType.STANDARD,
|
||||||
unit_price: 2000,
|
application_method: {
|
||||||
quantity: 1,
|
type: "fixed",
|
||||||
title: "Test item",
|
target_type: "items",
|
||||||
product_id: "prod_mat",
|
allocation: "each",
|
||||||
} as any,
|
value: "300",
|
||||||
{
|
apply_to_quantity: 1,
|
||||||
id: "item-2",
|
max_quantity: 1,
|
||||||
unit_price: 1000,
|
target_rules: [
|
||||||
quantity: 1,
|
{
|
||||||
title: "Test item",
|
attribute: "product_id",
|
||||||
product_id: "prod_tshirt",
|
operator: "eq",
|
||||||
} as any,
|
values: "prod_tshirt",
|
||||||
],
|
},
|
||||||
})
|
|
||||||
|
|
||||||
const [adjustment1, adjustment2] =
|
|
||||||
await cartModuleService.addLineItemAdjustments([
|
|
||||||
{
|
|
||||||
code: appliedPromotion.code!,
|
|
||||||
amount: 300,
|
|
||||||
item_id: "item-2",
|
|
||||||
promotion_id: appliedPromotionToRemove.id,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
code: appliedPromotionToRemove.code!,
|
|
||||||
amount: 150,
|
|
||||||
item_id: "item-1",
|
|
||||||
promotion_id: appliedPromotionToRemove.id,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
code: appliedPromotionToRemove.code!,
|
|
||||||
amount: 150,
|
|
||||||
item_id: "item-2",
|
|
||||||
promotion_id: appliedPromotionToRemove.id,
|
|
||||||
},
|
|
||||||
])
|
|
||||||
|
|
||||||
await remoteLinkService.create([
|
|
||||||
{
|
|
||||||
[Modules.CART]: { cart_id: cart.id },
|
|
||||||
[Modules.PROMOTION]: { promotion_id: appliedPromotion.id },
|
|
||||||
},
|
|
||||||
{
|
|
||||||
[Modules.CART]: { cart_id: cart.id },
|
|
||||||
[Modules.PROMOTION]: { promotion_id: appliedPromotionToRemove.id },
|
|
||||||
},
|
|
||||||
])
|
|
||||||
|
|
||||||
const api = useApi() as any
|
|
||||||
|
|
||||||
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(
|
|
||||||
expect.objectContaining({
|
|
||||||
id: expect.any(String),
|
|
||||||
items: expect.arrayContaining([
|
|
||||||
expect.objectContaining({
|
|
||||||
id: "item-1",
|
|
||||||
adjustments: [],
|
|
||||||
}),
|
|
||||||
expect.objectContaining({
|
|
||||||
id: "item-2",
|
|
||||||
adjustments: [
|
|
||||||
expect.objectContaining({
|
|
||||||
amount: 300,
|
|
||||||
code: appliedPromotion.code,
|
|
||||||
}),
|
|
||||||
],
|
],
|
||||||
}),
|
|
||||||
]),
|
|
||||||
})
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
it("should add shipping method adjustments to a cart based on promotions", async () => {
|
|
||||||
const appliedPromotion = await promotionModuleService.create({
|
|
||||||
code: "PROMOTION_APPLIED",
|
|
||||||
type: PromotionType.STANDARD,
|
|
||||||
rules: [
|
|
||||||
{
|
|
||||||
attribute: "customer_id",
|
|
||||||
operator: "in",
|
|
||||||
values: ["cus_test"],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
attribute: "currency_code",
|
|
||||||
operator: "in",
|
|
||||||
values: ["eur"],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
application_method: {
|
|
||||||
type: "fixed",
|
|
||||||
target_type: "shipping_methods",
|
|
||||||
allocation: "each",
|
|
||||||
value: "100",
|
|
||||||
max_quantity: 1,
|
|
||||||
target_rules: [
|
|
||||||
{
|
|
||||||
attribute: "name",
|
|
||||||
operator: "in",
|
|
||||||
values: ["express"],
|
|
||||||
},
|
},
|
||||||
],
|
})
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
const appliedPromotionToRemove = await promotionModuleService.create({
|
const appliedPromotionToRemove = await promotionModuleService.create({
|
||||||
code: "PROMOTION_APPLIED_TO_REMOVE",
|
code: "PROMOTION_APPLIED_TO_REMOVE",
|
||||||
type: PromotionType.STANDARD,
|
type: PromotionType.STANDARD,
|
||||||
rules: [
|
application_method: {
|
||||||
{
|
type: "fixed",
|
||||||
attribute: "customer_id",
|
target_type: "items",
|
||||||
operator: "in",
|
allocation: "each",
|
||||||
values: ["cus_test"],
|
value: "300",
|
||||||
},
|
apply_to_quantity: 1,
|
||||||
{
|
max_quantity: 1,
|
||||||
attribute: "currency_code",
|
target_rules: [
|
||||||
operator: "in",
|
{
|
||||||
values: ["eur"],
|
attribute: "product_id",
|
||||||
},
|
operator: "eq",
|
||||||
],
|
values: "prod_tshirt",
|
||||||
application_method: {
|
},
|
||||||
type: "fixed",
|
],
|
||||||
target_type: "shipping_methods",
|
|
||||||
allocation: "each",
|
|
||||||
value: "100",
|
|
||||||
max_quantity: 1,
|
|
||||||
target_rules: [
|
|
||||||
{
|
|
||||||
attribute: "name",
|
|
||||||
operator: "in",
|
|
||||||
values: ["express"],
|
|
||||||
},
|
},
|
||||||
],
|
})
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
const cart = await cartModuleService.create({
|
const cart = await cartModuleService.create({
|
||||||
currency_code: "eur",
|
currency_code: "usd",
|
||||||
customer_id: "cus_test",
|
items: [
|
||||||
items: [
|
{
|
||||||
{
|
id: "item-1",
|
||||||
unit_price: 2000,
|
unit_price: 2000,
|
||||||
quantity: 1,
|
quantity: 1,
|
||||||
title: "Test item",
|
title: "Test item",
|
||||||
product_id: "prod_mat",
|
product_id: "prod_mat",
|
||||||
},
|
} as any,
|
||||||
],
|
{
|
||||||
})
|
id: "item-2",
|
||||||
|
unit_price: 1000,
|
||||||
|
quantity: 1,
|
||||||
|
title: "Test item",
|
||||||
|
product_id: "prod_tshirt",
|
||||||
|
} as any,
|
||||||
|
],
|
||||||
|
})
|
||||||
|
|
||||||
const [express, standard] = await cartModuleService.addShippingMethods(
|
const [adjustment1, adjustment2] =
|
||||||
cart.id,
|
await cartModuleService.addLineItemAdjustments([
|
||||||
[
|
{
|
||||||
{
|
code: appliedPromotion.code!,
|
||||||
amount: 500,
|
amount: 300,
|
||||||
name: "express",
|
item_id: "item-2",
|
||||||
},
|
promotion_id: appliedPromotionToRemove.id,
|
||||||
{
|
},
|
||||||
amount: 500,
|
{
|
||||||
name: "standard",
|
code: appliedPromotionToRemove.code!,
|
||||||
},
|
amount: 150,
|
||||||
]
|
item_id: "item-1",
|
||||||
)
|
promotion_id: appliedPromotionToRemove.id,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
code: appliedPromotionToRemove.code!,
|
||||||
|
amount: 150,
|
||||||
|
item_id: "item-2",
|
||||||
|
promotion_id: appliedPromotionToRemove.id,
|
||||||
|
},
|
||||||
|
])
|
||||||
|
|
||||||
await cartModuleService.addShippingMethodAdjustments(cart.id, [
|
await remoteLinkService.create([
|
||||||
{
|
{
|
||||||
shipping_method_id: express.id,
|
[Modules.CART]: { cart_id: cart.id },
|
||||||
amount: 100,
|
[Modules.PROMOTION]: { promotion_id: appliedPromotion.id },
|
||||||
code: appliedPromotion.code!,
|
},
|
||||||
},
|
{
|
||||||
{
|
[Modules.CART]: { cart_id: cart.id },
|
||||||
shipping_method_id: express.id,
|
[Modules.PROMOTION]: {
|
||||||
amount: 100,
|
promotion_id: appliedPromotionToRemove.id,
|
||||||
code: appliedPromotionToRemove.code!,
|
},
|
||||||
},
|
},
|
||||||
])
|
])
|
||||||
|
|
||||||
await remoteLinkService.create([
|
const response = await api.delete(
|
||||||
{
|
`/store/carts/${cart.id}/promotions`,
|
||||||
[Modules.CART]: { cart_id: cart.id },
|
{
|
||||||
[Modules.PROMOTION]: { promotion_id: appliedPromotion.id },
|
data: {
|
||||||
},
|
promo_codes: [appliedPromotionToRemove.code],
|
||||||
{
|
},
|
||||||
[Modules.CART]: { cart_id: cart.id },
|
}
|
||||||
[Modules.PROMOTION]: { promotion_id: appliedPromotionToRemove.id },
|
)
|
||||||
},
|
|
||||||
])
|
|
||||||
|
|
||||||
const api = useApi() as any
|
expect(response.status).toEqual(200)
|
||||||
|
expect(response.data.cart).toEqual(
|
||||||
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(
|
|
||||||
expect.objectContaining({
|
|
||||||
id: expect.any(String),
|
|
||||||
items: expect.arrayContaining([
|
|
||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
id: expect.any(String),
|
id: expect.any(String),
|
||||||
}),
|
items: expect.arrayContaining([
|
||||||
]),
|
|
||||||
shipping_methods: expect.arrayContaining([
|
|
||||||
expect.objectContaining({
|
|
||||||
id: express.id,
|
|
||||||
adjustments: [
|
|
||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
amount: 100,
|
id: "item-1",
|
||||||
code: appliedPromotion.code,
|
adjustments: [],
|
||||||
}),
|
}),
|
||||||
],
|
expect.objectContaining({
|
||||||
}),
|
id: "item-2",
|
||||||
expect.objectContaining({
|
adjustments: [
|
||||||
id: standard.id,
|
expect.objectContaining({
|
||||||
adjustments: [],
|
amount: 300,
|
||||||
}),
|
code: appliedPromotion.code,
|
||||||
]),
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
]),
|
||||||
|
})
|
||||||
|
)
|
||||||
})
|
})
|
||||||
)
|
|
||||||
|
it("should add shipping method adjustments to a cart based on promotions", async () => {
|
||||||
|
const appliedPromotion = await promotionModuleService.create({
|
||||||
|
code: "PROMOTION_APPLIED",
|
||||||
|
type: PromotionType.STANDARD,
|
||||||
|
rules: [
|
||||||
|
{
|
||||||
|
attribute: "customer_id",
|
||||||
|
operator: "in",
|
||||||
|
values: ["cus_test"],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
attribute: "currency_code",
|
||||||
|
operator: "in",
|
||||||
|
values: ["eur"],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
application_method: {
|
||||||
|
type: "fixed",
|
||||||
|
target_type: "shipping_methods",
|
||||||
|
allocation: "each",
|
||||||
|
value: "100",
|
||||||
|
max_quantity: 1,
|
||||||
|
target_rules: [
|
||||||
|
{
|
||||||
|
attribute: "name",
|
||||||
|
operator: "in",
|
||||||
|
values: ["express"],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
const appliedPromotionToRemove = await promotionModuleService.create({
|
||||||
|
code: "PROMOTION_APPLIED_TO_REMOVE",
|
||||||
|
type: PromotionType.STANDARD,
|
||||||
|
rules: [
|
||||||
|
{
|
||||||
|
attribute: "customer_id",
|
||||||
|
operator: "in",
|
||||||
|
values: ["cus_test"],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
attribute: "currency_code",
|
||||||
|
operator: "in",
|
||||||
|
values: ["eur"],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
application_method: {
|
||||||
|
type: "fixed",
|
||||||
|
target_type: "shipping_methods",
|
||||||
|
allocation: "each",
|
||||||
|
value: "100",
|
||||||
|
max_quantity: 1,
|
||||||
|
target_rules: [
|
||||||
|
{
|
||||||
|
attribute: "name",
|
||||||
|
operator: "in",
|
||||||
|
values: ["express"],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
const cart = await cartModuleService.create({
|
||||||
|
currency_code: "eur",
|
||||||
|
customer_id: "cus_test",
|
||||||
|
items: [
|
||||||
|
{
|
||||||
|
unit_price: 2000,
|
||||||
|
quantity: 1,
|
||||||
|
title: "Test item",
|
||||||
|
product_id: "prod_mat",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
})
|
||||||
|
|
||||||
|
const [express, standard] =
|
||||||
|
await cartModuleService.addShippingMethods(cart.id, [
|
||||||
|
{
|
||||||
|
amount: 500,
|
||||||
|
name: "express",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
amount: 500,
|
||||||
|
name: "standard",
|
||||||
|
},
|
||||||
|
])
|
||||||
|
|
||||||
|
await cartModuleService.addShippingMethodAdjustments(cart.id, [
|
||||||
|
{
|
||||||
|
shipping_method_id: express.id,
|
||||||
|
amount: 100,
|
||||||
|
code: appliedPromotion.code!,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
shipping_method_id: express.id,
|
||||||
|
amount: 100,
|
||||||
|
code: appliedPromotionToRemove.code!,
|
||||||
|
},
|
||||||
|
])
|
||||||
|
|
||||||
|
await remoteLinkService.create([
|
||||||
|
{
|
||||||
|
[Modules.CART]: { cart_id: cart.id },
|
||||||
|
[Modules.PROMOTION]: { promotion_id: appliedPromotion.id },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
[Modules.CART]: { cart_id: cart.id },
|
||||||
|
[Modules.PROMOTION]: {
|
||||||
|
promotion_id: appliedPromotionToRemove.id,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
])
|
||||||
|
|
||||||
|
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(
|
||||||
|
expect.objectContaining({
|
||||||
|
id: expect.any(String),
|
||||||
|
items: expect.arrayContaining([
|
||||||
|
expect.objectContaining({
|
||||||
|
id: expect.any(String),
|
||||||
|
}),
|
||||||
|
]),
|
||||||
|
shipping_methods: expect.arrayContaining([
|
||||||
|
expect.objectContaining({
|
||||||
|
id: express.id,
|
||||||
|
adjustments: [
|
||||||
|
expect.objectContaining({
|
||||||
|
amount: 100,
|
||||||
|
code: appliedPromotion.code,
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
expect.objectContaining({
|
||||||
|
id: standard.id,
|
||||||
|
adjustments: [],
|
||||||
|
}),
|
||||||
|
]),
|
||||||
|
})
|
||||||
|
)
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
},
|
||||||
})
|
})
|
||||||
@@ -1,12 +1,5 @@
|
|||||||
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
|
||||||
import { ICurrencyModuleService } from "@medusajs/types"
|
|
||||||
import path from "path"
|
|
||||||
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
|
|
||||||
import { useApi } from "../../../../environment-helpers/use-api"
|
|
||||||
import { getContainer } from "../../../../environment-helpers/use-container"
|
|
||||||
import { initDb, useDb } from "../../../../environment-helpers/use-db"
|
|
||||||
import { DataSource } from "typeorm"
|
|
||||||
import { createAdminUser } from "../../../helpers/create-admin-user"
|
import { createAdminUser } from "../../../helpers/create-admin-user"
|
||||||
|
import { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||||
|
|
||||||
jest.setTimeout(50000)
|
jest.setTimeout(50000)
|
||||||
|
|
||||||
@@ -15,53 +8,39 @@ const adminHeaders = {
|
|||||||
headers: { "x-medusa-access-token": "test_token" },
|
headers: { "x-medusa-access-token": "test_token" },
|
||||||
}
|
}
|
||||||
|
|
||||||
describe("Currency - Admin", () => {
|
medusaIntegrationTestRunner({
|
||||||
let dbConnection: DataSource
|
env,
|
||||||
let appContainer
|
testSuite: ({ dbConnection, api, getContainer }) => {
|
||||||
let shutdownServer
|
describe("Currency - Admin", () => {
|
||||||
let service: ICurrencyModuleService
|
let container
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeEach(async () => {
|
||||||
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
|
container = getContainer()
|
||||||
dbConnection = await initDb({ cwd, env } as any)
|
await createAdminUser(dbConnection, adminHeaders, container)
|
||||||
shutdownServer = await startBootstrapApp({ cwd, env })
|
})
|
||||||
appContainer = getContainer()
|
|
||||||
service = appContainer.resolve(ModuleRegistrationName.CURRENCY)
|
|
||||||
})
|
|
||||||
|
|
||||||
afterAll(async () => {
|
it("should correctly retrieve and list currencies", async () => {
|
||||||
const db = useDb()
|
const listResp = await api.get("/admin/currencies", adminHeaders)
|
||||||
await db.shutdown()
|
|
||||||
await shutdownServer()
|
|
||||||
})
|
|
||||||
|
|
||||||
beforeEach(async () => {
|
expect(listResp.data.currencies).toEqual(
|
||||||
await createAdminUser(dbConnection, adminHeaders)
|
expect.arrayContaining([
|
||||||
})
|
expect.objectContaining({
|
||||||
|
code: "aud",
|
||||||
|
}),
|
||||||
|
expect.objectContaining({
|
||||||
|
code: "cad",
|
||||||
|
}),
|
||||||
|
])
|
||||||
|
)
|
||||||
|
|
||||||
afterEach(async () => {
|
const retrieveResp = await api.get(
|
||||||
const db = useDb()
|
`/admin/currencies/aud`,
|
||||||
await db.teardown()
|
adminHeaders
|
||||||
})
|
)
|
||||||
|
expect(retrieveResp.data.currency).toEqual(
|
||||||
it("should correctly retrieve and list currencies", async () => {
|
listResp.data.currencies.find((c) => c.code === "aud")
|
||||||
const api = useApi() as any
|
)
|
||||||
const listResp = await api.get("/admin/currencies", adminHeaders)
|
})
|
||||||
|
})
|
||||||
expect(listResp.data.currencies).toEqual(
|
},
|
||||||
expect.arrayContaining([
|
|
||||||
expect.objectContaining({
|
|
||||||
code: "aud",
|
|
||||||
}),
|
|
||||||
expect.objectContaining({
|
|
||||||
code: "cad",
|
|
||||||
}),
|
|
||||||
])
|
|
||||||
)
|
|
||||||
|
|
||||||
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 { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||||
import { ICurrencyModuleService } from "@medusajs/types"
|
|
||||||
import path from "path"
|
|
||||||
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
|
|
||||||
import { useApi } from "../../../../environment-helpers/use-api"
|
|
||||||
import { getContainer } from "../../../../environment-helpers/use-container"
|
|
||||||
import { initDb, useDb } from "../../../../environment-helpers/use-db"
|
|
||||||
import { DataSource } from "typeorm"
|
|
||||||
|
|
||||||
jest.setTimeout(50000)
|
jest.setTimeout(50000)
|
||||||
|
|
||||||
@@ -14,49 +7,32 @@ const storeHeaders = {
|
|||||||
headers: {},
|
headers: {},
|
||||||
}
|
}
|
||||||
|
|
||||||
describe("Currency - Store", () => {
|
medusaIntegrationTestRunner({
|
||||||
let dbConnection: DataSource
|
env,
|
||||||
let appContainer
|
testSuite: ({ api }) => {
|
||||||
let shutdownServer
|
describe("Currency - Store", () => {
|
||||||
let service: ICurrencyModuleService
|
it("should correctly retrieve and list currencies", async () => {
|
||||||
|
const listResp = await api.get("/store/currencies", storeHeaders)
|
||||||
|
|
||||||
beforeAll(async () => {
|
expect(listResp.data.currencies).toEqual(
|
||||||
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
|
expect.arrayContaining([
|
||||||
dbConnection = await initDb({ cwd, env } as any)
|
expect.objectContaining({
|
||||||
shutdownServer = await startBootstrapApp({ cwd, env })
|
code: "aud",
|
||||||
appContainer = getContainer()
|
}),
|
||||||
service = appContainer.resolve(ModuleRegistrationName.CURRENCY)
|
expect.objectContaining({
|
||||||
})
|
code: "cad",
|
||||||
|
}),
|
||||||
|
])
|
||||||
|
)
|
||||||
|
|
||||||
afterAll(async () => {
|
const retrieveResp = await api.get(
|
||||||
const db = useDb()
|
`/store/currencies/aud`,
|
||||||
await db.shutdown()
|
storeHeaders
|
||||||
await shutdownServer()
|
)
|
||||||
})
|
expect(retrieveResp.data.currency).toEqual(
|
||||||
|
listResp.data.currencies.find((c) => c.code === "aud")
|
||||||
afterEach(async () => {
|
)
|
||||||
const db = useDb()
|
})
|
||||||
await db.teardown()
|
})
|
||||||
})
|
},
|
||||||
|
|
||||||
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(
|
|
||||||
expect.arrayContaining([
|
|
||||||
expect.objectContaining({
|
|
||||||
code: "aud",
|
|
||||||
}),
|
|
||||||
expect.objectContaining({
|
|
||||||
code: "cad",
|
|
||||||
}),
|
|
||||||
])
|
|
||||||
)
|
|
||||||
|
|
||||||
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 { ICustomerModuleService } from "@medusajs/types"
|
||||||
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||||
import adminSeeder from "../../../../helpers/admin-seeder"
|
|
||||||
import { createAdminUser } from "../../../helpers/create-admin-user"
|
import { createAdminUser } from "../../../helpers/create-admin-user"
|
||||||
import { getContainer } from "../../../../environment-helpers/use-container"
|
import { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||||
import path from "path"
|
|
||||||
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
|
|
||||||
import { useApi } from "../../../../environment-helpers/use-api"
|
|
||||||
|
|
||||||
jest.setTimeout(50000)
|
jest.setTimeout(50000)
|
||||||
|
|
||||||
@@ -16,74 +10,61 @@ const adminHeaders = {
|
|||||||
headers: { "x-medusa-access-token": "test_token" },
|
headers: { "x-medusa-access-token": "test_token" },
|
||||||
}
|
}
|
||||||
|
|
||||||
describe("POST /admin/customer-groups/:id/customers/batch", () => {
|
medusaIntegrationTestRunner({
|
||||||
let dbConnection
|
env,
|
||||||
let appContainer
|
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||||
let shutdownServer
|
describe("POST /admin/customer-groups/:id/customers/batch", () => {
|
||||||
let customerModuleService: ICustomerModuleService
|
let appContainer
|
||||||
|
let customerModuleService: ICustomerModuleService
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
|
appContainer = getContainer()
|
||||||
dbConnection = await initDb({ cwd, env } as any)
|
customerModuleService = appContainer.resolve(
|
||||||
shutdownServer = await startBootstrapApp({ cwd, env })
|
ModuleRegistrationName.CUSTOMER
|
||||||
appContainer = getContainer()
|
)
|
||||||
customerModuleService = appContainer.resolve(
|
})
|
||||||
ModuleRegistrationName.CUSTOMER
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
afterAll(async () => {
|
beforeEach(async () => {
|
||||||
const db = useDb()
|
await createAdminUser(dbConnection, adminHeaders, appContainer)
|
||||||
await db.shutdown()
|
})
|
||||||
await shutdownServer()
|
|
||||||
})
|
|
||||||
|
|
||||||
beforeEach(async () => {
|
it("should batch add customers to a group", async () => {
|
||||||
await createAdminUser(dbConnection, adminHeaders)
|
const group = await customerModuleService.createCustomerGroup({
|
||||||
})
|
name: "VIP",
|
||||||
|
})
|
||||||
|
const customers = await customerModuleService.create([
|
||||||
|
{
|
||||||
|
first_name: "Test",
|
||||||
|
last_name: "Test",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
first_name: "Test2",
|
||||||
|
last_name: "Test2",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
first_name: "Test3",
|
||||||
|
last_name: "Test3",
|
||||||
|
},
|
||||||
|
])
|
||||||
|
|
||||||
afterEach(async () => {
|
const response = await api.post(
|
||||||
const db = useDb()
|
`/admin/customer-groups/${group.id}/customers/batch`,
|
||||||
await db.teardown()
|
{
|
||||||
})
|
customer_ids: customers.map((c) => ({ id: c.id })),
|
||||||
|
},
|
||||||
|
adminHeaders
|
||||||
|
)
|
||||||
|
|
||||||
it("should batch add customers to a group", async () => {
|
expect(response.status).toEqual(200)
|
||||||
const api = useApi() as any
|
|
||||||
|
|
||||||
const group = await customerModuleService.createCustomerGroup({
|
const updatedGroup = await customerModuleService.retrieveCustomerGroup(
|
||||||
name: "VIP",
|
group.id,
|
||||||
|
{
|
||||||
|
relations: ["customers"],
|
||||||
|
}
|
||||||
|
)
|
||||||
|
expect(updatedGroup.customers?.length).toEqual(3)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
const customers = await customerModuleService.create([
|
},
|
||||||
{
|
|
||||||
first_name: "Test",
|
|
||||||
last_name: "Test",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
first_name: "Test2",
|
|
||||||
last_name: "Test2",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
first_name: "Test3",
|
|
||||||
last_name: "Test3",
|
|
||||||
},
|
|
||||||
])
|
|
||||||
|
|
||||||
const response = await api.post(
|
|
||||||
`/admin/customer-groups/${group.id}/customers/batch`,
|
|
||||||
{
|
|
||||||
customer_ids: customers.map((c) => ({ id: c.id })),
|
|
||||||
},
|
|
||||||
adminHeaders
|
|
||||||
)
|
|
||||||
|
|
||||||
expect(response.status).toEqual(200)
|
|
||||||
|
|
||||||
const updatedGroup = await customerModuleService.retrieveCustomerGroup(
|
|
||||||
group.id,
|
|
||||||
{
|
|
||||||
relations: ["customers"],
|
|
||||||
}
|
|
||||||
)
|
|
||||||
expect(updatedGroup.customers?.length).toEqual(3)
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
+58
-74
@@ -1,13 +1,7 @@
|
|||||||
import { initDb, useDb } from "../../../../environment-helpers/use-db"
|
|
||||||
|
|
||||||
import { ICustomerModuleService } from "@medusajs/types"
|
import { ICustomerModuleService } from "@medusajs/types"
|
||||||
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||||
import adminSeeder from "../../../../helpers/admin-seeder"
|
|
||||||
import { createAdminUser } from "../../../helpers/create-admin-user"
|
import { createAdminUser } from "../../../helpers/create-admin-user"
|
||||||
import { getContainer } from "../../../../environment-helpers/use-container"
|
import { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||||
import path from "path"
|
|
||||||
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
|
|
||||||
import { useApi } from "../../../../environment-helpers/use-api"
|
|
||||||
|
|
||||||
jest.setTimeout(50000)
|
jest.setTimeout(50000)
|
||||||
|
|
||||||
@@ -16,78 +10,68 @@ const adminHeaders = {
|
|||||||
headers: { "x-medusa-access-token": "test_token" },
|
headers: { "x-medusa-access-token": "test_token" },
|
||||||
}
|
}
|
||||||
|
|
||||||
describe("DELETE /admin/customer-groups/:id/customers/remove", () => {
|
medusaIntegrationTestRunner({
|
||||||
let dbConnection
|
env,
|
||||||
let appContainer
|
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||||
let shutdownServer
|
describe("DELETE /admin/customer-groups/:id/customers/remove", () => {
|
||||||
let customerModuleService: ICustomerModuleService
|
let appContainer
|
||||||
|
let customerModuleService: ICustomerModuleService
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
|
appContainer = getContainer()
|
||||||
dbConnection = await initDb({ cwd, env } as any)
|
customerModuleService = appContainer.resolve(
|
||||||
shutdownServer = await startBootstrapApp({ cwd, env })
|
ModuleRegistrationName.CUSTOMER
|
||||||
appContainer = getContainer()
|
)
|
||||||
customerModuleService = appContainer.resolve(
|
})
|
||||||
ModuleRegistrationName.CUSTOMER
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
afterAll(async () => {
|
beforeEach(async () => {
|
||||||
const db = useDb()
|
await createAdminUser(dbConnection, adminHeaders, appContainer)
|
||||||
await db.shutdown()
|
})
|
||||||
await shutdownServer()
|
|
||||||
})
|
|
||||||
|
|
||||||
beforeEach(async () => {
|
it("should batch delete customers from a group", async () => {
|
||||||
await createAdminUser(dbConnection, adminHeaders)
|
const group = await customerModuleService.createCustomerGroup({
|
||||||
})
|
name: "VIP",
|
||||||
|
})
|
||||||
|
const customers = await customerModuleService.create([
|
||||||
|
{
|
||||||
|
first_name: "Test",
|
||||||
|
last_name: "Test",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
first_name: "Test2",
|
||||||
|
last_name: "Test2",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
first_name: "Test3",
|
||||||
|
last_name: "Test3",
|
||||||
|
},
|
||||||
|
])
|
||||||
|
|
||||||
afterEach(async () => {
|
await customerModuleService.addCustomerToGroup(
|
||||||
const db = useDb()
|
customers.map((c) => ({
|
||||||
await db.teardown()
|
customer_id: c.id,
|
||||||
})
|
customer_group_id: group.id,
|
||||||
|
}))
|
||||||
|
)
|
||||||
|
|
||||||
it("should batch delete customers from a group", async () => {
|
const response = await api.post(
|
||||||
const api = useApi() as any
|
`/admin/customer-groups/${group.id}/customers/remove`,
|
||||||
|
{
|
||||||
|
customer_ids: customers.map((c) => ({ id: c.id })),
|
||||||
|
},
|
||||||
|
adminHeaders
|
||||||
|
)
|
||||||
|
|
||||||
const group = await customerModuleService.createCustomerGroup({
|
expect(response.status).toEqual(200)
|
||||||
name: "VIP",
|
|
||||||
|
const updatedGroup = await customerModuleService.retrieveCustomerGroup(
|
||||||
|
group.id,
|
||||||
|
{
|
||||||
|
relations: ["customers"],
|
||||||
|
}
|
||||||
|
)
|
||||||
|
expect(updatedGroup.customers?.length).toEqual(0)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
const customers = await customerModuleService.create([
|
},
|
||||||
{
|
|
||||||
first_name: "Test",
|
|
||||||
last_name: "Test",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
first_name: "Test2",
|
|
||||||
last_name: "Test2",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
first_name: "Test3",
|
|
||||||
last_name: "Test3",
|
|
||||||
},
|
|
||||||
])
|
|
||||||
|
|
||||||
await customerModuleService.addCustomerToGroup(
|
|
||||||
customers.map((c) => ({ customer_id: c.id, customer_group_id: group.id }))
|
|
||||||
)
|
|
||||||
|
|
||||||
const response = await api.post(
|
|
||||||
`/admin/customer-groups/${group.id}/customers/remove`,
|
|
||||||
{
|
|
||||||
customer_ids: customers.map((c) => ({ id: c.id })),
|
|
||||||
},
|
|
||||||
adminHeaders
|
|
||||||
)
|
|
||||||
|
|
||||||
expect(response.status).toEqual(200)
|
|
||||||
|
|
||||||
const updatedGroup = await customerModuleService.retrieveCustomerGroup(
|
|
||||||
group.id,
|
|
||||||
{
|
|
||||||
relations: ["customers"],
|
|
||||||
}
|
|
||||||
)
|
|
||||||
expect(updatedGroup.customers?.length).toEqual(0)
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
@@ -1,13 +1,7 @@
|
|||||||
import { initDb, useDb } from "../../../../environment-helpers/use-db"
|
|
||||||
|
|
||||||
import { ICustomerModuleService } from "@medusajs/types"
|
import { ICustomerModuleService } from "@medusajs/types"
|
||||||
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||||
import adminSeeder from "../../../../helpers/admin-seeder"
|
|
||||||
import { createAdminUser } from "../../../helpers/create-admin-user"
|
import { createAdminUser } from "../../../helpers/create-admin-user"
|
||||||
import { getContainer } from "../../../../environment-helpers/use-container"
|
import { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||||
import path from "path"
|
|
||||||
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
|
|
||||||
import { useApi } from "../../../../environment-helpers/use-api"
|
|
||||||
|
|
||||||
jest.setTimeout(50000)
|
jest.setTimeout(50000)
|
||||||
|
|
||||||
@@ -16,55 +10,43 @@ const adminHeaders = {
|
|||||||
headers: { "x-medusa-access-token": "test_token" },
|
headers: { "x-medusa-access-token": "test_token" },
|
||||||
}
|
}
|
||||||
|
|
||||||
describe("POST /admin/customer-groups", () => {
|
medusaIntegrationTestRunner({
|
||||||
let dbConnection
|
env,
|
||||||
let appContainer
|
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||||
let shutdownServer
|
describe("POST /admin/customer-groups", () => {
|
||||||
let customerModuleService: ICustomerModuleService
|
let appContainer
|
||||||
|
let customerModuleService: ICustomerModuleService
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
|
appContainer = getContainer()
|
||||||
dbConnection = await initDb({ cwd, env } as any)
|
customerModuleService = appContainer.resolve(
|
||||||
shutdownServer = await startBootstrapApp({ cwd, env })
|
ModuleRegistrationName.CUSTOMER
|
||||||
appContainer = getContainer()
|
)
|
||||||
customerModuleService = appContainer.resolve(
|
|
||||||
ModuleRegistrationName.CUSTOMER
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
afterAll(async () => {
|
|
||||||
const db = useDb()
|
|
||||||
await db.shutdown()
|
|
||||||
await shutdownServer()
|
|
||||||
})
|
|
||||||
|
|
||||||
beforeEach(async () => {
|
|
||||||
await createAdminUser(dbConnection, adminHeaders)
|
|
||||||
// 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`,
|
|
||||||
{
|
|
||||||
name: "VIP",
|
|
||||||
},
|
|
||||||
adminHeaders
|
|
||||||
)
|
|
||||||
|
|
||||||
expect(response.status).toEqual(200)
|
|
||||||
expect(response.data.customer_group).toEqual(
|
|
||||||
expect.objectContaining({
|
|
||||||
id: expect.any(String),
|
|
||||||
name: "VIP",
|
|
||||||
created_by: "admin_user",
|
|
||||||
})
|
})
|
||||||
)
|
|
||||||
})
|
beforeEach(async () => {
|
||||||
|
await createAdminUser(dbConnection, adminHeaders, appContainer)
|
||||||
|
// await adminSeeder(dbConnection)
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should create a customer group", async () => {
|
||||||
|
const response = await api.post(
|
||||||
|
`/admin/customer-groups`,
|
||||||
|
{
|
||||||
|
name: "VIP",
|
||||||
|
},
|
||||||
|
adminHeaders
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(response.status).toEqual(200)
|
||||||
|
expect(response.data.customer_group).toEqual(
|
||||||
|
expect.objectContaining({
|
||||||
|
id: expect.any(String),
|
||||||
|
name: "VIP",
|
||||||
|
created_by: "admin_user",
|
||||||
|
})
|
||||||
|
)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
},
|
||||||
})
|
})
|
||||||
@@ -1,13 +1,7 @@
|
|||||||
import { initDb, useDb } from "../../../../environment-helpers/use-db"
|
|
||||||
|
|
||||||
import { ICustomerModuleService } from "@medusajs/types"
|
import { ICustomerModuleService } from "@medusajs/types"
|
||||||
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||||
import adminSeeder from "../../../../helpers/admin-seeder"
|
|
||||||
import { createAdminUser } from "../../../helpers/create-admin-user"
|
import { createAdminUser } from "../../../helpers/create-admin-user"
|
||||||
import { getContainer } from "../../../../environment-helpers/use-container"
|
import { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||||
import path from "path"
|
|
||||||
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
|
|
||||||
import { useApi } from "../../../../environment-helpers/use-api"
|
|
||||||
|
|
||||||
jest.setTimeout(50000)
|
jest.setTimeout(50000)
|
||||||
|
|
||||||
@@ -16,54 +10,42 @@ const adminHeaders = {
|
|||||||
headers: { "x-medusa-access-token": "test_token" },
|
headers: { "x-medusa-access-token": "test_token" },
|
||||||
}
|
}
|
||||||
|
|
||||||
describe("DELETE /admin/customer-groups/:id", () => {
|
medusaIntegrationTestRunner({
|
||||||
let dbConnection
|
env,
|
||||||
let appContainer
|
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||||
let shutdownServer
|
describe("DELETE /admin/customer-groups/:id", () => {
|
||||||
let customerModuleService: ICustomerModuleService
|
let appContainer
|
||||||
|
let customerModuleService: ICustomerModuleService
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
|
appContainer = getContainer()
|
||||||
dbConnection = await initDb({ cwd, env } as any)
|
customerModuleService = appContainer.resolve(
|
||||||
shutdownServer = await startBootstrapApp({ cwd, env })
|
ModuleRegistrationName.CUSTOMER
|
||||||
appContainer = getContainer()
|
)
|
||||||
customerModuleService = appContainer.resolve(
|
})
|
||||||
ModuleRegistrationName.CUSTOMER
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
afterAll(async () => {
|
beforeEach(async () => {
|
||||||
const db = useDb()
|
await createAdminUser(dbConnection, adminHeaders, appContainer)
|
||||||
await db.shutdown()
|
})
|
||||||
await shutdownServer()
|
|
||||||
})
|
|
||||||
|
|
||||||
beforeEach(async () => {
|
it("should delete a group", async () => {
|
||||||
await createAdminUser(dbConnection, adminHeaders)
|
const group = await customerModuleService.createCustomerGroup({
|
||||||
})
|
name: "VIP",
|
||||||
|
})
|
||||||
|
|
||||||
afterEach(async () => {
|
const response = await api.delete(
|
||||||
const db = useDb()
|
`/admin/customer-groups/${group.id}`,
|
||||||
await db.teardown()
|
adminHeaders
|
||||||
})
|
)
|
||||||
|
|
||||||
it("should delete a group", async () => {
|
expect(response.status).toEqual(200)
|
||||||
const group = await customerModuleService.createCustomerGroup({
|
|
||||||
name: "VIP",
|
const deletedCustomer =
|
||||||
|
await customerModuleService.retrieveCustomerGroup(group.id, {
|
||||||
|
withDeleted: true,
|
||||||
|
})
|
||||||
|
expect(deletedCustomer.deleted_at).toBeTruthy()
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
},
|
||||||
const api = useApi() as any
|
|
||||||
const response = await api.delete(
|
|
||||||
`/admin/customer-groups/${group.id}`,
|
|
||||||
adminHeaders
|
|
||||||
)
|
|
||||||
|
|
||||||
expect(response.status).toEqual(200)
|
|
||||||
|
|
||||||
const deletedCustomer = await customerModuleService.retrieveCustomerGroup(
|
|
||||||
group.id,
|
|
||||||
{ withDeleted: true }
|
|
||||||
)
|
|
||||||
expect(deletedCustomer.deleted_at).toBeTruthy()
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
+58
-74
@@ -1,13 +1,7 @@
|
|||||||
import { initDb, useDb } from "../../../../environment-helpers/use-db"
|
|
||||||
|
|
||||||
import { ICustomerModuleService } from "@medusajs/types"
|
import { ICustomerModuleService } from "@medusajs/types"
|
||||||
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||||
import adminSeeder from "../../../../helpers/admin-seeder"
|
|
||||||
import { createAdminUser } from "../../../helpers/create-admin-user"
|
import { createAdminUser } from "../../../helpers/create-admin-user"
|
||||||
import { getContainer } from "../../../../environment-helpers/use-container"
|
import { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||||
import path from "path"
|
|
||||||
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
|
|
||||||
import { useApi } from "../../../../environment-helpers/use-api"
|
|
||||||
|
|
||||||
jest.setTimeout(50000)
|
jest.setTimeout(50000)
|
||||||
|
|
||||||
@@ -16,77 +10,67 @@ const adminHeaders = {
|
|||||||
headers: { "x-medusa-access-token": "test_token" },
|
headers: { "x-medusa-access-token": "test_token" },
|
||||||
}
|
}
|
||||||
|
|
||||||
describe("GET /admin/customer-groups/:id/customers", () => {
|
medusaIntegrationTestRunner({
|
||||||
let dbConnection
|
env,
|
||||||
let appContainer
|
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||||
let shutdownServer
|
describe("GET /admin/customer-groups/:id/customers", () => {
|
||||||
let customerModuleService: ICustomerModuleService
|
let appContainer
|
||||||
|
let customerModuleService: ICustomerModuleService
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
|
appContainer = getContainer()
|
||||||
dbConnection = await initDb({ cwd, env } as any)
|
customerModuleService = appContainer.resolve(
|
||||||
shutdownServer = await startBootstrapApp({ cwd, env })
|
ModuleRegistrationName.CUSTOMER
|
||||||
appContainer = getContainer()
|
)
|
||||||
customerModuleService = appContainer.resolve(
|
})
|
||||||
ModuleRegistrationName.CUSTOMER
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
afterAll(async () => {
|
beforeEach(async () => {
|
||||||
const db = useDb()
|
await createAdminUser(dbConnection, adminHeaders, appContainer)
|
||||||
await db.shutdown()
|
})
|
||||||
await shutdownServer()
|
|
||||||
})
|
|
||||||
|
|
||||||
beforeEach(async () => {
|
it("should get all customer groups and its count", async () => {
|
||||||
await createAdminUser(dbConnection, adminHeaders)
|
const group = await customerModuleService.createCustomerGroup({
|
||||||
})
|
name: "Test",
|
||||||
|
})
|
||||||
|
|
||||||
afterEach(async () => {
|
const customers = await customerModuleService.create([
|
||||||
const db = useDb()
|
{
|
||||||
await db.teardown()
|
first_name: "Test",
|
||||||
})
|
last_name: "Test",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
first_name: "Test2",
|
||||||
|
last_name: "Test2",
|
||||||
|
},
|
||||||
|
])
|
||||||
|
|
||||||
it("should get all customer groups and its count", async () => {
|
// add to group
|
||||||
const group = await customerModuleService.createCustomerGroup({
|
|
||||||
name: "Test",
|
await customerModuleService.addCustomerToGroup(
|
||||||
|
customers.map((c) => ({
|
||||||
|
customer_id: c.id,
|
||||||
|
customer_group_id: group.id,
|
||||||
|
}))
|
||||||
|
)
|
||||||
|
|
||||||
|
const response = await api.get(
|
||||||
|
`/admin/customer-groups/${group.id}/customers`,
|
||||||
|
adminHeaders
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(response.status).toEqual(200)
|
||||||
|
expect(response.data.count).toEqual(2)
|
||||||
|
expect(response.data.customers).toEqual(
|
||||||
|
expect.arrayContaining([
|
||||||
|
expect.objectContaining({
|
||||||
|
id: customers[0].id,
|
||||||
|
}),
|
||||||
|
expect.objectContaining({
|
||||||
|
id: customers[1].id,
|
||||||
|
}),
|
||||||
|
])
|
||||||
|
)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
},
|
||||||
const customers = await customerModuleService.create([
|
|
||||||
{
|
|
||||||
first_name: "Test",
|
|
||||||
last_name: "Test",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
first_name: "Test2",
|
|
||||||
last_name: "Test2",
|
|
||||||
},
|
|
||||||
])
|
|
||||||
|
|
||||||
// add to group
|
|
||||||
|
|
||||||
await customerModuleService.addCustomerToGroup(
|
|
||||||
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
|
|
||||||
)
|
|
||||||
|
|
||||||
expect(response.status).toEqual(200)
|
|
||||||
expect(response.data.count).toEqual(2)
|
|
||||||
expect(response.data.customers).toEqual(
|
|
||||||
expect.arrayContaining([
|
|
||||||
expect.objectContaining({
|
|
||||||
id: customers[0].id,
|
|
||||||
}),
|
|
||||||
expect.objectContaining({
|
|
||||||
id: customers[1].id,
|
|
||||||
}),
|
|
||||||
])
|
|
||||||
)
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
+31
-49
@@ -1,13 +1,7 @@
|
|||||||
import { initDb, useDb } from "../../../../environment-helpers/use-db"
|
|
||||||
|
|
||||||
import { ICustomerModuleService } from "@medusajs/types"
|
import { ICustomerModuleService } from "@medusajs/types"
|
||||||
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||||
import adminSeeder from "../../../../helpers/admin-seeder"
|
|
||||||
import { createAdminUser } from "../../../helpers/create-admin-user"
|
import { createAdminUser } from "../../../helpers/create-admin-user"
|
||||||
import { getContainer } from "../../../../environment-helpers/use-container"
|
import { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||||
import path from "path"
|
|
||||||
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
|
|
||||||
import { useApi } from "../../../../environment-helpers/use-api"
|
|
||||||
|
|
||||||
jest.setTimeout(50000)
|
jest.setTimeout(50000)
|
||||||
|
|
||||||
@@ -16,52 +10,40 @@ const adminHeaders = {
|
|||||||
headers: { "x-medusa-access-token": "test_token" },
|
headers: { "x-medusa-access-token": "test_token" },
|
||||||
}
|
}
|
||||||
|
|
||||||
describe("GET /admin/customer-groups", () => {
|
medusaIntegrationTestRunner({
|
||||||
let dbConnection
|
env,
|
||||||
let appContainer
|
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||||
let shutdownServer
|
describe("GET /admin/customer-groups", () => {
|
||||||
let customerModuleService: ICustomerModuleService
|
let appContainer
|
||||||
|
let customerModuleService: ICustomerModuleService
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
|
appContainer = getContainer()
|
||||||
dbConnection = await initDb({ cwd, env } as any)
|
customerModuleService = appContainer.resolve(
|
||||||
shutdownServer = await startBootstrapApp({ cwd, env })
|
ModuleRegistrationName.CUSTOMER
|
||||||
appContainer = getContainer()
|
)
|
||||||
customerModuleService = appContainer.resolve(
|
})
|
||||||
ModuleRegistrationName.CUSTOMER
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
afterAll(async () => {
|
beforeEach(async () => {
|
||||||
const db = useDb()
|
await createAdminUser(dbConnection, adminHeaders, appContainer)
|
||||||
await db.shutdown()
|
})
|
||||||
await shutdownServer()
|
|
||||||
})
|
|
||||||
|
|
||||||
beforeEach(async () => {
|
it("should get all customer groups and its count", async () => {
|
||||||
await createAdminUser(dbConnection, adminHeaders)
|
await customerModuleService.createCustomerGroup({
|
||||||
})
|
name: "Test",
|
||||||
|
})
|
||||||
|
|
||||||
afterEach(async () => {
|
const response = await api.get(`/admin/customer-groups`, adminHeaders)
|
||||||
const db = useDb()
|
|
||||||
await db.teardown()
|
|
||||||
})
|
|
||||||
|
|
||||||
it("should get all customer groups and its count", async () => {
|
expect(response.status).toEqual(200)
|
||||||
await customerModuleService.createCustomerGroup({
|
expect(response.data.count).toEqual(1)
|
||||||
name: "Test",
|
expect(response.data.customer_groups).toEqual([
|
||||||
|
expect.objectContaining({
|
||||||
|
id: expect.any(String),
|
||||||
|
name: "Test",
|
||||||
|
}),
|
||||||
|
])
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
},
|
||||||
const api = useApi() as any
|
|
||||||
const response = await api.get(`/admin/customer-groups`, adminHeaders)
|
|
||||||
|
|
||||||
expect(response.status).toEqual(200)
|
|
||||||
expect(response.data.count).toEqual(1)
|
|
||||||
expect(response.data.customer_groups).toEqual([
|
|
||||||
expect.objectContaining({
|
|
||||||
id: expect.any(String),
|
|
||||||
name: "Test",
|
|
||||||
}),
|
|
||||||
])
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
+37
-55
@@ -1,13 +1,7 @@
|
|||||||
import { initDb, useDb } from "../../../../environment-helpers/use-db"
|
|
||||||
|
|
||||||
import { ICustomerModuleService } from "@medusajs/types"
|
import { ICustomerModuleService } from "@medusajs/types"
|
||||||
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||||
import adminSeeder from "../../../../helpers/admin-seeder"
|
|
||||||
import { createAdminUser } from "../../../helpers/create-admin-user"
|
import { createAdminUser } from "../../../helpers/create-admin-user"
|
||||||
import { getContainer } from "../../../../environment-helpers/use-container"
|
import { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||||
import path from "path"
|
|
||||||
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
|
|
||||||
import { useApi } from "../../../../environment-helpers/use-api"
|
|
||||||
|
|
||||||
jest.setTimeout(50000)
|
jest.setTimeout(50000)
|
||||||
|
|
||||||
@@ -16,54 +10,42 @@ const adminHeaders = {
|
|||||||
headers: { "x-medusa-access-token": "test_token" },
|
headers: { "x-medusa-access-token": "test_token" },
|
||||||
}
|
}
|
||||||
|
|
||||||
describe("GET /admin/customer-groups/:id", () => {
|
medusaIntegrationTestRunner({
|
||||||
let dbConnection
|
env,
|
||||||
let appContainer
|
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||||
let shutdownServer
|
describe("GET /admin/customer-groups/:id", () => {
|
||||||
let customerModuleService: ICustomerModuleService
|
let appContainer
|
||||||
|
let customerModuleService: ICustomerModuleService
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
|
appContainer = getContainer()
|
||||||
dbConnection = await initDb({ cwd, env } as any)
|
customerModuleService = appContainer.resolve(
|
||||||
shutdownServer = await startBootstrapApp({ cwd, env })
|
ModuleRegistrationName.CUSTOMER
|
||||||
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()
|
|
||||||
})
|
|
||||||
|
|
||||||
it("should retrieve customer group", async () => {
|
|
||||||
const group = await customerModuleService.createCustomerGroup({
|
|
||||||
name: "Test",
|
|
||||||
})
|
|
||||||
|
|
||||||
const api = useApi() as any
|
|
||||||
const response = await api.get(
|
|
||||||
`/admin/customer-groups/${group.id}`,
|
|
||||||
adminHeaders
|
|
||||||
)
|
|
||||||
|
|
||||||
expect(response.status).toEqual(200)
|
|
||||||
expect(response.data.customer_group).toEqual(
|
|
||||||
expect.objectContaining({
|
|
||||||
id: expect.any(String),
|
|
||||||
name: "Test",
|
|
||||||
})
|
})
|
||||||
)
|
|
||||||
})
|
beforeEach(async () => {
|
||||||
|
await createAdminUser(dbConnection, adminHeaders, appContainer)
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should retrieve customer group", async () => {
|
||||||
|
const group = await customerModuleService.createCustomerGroup({
|
||||||
|
name: "Test",
|
||||||
|
})
|
||||||
|
|
||||||
|
const response = await api.get(
|
||||||
|
`/admin/customer-groups/${group.id}`,
|
||||||
|
adminHeaders
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(response.status).toEqual(200)
|
||||||
|
expect(response.data.customer_group).toEqual(
|
||||||
|
expect.objectContaining({
|
||||||
|
id: expect.any(String),
|
||||||
|
name: "Test",
|
||||||
|
})
|
||||||
|
)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
},
|
||||||
})
|
})
|
||||||
@@ -1,13 +1,7 @@
|
|||||||
import { initDb, useDb } from "../../../../environment-helpers/use-db"
|
|
||||||
|
|
||||||
import { ICustomerModuleService } from "@medusajs/types"
|
import { ICustomerModuleService } from "@medusajs/types"
|
||||||
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||||
import adminSeeder from "../../../../helpers/admin-seeder"
|
|
||||||
import { createAdminUser } from "../../../helpers/create-admin-user"
|
import { createAdminUser } from "../../../helpers/create-admin-user"
|
||||||
import { getContainer } from "../../../../environment-helpers/use-container"
|
import { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||||
import path from "path"
|
|
||||||
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
|
|
||||||
import { useApi } from "../../../../environment-helpers/use-api"
|
|
||||||
|
|
||||||
jest.setTimeout(50000)
|
jest.setTimeout(50000)
|
||||||
|
|
||||||
@@ -16,57 +10,45 @@ const adminHeaders = {
|
|||||||
headers: { "x-medusa-access-token": "test_token" },
|
headers: { "x-medusa-access-token": "test_token" },
|
||||||
}
|
}
|
||||||
|
|
||||||
describe("POST /admin/customer-groups/:id", () => {
|
medusaIntegrationTestRunner({
|
||||||
let dbConnection
|
env,
|
||||||
let appContainer
|
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||||
let shutdownServer
|
describe("POST /admin/customer-groups/:id", () => {
|
||||||
let customerModuleService: ICustomerModuleService
|
let appContainer
|
||||||
|
let customerModuleService: ICustomerModuleService
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
|
appContainer = getContainer()
|
||||||
dbConnection = await initDb({ cwd, env } as any)
|
customerModuleService = appContainer.resolve(
|
||||||
shutdownServer = await startBootstrapApp({ cwd, env })
|
ModuleRegistrationName.CUSTOMER
|
||||||
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()
|
|
||||||
})
|
|
||||||
|
|
||||||
it("should update a customer group", async () => {
|
|
||||||
const customer = await customerModuleService.createCustomerGroup({
|
|
||||||
name: "VIP",
|
|
||||||
})
|
|
||||||
|
|
||||||
const api = useApi() as any
|
|
||||||
const response = await api.post(
|
|
||||||
`/admin/customer-groups/${customer.id}`,
|
|
||||||
{
|
|
||||||
name: "regular",
|
|
||||||
},
|
|
||||||
adminHeaders
|
|
||||||
)
|
|
||||||
|
|
||||||
expect(response.status).toEqual(200)
|
|
||||||
expect(response.data.customer_group).toEqual(
|
|
||||||
expect.objectContaining({
|
|
||||||
id: expect.any(String),
|
|
||||||
name: "regular",
|
|
||||||
})
|
})
|
||||||
)
|
|
||||||
})
|
beforeEach(async () => {
|
||||||
|
await createAdminUser(dbConnection, adminHeaders, appContainer)
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should update a customer group", async () => {
|
||||||
|
const customer = await customerModuleService.createCustomerGroup({
|
||||||
|
name: "VIP",
|
||||||
|
})
|
||||||
|
|
||||||
|
const response = await api.post(
|
||||||
|
`/admin/customer-groups/${customer.id}`,
|
||||||
|
{
|
||||||
|
name: "regular",
|
||||||
|
},
|
||||||
|
adminHeaders
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(response.status).toEqual(200)
|
||||||
|
expect(response.data.customer_group).toEqual(
|
||||||
|
expect.objectContaining({
|
||||||
|
id: expect.any(String),
|
||||||
|
name: "regular",
|
||||||
|
})
|
||||||
|
)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
},
|
||||||
})
|
})
|
||||||
@@ -1,13 +1,7 @@
|
|||||||
import { initDb, useDb } from "../../../../environment-helpers/use-db"
|
|
||||||
|
|
||||||
import { ICustomerModuleService } from "@medusajs/types"
|
import { ICustomerModuleService } from "@medusajs/types"
|
||||||
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||||
import adminSeeder from "../../../../helpers/admin-seeder"
|
|
||||||
import { createAdminUser } from "../../../helpers/create-admin-user"
|
import { createAdminUser } from "../../../helpers/create-admin-user"
|
||||||
import { getContainer } from "../../../../environment-helpers/use-container"
|
import { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||||
import path from "path"
|
|
||||||
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
|
|
||||||
import { useApi } from "../../../../environment-helpers/use-api"
|
|
||||||
|
|
||||||
jest.setTimeout(50000)
|
jest.setTimeout(50000)
|
||||||
|
|
||||||
@@ -16,142 +10,127 @@ const adminHeaders = {
|
|||||||
headers: { "x-medusa-access-token": "test_token" },
|
headers: { "x-medusa-access-token": "test_token" },
|
||||||
}
|
}
|
||||||
|
|
||||||
describe("POST /admin/customers/:id/addresses", () => {
|
medusaIntegrationTestRunner({
|
||||||
let dbConnection
|
env,
|
||||||
let appContainer
|
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||||
let shutdownServer
|
describe("POST /admin/customers/:id/addresses", () => {
|
||||||
let customerModuleService: ICustomerModuleService
|
let appContainer
|
||||||
|
let customerModuleService: ICustomerModuleService
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
|
appContainer = getContainer()
|
||||||
dbConnection = await initDb({ cwd, env } as any)
|
customerModuleService = appContainer.resolve(
|
||||||
shutdownServer = await startBootstrapApp({ cwd, env })
|
ModuleRegistrationName.CUSTOMER
|
||||||
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()
|
|
||||||
})
|
|
||||||
|
|
||||||
it("should create a customer address", async () => {
|
|
||||||
// Create a customer
|
|
||||||
const customer = await customerModuleService.create({
|
|
||||||
first_name: "John",
|
|
||||||
last_name: "Doe",
|
|
||||||
})
|
|
||||||
|
|
||||||
const api = useApi() as any
|
|
||||||
const response = await api.post(
|
|
||||||
`/admin/customers/${customer.id}/addresses`,
|
|
||||||
{
|
|
||||||
first_name: "John",
|
|
||||||
last_name: "Doe",
|
|
||||||
address_1: "Test street 1",
|
|
||||||
},
|
|
||||||
adminHeaders
|
|
||||||
)
|
|
||||||
|
|
||||||
expect(response.status).toEqual(200)
|
|
||||||
expect(response.data.address).toEqual(
|
|
||||||
expect.objectContaining({
|
|
||||||
id: expect.any(String),
|
|
||||||
first_name: "John",
|
|
||||||
last_name: "Doe",
|
|
||||||
address_1: "Test street 1",
|
|
||||||
})
|
})
|
||||||
)
|
|
||||||
|
|
||||||
const customerWithAddresses = await customerModuleService.retrieve(
|
beforeEach(async () => {
|
||||||
customer.id,
|
await createAdminUser(dbConnection, adminHeaders, appContainer)
|
||||||
{ relations: ["addresses"] }
|
})
|
||||||
)
|
it("should create a customer address", async () => {
|
||||||
|
// Create a customer
|
||||||
expect(customerWithAddresses.addresses?.length).toEqual(1)
|
const customer = await customerModuleService.create({
|
||||||
})
|
|
||||||
|
|
||||||
it("sets new shipping address as default and unsets the old one", async () => {
|
|
||||||
const customer = await customerModuleService.create({
|
|
||||||
first_name: "John",
|
|
||||||
last_name: "Doe",
|
|
||||||
addresses: [
|
|
||||||
{
|
|
||||||
first_name: "John",
|
first_name: "John",
|
||||||
last_name: "Doe",
|
last_name: "Doe",
|
||||||
address_1: "Test street 1",
|
})
|
||||||
|
|
||||||
|
const response = await api.post(
|
||||||
|
`/admin/customers/${customer.id}/addresses`,
|
||||||
|
{
|
||||||
|
first_name: "John",
|
||||||
|
last_name: "Doe",
|
||||||
|
address_1: "Test street 1",
|
||||||
|
},
|
||||||
|
adminHeaders
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(response.status).toEqual(200)
|
||||||
|
expect(response.data.address).toEqual(
|
||||||
|
expect.objectContaining({
|
||||||
|
id: expect.any(String),
|
||||||
|
first_name: "John",
|
||||||
|
last_name: "Doe",
|
||||||
|
address_1: "Test street 1",
|
||||||
|
})
|
||||||
|
)
|
||||||
|
|
||||||
|
const customerWithAddresses = await customerModuleService.retrieve(
|
||||||
|
customer.id,
|
||||||
|
{ relations: ["addresses"] }
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(customerWithAddresses.addresses?.length).toEqual(1)
|
||||||
|
})
|
||||||
|
|
||||||
|
it("sets new shipping address as default and unsets the old one", async () => {
|
||||||
|
const customer = await customerModuleService.create({
|
||||||
|
first_name: "John",
|
||||||
|
last_name: "Doe",
|
||||||
|
addresses: [
|
||||||
|
{
|
||||||
|
first_name: "John",
|
||||||
|
last_name: "Doe",
|
||||||
|
address_1: "Test street 1",
|
||||||
|
is_default_shipping: true,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
})
|
||||||
|
|
||||||
|
const response = await api.post(
|
||||||
|
`/admin/customers/${customer.id}/addresses`,
|
||||||
|
{
|
||||||
|
first_name: "John",
|
||||||
|
last_name: "Doe",
|
||||||
|
address_1: "Test street 2",
|
||||||
|
is_default_shipping: true,
|
||||||
|
},
|
||||||
|
adminHeaders
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(response.status).toEqual(200)
|
||||||
|
|
||||||
|
const [address] = await customerModuleService.listAddresses({
|
||||||
|
customer_id: customer.id,
|
||||||
is_default_shipping: true,
|
is_default_shipping: true,
|
||||||
},
|
})
|
||||||
],
|
|
||||||
})
|
|
||||||
|
|
||||||
const api = useApi() as any
|
expect(address.address_1).toEqual("Test street 2")
|
||||||
const response = await api.post(
|
})
|
||||||
`/admin/customers/${customer.id}/addresses`,
|
|
||||||
{
|
|
||||||
first_name: "John",
|
|
||||||
last_name: "Doe",
|
|
||||||
address_1: "Test street 2",
|
|
||||||
is_default_shipping: true,
|
|
||||||
},
|
|
||||||
adminHeaders
|
|
||||||
)
|
|
||||||
|
|
||||||
expect(response.status).toEqual(200)
|
it("sets new billing address as default and unsets the old one", async () => {
|
||||||
|
const customer = await customerModuleService.create({
|
||||||
const [address] = await customerModuleService.listAddresses({
|
|
||||||
customer_id: customer.id,
|
|
||||||
is_default_shipping: true,
|
|
||||||
})
|
|
||||||
|
|
||||||
expect(address.address_1).toEqual("Test street 2")
|
|
||||||
})
|
|
||||||
|
|
||||||
it("sets new billing address as default and unsets the old one", async () => {
|
|
||||||
const customer = await customerModuleService.create({
|
|
||||||
first_name: "John",
|
|
||||||
last_name: "Doe",
|
|
||||||
addresses: [
|
|
||||||
{
|
|
||||||
first_name: "John",
|
first_name: "John",
|
||||||
last_name: "Doe",
|
last_name: "Doe",
|
||||||
address_1: "Test street 1",
|
addresses: [
|
||||||
|
{
|
||||||
|
first_name: "John",
|
||||||
|
last_name: "Doe",
|
||||||
|
address_1: "Test street 1",
|
||||||
|
is_default_billing: true,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
})
|
||||||
|
|
||||||
|
const response = await api.post(
|
||||||
|
`/admin/customers/${customer.id}/addresses`,
|
||||||
|
{
|
||||||
|
first_name: "John",
|
||||||
|
last_name: "Doe",
|
||||||
|
address_1: "Test street 2",
|
||||||
|
is_default_billing: true,
|
||||||
|
},
|
||||||
|
adminHeaders
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(response.status).toEqual(200)
|
||||||
|
|
||||||
|
const [address] = await customerModuleService.listAddresses({
|
||||||
|
customer_id: customer.id,
|
||||||
is_default_billing: true,
|
is_default_billing: true,
|
||||||
},
|
})
|
||||||
],
|
|
||||||
|
expect(address.address_1).toEqual("Test street 2")
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
},
|
||||||
const api = useApi() as any
|
|
||||||
const response = await api.post(
|
|
||||||
`/admin/customers/${customer.id}/addresses`,
|
|
||||||
{
|
|
||||||
first_name: "John",
|
|
||||||
last_name: "Doe",
|
|
||||||
address_1: "Test street 2",
|
|
||||||
is_default_billing: true,
|
|
||||||
},
|
|
||||||
adminHeaders
|
|
||||||
)
|
|
||||||
|
|
||||||
expect(response.status).toEqual(200)
|
|
||||||
|
|
||||||
const [address] = await customerModuleService.listAddresses({
|
|
||||||
customer_id: customer.id,
|
|
||||||
is_default_billing: true,
|
|
||||||
})
|
|
||||||
|
|
||||||
expect(address.address_1).toEqual("Test street 2")
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
@@ -1,13 +1,7 @@
|
|||||||
import { initDb, useDb } from "../../../../environment-helpers/use-db"
|
|
||||||
|
|
||||||
import { ICustomerModuleService } from "@medusajs/types"
|
import { ICustomerModuleService } from "@medusajs/types"
|
||||||
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||||
import adminSeeder from "../../../../helpers/admin-seeder"
|
|
||||||
import { createAdminUser } from "../../../helpers/create-admin-user"
|
import { createAdminUser } from "../../../helpers/create-admin-user"
|
||||||
import { getContainer } from "../../../../environment-helpers/use-container"
|
import { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||||
import path from "path"
|
|
||||||
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
|
|
||||||
import { useApi } from "../../../../environment-helpers/use-api"
|
|
||||||
|
|
||||||
jest.setTimeout(50000)
|
jest.setTimeout(50000)
|
||||||
|
|
||||||
@@ -16,56 +10,44 @@ const adminHeaders = {
|
|||||||
headers: { "x-medusa-access-token": "test_token" },
|
headers: { "x-medusa-access-token": "test_token" },
|
||||||
}
|
}
|
||||||
|
|
||||||
describe("POST /admin/customers", () => {
|
medusaIntegrationTestRunner({
|
||||||
let dbConnection
|
env,
|
||||||
let appContainer
|
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||||
let shutdownServer
|
describe("POST /admin/customers", () => {
|
||||||
let customerModuleService: ICustomerModuleService
|
let appContainer
|
||||||
|
let customerModuleService: ICustomerModuleService
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
|
appContainer = getContainer()
|
||||||
dbConnection = await initDb({ cwd, env } as any)
|
customerModuleService = appContainer.resolve(
|
||||||
shutdownServer = await startBootstrapApp({ cwd, env })
|
ModuleRegistrationName.CUSTOMER
|
||||||
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()
|
|
||||||
})
|
|
||||||
|
|
||||||
it("should create a customer", async () => {
|
|
||||||
const api = useApi() as any
|
|
||||||
const response = await api.post(
|
|
||||||
`/admin/customers`,
|
|
||||||
{
|
|
||||||
first_name: "John",
|
|
||||||
last_name: "Doe",
|
|
||||||
},
|
|
||||||
adminHeaders
|
|
||||||
)
|
|
||||||
|
|
||||||
expect(response.status).toEqual(200)
|
|
||||||
expect(response.data.customer).toEqual(
|
|
||||||
expect.objectContaining({
|
|
||||||
id: expect.any(String),
|
|
||||||
first_name: "John",
|
|
||||||
last_name: "Doe",
|
|
||||||
created_by: "admin_user",
|
|
||||||
})
|
})
|
||||||
)
|
|
||||||
})
|
beforeEach(async () => {
|
||||||
|
await createAdminUser(dbConnection, adminHeaders, appContainer)
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should create a customer", async () => {
|
||||||
|
const response = await api.post(
|
||||||
|
`/admin/customers`,
|
||||||
|
{
|
||||||
|
first_name: "John",
|
||||||
|
last_name: "Doe",
|
||||||
|
},
|
||||||
|
adminHeaders
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(response.status).toEqual(200)
|
||||||
|
expect(response.data.customer).toEqual(
|
||||||
|
expect.objectContaining({
|
||||||
|
id: expect.any(String),
|
||||||
|
first_name: "John",
|
||||||
|
last_name: "Doe",
|
||||||
|
created_by: "admin_user",
|
||||||
|
})
|
||||||
|
)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
},
|
||||||
})
|
})
|
||||||
+44
-59
@@ -1,13 +1,7 @@
|
|||||||
import { initDb, useDb } from "../../../../environment-helpers/use-db"
|
|
||||||
|
|
||||||
import { ICustomerModuleService } from "@medusajs/types"
|
import { ICustomerModuleService } from "@medusajs/types"
|
||||||
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||||
import adminSeeder from "../../../../helpers/admin-seeder"
|
|
||||||
import { createAdminUser } from "../../../helpers/create-admin-user"
|
import { createAdminUser } from "../../../helpers/create-admin-user"
|
||||||
import { getContainer } from "../../../../environment-helpers/use-container"
|
import { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||||
import path from "path"
|
|
||||||
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
|
|
||||||
import { useApi } from "../../../../environment-helpers/use-api"
|
|
||||||
|
|
||||||
jest.setTimeout(50000)
|
jest.setTimeout(50000)
|
||||||
|
|
||||||
@@ -16,62 +10,53 @@ const adminHeaders = {
|
|||||||
headers: { "x-medusa-access-token": "test_token" },
|
headers: { "x-medusa-access-token": "test_token" },
|
||||||
}
|
}
|
||||||
|
|
||||||
describe("DELETE /admin/customers/:id/addresses/:address_id", () => {
|
medusaIntegrationTestRunner({
|
||||||
let dbConnection
|
env,
|
||||||
let appContainer
|
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||||
let shutdownServer
|
describe("DELETE /admin/customers/:id/addresses/:address_id", () => {
|
||||||
let customerModuleService: ICustomerModuleService
|
let appContainer
|
||||||
|
let customerModuleService: ICustomerModuleService
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
|
appContainer = getContainer()
|
||||||
dbConnection = await initDb({ cwd, env } as any)
|
customerModuleService = appContainer.resolve(
|
||||||
shutdownServer = await startBootstrapApp({ cwd, env })
|
ModuleRegistrationName.CUSTOMER
|
||||||
appContainer = getContainer()
|
)
|
||||||
customerModuleService = appContainer.resolve(
|
})
|
||||||
ModuleRegistrationName.CUSTOMER
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
afterAll(async () => {
|
beforeEach(async () => {
|
||||||
const db = useDb()
|
await createAdminUser(dbConnection, adminHeaders, appContainer)
|
||||||
await db.shutdown()
|
})
|
||||||
await shutdownServer()
|
|
||||||
})
|
|
||||||
|
|
||||||
beforeEach(async () => {
|
it("should update a customer address", async () => {
|
||||||
await createAdminUser(dbConnection, adminHeaders)
|
const customer = await customerModuleService.create({
|
||||||
})
|
first_name: "John",
|
||||||
|
last_name: "Doe",
|
||||||
|
})
|
||||||
|
|
||||||
afterEach(async () => {
|
const address = await customerModuleService.addAddresses({
|
||||||
const db = useDb()
|
customer_id: customer.id,
|
||||||
await db.teardown()
|
first_name: "John",
|
||||||
})
|
last_name: "Doe",
|
||||||
|
address_1: "Test street 1",
|
||||||
|
})
|
||||||
|
|
||||||
it("should update a customer address", async () => {
|
const response = await api.delete(
|
||||||
const customer = await customerModuleService.create({
|
`/admin/customers/${customer.id}/addresses/${address.id}`,
|
||||||
first_name: "John",
|
adminHeaders
|
||||||
last_name: "Doe",
|
)
|
||||||
|
|
||||||
|
expect(response.status).toEqual(200)
|
||||||
|
|
||||||
|
const updatedCustomer = await customerModuleService.retrieve(
|
||||||
|
customer.id,
|
||||||
|
{
|
||||||
|
relations: ["addresses"],
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(updatedCustomer.addresses?.length).toEqual(0)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
},
|
||||||
const address = await customerModuleService.addAddresses({
|
|
||||||
customer_id: customer.id,
|
|
||||||
first_name: "John",
|
|
||||||
last_name: "Doe",
|
|
||||||
address_1: "Test street 1",
|
|
||||||
})
|
|
||||||
|
|
||||||
const api = useApi() as any
|
|
||||||
const response = await api.delete(
|
|
||||||
`/admin/customers/${customer.id}/addresses/${address.id}`,
|
|
||||||
adminHeaders
|
|
||||||
)
|
|
||||||
|
|
||||||
expect(response.status).toEqual(200)
|
|
||||||
|
|
||||||
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 { ICustomerModuleService } from "@medusajs/types"
|
||||||
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||||
import adminSeeder from "../../../../helpers/admin-seeder"
|
|
||||||
import { createAdminUser } from "../../../helpers/create-admin-user"
|
import { createAdminUser } from "../../../helpers/create-admin-user"
|
||||||
import { getContainer } from "../../../../environment-helpers/use-container"
|
import { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||||
import path from "path"
|
|
||||||
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
|
|
||||||
import { useApi } from "../../../../environment-helpers/use-api"
|
|
||||||
|
|
||||||
jest.setTimeout(50000)
|
jest.setTimeout(50000)
|
||||||
|
|
||||||
@@ -16,54 +10,45 @@ const adminHeaders = {
|
|||||||
headers: { "x-medusa-access-token": "test_token" },
|
headers: { "x-medusa-access-token": "test_token" },
|
||||||
}
|
}
|
||||||
|
|
||||||
describe("DELETE /admin/customers/:id", () => {
|
medusaIntegrationTestRunner({
|
||||||
let dbConnection
|
env,
|
||||||
let appContainer
|
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||||
let shutdownServer
|
describe("DELETE /admin/customers/:id", () => {
|
||||||
let customerModuleService: ICustomerModuleService
|
let appContainer
|
||||||
|
let customerModuleService: ICustomerModuleService
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
|
appContainer = getContainer()
|
||||||
dbConnection = await initDb({ cwd, env } as any)
|
customerModuleService = appContainer.resolve(
|
||||||
shutdownServer = await startBootstrapApp({ cwd, env })
|
ModuleRegistrationName.CUSTOMER
|
||||||
appContainer = getContainer()
|
)
|
||||||
customerModuleService = appContainer.resolve(
|
})
|
||||||
ModuleRegistrationName.CUSTOMER
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
afterAll(async () => {
|
beforeEach(async () => {
|
||||||
const db = useDb()
|
await createAdminUser(dbConnection, adminHeaders, appContainer)
|
||||||
await db.shutdown()
|
})
|
||||||
await shutdownServer()
|
|
||||||
})
|
|
||||||
|
|
||||||
beforeEach(async () => {
|
it("should delete a customer", async () => {
|
||||||
await createAdminUser(dbConnection, adminHeaders)
|
const customer = await customerModuleService.create({
|
||||||
})
|
first_name: "John",
|
||||||
|
last_name: "Doe",
|
||||||
|
})
|
||||||
|
|
||||||
afterEach(async () => {
|
const response = await api.delete(
|
||||||
const db = useDb()
|
`/admin/customers/${customer.id}`,
|
||||||
await db.teardown()
|
adminHeaders
|
||||||
})
|
)
|
||||||
|
|
||||||
it("should delete a customer", async () => {
|
expect(response.status).toEqual(200)
|
||||||
const customer = await customerModuleService.create({
|
|
||||||
first_name: "John",
|
const deletedCustomer = await customerModuleService.retrieve(
|
||||||
last_name: "Doe",
|
customer.id,
|
||||||
|
{
|
||||||
|
withDeleted: true,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
expect(deletedCustomer.deleted_at).toBeTruthy()
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
},
|
||||||
const api = useApi() as any
|
|
||||||
const response = await api.delete(
|
|
||||||
`/admin/customers/${customer.id}`,
|
|
||||||
adminHeaders
|
|
||||||
)
|
|
||||||
|
|
||||||
expect(response.status).toEqual(200)
|
|
||||||
|
|
||||||
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 { ICustomerModuleService } from "@medusajs/types"
|
||||||
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||||
import adminSeeder from "../../../../helpers/admin-seeder"
|
|
||||||
import { createAdminUser } from "../../../helpers/create-admin-user"
|
import { createAdminUser } from "../../../helpers/create-admin-user"
|
||||||
import { getContainer } from "../../../../environment-helpers/use-container"
|
import { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||||
import path from "path"
|
|
||||||
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
|
|
||||||
import { useApi } from "../../../../environment-helpers/use-api"
|
|
||||||
|
|
||||||
jest.setTimeout(50000)
|
jest.setTimeout(50000)
|
||||||
|
|
||||||
@@ -16,100 +10,88 @@ const adminHeaders = {
|
|||||||
headers: { "x-medusa-access-token": "test_token" },
|
headers: { "x-medusa-access-token": "test_token" },
|
||||||
}
|
}
|
||||||
|
|
||||||
describe("GET /admin/customers/:id/addresses", () => {
|
medusaIntegrationTestRunner({
|
||||||
let dbConnection
|
env,
|
||||||
let appContainer
|
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||||
let shutdownServer
|
describe("GET /admin/customers/:id/addresses", () => {
|
||||||
let customerModuleService: ICustomerModuleService
|
let appContainer
|
||||||
|
let customerModuleService: ICustomerModuleService
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
|
appContainer = getContainer()
|
||||||
dbConnection = await initDb({ cwd, env } as any)
|
customerModuleService = appContainer.resolve(
|
||||||
shutdownServer = await startBootstrapApp({ cwd, env })
|
ModuleRegistrationName.CUSTOMER
|
||||||
appContainer = getContainer()
|
)
|
||||||
customerModuleService = appContainer.resolve(
|
})
|
||||||
ModuleRegistrationName.CUSTOMER
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
afterAll(async () => {
|
beforeEach(async () => {
|
||||||
const db = useDb()
|
await createAdminUser(dbConnection, adminHeaders, appContainer)
|
||||||
await db.shutdown()
|
})
|
||||||
await shutdownServer()
|
|
||||||
})
|
|
||||||
|
|
||||||
beforeEach(async () => {
|
it("should get all customer addresses and its count", async () => {
|
||||||
await createAdminUser(dbConnection, adminHeaders)
|
const [customer] = await customerModuleService.create([
|
||||||
})
|
|
||||||
|
|
||||||
afterEach(async () => {
|
|
||||||
const db = useDb()
|
|
||||||
await db.teardown()
|
|
||||||
})
|
|
||||||
|
|
||||||
it("should get all customer addresses and its count", async () => {
|
|
||||||
const [customer] = await customerModuleService.create([
|
|
||||||
{
|
|
||||||
first_name: "Test",
|
|
||||||
last_name: "Test",
|
|
||||||
email: "test@me.com",
|
|
||||||
addresses: [
|
|
||||||
{
|
{
|
||||||
first_name: "Test",
|
first_name: "Test",
|
||||||
last_name: "Test",
|
last_name: "Test",
|
||||||
address_1: "Test street 1",
|
email: "test@me.com",
|
||||||
|
addresses: [
|
||||||
|
{
|
||||||
|
first_name: "Test",
|
||||||
|
last_name: "Test",
|
||||||
|
address_1: "Test street 1",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
first_name: "Test",
|
||||||
|
last_name: "Test",
|
||||||
|
address_1: "Test street 2",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
first_name: "Test",
|
||||||
|
last_name: "Test",
|
||||||
|
address_1: "Test street 3",
|
||||||
|
},
|
||||||
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
first_name: "Test",
|
first_name: "Test Test",
|
||||||
last_name: "Test",
|
last_name: "Test Test",
|
||||||
address_1: "Test street 2",
|
addresses: [
|
||||||
|
{
|
||||||
|
first_name: "Test TEST",
|
||||||
|
last_name: "Test TEST",
|
||||||
|
address_1: "NOT street 1",
|
||||||
|
},
|
||||||
|
],
|
||||||
},
|
},
|
||||||
{
|
])
|
||||||
first_name: "Test",
|
|
||||||
last_name: "Test",
|
|
||||||
address_1: "Test street 3",
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
first_name: "Test Test",
|
|
||||||
last_name: "Test Test",
|
|
||||||
addresses: [
|
|
||||||
{
|
|
||||||
first_name: "Test TEST",
|
|
||||||
last_name: "Test TEST",
|
|
||||||
address_1: "NOT street 1",
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
])
|
|
||||||
|
|
||||||
const api = useApi() as any
|
const response = await api.get(
|
||||||
const response = await api.get(
|
`/admin/customers/${customer.id}/addresses`,
|
||||||
`/admin/customers/${customer.id}/addresses`,
|
adminHeaders
|
||||||
adminHeaders
|
)
|
||||||
)
|
|
||||||
|
|
||||||
expect(response.status).toEqual(200)
|
expect(response.status).toEqual(200)
|
||||||
expect(response.data.count).toEqual(3)
|
expect(response.data.count).toEqual(3)
|
||||||
expect(response.data.addresses).toEqual(
|
expect(response.data.addresses).toEqual(
|
||||||
expect.arrayContaining([
|
expect.arrayContaining([
|
||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
id: expect.any(String),
|
id: expect.any(String),
|
||||||
customer_id: customer.id,
|
customer_id: customer.id,
|
||||||
address_1: "Test street 1",
|
address_1: "Test street 1",
|
||||||
}),
|
}),
|
||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
id: expect.any(String),
|
id: expect.any(String),
|
||||||
customer_id: customer.id,
|
customer_id: customer.id,
|
||||||
address_1: "Test street 2",
|
address_1: "Test street 2",
|
||||||
}),
|
}),
|
||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
id: expect.any(String),
|
id: expect.any(String),
|
||||||
customer_id: customer.id,
|
customer_id: customer.id,
|
||||||
address_1: "Test street 3",
|
address_1: "Test street 3",
|
||||||
}),
|
}),
|
||||||
])
|
])
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
})
|
||||||
|
},
|
||||||
})
|
})
|
||||||
@@ -1,13 +1,7 @@
|
|||||||
import { initDb, useDb } from "../../../../environment-helpers/use-db"
|
|
||||||
|
|
||||||
import { ICustomerModuleService } from "@medusajs/types"
|
import { ICustomerModuleService } from "@medusajs/types"
|
||||||
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||||
import adminSeeder from "../../../../helpers/admin-seeder"
|
|
||||||
import { createAdminUser } from "../../../helpers/create-admin-user"
|
import { createAdminUser } from "../../../helpers/create-admin-user"
|
||||||
import { getContainer } from "../../../../environment-helpers/use-container"
|
import { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||||
import path from "path"
|
|
||||||
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
|
|
||||||
import { useApi } from "../../../../environment-helpers/use-api"
|
|
||||||
|
|
||||||
jest.setTimeout(50000)
|
jest.setTimeout(50000)
|
||||||
|
|
||||||
@@ -16,108 +10,96 @@ const adminHeaders = {
|
|||||||
headers: { "x-medusa-access-token": "test_token" },
|
headers: { "x-medusa-access-token": "test_token" },
|
||||||
}
|
}
|
||||||
|
|
||||||
describe("GET /admin/customers", () => {
|
medusaIntegrationTestRunner({
|
||||||
let dbConnection
|
env,
|
||||||
let appContainer
|
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||||
let shutdownServer
|
describe("GET /admin/customers", () => {
|
||||||
let customerModuleService: ICustomerModuleService
|
let appContainer
|
||||||
|
let shutdownServer
|
||||||
|
let customerModuleService: ICustomerModuleService
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
|
appContainer = getContainer()
|
||||||
dbConnection = await initDb({ cwd, env } as any)
|
customerModuleService = appContainer.resolve(
|
||||||
shutdownServer = await startBootstrapApp({ cwd, env })
|
ModuleRegistrationName.CUSTOMER
|
||||||
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()
|
|
||||||
})
|
|
||||||
|
|
||||||
it("should get all customers and its count", async () => {
|
|
||||||
await customerModuleService.create([
|
|
||||||
{
|
|
||||||
first_name: "Test",
|
|
||||||
last_name: "Test",
|
|
||||||
email: "test@me.com",
|
|
||||||
},
|
|
||||||
])
|
|
||||||
|
|
||||||
const api = useApi() as any
|
|
||||||
const response = await api.get(`/admin/customers`, adminHeaders)
|
|
||||||
|
|
||||||
expect(response.status).toEqual(200)
|
|
||||||
expect(response.data.count).toEqual(1)
|
|
||||||
expect(response.data.customers).toEqual([
|
|
||||||
expect.objectContaining({
|
|
||||||
id: expect.any(String),
|
|
||||||
first_name: "Test",
|
|
||||||
last_name: "Test",
|
|
||||||
email: "test@me.com",
|
|
||||||
}),
|
|
||||||
])
|
|
||||||
})
|
|
||||||
|
|
||||||
it("should filter customers by last name", async () => {
|
|
||||||
await customerModuleService.create([
|
|
||||||
{
|
|
||||||
first_name: "Jane",
|
|
||||||
last_name: "Doe",
|
|
||||||
email: "jane@me.com",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
first_name: "John",
|
|
||||||
last_name: "Doe",
|
|
||||||
email: "john@me.com",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
first_name: "LeBron",
|
|
||||||
last_name: "James",
|
|
||||||
email: "lebron@me.com",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
first_name: "John",
|
|
||||||
last_name: "Silver",
|
|
||||||
email: "johns@me.com",
|
|
||||||
},
|
|
||||||
])
|
|
||||||
|
|
||||||
const api = useApi() as any
|
|
||||||
const response = await api.get(
|
|
||||||
`/admin/customers?last_name=Doe`,
|
|
||||||
adminHeaders
|
|
||||||
)
|
|
||||||
|
|
||||||
expect(response.status).toEqual(200)
|
|
||||||
expect(response.data.count).toEqual(2)
|
|
||||||
expect(response.data.customers).toContainEqual(
|
|
||||||
expect.objectContaining({
|
|
||||||
id: expect.any(String),
|
|
||||||
first_name: "Jane",
|
|
||||||
last_name: "Doe",
|
|
||||||
email: "jane@me.com",
|
|
||||||
})
|
})
|
||||||
)
|
|
||||||
expect(response.data.customers).toContainEqual(
|
beforeEach(async () => {
|
||||||
expect.objectContaining({
|
await createAdminUser(dbConnection, adminHeaders, appContainer)
|
||||||
id: expect.any(String),
|
|
||||||
first_name: "John",
|
|
||||||
last_name: "Doe",
|
|
||||||
email: "john@me.com",
|
|
||||||
})
|
})
|
||||||
)
|
|
||||||
})
|
it("should get all customers and its count", async () => {
|
||||||
|
await customerModuleService.create([
|
||||||
|
{
|
||||||
|
first_name: "Test",
|
||||||
|
last_name: "Test",
|
||||||
|
email: "test@me.com",
|
||||||
|
},
|
||||||
|
])
|
||||||
|
|
||||||
|
const response = await api.get(`/admin/customers`, adminHeaders)
|
||||||
|
|
||||||
|
expect(response.status).toEqual(200)
|
||||||
|
expect(response.data.count).toEqual(1)
|
||||||
|
expect(response.data.customers).toEqual([
|
||||||
|
expect.objectContaining({
|
||||||
|
id: expect.any(String),
|
||||||
|
first_name: "Test",
|
||||||
|
last_name: "Test",
|
||||||
|
email: "test@me.com",
|
||||||
|
}),
|
||||||
|
])
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should filter customers by last name", async () => {
|
||||||
|
await customerModuleService.create([
|
||||||
|
{
|
||||||
|
first_name: "Jane",
|
||||||
|
last_name: "Doe",
|
||||||
|
email: "jane@me.com",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
first_name: "John",
|
||||||
|
last_name: "Doe",
|
||||||
|
email: "john@me.com",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
first_name: "LeBron",
|
||||||
|
last_name: "James",
|
||||||
|
email: "lebron@me.com",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
first_name: "John",
|
||||||
|
last_name: "Silver",
|
||||||
|
email: "johns@me.com",
|
||||||
|
},
|
||||||
|
])
|
||||||
|
|
||||||
|
const response = await api.get(
|
||||||
|
`/admin/customers?last_name=Doe`,
|
||||||
|
adminHeaders
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(response.status).toEqual(200)
|
||||||
|
expect(response.data.count).toEqual(2)
|
||||||
|
expect(response.data.customers).toContainEqual(
|
||||||
|
expect.objectContaining({
|
||||||
|
id: expect.any(String),
|
||||||
|
first_name: "Jane",
|
||||||
|
last_name: "Doe",
|
||||||
|
email: "jane@me.com",
|
||||||
|
})
|
||||||
|
)
|
||||||
|
expect(response.data.customers).toContainEqual(
|
||||||
|
expect.objectContaining({
|
||||||
|
id: expect.any(String),
|
||||||
|
first_name: "John",
|
||||||
|
last_name: "Doe",
|
||||||
|
email: "john@me.com",
|
||||||
|
})
|
||||||
|
)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
},
|
||||||
})
|
})
|
||||||
+130
-150
@@ -1,13 +1,7 @@
|
|||||||
import { initDb, useDb } from "../../../../environment-helpers/use-db"
|
|
||||||
|
|
||||||
import { ICustomerModuleService } from "@medusajs/types"
|
import { ICustomerModuleService } from "@medusajs/types"
|
||||||
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||||
import adminSeeder from "../../../../helpers/admin-seeder"
|
|
||||||
import { createAdminUser } from "../../../helpers/create-admin-user"
|
import { createAdminUser } from "../../../helpers/create-admin-user"
|
||||||
import { getContainer } from "../../../../environment-helpers/use-container"
|
import { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||||
import path from "path"
|
|
||||||
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
|
|
||||||
import { useApi } from "../../../../environment-helpers/use-api"
|
|
||||||
|
|
||||||
jest.setTimeout(50000)
|
jest.setTimeout(50000)
|
||||||
|
|
||||||
@@ -16,151 +10,137 @@ const adminHeaders = {
|
|||||||
headers: { "x-medusa-access-token": "test_token" },
|
headers: { "x-medusa-access-token": "test_token" },
|
||||||
}
|
}
|
||||||
|
|
||||||
describe("POST /admin/customers/:id/addresses/:address_id", () => {
|
medusaIntegrationTestRunner({
|
||||||
let dbConnection
|
env,
|
||||||
let appContainer
|
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||||
let shutdownServer
|
describe("POST /admin/customers/:id/addresses/:address_id", () => {
|
||||||
let customerModuleService: ICustomerModuleService
|
let appContainer
|
||||||
|
let customerModuleService: ICustomerModuleService
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
|
appContainer = getContainer()
|
||||||
dbConnection = await initDb({ cwd, env } as any)
|
customerModuleService = appContainer.resolve(
|
||||||
shutdownServer = await startBootstrapApp({ cwd, env })
|
ModuleRegistrationName.CUSTOMER
|
||||||
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()
|
|
||||||
})
|
|
||||||
|
|
||||||
it("should update a customer address", async () => {
|
|
||||||
const customer = await customerModuleService.create({
|
|
||||||
first_name: "John",
|
|
||||||
last_name: "Doe",
|
|
||||||
})
|
|
||||||
|
|
||||||
const address = await customerModuleService.addAddresses({
|
|
||||||
customer_id: customer.id,
|
|
||||||
first_name: "John",
|
|
||||||
last_name: "Doe",
|
|
||||||
address_1: "Test street 1",
|
|
||||||
})
|
|
||||||
|
|
||||||
const api = useApi() as any
|
|
||||||
const response = await api.post(
|
|
||||||
`/admin/customers/${customer.id}/addresses/${address.id}`,
|
|
||||||
{
|
|
||||||
first_name: "Jane",
|
|
||||||
},
|
|
||||||
adminHeaders
|
|
||||||
)
|
|
||||||
|
|
||||||
expect(response.status).toEqual(200)
|
|
||||||
expect(response.data.address).toEqual(
|
|
||||||
expect.objectContaining({
|
|
||||||
id: expect.any(String),
|
|
||||||
first_name: "Jane",
|
|
||||||
last_name: "Doe",
|
|
||||||
})
|
})
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
it("updates a new address to be default and unsets old one", async () => {
|
beforeEach(async () => {
|
||||||
const customer = await customerModuleService.create({
|
await createAdminUser(dbConnection, adminHeaders, appContainer)
|
||||||
first_name: "John",
|
})
|
||||||
last_name: "Doe",
|
|
||||||
|
it("should update a customer address", async () => {
|
||||||
|
const customer = await customerModuleService.create({
|
||||||
|
first_name: "John",
|
||||||
|
last_name: "Doe",
|
||||||
|
})
|
||||||
|
|
||||||
|
const address = await customerModuleService.addAddresses({
|
||||||
|
customer_id: customer.id,
|
||||||
|
first_name: "John",
|
||||||
|
last_name: "Doe",
|
||||||
|
address_1: "Test street 1",
|
||||||
|
})
|
||||||
|
|
||||||
|
const response = await api.post(
|
||||||
|
`/admin/customers/${customer.id}/addresses/${address.id}`,
|
||||||
|
{
|
||||||
|
first_name: "Jane",
|
||||||
|
},
|
||||||
|
adminHeaders
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(response.status).toEqual(200)
|
||||||
|
expect(response.data.address).toEqual(
|
||||||
|
expect.objectContaining({
|
||||||
|
id: expect.any(String),
|
||||||
|
first_name: "Jane",
|
||||||
|
last_name: "Doe",
|
||||||
|
})
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
it("updates a new address to be default and unsets old one", async () => {
|
||||||
|
const customer = await customerModuleService.create({
|
||||||
|
first_name: "John",
|
||||||
|
last_name: "Doe",
|
||||||
|
})
|
||||||
|
const [, address] = await customerModuleService.addAddresses([
|
||||||
|
{
|
||||||
|
customer_id: customer.id,
|
||||||
|
first_name: "John",
|
||||||
|
last_name: "Doe",
|
||||||
|
address_1: "Test street 1",
|
||||||
|
is_default_shipping: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
customer_id: customer.id,
|
||||||
|
first_name: "John",
|
||||||
|
last_name: "Doe",
|
||||||
|
address_1: "Test street 2",
|
||||||
|
},
|
||||||
|
])
|
||||||
|
|
||||||
|
const response = await api.post(
|
||||||
|
`/admin/customers/${customer.id}/addresses/${address.id}`,
|
||||||
|
{
|
||||||
|
first_name: "jane",
|
||||||
|
is_default_shipping: true,
|
||||||
|
},
|
||||||
|
adminHeaders
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(response.status).toEqual(200)
|
||||||
|
|
||||||
|
const [defaultAddress] = await customerModuleService.listAddresses({
|
||||||
|
customer_id: customer.id,
|
||||||
|
is_default_shipping: true,
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(defaultAddress.first_name).toEqual("jane")
|
||||||
|
expect(defaultAddress.address_1).toEqual("Test street 2")
|
||||||
|
})
|
||||||
|
|
||||||
|
// do the same as above but for billing address
|
||||||
|
it("updates a new address to be default and unsets old one", async () => {
|
||||||
|
const customer = await customerModuleService.create({
|
||||||
|
first_name: "John",
|
||||||
|
last_name: "Doe",
|
||||||
|
})
|
||||||
|
const [, address] = await customerModuleService.addAddresses([
|
||||||
|
{
|
||||||
|
customer_id: customer.id,
|
||||||
|
first_name: "John",
|
||||||
|
last_name: "Doe",
|
||||||
|
address_1: "Test street 1",
|
||||||
|
is_default_billing: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
customer_id: customer.id,
|
||||||
|
first_name: "John",
|
||||||
|
last_name: "Doe",
|
||||||
|
address_1: "Test street 2",
|
||||||
|
},
|
||||||
|
])
|
||||||
|
|
||||||
|
const response = await api.post(
|
||||||
|
`/admin/customers/${customer.id}/addresses/${address.id}`,
|
||||||
|
{
|
||||||
|
first_name: "jane",
|
||||||
|
is_default_billing: true,
|
||||||
|
},
|
||||||
|
adminHeaders
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(response.status).toEqual(200)
|
||||||
|
|
||||||
|
const [defaultAddress] = await customerModuleService.listAddresses({
|
||||||
|
customer_id: customer.id,
|
||||||
|
is_default_billing: true,
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(defaultAddress.first_name).toEqual("jane")
|
||||||
|
expect(defaultAddress.address_1).toEqual("Test street 2")
|
||||||
|
})
|
||||||
})
|
})
|
||||||
const [, address] = await customerModuleService.addAddresses([
|
},
|
||||||
{
|
|
||||||
customer_id: customer.id,
|
|
||||||
first_name: "John",
|
|
||||||
last_name: "Doe",
|
|
||||||
address_1: "Test street 1",
|
|
||||||
is_default_shipping: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
customer_id: customer.id,
|
|
||||||
first_name: "John",
|
|
||||||
last_name: "Doe",
|
|
||||||
address_1: "Test street 2",
|
|
||||||
},
|
|
||||||
])
|
|
||||||
|
|
||||||
const api = useApi() as any
|
|
||||||
const response = await api.post(
|
|
||||||
`/admin/customers/${customer.id}/addresses/${address.id}`,
|
|
||||||
{
|
|
||||||
first_name: "jane",
|
|
||||||
is_default_shipping: true,
|
|
||||||
},
|
|
||||||
adminHeaders
|
|
||||||
)
|
|
||||||
|
|
||||||
expect(response.status).toEqual(200)
|
|
||||||
|
|
||||||
const [defaultAddress] = await customerModuleService.listAddresses({
|
|
||||||
customer_id: customer.id,
|
|
||||||
is_default_shipping: true,
|
|
||||||
})
|
|
||||||
|
|
||||||
expect(defaultAddress.first_name).toEqual("jane")
|
|
||||||
expect(defaultAddress.address_1).toEqual("Test street 2")
|
|
||||||
})
|
|
||||||
|
|
||||||
// do the same as above but for billing address
|
|
||||||
it("updates a new address to be default and unsets old one", async () => {
|
|
||||||
const customer = await customerModuleService.create({
|
|
||||||
first_name: "John",
|
|
||||||
last_name: "Doe",
|
|
||||||
})
|
|
||||||
const [, address] = await customerModuleService.addAddresses([
|
|
||||||
{
|
|
||||||
customer_id: customer.id,
|
|
||||||
first_name: "John",
|
|
||||||
last_name: "Doe",
|
|
||||||
address_1: "Test street 1",
|
|
||||||
is_default_billing: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
customer_id: customer.id,
|
|
||||||
first_name: "John",
|
|
||||||
last_name: "Doe",
|
|
||||||
address_1: "Test street 2",
|
|
||||||
},
|
|
||||||
])
|
|
||||||
|
|
||||||
const api = useApi() as any
|
|
||||||
const response = await api.post(
|
|
||||||
`/admin/customers/${customer.id}/addresses/${address.id}`,
|
|
||||||
{
|
|
||||||
first_name: "jane",
|
|
||||||
is_default_billing: true,
|
|
||||||
},
|
|
||||||
adminHeaders
|
|
||||||
)
|
|
||||||
|
|
||||||
expect(response.status).toEqual(200)
|
|
||||||
|
|
||||||
const [defaultAddress] = await customerModuleService.listAddresses({
|
|
||||||
customer_id: customer.id,
|
|
||||||
is_default_billing: true,
|
|
||||||
})
|
|
||||||
|
|
||||||
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 { ICustomerModuleService } from "@medusajs/types"
|
||||||
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||||
import adminSeeder from "../../../../helpers/admin-seeder"
|
|
||||||
import { createAdminUser } from "../../../helpers/create-admin-user"
|
import { createAdminUser } from "../../../helpers/create-admin-user"
|
||||||
import { getContainer } from "../../../../environment-helpers/use-container"
|
import { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||||
import path from "path"
|
|
||||||
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
|
|
||||||
import { useApi } from "../../../../environment-helpers/use-api"
|
|
||||||
|
|
||||||
jest.setTimeout(50000)
|
jest.setTimeout(50000)
|
||||||
|
|
||||||
@@ -16,59 +10,47 @@ const adminHeaders = {
|
|||||||
headers: { "x-medusa-access-token": "test_token" },
|
headers: { "x-medusa-access-token": "test_token" },
|
||||||
}
|
}
|
||||||
|
|
||||||
describe("POST /admin/customers/:id", () => {
|
medusaIntegrationTestRunner({
|
||||||
let dbConnection
|
env,
|
||||||
let appContainer
|
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||||
let shutdownServer
|
describe("POST /admin/customers/:id", () => {
|
||||||
let customerModuleService: ICustomerModuleService
|
let appContainer
|
||||||
|
let customerModuleService: ICustomerModuleService
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
|
appContainer = getContainer()
|
||||||
dbConnection = await initDb({ cwd, env } as any)
|
customerModuleService = appContainer.resolve(
|
||||||
shutdownServer = await startBootstrapApp({ cwd, env })
|
ModuleRegistrationName.CUSTOMER
|
||||||
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()
|
|
||||||
})
|
|
||||||
|
|
||||||
it("should update a customer", async () => {
|
|
||||||
const customer = await customerModuleService.create({
|
|
||||||
first_name: "John",
|
|
||||||
last_name: "Doe",
|
|
||||||
})
|
|
||||||
|
|
||||||
const api = useApi() as any
|
|
||||||
const response = await api.post(
|
|
||||||
`/admin/customers/${customer.id}`,
|
|
||||||
{
|
|
||||||
first_name: "Jane",
|
|
||||||
},
|
|
||||||
adminHeaders
|
|
||||||
)
|
|
||||||
|
|
||||||
expect(response.status).toEqual(200)
|
|
||||||
expect(response.data.customer).toEqual(
|
|
||||||
expect.objectContaining({
|
|
||||||
id: expect.any(String),
|
|
||||||
first_name: "Jane",
|
|
||||||
last_name: "Doe",
|
|
||||||
})
|
})
|
||||||
)
|
|
||||||
})
|
beforeEach(async () => {
|
||||||
|
await createAdminUser(dbConnection, adminHeaders, appContainer)
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should update a customer", async () => {
|
||||||
|
const customer = await customerModuleService.create({
|
||||||
|
first_name: "John",
|
||||||
|
last_name: "Doe",
|
||||||
|
})
|
||||||
|
|
||||||
|
const response = await api.post(
|
||||||
|
`/admin/customers/${customer.id}`,
|
||||||
|
{
|
||||||
|
first_name: "Jane",
|
||||||
|
},
|
||||||
|
adminHeaders
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(response.status).toEqual(200)
|
||||||
|
expect(response.data.customer).toEqual(
|
||||||
|
expect.objectContaining({
|
||||||
|
id: expect.any(String),
|
||||||
|
first_name: "Jane",
|
||||||
|
last_name: "Doe",
|
||||||
|
})
|
||||||
|
)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
},
|
||||||
})
|
})
|
||||||
@@ -1,74 +1,59 @@
|
|||||||
import { initDb, useDb } from "../../../../environment-helpers/use-db"
|
|
||||||
|
|
||||||
import { ICustomerModuleService } from "@medusajs/types"
|
import { ICustomerModuleService } from "@medusajs/types"
|
||||||
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||||
import { createAuthenticatedCustomer } from "../../../helpers/create-authenticated-customer"
|
import { createAuthenticatedCustomer } from "../../../helpers/create-authenticated-customer"
|
||||||
import { getContainer } from "../../../../environment-helpers/use-container"
|
import { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||||
import path from "path"
|
|
||||||
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
|
|
||||||
import { useApi } from "../../../../environment-helpers/use-api"
|
|
||||||
|
|
||||||
jest.setTimeout(50000)
|
jest.setTimeout(50000)
|
||||||
|
|
||||||
const env = { MEDUSA_FF_MEDUSA_V2: true }
|
const env = { MEDUSA_FF_MEDUSA_V2: true }
|
||||||
|
|
||||||
describe("POST /store/customers/me/addresses", () => {
|
medusaIntegrationTestRunner({
|
||||||
let dbConnection
|
env,
|
||||||
let appContainer
|
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||||
let shutdownServer
|
describe("POST /store/customers/me/addresses", () => {
|
||||||
let customerModuleService: ICustomerModuleService
|
let appContainer
|
||||||
|
let customerModuleService: ICustomerModuleService
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
|
appContainer = getContainer()
|
||||||
dbConnection = await initDb({ cwd, env } as any)
|
customerModuleService = appContainer.resolve(
|
||||||
shutdownServer = await startBootstrapApp({ cwd, env })
|
ModuleRegistrationName.CUSTOMER
|
||||||
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 api = useApi() as any
|
|
||||||
const response = await api.post(
|
|
||||||
`/store/customers/me/addresses`,
|
|
||||||
{
|
|
||||||
first_name: "John",
|
|
||||||
last_name: "Doe",
|
|
||||||
address_1: "Test street 1",
|
|
||||||
},
|
|
||||||
{ headers: { authorization: `Bearer ${jwt}` } }
|
|
||||||
)
|
|
||||||
|
|
||||||
expect(response.status).toEqual(200)
|
|
||||||
expect(response.data.address).toEqual(
|
|
||||||
expect.objectContaining({
|
|
||||||
id: expect.any(String),
|
|
||||||
first_name: "John",
|
|
||||||
last_name: "Doe",
|
|
||||||
address_1: "Test street 1",
|
|
||||||
customer_id: customer.id,
|
|
||||||
})
|
})
|
||||||
)
|
|
||||||
|
|
||||||
const customerWithAddresses = await customerModuleService.retrieve(
|
it("should create a customer address", async () => {
|
||||||
customer.id,
|
const { customer, jwt } = await createAuthenticatedCustomer(
|
||||||
{ relations: ["addresses"] }
|
appContainer
|
||||||
)
|
)
|
||||||
|
|
||||||
expect(customerWithAddresses.addresses?.length).toEqual(1)
|
const response = await api.post(
|
||||||
})
|
`/store/customers/me/addresses`,
|
||||||
|
{
|
||||||
|
first_name: "John",
|
||||||
|
last_name: "Doe",
|
||||||
|
address_1: "Test street 1",
|
||||||
|
},
|
||||||
|
{ headers: { authorization: `Bearer ${jwt}` } }
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(response.status).toEqual(200)
|
||||||
|
expect(response.data.address).toEqual(
|
||||||
|
expect.objectContaining({
|
||||||
|
id: expect.any(String),
|
||||||
|
first_name: "John",
|
||||||
|
last_name: "Doe",
|
||||||
|
address_1: "Test street 1",
|
||||||
|
customer_id: customer.id,
|
||||||
|
})
|
||||||
|
)
|
||||||
|
|
||||||
|
const customerWithAddresses = await customerModuleService.retrieve(
|
||||||
|
customer.id,
|
||||||
|
{ relations: ["addresses"] }
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(customerWithAddresses.addresses?.length).toEqual(1)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
},
|
||||||
})
|
})
|
||||||
@@ -1,82 +1,66 @@
|
|||||||
import { IAuthModuleService, ICustomerModuleService } from "@medusajs/types"
|
import { IAuthModuleService, ICustomerModuleService } from "@medusajs/types"
|
||||||
import { initDb, useDb } from "../../../../environment-helpers/use-db"
|
|
||||||
|
|
||||||
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||||
import adminSeeder from "../../../../helpers/admin-seeder"
|
import adminSeeder from "../../../../helpers/admin-seeder"
|
||||||
import { createAdminUser } from "../../../helpers/create-admin-user"
|
|
||||||
import { getContainer } from "../../../../environment-helpers/use-container"
|
|
||||||
import jwt from "jsonwebtoken"
|
import jwt from "jsonwebtoken"
|
||||||
import path from "path"
|
import { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||||
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
|
|
||||||
import { useApi } from "../../../../environment-helpers/use-api"
|
|
||||||
|
|
||||||
jest.setTimeout(50000)
|
jest.setTimeout(50000)
|
||||||
|
|
||||||
const env = { MEDUSA_FF_MEDUSA_V2: true }
|
const env = { MEDUSA_FF_MEDUSA_V2: true }
|
||||||
|
|
||||||
describe("POST /store/customers", () => {
|
medusaIntegrationTestRunner({
|
||||||
let dbConnection
|
env,
|
||||||
let appContainer
|
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||||
let shutdownServer
|
describe("POST /store/customers", () => {
|
||||||
let customerModuleService: ICustomerModuleService
|
let appContainer
|
||||||
|
let customerModuleService: ICustomerModuleService
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
|
appContainer = getContainer()
|
||||||
dbConnection = await initDb({ cwd, env } as any)
|
customerModuleService = appContainer.resolve(
|
||||||
shutdownServer = await startBootstrapApp({ cwd, env })
|
ModuleRegistrationName.CUSTOMER
|
||||||
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 authUser = await authService.create({
|
|
||||||
entity_id: "store_user",
|
|
||||||
provider: "emailpass",
|
|
||||||
scope: "store",
|
|
||||||
})
|
|
||||||
|
|
||||||
const token = jwt.sign(authUser, jwt_secret)
|
|
||||||
|
|
||||||
const api = useApi() as any
|
|
||||||
const response = await api.post(
|
|
||||||
`/store/customers`,
|
|
||||||
{
|
|
||||||
first_name: "John",
|
|
||||||
last_name: "Doe",
|
|
||||||
email: "john@me.com",
|
|
||||||
},
|
|
||||||
{ headers: { authorization: `Bearer ${token}` } }
|
|
||||||
)
|
|
||||||
|
|
||||||
expect(response.status).toEqual(200)
|
|
||||||
expect(response.data.customer).toEqual(
|
|
||||||
expect.objectContaining({
|
|
||||||
id: expect.any(String),
|
|
||||||
first_name: "John",
|
|
||||||
last_name: "Doe",
|
|
||||||
email: "john@me.com",
|
|
||||||
})
|
})
|
||||||
)
|
|
||||||
})
|
beforeEach(async () => {
|
||||||
|
await adminSeeder(dbConnection)
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should create a customer", async () => {
|
||||||
|
const authService: IAuthModuleService = appContainer.resolve(
|
||||||
|
ModuleRegistrationName.AUTH
|
||||||
|
)
|
||||||
|
const { jwt_secret } =
|
||||||
|
appContainer.resolve("configModule").projectConfig
|
||||||
|
const authUser = await authService.create({
|
||||||
|
entity_id: "store_user",
|
||||||
|
provider: "emailpass",
|
||||||
|
scope: "store",
|
||||||
|
})
|
||||||
|
|
||||||
|
const token = jwt.sign(authUser, jwt_secret)
|
||||||
|
|
||||||
|
const response = await api.post(
|
||||||
|
`/store/customers`,
|
||||||
|
{
|
||||||
|
first_name: "John",
|
||||||
|
last_name: "Doe",
|
||||||
|
email: "john@me.com",
|
||||||
|
},
|
||||||
|
{ headers: { authorization: `Bearer ${token}` } }
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(response.status).toEqual(200)
|
||||||
|
expect(response.data.customer).toEqual(
|
||||||
|
expect.objectContaining({
|
||||||
|
id: expect.any(String),
|
||||||
|
first_name: "John",
|
||||||
|
last_name: "Doe",
|
||||||
|
email: "john@me.com",
|
||||||
|
})
|
||||||
|
)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
},
|
||||||
})
|
})
|
||||||
+65
-78
@@ -1,90 +1,77 @@
|
|||||||
import { initDb, useDb } from "../../../../environment-helpers/use-db"
|
|
||||||
|
|
||||||
import { ICustomerModuleService } from "@medusajs/types"
|
import { ICustomerModuleService } from "@medusajs/types"
|
||||||
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||||
import { createAuthenticatedCustomer } from "../../../helpers/create-authenticated-customer"
|
import { createAuthenticatedCustomer } from "../../../helpers/create-authenticated-customer"
|
||||||
import { getContainer } from "../../../../environment-helpers/use-container"
|
import { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||||
import path from "path"
|
|
||||||
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
|
|
||||||
import { useApi } from "../../../../environment-helpers/use-api"
|
|
||||||
|
|
||||||
const env = { MEDUSA_FF_MEDUSA_V2: true }
|
const env = { MEDUSA_FF_MEDUSA_V2: true }
|
||||||
|
|
||||||
jest.setTimeout(50000)
|
jest.setTimeout(50000)
|
||||||
|
|
||||||
describe("DELETE /store/customers/me/addresses/:address_id", () => {
|
medusaIntegrationTestRunner({
|
||||||
let dbConnection
|
env,
|
||||||
let appContainer
|
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||||
let shutdownServer
|
describe("DELETE /store/customers/me/addresses/:address_id", () => {
|
||||||
let customerModuleService: ICustomerModuleService
|
let appContainer
|
||||||
|
let customerModuleService: ICustomerModuleService
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
|
appContainer = getContainer()
|
||||||
dbConnection = await initDb({ cwd, env } as any)
|
customerModuleService = appContainer.resolve(
|
||||||
shutdownServer = await startBootstrapApp({ cwd, env })
|
ModuleRegistrationName.CUSTOMER
|
||||||
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 address = await customerModuleService.addAddresses({
|
|
||||||
customer_id: customer.id,
|
|
||||||
first_name: "John",
|
|
||||||
last_name: "Doe",
|
|
||||||
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}` } }
|
|
||||||
)
|
|
||||||
|
|
||||||
expect(response.status).toEqual(200)
|
|
||||||
|
|
||||||
const updatedCustomer = await customerModuleService.retrieve(customer.id, {
|
|
||||||
relations: ["addresses"],
|
|
||||||
})
|
|
||||||
|
|
||||||
expect(updatedCustomer.addresses?.length).toEqual(0)
|
|
||||||
})
|
|
||||||
|
|
||||||
it("should fail to delete another customer's address", async () => {
|
|
||||||
const { jwt } = await createAuthenticatedCustomer(appContainer)
|
|
||||||
|
|
||||||
const otherCustomer = await customerModuleService.create({
|
|
||||||
first_name: "Jane",
|
|
||||||
last_name: "Doe",
|
|
||||||
})
|
|
||||||
const address = await customerModuleService.addAddresses({
|
|
||||||
customer_id: otherCustomer.id,
|
|
||||||
first_name: "John",
|
|
||||||
last_name: "Doe",
|
|
||||||
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}` },
|
|
||||||
})
|
})
|
||||||
.catch((e) => e.response)
|
|
||||||
|
|
||||||
expect(response.status).toEqual(404)
|
it("should delete a customer address", async () => {
|
||||||
})
|
const { customer, jwt } = await createAuthenticatedCustomer(
|
||||||
|
appContainer
|
||||||
|
)
|
||||||
|
|
||||||
|
const address = await customerModuleService.addAddresses({
|
||||||
|
customer_id: customer.id,
|
||||||
|
first_name: "John",
|
||||||
|
last_name: "Doe",
|
||||||
|
address_1: "Test street 1",
|
||||||
|
})
|
||||||
|
|
||||||
|
const response = await api.delete(
|
||||||
|
`/store/customers/me/addresses/${address.id}`,
|
||||||
|
{ headers: { authorization: `Bearer ${jwt}` } }
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(response.status).toEqual(200)
|
||||||
|
|
||||||
|
const updatedCustomer = await customerModuleService.retrieve(
|
||||||
|
customer.id,
|
||||||
|
{
|
||||||
|
relations: ["addresses"],
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(updatedCustomer.addresses?.length).toEqual(0)
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should fail to delete another customer's address", async () => {
|
||||||
|
const { jwt } = await createAuthenticatedCustomer(appContainer)
|
||||||
|
|
||||||
|
const otherCustomer = await customerModuleService.create({
|
||||||
|
first_name: "Jane",
|
||||||
|
last_name: "Doe",
|
||||||
|
})
|
||||||
|
const address = await customerModuleService.addAddresses({
|
||||||
|
customer_id: otherCustomer.id,
|
||||||
|
first_name: "John",
|
||||||
|
last_name: "Doe",
|
||||||
|
address_1: "Test street 1",
|
||||||
|
})
|
||||||
|
|
||||||
|
const response = await api
|
||||||
|
.delete(`/store/customers/me/addresses/${address.id}`, {
|
||||||
|
headers: { authorization: `Bearer ${jwt}` },
|
||||||
|
})
|
||||||
|
.catch((e) => e.response)
|
||||||
|
|
||||||
|
expect(response.status).toEqual(404)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
},
|
||||||
})
|
})
|
||||||
@@ -1,60 +1,45 @@
|
|||||||
import { initDb, useDb } from "../../../../environment-helpers/use-db"
|
|
||||||
|
|
||||||
import { ICustomerModuleService } from "@medusajs/types"
|
import { ICustomerModuleService } from "@medusajs/types"
|
||||||
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||||
import { createAuthenticatedCustomer } from "../../../helpers/create-authenticated-customer"
|
import { createAuthenticatedCustomer } from "../../../helpers/create-authenticated-customer"
|
||||||
import { getContainer } from "../../../../environment-helpers/use-container"
|
import { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||||
import path from "path"
|
|
||||||
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
|
|
||||||
import { useApi } from "../../../../environment-helpers/use-api"
|
|
||||||
|
|
||||||
jest.setTimeout(50000)
|
jest.setTimeout(50000)
|
||||||
|
|
||||||
const env = { MEDUSA_FF_MEDUSA_V2: true }
|
const env = { MEDUSA_FF_MEDUSA_V2: true }
|
||||||
|
|
||||||
describe("GET /store/customers", () => {
|
medusaIntegrationTestRunner({
|
||||||
let dbConnection
|
env,
|
||||||
let appContainer
|
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||||
let shutdownServer
|
describe("GET /store/customers", () => {
|
||||||
let customerModuleService: ICustomerModuleService
|
let appContainer
|
||||||
|
let customerModuleService: ICustomerModuleService
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
|
appContainer = getContainer()
|
||||||
dbConnection = await initDb({ cwd, env } as any)
|
customerModuleService = appContainer.resolve(
|
||||||
shutdownServer = await startBootstrapApp({ cwd, env })
|
ModuleRegistrationName.CUSTOMER
|
||||||
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 api = useApi() as any
|
|
||||||
const response = await api.get(`/store/customers/me`, {
|
|
||||||
headers: { authorization: `Bearer ${jwt}` },
|
|
||||||
})
|
|
||||||
|
|
||||||
expect(response.status).toEqual(200)
|
|
||||||
expect(response.data.customer).toEqual(
|
|
||||||
expect.objectContaining({
|
|
||||||
id: customer.id,
|
|
||||||
first_name: "John",
|
|
||||||
last_name: "Doe",
|
|
||||||
email: "john@me.com",
|
|
||||||
})
|
})
|
||||||
)
|
|
||||||
})
|
it("should retrieve auth user's customer", async () => {
|
||||||
|
const { customer, jwt } = await createAuthenticatedCustomer(
|
||||||
|
appContainer
|
||||||
|
)
|
||||||
|
|
||||||
|
const response = await api.get(`/store/customers/me`, {
|
||||||
|
headers: { authorization: `Bearer ${jwt}` },
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(response.status).toEqual(200)
|
||||||
|
expect(response.data.customer).toEqual(
|
||||||
|
expect.objectContaining({
|
||||||
|
id: customer.id,
|
||||||
|
first_name: "John",
|
||||||
|
last_name: "Doe",
|
||||||
|
email: "john@me.com",
|
||||||
|
})
|
||||||
|
)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
},
|
||||||
})
|
})
|
||||||
@@ -1,109 +1,90 @@
|
|||||||
import { initDb, useDb } from "../../../../environment-helpers/use-db"
|
|
||||||
|
|
||||||
import { ICustomerModuleService } from "@medusajs/types"
|
import { ICustomerModuleService } from "@medusajs/types"
|
||||||
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||||
import { createAuthenticatedCustomer } from "../../../helpers/create-authenticated-customer"
|
import { createAuthenticatedCustomer } from "../../../helpers/create-authenticated-customer"
|
||||||
import { getContainer } from "../../../../environment-helpers/use-container"
|
import {medusaIntegrationTestRunner} from "medusa-test-utils";
|
||||||
import path from "path"
|
|
||||||
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
|
|
||||||
import { useApi } from "../../../../environment-helpers/use-api"
|
|
||||||
|
|
||||||
const env = { MEDUSA_FF_MEDUSA_V2: true }
|
const env = { MEDUSA_FF_MEDUSA_V2: true }
|
||||||
|
|
||||||
jest.setTimeout(100000)
|
jest.setTimeout(100000)
|
||||||
|
|
||||||
describe("GET /store/customers/me/addresses", () => {
|
medusaIntegrationTestRunner({
|
||||||
let dbConnection
|
env,
|
||||||
let appContainer
|
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||||
let shutdownServer
|
describe("GET /store/customers/me/addresses", () => {
|
||||||
let customerModuleService: ICustomerModuleService
|
let appContainer
|
||||||
|
let customerModuleService: ICustomerModuleService
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
try {
|
appContainer = getContainer()
|
||||||
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
|
customerModuleService = appContainer.resolve(
|
||||||
dbConnection = await initDb({ cwd, env } as any)
|
ModuleRegistrationName.CUSTOMER
|
||||||
shutdownServer = await startBootstrapApp({ cwd, env })
|
)
|
||||||
appContainer = getContainer()
|
})
|
||||||
customerModuleService = appContainer.resolve(
|
|
||||||
ModuleRegistrationName.CUSTOMER
|
|
||||||
)
|
|
||||||
} catch (error) {
|
|
||||||
console.error(error)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
afterAll(async () => {
|
it("should get all customer addresses and its count", async () => {
|
||||||
const db = useDb()
|
const { customer, jwt } = await createAuthenticatedCustomer(
|
||||||
await db.shutdown()
|
appContainer
|
||||||
await shutdownServer()
|
)
|
||||||
})
|
|
||||||
|
|
||||||
afterEach(async () => {
|
await customerModuleService.addAddresses([
|
||||||
const db = useDb()
|
{
|
||||||
await db.teardown()
|
first_name: "Test",
|
||||||
})
|
last_name: "Test",
|
||||||
|
address_1: "Test street 1",
|
||||||
|
customer_id: customer.id,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
first_name: "Test",
|
||||||
|
last_name: "Test",
|
||||||
|
address_1: "Test street 2",
|
||||||
|
customer_id: customer.id,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
first_name: "Test",
|
||||||
|
last_name: "Test",
|
||||||
|
address_1: "Test street 3",
|
||||||
|
customer_id: customer.id,
|
||||||
|
},
|
||||||
|
])
|
||||||
|
|
||||||
it("should get all customer addresses and its count", async () => {
|
await customerModuleService.create({
|
||||||
const { customer, jwt } = await createAuthenticatedCustomer(appContainer)
|
first_name: "Test Test",
|
||||||
|
last_name: "Test Test",
|
||||||
|
addresses: [
|
||||||
|
{
|
||||||
|
first_name: "Test TEST",
|
||||||
|
last_name: "Test TEST",
|
||||||
|
address_1: "NOT street 1",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
})
|
||||||
|
|
||||||
await customerModuleService.addAddresses([
|
const response = await api.get(`/store/customers/me/addresses`, {
|
||||||
{
|
headers: { authorization: `Bearer ${jwt}` },
|
||||||
first_name: "Test",
|
})
|
||||||
last_name: "Test",
|
|
||||||
address_1: "Test street 1",
|
|
||||||
customer_id: customer.id,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
first_name: "Test",
|
|
||||||
last_name: "Test",
|
|
||||||
address_1: "Test street 2",
|
|
||||||
customer_id: customer.id,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
first_name: "Test",
|
|
||||||
last_name: "Test",
|
|
||||||
address_1: "Test street 3",
|
|
||||||
customer_id: customer.id,
|
|
||||||
},
|
|
||||||
])
|
|
||||||
|
|
||||||
await customerModuleService.create({
|
expect(response.status).toEqual(200)
|
||||||
first_name: "Test Test",
|
expect(response.data.count).toEqual(3)
|
||||||
last_name: "Test Test",
|
expect(response.data.addresses).toEqual(
|
||||||
addresses: [
|
expect.arrayContaining([
|
||||||
{
|
expect.objectContaining({
|
||||||
first_name: "Test TEST",
|
id: expect.any(String),
|
||||||
last_name: "Test TEST",
|
customer_id: customer.id,
|
||||||
address_1: "NOT street 1",
|
address_1: "Test street 1",
|
||||||
},
|
}),
|
||||||
],
|
expect.objectContaining({
|
||||||
|
id: expect.any(String),
|
||||||
|
customer_id: customer.id,
|
||||||
|
address_1: "Test street 2",
|
||||||
|
}),
|
||||||
|
expect.objectContaining({
|
||||||
|
id: expect.any(String),
|
||||||
|
customer_id: customer.id,
|
||||||
|
address_1: "Test street 3",
|
||||||
|
}),
|
||||||
|
])
|
||||||
|
)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
},
|
||||||
const api = useApi() as any
|
|
||||||
const response = await api.get(`/store/customers/me/addresses`, {
|
|
||||||
headers: { authorization: `Bearer ${jwt}` },
|
|
||||||
})
|
|
||||||
|
|
||||||
expect(response.status).toEqual(200)
|
|
||||||
expect(response.data.count).toEqual(3)
|
|
||||||
expect(response.data.addresses).toEqual(
|
|
||||||
expect.arrayContaining([
|
|
||||||
expect.objectContaining({
|
|
||||||
id: expect.any(String),
|
|
||||||
customer_id: customer.id,
|
|
||||||
address_1: "Test street 1",
|
|
||||||
}),
|
|
||||||
expect.objectContaining({
|
|
||||||
id: expect.any(String),
|
|
||||||
customer_id: customer.id,
|
|
||||||
address_1: "Test street 2",
|
|
||||||
}),
|
|
||||||
expect.objectContaining({
|
|
||||||
id: expect.any(String),
|
|
||||||
customer_id: customer.id,
|
|
||||||
address_1: "Test street 3",
|
|
||||||
}),
|
|
||||||
])
|
|
||||||
)
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
+67
-83
@@ -1,97 +1,81 @@
|
|||||||
import { initDb, useDb } from "../../../../environment-helpers/use-db"
|
|
||||||
|
|
||||||
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||||
import { ICustomerModuleService } from "@medusajs/types"
|
import { ICustomerModuleService } from "@medusajs/types"
|
||||||
import path from "path"
|
|
||||||
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
|
|
||||||
import { useApi } from "../../../../environment-helpers/use-api"
|
|
||||||
import { getContainer } from "../../../../environment-helpers/use-container"
|
|
||||||
import { createAuthenticatedCustomer } from "../../../helpers/create-authenticated-customer"
|
import { createAuthenticatedCustomer } from "../../../helpers/create-authenticated-customer"
|
||||||
|
import { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||||
|
|
||||||
jest.setTimeout(50000)
|
jest.setTimeout(50000)
|
||||||
|
|
||||||
const env = { MEDUSA_FF_MEDUSA_V2: true }
|
const env = { MEDUSA_FF_MEDUSA_V2: true }
|
||||||
|
|
||||||
describe("POST /store/customers/:id/addresses/:address_id", () => {
|
medusaIntegrationTestRunner({
|
||||||
let dbConnection
|
env,
|
||||||
let appContainer
|
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||||
let shutdownServer
|
describe("POST /store/customers/:id/addresses/:address_id", () => {
|
||||||
let customerModuleService: ICustomerModuleService
|
let appContainer
|
||||||
|
let customerModuleService: ICustomerModuleService
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
|
appContainer = getContainer()
|
||||||
dbConnection = await initDb({ cwd, env } as any)
|
customerModuleService = appContainer.resolve(
|
||||||
shutdownServer = await startBootstrapApp({ cwd, env })
|
ModuleRegistrationName.CUSTOMER
|
||||||
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 address = await customerModuleService.addAddresses({
|
|
||||||
customer_id: customer.id,
|
|
||||||
first_name: "John",
|
|
||||||
last_name: "Doe",
|
|
||||||
address_1: "Test street 1",
|
|
||||||
})
|
|
||||||
|
|
||||||
const api = useApi() as any
|
|
||||||
const response = await api.post(
|
|
||||||
`/store/customers/me/addresses/${address.id}`,
|
|
||||||
{
|
|
||||||
first_name: "Jane",
|
|
||||||
},
|
|
||||||
{ headers: { authorization: `Bearer ${jwt}` } }
|
|
||||||
)
|
|
||||||
|
|
||||||
expect(response.status).toEqual(200)
|
|
||||||
expect(response.data.address).toEqual(
|
|
||||||
expect.objectContaining({
|
|
||||||
id: address.id,
|
|
||||||
first_name: "Jane",
|
|
||||||
last_name: "Doe",
|
|
||||||
})
|
})
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
it("should fail to update another customer's address", async () => {
|
it("should update a customer address", async () => {
|
||||||
const { jwt } = await createAuthenticatedCustomer(appContainer)
|
const { customer, jwt } = await createAuthenticatedCustomer(
|
||||||
|
appContainer
|
||||||
|
)
|
||||||
|
|
||||||
const otherCustomer = await customerModuleService.create({
|
const address = await customerModuleService.addAddresses({
|
||||||
first_name: "Jane",
|
customer_id: customer.id,
|
||||||
last_name: "Doe",
|
first_name: "John",
|
||||||
|
last_name: "Doe",
|
||||||
|
address_1: "Test street 1",
|
||||||
|
})
|
||||||
|
|
||||||
|
const response = await api.post(
|
||||||
|
`/store/customers/me/addresses/${address.id}`,
|
||||||
|
{
|
||||||
|
first_name: "Jane",
|
||||||
|
},
|
||||||
|
{ headers: { authorization: `Bearer ${jwt}` } }
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(response.status).toEqual(200)
|
||||||
|
expect(response.data.address).toEqual(
|
||||||
|
expect.objectContaining({
|
||||||
|
id: address.id,
|
||||||
|
first_name: "Jane",
|
||||||
|
last_name: "Doe",
|
||||||
|
})
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should fail to update another customer's address", async () => {
|
||||||
|
const { jwt } = await createAuthenticatedCustomer(appContainer)
|
||||||
|
|
||||||
|
const otherCustomer = await customerModuleService.create({
|
||||||
|
first_name: "Jane",
|
||||||
|
last_name: "Doe",
|
||||||
|
})
|
||||||
|
|
||||||
|
const address = await customerModuleService.addAddresses({
|
||||||
|
customer_id: otherCustomer.id,
|
||||||
|
first_name: "John",
|
||||||
|
last_name: "Doe",
|
||||||
|
address_1: "Test street 1",
|
||||||
|
})
|
||||||
|
|
||||||
|
const response = await api
|
||||||
|
.post(
|
||||||
|
`/store/customers/me/addresses/${address.id}`,
|
||||||
|
{ first_name: "Jane" },
|
||||||
|
{ headers: { authorization: `Bearer ${jwt}` } }
|
||||||
|
)
|
||||||
|
.catch((e) => e.response)
|
||||||
|
|
||||||
|
expect(response.status).toEqual(404)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
},
|
||||||
const address = await customerModuleService.addAddresses({
|
|
||||||
customer_id: otherCustomer.id,
|
|
||||||
first_name: "John",
|
|
||||||
last_name: "Doe",
|
|
||||||
address_1: "Test street 1",
|
|
||||||
})
|
|
||||||
|
|
||||||
const api = useApi() as any
|
|
||||||
const response = await api
|
|
||||||
.post(
|
|
||||||
`/store/customers/me/addresses/${address.id}`,
|
|
||||||
{ first_name: "Jane" },
|
|
||||||
{ headers: { authorization: `Bearer ${jwt}` } }
|
|
||||||
)
|
|
||||||
.catch((e) => e.response)
|
|
||||||
|
|
||||||
expect(response.status).toEqual(404)
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
@@ -1,13 +1,7 @@
|
|||||||
import { IAuthModuleService, IUserModuleService } from "@medusajs/types"
|
import { IUserModuleService } from "@medusajs/types"
|
||||||
import { initDb, useDb } from "../../../environment-helpers/use-db"
|
|
||||||
|
|
||||||
import { AxiosInstance } from "axios"
|
|
||||||
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||||
import { createAdminUser } from "../../helpers/create-admin-user"
|
import { createAdminUser } from "../../helpers/create-admin-user"
|
||||||
import { getContainer } from "../../../environment-helpers/use-container"
|
import { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||||
import path from "path"
|
|
||||||
import { startBootstrapApp } from "../../../environment-helpers/bootstrap-app"
|
|
||||||
import { useApi } from "../../../environment-helpers/use-api"
|
|
||||||
|
|
||||||
jest.setTimeout(50000)
|
jest.setTimeout(50000)
|
||||||
|
|
||||||
@@ -16,97 +10,82 @@ const adminHeaders = {
|
|||||||
headers: { "x-medusa-access-token": "test_token" },
|
headers: { "x-medusa-access-token": "test_token" },
|
||||||
}
|
}
|
||||||
|
|
||||||
describe("GET /admin/invites/:id", () => {
|
medusaIntegrationTestRunner({
|
||||||
let dbConnection
|
env,
|
||||||
let appContainer
|
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||||
let shutdownServer
|
describe("GET /admin/invites/:id", () => {
|
||||||
let userModuleService: IUserModuleService
|
let appContainer
|
||||||
|
let userModuleService: IUserModuleService
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
const cwd = path.resolve(path.join(__dirname, "..", ".."))
|
appContainer = getContainer()
|
||||||
dbConnection = await initDb({ cwd, env } as any)
|
userModuleService = appContainer.resolve(ModuleRegistrationName.USER)
|
||||||
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()
|
|
||||||
})
|
|
||||||
|
|
||||||
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",
|
|
||||||
})
|
|
||||||
|
|
||||||
expect(authResponse.status).toEqual(200)
|
|
||||||
const token = authResponse.data.token
|
|
||||||
|
|
||||||
const acceptResponse = await api
|
|
||||||
.post(
|
|
||||||
`/admin/invites/accept?token=${"non-existing-token"}`,
|
|
||||||
{
|
|
||||||
first_name: "John",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
headers: {
|
|
||||||
Authorization: `Bearer ${token}`,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
)
|
|
||||||
.catch((e) => e)
|
|
||||||
|
|
||||||
expect(acceptResponse.response.status).toEqual(401)
|
|
||||||
expect(acceptResponse.response.data.message).toEqual("Unauthorized")
|
|
||||||
})
|
|
||||||
|
|
||||||
it("should accept an invite", async () => {
|
|
||||||
const invite = await userModuleService.createInvites({
|
|
||||||
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",
|
|
||||||
})
|
|
||||||
|
|
||||||
expect(authResponse.status).toEqual(200)
|
|
||||||
const token = authResponse.data.token
|
|
||||||
|
|
||||||
const acceptResponse = await api.post(
|
|
||||||
`/admin/invites/accept?token=${invite.token}`,
|
|
||||||
{
|
|
||||||
first_name: "John",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
headers: {
|
|
||||||
Authorization: `Bearer ${token}`,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
expect(acceptResponse.status).toEqual(200)
|
|
||||||
expect(acceptResponse.data.user).toEqual(
|
|
||||||
expect.objectContaining({
|
|
||||||
email: "potential_member@test.com",
|
|
||||||
first_name: "John",
|
|
||||||
})
|
})
|
||||||
)
|
|
||||||
})
|
beforeEach(async () => {
|
||||||
|
await createAdminUser(dbConnection, adminHeaders, appContainer)
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should fail to accept an invite with an invalid invite token", async () => {
|
||||||
|
const authResponse = await api.post(`/auth/admin/emailpass`, {
|
||||||
|
email: "potential_member@test.com",
|
||||||
|
password: "supersecret",
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(authResponse.status).toEqual(200)
|
||||||
|
const token = authResponse.data.token
|
||||||
|
|
||||||
|
const acceptResponse = await api
|
||||||
|
.post(
|
||||||
|
`/admin/invites/accept?token=${"non-existing-token"}`,
|
||||||
|
{
|
||||||
|
first_name: "John",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
headers: {
|
||||||
|
Authorization: `Bearer ${token}`,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
)
|
||||||
|
.catch((e) => e)
|
||||||
|
|
||||||
|
expect(acceptResponse.response.status).toEqual(401)
|
||||||
|
expect(acceptResponse.response.data.message).toEqual("Unauthorized")
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should accept an invite", async () => {
|
||||||
|
const invite = await userModuleService.createInvites({
|
||||||
|
email: "potential_member@test.com",
|
||||||
|
})
|
||||||
|
|
||||||
|
const authResponse = await api.post(`/auth/admin/emailpass`, {
|
||||||
|
email: "potential_member@test.com",
|
||||||
|
password: "supersecret",
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(authResponse.status).toEqual(200)
|
||||||
|
const token = authResponse.data.token
|
||||||
|
|
||||||
|
const acceptResponse = await api.post(
|
||||||
|
`/admin/invites/accept?token=${invite.token}`,
|
||||||
|
{
|
||||||
|
first_name: "John",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
headers: {
|
||||||
|
Authorization: `Bearer ${token}`,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(acceptResponse.status).toEqual(200)
|
||||||
|
expect(acceptResponse.data.user).toEqual(
|
||||||
|
expect.objectContaining({
|
||||||
|
email: "potential_member@test.com",
|
||||||
|
first_name: "John",
|
||||||
|
})
|
||||||
|
)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
},
|
||||||
})
|
})
|
||||||
@@ -1,11 +1,5 @@
|
|||||||
import { initDb, useDb } from "../../../environment-helpers/use-db"
|
|
||||||
|
|
||||||
import path from "path"
|
|
||||||
import { startBootstrapApp } from "../../../environment-helpers/bootstrap-app"
|
|
||||||
import { useApi } from "../../../environment-helpers/use-api"
|
|
||||||
import adminSeeder from "../../../helpers/admin-seeder"
|
|
||||||
import { AxiosInstance } from "axios"
|
|
||||||
import { createAdminUser } from "../../helpers/create-admin-user"
|
import { createAdminUser } from "../../helpers/create-admin-user"
|
||||||
|
import { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||||
|
|
||||||
jest.setTimeout(50000)
|
jest.setTimeout(50000)
|
||||||
|
|
||||||
@@ -14,43 +8,26 @@ const adminHeaders = {
|
|||||||
headers: { "x-medusa-access-token": "test_token" },
|
headers: { "x-medusa-access-token": "test_token" },
|
||||||
}
|
}
|
||||||
|
|
||||||
describe("POST /admin/invites", () => {
|
medusaIntegrationTestRunner({
|
||||||
let dbConnection
|
env,
|
||||||
let shutdownServer
|
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||||
|
describe("POST /admin/invites", () => {
|
||||||
|
beforeEach(async () => {
|
||||||
|
await createAdminUser(dbConnection, adminHeaders, getContainer())
|
||||||
|
})
|
||||||
|
|
||||||
beforeAll(async () => {
|
it("create an invite", async () => {
|
||||||
const cwd = path.resolve(path.join(__dirname, "..", ".."))
|
const body = {
|
||||||
dbConnection = await initDb({ cwd, env } as any)
|
email: "test_member@test.com",
|
||||||
shutdownServer = await startBootstrapApp({ cwd, env })
|
}
|
||||||
})
|
|
||||||
|
|
||||||
beforeEach(async () => {
|
const response = await api.post(`/admin/invites`, body, adminHeaders)
|
||||||
await createAdminUser(dbConnection, adminHeaders)
|
|
||||||
})
|
|
||||||
|
|
||||||
afterAll(async () => {
|
expect(response.status).toEqual(200)
|
||||||
const db = useDb()
|
expect(response.data).toEqual({
|
||||||
await db.shutdown()
|
invite: expect.objectContaining(body),
|
||||||
await shutdownServer()
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
afterEach(async () => {
|
|
||||||
const db = useDb()
|
|
||||||
await db.teardown()
|
|
||||||
})
|
|
||||||
|
|
||||||
it("create an invite", async () => {
|
|
||||||
const api = useApi()! as AxiosInstance
|
|
||||||
|
|
||||||
const body = {
|
|
||||||
email: "test_member@test.com",
|
|
||||||
}
|
|
||||||
|
|
||||||
const response = await api.post(`/admin/invites`, body, adminHeaders)
|
|
||||||
|
|
||||||
expect(response.status).toEqual(200)
|
|
||||||
expect(response.data).toEqual({
|
|
||||||
invite: expect.objectContaining(body),
|
|
||||||
})
|
})
|
||||||
})
|
},
|
||||||
})
|
})
|
||||||
@@ -1,14 +1,7 @@
|
|||||||
import { initDb, useDb } from "../../../environment-helpers/use-db"
|
|
||||||
|
|
||||||
import { IUserModuleService } from "@medusajs/types"
|
import { IUserModuleService } from "@medusajs/types"
|
||||||
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||||
import { getContainer } from "../../../environment-helpers/use-container"
|
|
||||||
import path from "path"
|
|
||||||
import { startBootstrapApp } from "../../../environment-helpers/bootstrap-app"
|
|
||||||
import { useApi } from "../../../environment-helpers/use-api"
|
|
||||||
import adminSeeder from "../../../helpers/admin-seeder"
|
|
||||||
import { AxiosInstance } from "axios"
|
|
||||||
import { createAdminUser } from "../../helpers/create-admin-user"
|
import { createAdminUser } from "../../helpers/create-admin-user"
|
||||||
|
import { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||||
|
|
||||||
jest.setTimeout(50000)
|
jest.setTimeout(50000)
|
||||||
|
|
||||||
@@ -17,61 +10,48 @@ const adminHeaders = {
|
|||||||
headers: { "x-medusa-access-token": "test_token" },
|
headers: { "x-medusa-access-token": "test_token" },
|
||||||
}
|
}
|
||||||
|
|
||||||
describe("DELETE /admin/invites/:id", () => {
|
medusaIntegrationTestRunner({
|
||||||
let dbConnection
|
env,
|
||||||
let appContainer
|
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||||
let shutdownServer
|
describe("DELETE /admin/invites/:id", () => {
|
||||||
let userModuleService: IUserModuleService
|
let appContainer
|
||||||
|
let userModuleService: IUserModuleService
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
const cwd = path.resolve(path.join(__dirname, "..", ".."))
|
appContainer = getContainer()
|
||||||
dbConnection = await initDb({ cwd, env } as any)
|
userModuleService = appContainer.resolve(ModuleRegistrationName.USER)
|
||||||
shutdownServer = await startBootstrapApp({ cwd, env })
|
})
|
||||||
appContainer = getContainer()
|
|
||||||
userModuleService = appContainer.resolve(ModuleRegistrationName.USER)
|
|
||||||
})
|
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
await createAdminUser(dbConnection, adminHeaders)
|
await createAdminUser(dbConnection, adminHeaders, appContainer)
|
||||||
})
|
})
|
||||||
|
|
||||||
afterAll(async () => {
|
it("should delete a single invite", async () => {
|
||||||
const db = useDb()
|
const invite = await userModuleService.createInvites({
|
||||||
await db.shutdown()
|
email: "potential_member@test.com",
|
||||||
await shutdownServer()
|
token: "test",
|
||||||
})
|
expires_at: new Date(),
|
||||||
|
})
|
||||||
|
|
||||||
afterEach(async () => {
|
const response = await api.delete(
|
||||||
const db = useDb()
|
`/admin/invites/${invite.id}`,
|
||||||
await db.teardown()
|
adminHeaders
|
||||||
})
|
)
|
||||||
|
|
||||||
it("should delete a single invite", async () => {
|
expect(response.status).toEqual(200)
|
||||||
const invite = await userModuleService.createInvites({
|
expect(response.data).toEqual({
|
||||||
email: "potential_member@test.com",
|
id: invite.id,
|
||||||
token: "test",
|
object: "invite",
|
||||||
expires_at: new Date(),
|
deleted: true,
|
||||||
|
})
|
||||||
|
|
||||||
|
const { response: deletedResponse } = await api
|
||||||
|
.get(`/admin/invites/${invite.id}`, adminHeaders)
|
||||||
|
.catch((e) => e)
|
||||||
|
|
||||||
|
expect(deletedResponse.status).toEqual(404)
|
||||||
|
expect(deletedResponse.data.type).toEqual("not_found")
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
},
|
||||||
const api = useApi()! as AxiosInstance
|
|
||||||
|
|
||||||
const response = await api.delete(
|
|
||||||
`/admin/invites/${invite.id}`,
|
|
||||||
adminHeaders
|
|
||||||
)
|
|
||||||
|
|
||||||
expect(response.status).toEqual(200)
|
|
||||||
expect(response.data).toEqual({
|
|
||||||
id: invite.id,
|
|
||||||
object: "invite",
|
|
||||||
deleted: true,
|
|
||||||
})
|
|
||||||
|
|
||||||
const { response: deletedResponse } = await api
|
|
||||||
.get(`/admin/invites/${invite.id}`, adminHeaders)
|
|
||||||
.catch((e) => e)
|
|
||||||
|
|
||||||
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 { IUserModuleService } from "@medusajs/types"
|
||||||
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||||
import { getContainer } from "../../../environment-helpers/use-container"
|
|
||||||
import path from "path"
|
|
||||||
import { startBootstrapApp } from "../../../environment-helpers/bootstrap-app"
|
|
||||||
import { useApi } from "../../../environment-helpers/use-api"
|
|
||||||
import adminSeeder from "../../../helpers/admin-seeder"
|
|
||||||
import { AxiosInstance } from "axios"
|
|
||||||
import { createAdminUser } from "../../helpers/create-admin-user"
|
import { createAdminUser } from "../../helpers/create-admin-user"
|
||||||
|
import { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||||
|
|
||||||
jest.setTimeout(50000)
|
jest.setTimeout(50000)
|
||||||
|
|
||||||
@@ -17,54 +10,41 @@ const adminHeaders = {
|
|||||||
headers: { "x-medusa-access-token": "test_token" },
|
headers: { "x-medusa-access-token": "test_token" },
|
||||||
}
|
}
|
||||||
|
|
||||||
describe("GET /admin/invites", () => {
|
medusaIntegrationTestRunner({
|
||||||
let dbConnection
|
env,
|
||||||
let appContainer
|
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||||
let shutdownServer
|
describe("GET /admin/invites", () => {
|
||||||
let userModuleService: IUserModuleService
|
let appContainer
|
||||||
|
let userModuleService: IUserModuleService
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
const cwd = path.resolve(path.join(__dirname, "..", ".."))
|
appContainer = getContainer()
|
||||||
dbConnection = await initDb({ cwd, env } as any)
|
userModuleService = appContainer.resolve(ModuleRegistrationName.USER)
|
||||||
shutdownServer = await startBootstrapApp({ cwd, env })
|
})
|
||||||
appContainer = getContainer()
|
|
||||||
userModuleService = appContainer.resolve(ModuleRegistrationName.USER)
|
|
||||||
})
|
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
await createAdminUser(dbConnection, adminHeaders)
|
await createAdminUser(dbConnection, adminHeaders, appContainer)
|
||||||
})
|
})
|
||||||
|
|
||||||
afterAll(async () => {
|
it("should list invites", async () => {
|
||||||
const db = useDb()
|
await userModuleService.createInvites({
|
||||||
await db.shutdown()
|
email: "potential_member@test.com",
|
||||||
await shutdownServer()
|
token: "test",
|
||||||
})
|
expires_at: new Date(),
|
||||||
|
})
|
||||||
|
|
||||||
afterEach(async () => {
|
const response = await api.get(`/admin/invites`, adminHeaders)
|
||||||
const db = useDb()
|
|
||||||
await db.teardown()
|
|
||||||
})
|
|
||||||
|
|
||||||
it("should list invites", async () => {
|
expect(response.status).toEqual(200)
|
||||||
await userModuleService.createInvites({
|
expect(response.data).toEqual({
|
||||||
email: "potential_member@test.com",
|
invites: [
|
||||||
token: "test",
|
expect.objectContaining({ email: "potential_member@test.com" }),
|
||||||
expires_at: new Date(),
|
],
|
||||||
|
count: 1,
|
||||||
|
offset: 0,
|
||||||
|
limit: 50,
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
},
|
||||||
const api = useApi()! as AxiosInstance
|
|
||||||
|
|
||||||
const response = await api.get(`/admin/invites`, adminHeaders)
|
|
||||||
|
|
||||||
expect(response.status).toEqual(200)
|
|
||||||
expect(response.data).toEqual({
|
|
||||||
invites: [
|
|
||||||
expect.objectContaining({ email: "potential_member@test.com" }),
|
|
||||||
],
|
|
||||||
count: 1,
|
|
||||||
offset: 0,
|
|
||||||
limit: 50,
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
@@ -1,13 +1,7 @@
|
|||||||
import { IAuthModuleService, IUserModuleService } from "@medusajs/types"
|
import { IUserModuleService } from "@medusajs/types"
|
||||||
import { initDb, useDb } from "../../../environment-helpers/use-db"
|
|
||||||
|
|
||||||
import { AxiosInstance } from "axios"
|
|
||||||
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||||
import { createAdminUser } from "../../helpers/create-admin-user"
|
import { createAdminUser } from "../../helpers/create-admin-user"
|
||||||
import { getContainer } from "../../../environment-helpers/use-container"
|
import { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||||
import path from "path"
|
|
||||||
import { startBootstrapApp } from "../../../environment-helpers/bootstrap-app"
|
|
||||||
import { useApi } from "../../../environment-helpers/use-api"
|
|
||||||
|
|
||||||
jest.setTimeout(50000)
|
jest.setTimeout(50000)
|
||||||
|
|
||||||
@@ -16,52 +10,39 @@ const adminHeaders = {
|
|||||||
headers: { "x-medusa-access-token": "test_token" },
|
headers: { "x-medusa-access-token": "test_token" },
|
||||||
}
|
}
|
||||||
|
|
||||||
describe("POST /admin/invites/:id/resend", () => {
|
medusaIntegrationTestRunner({
|
||||||
let dbConnection
|
env,
|
||||||
let appContainer
|
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||||
let shutdownServer
|
describe("POST /admin/invites/:id/resend", () => {
|
||||||
let userModuleService: IUserModuleService
|
let appContainer
|
||||||
|
let userModuleService: IUserModuleService
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
const cwd = path.resolve(path.join(__dirname, "..", ".."))
|
appContainer = getContainer()
|
||||||
dbConnection = await initDb({ cwd, env } as any)
|
userModuleService = appContainer.resolve(ModuleRegistrationName.USER)
|
||||||
shutdownServer = await startBootstrapApp({ cwd, env })
|
})
|
||||||
appContainer = getContainer()
|
|
||||||
userModuleService = appContainer.resolve(ModuleRegistrationName.USER)
|
|
||||||
})
|
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
await createAdminUser(dbConnection, adminHeaders)
|
await createAdminUser(dbConnection, adminHeaders, appContainer)
|
||||||
})
|
})
|
||||||
|
|
||||||
afterAll(async () => {
|
it("should resend a single invite", async () => {
|
||||||
const db = useDb()
|
const invite = await userModuleService.createInvites({
|
||||||
await db.shutdown()
|
email: "potential_member@test.com",
|
||||||
await shutdownServer()
|
})
|
||||||
})
|
|
||||||
|
|
||||||
afterEach(async () => {
|
const response = await api.post(
|
||||||
const db = useDb()
|
`/admin/invites/${invite.id}/resend`,
|
||||||
await db.teardown()
|
{},
|
||||||
})
|
adminHeaders
|
||||||
|
)
|
||||||
|
|
||||||
it("should resend a single invite", async () => {
|
expect(response.status).toEqual(200)
|
||||||
const invite = await userModuleService.createInvites({
|
expect(response.data.invite.token).not.toEqual(invite.token)
|
||||||
email: "potential_member@test.com",
|
expect(response.data.invite).toEqual(
|
||||||
|
expect.objectContaining({ email: "potential_member@test.com" })
|
||||||
|
)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
},
|
||||||
const api = useApi()! as AxiosInstance
|
|
||||||
|
|
||||||
const response = await api.post(
|
|
||||||
`/admin/invites/${invite.id}/resend`,
|
|
||||||
{},
|
|
||||||
adminHeaders
|
|
||||||
)
|
|
||||||
|
|
||||||
expect(response.status).toEqual(200)
|
|
||||||
expect(response.data.invite.token).not.toEqual(invite.token)
|
|
||||||
expect(response.data.invite).toEqual(
|
|
||||||
expect.objectContaining({ email: "potential_member@test.com" })
|
|
||||||
)
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
@@ -1,13 +1,7 @@
|
|||||||
import { initDb, useDb } from "../../../environment-helpers/use-db"
|
import { IUserModuleService } from "@medusajs/types"
|
||||||
|
|
||||||
import { IAuthModuleService, IUserModuleService } from "@medusajs/types"
|
|
||||||
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||||
import { getContainer } from "../../../environment-helpers/use-container"
|
|
||||||
import path from "path"
|
|
||||||
import { startBootstrapApp } from "../../../environment-helpers/bootstrap-app"
|
|
||||||
import { useApi } from "../../../environment-helpers/use-api"
|
|
||||||
import { AxiosInstance } from "axios"
|
|
||||||
import { createAdminUser } from "../../helpers/create-admin-user"
|
import { createAdminUser } from "../../helpers/create-admin-user"
|
||||||
|
import { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||||
|
|
||||||
jest.setTimeout(50000)
|
jest.setTimeout(50000)
|
||||||
|
|
||||||
@@ -16,47 +10,37 @@ const adminHeaders = {
|
|||||||
headers: { "x-medusa-access-token": "test_token" },
|
headers: { "x-medusa-access-token": "test_token" },
|
||||||
}
|
}
|
||||||
|
|
||||||
describe("GET /admin/invites/:id", () => {
|
medusaIntegrationTestRunner({
|
||||||
let dbConnection
|
env,
|
||||||
let appContainer
|
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||||
let shutdownServer
|
describe("GET /admin/invites/:id", () => {
|
||||||
let userModuleService: IUserModuleService
|
let appContainer
|
||||||
|
let userModuleService: IUserModuleService
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
const cwd = path.resolve(path.join(__dirname, "..", ".."))
|
appContainer = getContainer()
|
||||||
dbConnection = await initDb({ cwd, env } as any)
|
userModuleService = appContainer.resolve(ModuleRegistrationName.USER)
|
||||||
shutdownServer = await startBootstrapApp({ cwd, env })
|
})
|
||||||
appContainer = getContainer()
|
|
||||||
userModuleService = appContainer.resolve(ModuleRegistrationName.USER)
|
|
||||||
})
|
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
await createAdminUser(dbConnection, adminHeaders)
|
await createAdminUser(dbConnection, adminHeaders, appContainer)
|
||||||
})
|
})
|
||||||
|
|
||||||
afterAll(async () => {
|
it("should retrieve a single invite", async () => {
|
||||||
const db = useDb()
|
const invite = await userModuleService.createInvites({
|
||||||
await db.shutdown()
|
email: "potential_member@test.com",
|
||||||
await shutdownServer()
|
})
|
||||||
})
|
|
||||||
|
|
||||||
afterEach(async () => {
|
const response = await api.get(
|
||||||
const db = useDb()
|
`/admin/invites/${invite.id}`,
|
||||||
await db.teardown()
|
adminHeaders
|
||||||
})
|
)
|
||||||
|
|
||||||
it("should retrieve a single invite", async () => {
|
expect(response.status).toEqual(200)
|
||||||
const invite = await userModuleService.createInvites({
|
expect(response.data.invite).toEqual(
|
||||||
email: "potential_member@test.com",
|
expect.objectContaining({ email: "potential_member@test.com" })
|
||||||
|
)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
},
|
||||||
const api = useApi()! as AxiosInstance
|
|
||||||
|
|
||||||
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,200 +6,190 @@ import {
|
|||||||
IRegionModuleService,
|
IRegionModuleService,
|
||||||
ISalesChannelModuleService,
|
ISalesChannelModuleService,
|
||||||
} from "@medusajs/types"
|
} from "@medusajs/types"
|
||||||
import path from "path"
|
import { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||||
import { startBootstrapApp } from "../../../environment-helpers/bootstrap-app"
|
|
||||||
import { getContainer } from "../../../environment-helpers/use-container"
|
|
||||||
import { initDb, useDb } from "../../../environment-helpers/use-db"
|
|
||||||
|
|
||||||
jest.setTimeout(50000)
|
jest.setTimeout(50000)
|
||||||
|
|
||||||
const env = { MEDUSA_FF_MEDUSA_V2: true }
|
const env = { MEDUSA_FF_MEDUSA_V2: true }
|
||||||
|
|
||||||
describe("Cart links", () => {
|
medusaIntegrationTestRunner({
|
||||||
let dbConnection
|
env,
|
||||||
let appContainer
|
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||||
let shutdownServer
|
describe("Cart links", () => {
|
||||||
let cartModuleService: ICartModuleService
|
let appContainer
|
||||||
let regionModule: IRegionModuleService
|
let cartModuleService: ICartModuleService
|
||||||
let customerModule: ICustomerModuleService
|
let regionModule: IRegionModuleService
|
||||||
let scModuleService: ISalesChannelModuleService
|
let customerModule: ICustomerModuleService
|
||||||
let paymentModuleService: IPaymentModuleService
|
let scModuleService: ISalesChannelModuleService
|
||||||
let remoteQuery, remoteLink
|
let paymentModuleService: IPaymentModuleService
|
||||||
|
let remoteQuery, remoteLink
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
const cwd = path.resolve(path.join(__dirname, "..", ".."))
|
appContainer = getContainer()
|
||||||
dbConnection = await initDb({ cwd, env } as any)
|
cartModuleService = appContainer.resolve(ModuleRegistrationName.CART)
|
||||||
shutdownServer = await startBootstrapApp({ cwd, env })
|
regionModule = appContainer.resolve(ModuleRegistrationName.REGION)
|
||||||
appContainer = getContainer()
|
customerModule = appContainer.resolve(ModuleRegistrationName.CUSTOMER)
|
||||||
cartModuleService = appContainer.resolve(ModuleRegistrationName.CART)
|
scModuleService = appContainer.resolve(
|
||||||
regionModule = appContainer.resolve(ModuleRegistrationName.REGION)
|
ModuleRegistrationName.SALES_CHANNEL
|
||||||
customerModule = appContainer.resolve(ModuleRegistrationName.CUSTOMER)
|
)
|
||||||
scModuleService = appContainer.resolve(ModuleRegistrationName.SALES_CHANNEL)
|
regionModule = appContainer.resolve(ModuleRegistrationName.REGION)
|
||||||
regionModule = appContainer.resolve(ModuleRegistrationName.REGION)
|
paymentModuleService = appContainer.resolve(
|
||||||
paymentModuleService = appContainer.resolve(ModuleRegistrationName.PAYMENT)
|
ModuleRegistrationName.PAYMENT
|
||||||
remoteQuery = appContainer.resolve("remoteQuery")
|
)
|
||||||
remoteLink = appContainer.resolve("remoteLink")
|
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",
|
|
||||||
currency_code: "usd",
|
|
||||||
})
|
|
||||||
|
|
||||||
const customer = await customerModule.create({
|
|
||||||
email: "tony@stark.com",
|
|
||||||
})
|
|
||||||
|
|
||||||
const salesChannel = await scModuleService.create({
|
|
||||||
name: "Webshop",
|
|
||||||
})
|
|
||||||
|
|
||||||
const cart = await cartModuleService.create({
|
|
||||||
email: "tony@stark.com",
|
|
||||||
currency_code: "usd",
|
|
||||||
region_id: region.id,
|
|
||||||
sales_channel_id: salesChannel.id,
|
|
||||||
customer_id: customer.id,
|
|
||||||
})
|
|
||||||
|
|
||||||
const paymentCollection =
|
|
||||||
await paymentModuleService.createPaymentCollections({
|
|
||||||
currency_code: "usd",
|
|
||||||
region_id: region.id,
|
|
||||||
amount: 1000,
|
|
||||||
})
|
})
|
||||||
|
|
||||||
await remoteLink.create([
|
it("should query carts, sales channels, customers, regions with remote query", async () => {
|
||||||
{
|
const region = await regionModule.create({
|
||||||
[Modules.CART]: {
|
name: "Region",
|
||||||
cart_id: cart.id,
|
currency_code: "usd",
|
||||||
},
|
})
|
||||||
[Modules.PAYMENT]: {
|
|
||||||
payment_collection_id: paymentCollection.id,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
])
|
|
||||||
|
|
||||||
const carts = await remoteQuery({
|
const customer = await customerModule.create({
|
||||||
cart: {
|
email: "tony@stark.com",
|
||||||
fields: ["id"],
|
})
|
||||||
region: {
|
|
||||||
fields: ["id"],
|
const salesChannel = await scModuleService.create({
|
||||||
},
|
name: "Webshop",
|
||||||
customer: {
|
})
|
||||||
fields: ["id"],
|
|
||||||
},
|
const cart = await cartModuleService.create({
|
||||||
sales_channel: {
|
email: "tony@stark.com",
|
||||||
fields: ["id"],
|
currency_code: "usd",
|
||||||
},
|
region_id: region.id,
|
||||||
payment_collection: {
|
sales_channel_id: salesChannel.id,
|
||||||
fields: ["id"],
|
customer_id: customer.id,
|
||||||
},
|
})
|
||||||
},
|
|
||||||
|
const paymentCollection =
|
||||||
|
await paymentModuleService.createPaymentCollections({
|
||||||
|
currency_code: "usd",
|
||||||
|
region_id: region.id,
|
||||||
|
amount: 1000,
|
||||||
|
})
|
||||||
|
|
||||||
|
await remoteLink.create([
|
||||||
|
{
|
||||||
|
[Modules.CART]: {
|
||||||
|
cart_id: cart.id,
|
||||||
|
},
|
||||||
|
[Modules.PAYMENT]: {
|
||||||
|
payment_collection_id: paymentCollection.id,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
])
|
||||||
|
|
||||||
|
const carts = await remoteQuery({
|
||||||
|
cart: {
|
||||||
|
fields: ["id"],
|
||||||
|
region: {
|
||||||
|
fields: ["id"],
|
||||||
|
},
|
||||||
|
customer: {
|
||||||
|
fields: ["id"],
|
||||||
|
},
|
||||||
|
sales_channel: {
|
||||||
|
fields: ["id"],
|
||||||
|
},
|
||||||
|
payment_collection: {
|
||||||
|
fields: ["id"],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
const salesChannels = await remoteQuery({
|
||||||
|
sales_channel: {
|
||||||
|
fields: ["id"],
|
||||||
|
carts: {
|
||||||
|
fields: ["id"],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
const customers = await remoteQuery({
|
||||||
|
customer: {
|
||||||
|
fields: ["id"],
|
||||||
|
carts: {
|
||||||
|
fields: ["id"],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
const regions = await remoteQuery({
|
||||||
|
region: {
|
||||||
|
fields: ["id"],
|
||||||
|
carts: {
|
||||||
|
fields: ["id"],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
const paymentCollections = await remoteQuery({
|
||||||
|
payment: {
|
||||||
|
fields: ["id"],
|
||||||
|
cart: {
|
||||||
|
fields: ["id"],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(carts).toEqual(
|
||||||
|
expect.arrayContaining([
|
||||||
|
expect.objectContaining({
|
||||||
|
id: cart.id,
|
||||||
|
customer: expect.objectContaining({ id: customer.id }),
|
||||||
|
sales_channel: expect.objectContaining({ id: salesChannel.id }),
|
||||||
|
region: expect.objectContaining({ id: region.id }),
|
||||||
|
payment_collection: expect.objectContaining({
|
||||||
|
id: paymentCollection.id,
|
||||||
|
}),
|
||||||
|
}),
|
||||||
|
])
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(salesChannels).toEqual(
|
||||||
|
expect.arrayContaining([
|
||||||
|
expect.objectContaining({
|
||||||
|
id: salesChannel.id,
|
||||||
|
carts: expect.arrayContaining([
|
||||||
|
expect.objectContaining({ id: cart.id }),
|
||||||
|
]),
|
||||||
|
}),
|
||||||
|
])
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(customers).toEqual(
|
||||||
|
expect.arrayContaining([
|
||||||
|
expect.objectContaining({
|
||||||
|
id: customer.id,
|
||||||
|
carts: expect.arrayContaining([
|
||||||
|
expect.objectContaining({ id: cart.id }),
|
||||||
|
]),
|
||||||
|
}),
|
||||||
|
])
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(regions).toEqual(
|
||||||
|
expect.arrayContaining([
|
||||||
|
expect.objectContaining({
|
||||||
|
id: region.id,
|
||||||
|
carts: expect.arrayContaining([
|
||||||
|
expect.objectContaining({ id: cart.id }),
|
||||||
|
]),
|
||||||
|
}),
|
||||||
|
])
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(paymentCollections).toEqual(
|
||||||
|
expect.arrayContaining([
|
||||||
|
expect.objectContaining({
|
||||||
|
id: paymentCollection.id,
|
||||||
|
cart: expect.objectContaining({ id: cart.id }),
|
||||||
|
}),
|
||||||
|
])
|
||||||
|
)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
},
|
||||||
const salesChannels = await remoteQuery({
|
|
||||||
sales_channel: {
|
|
||||||
fields: ["id"],
|
|
||||||
carts: {
|
|
||||||
fields: ["id"],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
const customers = await remoteQuery({
|
|
||||||
customer: {
|
|
||||||
fields: ["id"],
|
|
||||||
carts: {
|
|
||||||
fields: ["id"],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
const regions = await remoteQuery({
|
|
||||||
region: {
|
|
||||||
fields: ["id"],
|
|
||||||
carts: {
|
|
||||||
fields: ["id"],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
const paymentCollections = await remoteQuery({
|
|
||||||
payment: {
|
|
||||||
fields: ["id"],
|
|
||||||
cart: {
|
|
||||||
fields: ["id"],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
expect(carts).toEqual(
|
|
||||||
expect.arrayContaining([
|
|
||||||
expect.objectContaining({
|
|
||||||
id: cart.id,
|
|
||||||
customer: expect.objectContaining({ id: customer.id }),
|
|
||||||
sales_channel: expect.objectContaining({ id: salesChannel.id }),
|
|
||||||
region: expect.objectContaining({ id: region.id }),
|
|
||||||
payment_collection: expect.objectContaining({
|
|
||||||
id: paymentCollection.id,
|
|
||||||
}),
|
|
||||||
}),
|
|
||||||
])
|
|
||||||
)
|
|
||||||
|
|
||||||
expect(salesChannels).toEqual(
|
|
||||||
expect.arrayContaining([
|
|
||||||
expect.objectContaining({
|
|
||||||
id: salesChannel.id,
|
|
||||||
carts: expect.arrayContaining([
|
|
||||||
expect.objectContaining({ id: cart.id }),
|
|
||||||
]),
|
|
||||||
}),
|
|
||||||
])
|
|
||||||
)
|
|
||||||
|
|
||||||
expect(customers).toEqual(
|
|
||||||
expect.arrayContaining([
|
|
||||||
expect.objectContaining({
|
|
||||||
id: customer.id,
|
|
||||||
carts: expect.arrayContaining([
|
|
||||||
expect.objectContaining({ id: cart.id }),
|
|
||||||
]),
|
|
||||||
}),
|
|
||||||
])
|
|
||||||
)
|
|
||||||
|
|
||||||
expect(regions).toEqual(
|
|
||||||
expect.arrayContaining([
|
|
||||||
expect.objectContaining({
|
|
||||||
id: region.id,
|
|
||||||
carts: expect.arrayContaining([
|
|
||||||
expect.objectContaining({ id: cart.id }),
|
|
||||||
]),
|
|
||||||
}),
|
|
||||||
])
|
|
||||||
)
|
|
||||||
|
|
||||||
expect(paymentCollections).toEqual(
|
|
||||||
expect.arrayContaining([
|
|
||||||
expect.objectContaining({
|
|
||||||
id: paymentCollection.id,
|
|
||||||
cart: expect.objectContaining({ id: cart.id }),
|
|
||||||
}),
|
|
||||||
])
|
|
||||||
)
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
@@ -1,91 +1,77 @@
|
|||||||
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||||
import { ICartModuleService, IRegionModuleService } from "@medusajs/types"
|
import { ICartModuleService, IRegionModuleService } from "@medusajs/types"
|
||||||
import path from "path"
|
import { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||||
import { startBootstrapApp } from "../../../environment-helpers/bootstrap-app"
|
|
||||||
import { getContainer } from "../../../environment-helpers/use-container"
|
|
||||||
import { initDb, useDb } from "../../../environment-helpers/use-db"
|
|
||||||
|
|
||||||
jest.setTimeout(50000)
|
jest.setTimeout(50000)
|
||||||
|
|
||||||
const env = { MEDUSA_FF_MEDUSA_V2: true }
|
const env = { MEDUSA_FF_MEDUSA_V2: true }
|
||||||
|
|
||||||
describe("Link: Cart Region", () => {
|
medusaIntegrationTestRunner({
|
||||||
let dbConnection
|
env,
|
||||||
let appContainer
|
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||||
let shutdownServer
|
describe("Link: Cart Region", () => {
|
||||||
let cartModuleService: ICartModuleService
|
let appContainer
|
||||||
let regionModule: IRegionModuleService
|
let cartModuleService: ICartModuleService
|
||||||
let remoteQuery
|
let regionModule: IRegionModuleService
|
||||||
|
let remoteQuery
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
const cwd = path.resolve(path.join(__dirname, "..", ".."))
|
appContainer = getContainer()
|
||||||
dbConnection = await initDb({ cwd, env } as any)
|
cartModuleService = appContainer.resolve(ModuleRegistrationName.CART)
|
||||||
shutdownServer = await startBootstrapApp({ cwd, env })
|
regionModule = appContainer.resolve(ModuleRegistrationName.REGION)
|
||||||
appContainer = getContainer()
|
remoteQuery = appContainer.resolve("remoteQuery")
|
||||||
cartModuleService = appContainer.resolve(ModuleRegistrationName.CART)
|
})
|
||||||
regionModule = appContainer.resolve(ModuleRegistrationName.REGION)
|
|
||||||
remoteQuery = appContainer.resolve("remoteQuery")
|
|
||||||
})
|
|
||||||
|
|
||||||
afterAll(async () => {
|
it("should query carts and regions with remote query", async () => {
|
||||||
const db = useDb()
|
const region = await regionModule.create({
|
||||||
await db.shutdown()
|
name: "Region",
|
||||||
await shutdownServer()
|
currency_code: "usd",
|
||||||
})
|
})
|
||||||
|
|
||||||
afterEach(async () => {
|
const cart = await cartModuleService.create({
|
||||||
const db = useDb()
|
email: "tony@stark.com",
|
||||||
await db.teardown()
|
currency_code: "usd",
|
||||||
})
|
region_id: region.id,
|
||||||
|
})
|
||||||
|
|
||||||
it("should query carts and regions with remote query", async () => {
|
const carts = await remoteQuery({
|
||||||
const region = await regionModule.create({
|
cart: {
|
||||||
name: "Region",
|
fields: ["id"],
|
||||||
currency_code: "usd",
|
region: {
|
||||||
|
fields: ["id"],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
const regions = await remoteQuery({
|
||||||
|
region: {
|
||||||
|
fields: ["id"],
|
||||||
|
carts: {
|
||||||
|
fields: ["id"],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(carts).toEqual(
|
||||||
|
expect.arrayContaining([
|
||||||
|
expect.objectContaining({
|
||||||
|
id: cart.id,
|
||||||
|
region: expect.objectContaining({ id: region.id }),
|
||||||
|
}),
|
||||||
|
])
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(regions).toEqual(
|
||||||
|
expect.arrayContaining([
|
||||||
|
expect.objectContaining({
|
||||||
|
id: region.id,
|
||||||
|
carts: expect.arrayContaining([
|
||||||
|
expect.objectContaining({ id: cart.id }),
|
||||||
|
]),
|
||||||
|
}),
|
||||||
|
])
|
||||||
|
)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
},
|
||||||
const cart = await cartModuleService.create({
|
|
||||||
email: "tony@stark.com",
|
|
||||||
currency_code: "usd",
|
|
||||||
region_id: region.id,
|
|
||||||
})
|
|
||||||
|
|
||||||
const carts = await remoteQuery({
|
|
||||||
cart: {
|
|
||||||
fields: ["id"],
|
|
||||||
region: {
|
|
||||||
fields: ["id"],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
const regions = await remoteQuery({
|
|
||||||
region: {
|
|
||||||
fields: ["id"],
|
|
||||||
carts: {
|
|
||||||
fields: ["id"],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
expect(carts).toEqual(
|
|
||||||
expect.arrayContaining([
|
|
||||||
expect.objectContaining({
|
|
||||||
id: cart.id,
|
|
||||||
region: expect.objectContaining({ id: region.id }),
|
|
||||||
}),
|
|
||||||
])
|
|
||||||
)
|
|
||||||
|
|
||||||
expect(regions).toEqual(
|
|
||||||
expect.arrayContaining([
|
|
||||||
expect.objectContaining({
|
|
||||||
id: region.id,
|
|
||||||
carts: expect.arrayContaining([
|
|
||||||
expect.objectContaining({ id: cart.id }),
|
|
||||||
]),
|
|
||||||
}),
|
|
||||||
])
|
|
||||||
)
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
+76
-88
@@ -3,103 +3,91 @@ import {
|
|||||||
IApiKeyModuleService,
|
IApiKeyModuleService,
|
||||||
ISalesChannelModuleService,
|
ISalesChannelModuleService,
|
||||||
} from "@medusajs/types"
|
} from "@medusajs/types"
|
||||||
import path from "path"
|
|
||||||
import { startBootstrapApp } from "../../../environment-helpers/bootstrap-app"
|
|
||||||
import { getContainer } from "../../../environment-helpers/use-container"
|
|
||||||
import { initDb, useDb } from "../../../environment-helpers/use-db"
|
|
||||||
import { remoteQueryObjectFromString } from "@medusajs/utils"
|
import { remoteQueryObjectFromString } from "@medusajs/utils"
|
||||||
|
import { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||||
|
|
||||||
jest.setTimeout(50000)
|
jest.setTimeout(50000)
|
||||||
|
|
||||||
const env = { MEDUSA_FF_MEDUSA_V2: true }
|
const env = { MEDUSA_FF_MEDUSA_V2: true }
|
||||||
|
|
||||||
describe("Publishable keys and sales channel link", () => {
|
medusaIntegrationTestRunner({
|
||||||
let dbConnection
|
env,
|
||||||
let appContainer
|
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||||
let shutdownServer
|
describe("Publishable keys and sales channel link", () => {
|
||||||
let apiKeyModule: IApiKeyModuleService
|
let appContainer
|
||||||
let scModuleService: ISalesChannelModuleService
|
let apiKeyModule: IApiKeyModuleService
|
||||||
let remoteQuery
|
let scModuleService: ISalesChannelModuleService
|
||||||
let remoteLink
|
let remoteQuery
|
||||||
|
let remoteLink
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
const cwd = path.resolve(path.join(__dirname, "..", ".."))
|
appContainer = getContainer()
|
||||||
dbConnection = await initDb({ cwd, env } as any)
|
apiKeyModule = appContainer.resolve(ModuleRegistrationName.API_KEY)
|
||||||
shutdownServer = await startBootstrapApp({ cwd, env })
|
scModuleService = appContainer.resolve(
|
||||||
appContainer = getContainer()
|
ModuleRegistrationName.SALES_CHANNEL
|
||||||
apiKeyModule = appContainer.resolve(ModuleRegistrationName.API_KEY)
|
)
|
||||||
scModuleService = appContainer.resolve(ModuleRegistrationName.SALES_CHANNEL)
|
remoteQuery = appContainer.resolve("remoteQuery")
|
||||||
remoteQuery = appContainer.resolve("remoteQuery")
|
remoteLink = appContainer.resolve("remoteLink")
|
||||||
remoteLink = appContainer.resolve("remoteLink")
|
})
|
||||||
})
|
|
||||||
|
|
||||||
afterAll(async () => {
|
it("should query api key and sales channels link with remote query", async () => {
|
||||||
const db = useDb()
|
const salesChannel = await scModuleService.create({
|
||||||
await db.shutdown()
|
name: "Webshop",
|
||||||
await shutdownServer()
|
})
|
||||||
})
|
|
||||||
|
|
||||||
afterEach(async () => {
|
const apiKeys = await apiKeyModule.create([
|
||||||
const db = useDb()
|
{
|
||||||
await db.teardown()
|
title: "Api key",
|
||||||
})
|
type: "publishable",
|
||||||
|
created_by: "test",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: "Api key 2",
|
||||||
|
type: "publishable",
|
||||||
|
created_by: "test",
|
||||||
|
},
|
||||||
|
])
|
||||||
|
|
||||||
it("should query api key and sales channels link with remote query", async () => {
|
await remoteLink.create([
|
||||||
const salesChannel = await scModuleService.create({
|
{
|
||||||
name: "Webshop",
|
[Modules.API_KEY]: {
|
||||||
|
publishable_key_id: apiKeys[0].id,
|
||||||
|
},
|
||||||
|
[Modules.SALES_CHANNEL]: {
|
||||||
|
sales_channel_id: salesChannel.id,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
[Modules.API_KEY]: {
|
||||||
|
publishable_key_id: apiKeys[1].id,
|
||||||
|
},
|
||||||
|
[Modules.SALES_CHANNEL]: {
|
||||||
|
sales_channel_id: salesChannel.id,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
])
|
||||||
|
|
||||||
|
const queryObject = remoteQueryObjectFromString({
|
||||||
|
entryPoint: "api_key",
|
||||||
|
variables: {
|
||||||
|
filters: { token: apiKeys[0].token },
|
||||||
|
},
|
||||||
|
fields: ["id", "sales_channels.id"],
|
||||||
|
})
|
||||||
|
const keyLinks = await remoteQuery(queryObject)
|
||||||
|
|
||||||
|
expect(keyLinks).toHaveLength(1)
|
||||||
|
expect(keyLinks).toEqual(
|
||||||
|
expect.arrayContaining([
|
||||||
|
expect.objectContaining({
|
||||||
|
id: apiKeys[0].id,
|
||||||
|
sales_channels: expect.arrayContaining([
|
||||||
|
expect.objectContaining({ id: salesChannel.id }),
|
||||||
|
]),
|
||||||
|
}),
|
||||||
|
])
|
||||||
|
)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
},
|
||||||
const apiKeys = await apiKeyModule.create([
|
|
||||||
{
|
|
||||||
title: "Api key",
|
|
||||||
type: "publishable",
|
|
||||||
created_by: "test",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: "Api key 2",
|
|
||||||
type: "publishable",
|
|
||||||
created_by: "test",
|
|
||||||
},
|
|
||||||
])
|
|
||||||
|
|
||||||
await remoteLink.create([
|
|
||||||
{
|
|
||||||
[Modules.API_KEY]: {
|
|
||||||
publishable_key_id: apiKeys[0].id,
|
|
||||||
},
|
|
||||||
[Modules.SALES_CHANNEL]: {
|
|
||||||
sales_channel_id: salesChannel.id,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
[Modules.API_KEY]: {
|
|
||||||
publishable_key_id: apiKeys[1].id,
|
|
||||||
},
|
|
||||||
[Modules.SALES_CHANNEL]: {
|
|
||||||
sales_channel_id: salesChannel.id,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
])
|
|
||||||
|
|
||||||
const queryObject = remoteQueryObjectFromString({
|
|
||||||
entryPoint: "api_key",
|
|
||||||
variables: {
|
|
||||||
filters: { token: apiKeys[0].token },
|
|
||||||
},
|
|
||||||
fields: ["id", "sales_channels.id"],
|
|
||||||
})
|
|
||||||
const keyLinks = await remoteQuery(queryObject)
|
|
||||||
|
|
||||||
expect(keyLinks).toHaveLength(1)
|
|
||||||
expect(keyLinks).toEqual(
|
|
||||||
expect.arrayContaining([
|
|
||||||
expect.objectContaining({
|
|
||||||
id: apiKeys[0].id,
|
|
||||||
sales_channels: expect.arrayContaining([
|
|
||||||
expect.objectContaining({ id: salesChannel.id }),
|
|
||||||
]),
|
|
||||||
}),
|
|
||||||
])
|
|
||||||
)
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
@@ -1,106 +1,92 @@
|
|||||||
import { ModuleRegistrationName, Modules } from "@medusajs/modules-sdk"
|
import { ModuleRegistrationName, Modules } from "@medusajs/modules-sdk"
|
||||||
import { IPaymentModuleService, IRegionModuleService } from "@medusajs/types"
|
import { IPaymentModuleService, IRegionModuleService } from "@medusajs/types"
|
||||||
import path from "path"
|
import { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||||
import { startBootstrapApp } from "../../../environment-helpers/bootstrap-app"
|
|
||||||
import { getContainer } from "../../../environment-helpers/use-container"
|
|
||||||
import { initDb, useDb } from "../../../environment-helpers/use-db"
|
|
||||||
|
|
||||||
jest.setTimeout(50000)
|
jest.setTimeout(50000)
|
||||||
|
|
||||||
const env = { MEDUSA_FF_MEDUSA_V2: true }
|
const env = { MEDUSA_FF_MEDUSA_V2: true }
|
||||||
|
|
||||||
describe("Region and Payment Providers", () => {
|
medusaIntegrationTestRunner({
|
||||||
let dbConnection
|
env,
|
||||||
let appContainer
|
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||||
let shutdownServer
|
describe("Region and Payment Providers", () => {
|
||||||
let regionModule: IRegionModuleService
|
let appContainer
|
||||||
let paymentModule: IPaymentModuleService
|
let regionModule: IRegionModuleService
|
||||||
let remoteQuery
|
let paymentModule: IPaymentModuleService
|
||||||
let remoteLink
|
let remoteQuery
|
||||||
|
let remoteLink
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
const cwd = path.resolve(path.join(__dirname, "..", ".."))
|
appContainer = getContainer()
|
||||||
dbConnection = await initDb({ cwd, env } as any)
|
regionModule = appContainer.resolve(ModuleRegistrationName.REGION)
|
||||||
shutdownServer = await startBootstrapApp({ cwd, env })
|
paymentModule = appContainer.resolve(ModuleRegistrationName.PAYMENT)
|
||||||
appContainer = getContainer()
|
remoteQuery = appContainer.resolve("remoteQuery")
|
||||||
regionModule = appContainer.resolve(ModuleRegistrationName.REGION)
|
remoteLink = appContainer.resolve("remoteLink")
|
||||||
paymentModule = appContainer.resolve(ModuleRegistrationName.PAYMENT)
|
})
|
||||||
remoteQuery = appContainer.resolve("remoteQuery")
|
|
||||||
remoteLink = appContainer.resolve("remoteLink")
|
|
||||||
})
|
|
||||||
|
|
||||||
afterAll(async () => {
|
it("should query region and payment provider link with remote query", async () => {
|
||||||
const db = useDb()
|
const region = await regionModule.create({
|
||||||
await db.shutdown()
|
name: "North America",
|
||||||
await shutdownServer()
|
currency_code: "usd",
|
||||||
})
|
})
|
||||||
|
|
||||||
afterEach(async () => {
|
await remoteLink.create([
|
||||||
const db = useDb()
|
{
|
||||||
await db.teardown()
|
[Modules.REGION]: {
|
||||||
})
|
region_id: region.id,
|
||||||
|
},
|
||||||
|
[Modules.PAYMENT]: {
|
||||||
|
payment_provider_id: "pp_system_default",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
])
|
||||||
|
|
||||||
it("should query region and payment provider link with remote query", async () => {
|
const links = await remoteQuery({
|
||||||
const region = await regionModule.create({
|
region: {
|
||||||
name: "North America",
|
fields: ["id"],
|
||||||
currency_code: "usd",
|
payment_providers: {
|
||||||
})
|
fields: ["id"],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
await remoteLink.create([
|
const otherLink = await remoteQuery({
|
||||||
{
|
payment_providers: {
|
||||||
[Modules.REGION]: {
|
fields: ["id"],
|
||||||
region_id: region.id,
|
regions: {
|
||||||
},
|
fields: ["id"],
|
||||||
[Modules.PAYMENT]: {
|
},
|
||||||
payment_provider_id: "pp_system_default",
|
},
|
||||||
},
|
})
|
||||||
},
|
|
||||||
])
|
|
||||||
|
|
||||||
const links = await remoteQuery({
|
expect(links).toHaveLength(1)
|
||||||
region: {
|
expect(links).toEqual(
|
||||||
fields: ["id"],
|
expect.arrayContaining([
|
||||||
payment_providers: {
|
|
||||||
fields: ["id"],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
const otherLink = await remoteQuery({
|
|
||||||
payment_providers: {
|
|
||||||
fields: ["id"],
|
|
||||||
regions: {
|
|
||||||
fields: ["id"],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
expect(links).toHaveLength(1)
|
|
||||||
expect(links).toEqual(
|
|
||||||
expect.arrayContaining([
|
|
||||||
expect.objectContaining({
|
|
||||||
id: region.id,
|
|
||||||
payment_providers: expect.arrayContaining([
|
|
||||||
expect.objectContaining({
|
|
||||||
id: "pp_system_default",
|
|
||||||
}),
|
|
||||||
]),
|
|
||||||
}),
|
|
||||||
])
|
|
||||||
)
|
|
||||||
|
|
||||||
expect(otherLink).toHaveLength(1)
|
|
||||||
expect(otherLink).toEqual(
|
|
||||||
expect.arrayContaining([
|
|
||||||
expect.objectContaining({
|
|
||||||
id: "pp_system_default",
|
|
||||||
regions: expect.arrayContaining([
|
|
||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
id: region.id,
|
id: region.id,
|
||||||
|
payment_providers: expect.arrayContaining([
|
||||||
|
expect.objectContaining({
|
||||||
|
id: "pp_system_default",
|
||||||
|
}),
|
||||||
|
]),
|
||||||
}),
|
}),
|
||||||
]),
|
])
|
||||||
}),
|
)
|
||||||
])
|
|
||||||
)
|
expect(otherLink).toHaveLength(1)
|
||||||
})
|
expect(otherLink).toEqual(
|
||||||
|
expect.arrayContaining([
|
||||||
|
expect.objectContaining({
|
||||||
|
id: "pp_system_default",
|
||||||
|
regions: expect.arrayContaining([
|
||||||
|
expect.objectContaining({
|
||||||
|
id: region.id,
|
||||||
|
}),
|
||||||
|
]),
|
||||||
|
}),
|
||||||
|
])
|
||||||
|
)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
},
|
||||||
})
|
})
|
||||||
@@ -1,29 +1,27 @@
|
|||||||
import dbFactory from "./../../../environment-helpers/use-template-db"
|
import { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||||
|
|
||||||
jest.setTimeout(30000)
|
jest.setTimeout(30000)
|
||||||
|
|
||||||
describe("Standalone Modules", () => {
|
medusaIntegrationTestRunner({
|
||||||
beforeAll(async () => {
|
testSuite: ({ dbConnection }) => {
|
||||||
const DB_HOST = process.env.DB_HOST
|
describe("Standalone Modules", () => {
|
||||||
const DB_USERNAME = process.env.DB_USERNAME
|
beforeAll(async () => {
|
||||||
const DB_PASSWORD = process.env.DB_PASSWORD
|
process.env.POSTGRES_URL = dbConnection.manager.connection.options.url
|
||||||
const DB_NAME = process.env.DB_TEMP_NAME
|
})
|
||||||
|
|
||||||
process.env.POSTGRES_URL = `postgres://${DB_USERNAME}:${DB_PASSWORD}@${DB_HOST}/${DB_NAME}`
|
afterAll(async () => {
|
||||||
await dbFactory.createFromTemplate(DB_NAME)
|
process.env.POSTGRES_URL = undefined
|
||||||
})
|
})
|
||||||
|
|
||||||
afterAll(async () => {
|
it("Should migrate database and initialize Product module using connection string from environment variable ", async function () {
|
||||||
process.env.POSTGRES_URL = undefined
|
const { initialize, runMigrations } = require("@medusajs/product")
|
||||||
})
|
await runMigrations()
|
||||||
|
|
||||||
it("Should migrate database and initialize Product module using connection string from environment variable ", async function () {
|
const product = await initialize()
|
||||||
const { initialize, runMigrations } = require("@medusajs/product")
|
const productList = await product.list()
|
||||||
await runMigrations()
|
|
||||||
|
|
||||||
const product = await initialize()
|
expect(productList).toEqual(expect.arrayContaining([]))
|
||||||
const productList = await product.list()
|
})
|
||||||
|
})
|
||||||
expect(productList).toEqual(expect.arrayContaining([]))
|
},
|
||||||
})
|
|
||||||
})
|
})
|
||||||
@@ -4,139 +4,126 @@ import {
|
|||||||
} from "@medusajs/core-flows"
|
} from "@medusajs/core-flows"
|
||||||
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||||
import { IPaymentModuleService, IRegionModuleService } from "@medusajs/types"
|
import { IPaymentModuleService, IRegionModuleService } from "@medusajs/types"
|
||||||
import path from "path"
|
import { medusaIntegrationTestRunner } from "medusa-test-utils/dist"
|
||||||
import { startBootstrapApp } from "../../../environment-helpers/bootstrap-app"
|
|
||||||
import { getContainer } from "../../../environment-helpers/use-container"
|
|
||||||
import { initDb, useDb } from "../../../environment-helpers/use-db"
|
|
||||||
|
|
||||||
jest.setTimeout(50000)
|
jest.setTimeout(50000)
|
||||||
|
|
||||||
const env = { MEDUSA_FF_MEDUSA_V2: true }
|
const env = { MEDUSA_FF_MEDUSA_V2: true }
|
||||||
|
|
||||||
describe("Carts workflows", () => {
|
medusaIntegrationTestRunner({
|
||||||
let dbConnection
|
env,
|
||||||
let appContainer
|
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||||
let shutdownServer
|
describe("Carts workflows", () => {
|
||||||
let paymentModule: IPaymentModuleService
|
let appContainer
|
||||||
let regionModule: IRegionModuleService
|
let paymentModule: IPaymentModuleService
|
||||||
let remoteLink
|
let regionModule: IRegionModuleService
|
||||||
|
let remoteLink
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
const cwd = path.resolve(path.join(__dirname, "..", ".."))
|
appContainer = getContainer()
|
||||||
dbConnection = await initDb({ cwd, env } as any)
|
paymentModule = appContainer.resolve(ModuleRegistrationName.PAYMENT)
|
||||||
shutdownServer = await startBootstrapApp({ cwd, env })
|
regionModule = appContainer.resolve(ModuleRegistrationName.REGION)
|
||||||
appContainer = getContainer()
|
remoteLink = appContainer.resolve("remoteLink")
|
||||||
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({
|
|
||||||
currency_code: "usd",
|
|
||||||
name: "US",
|
|
||||||
})
|
})
|
||||||
|
|
||||||
let paymentCollection = await paymentModule.createPaymentCollections({
|
describe("createPaymentSessionWorkflow", () => {
|
||||||
currency_code: "usd",
|
it("should create payment sessions", async () => {
|
||||||
amount: 1000,
|
const region = await regionModule.create({
|
||||||
region_id: region.id,
|
currency_code: "usd",
|
||||||
})
|
name: "US",
|
||||||
|
})
|
||||||
|
|
||||||
await createPaymentSessionsWorkflow(appContainer).run({
|
let paymentCollection = await paymentModule.createPaymentCollections({
|
||||||
input: {
|
currency_code: "usd",
|
||||||
payment_collection_id: paymentCollection.id,
|
amount: 1000,
|
||||||
provider_id: "pp_system_default",
|
region_id: region.id,
|
||||||
context: {},
|
})
|
||||||
data: {},
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
paymentCollection = await paymentModule.retrievePaymentCollection(
|
await createPaymentSessionsWorkflow(appContainer).run({
|
||||||
paymentCollection.id,
|
input: {
|
||||||
{
|
payment_collection_id: paymentCollection.id,
|
||||||
relations: ["payment_sessions"],
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
expect(paymentCollection).toEqual(
|
|
||||||
expect.objectContaining({
|
|
||||||
id: paymentCollection.id,
|
|
||||||
currency_code: "usd",
|
|
||||||
amount: 1000,
|
|
||||||
region_id: region.id,
|
|
||||||
payment_sessions: expect.arrayContaining([
|
|
||||||
expect.objectContaining({
|
|
||||||
amount: 1000,
|
|
||||||
currency_code: "usd",
|
|
||||||
provider_id: "pp_system_default",
|
provider_id: "pp_system_default",
|
||||||
}),
|
context: {},
|
||||||
]),
|
data: {},
|
||||||
})
|
},
|
||||||
)
|
})
|
||||||
})
|
|
||||||
|
|
||||||
describe("compensation", () => {
|
paymentCollection = await paymentModule.retrievePaymentCollection(
|
||||||
it("should delete created payment collection if a subsequent step fails", async () => {
|
paymentCollection.id,
|
||||||
const workflow = createPaymentSessionsWorkflow(appContainer)
|
{
|
||||||
|
relations: ["payment_sessions"],
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
workflow.appendAction("throw", createPaymentSessionsWorkflowId, {
|
expect(paymentCollection).toEqual(
|
||||||
invoke: async function failStep() {
|
expect.objectContaining({
|
||||||
throw new Error(
|
id: paymentCollection.id,
|
||||||
`Failed to do something after creating payment sessions`
|
currency_code: "usd",
|
||||||
)
|
amount: 1000,
|
||||||
},
|
region_id: region.id,
|
||||||
|
payment_sessions: expect.arrayContaining([
|
||||||
|
expect.objectContaining({
|
||||||
|
amount: 1000,
|
||||||
|
currency_code: "usd",
|
||||||
|
provider_id: "pp_system_default",
|
||||||
|
}),
|
||||||
|
]),
|
||||||
|
})
|
||||||
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
const region = await regionModule.create({
|
describe("compensation", () => {
|
||||||
currency_code: "usd",
|
it("should delete created payment collection if a subsequent step fails", async () => {
|
||||||
name: "US",
|
const workflow = createPaymentSessionsWorkflow(appContainer)
|
||||||
|
|
||||||
|
workflow.appendAction("throw", createPaymentSessionsWorkflowId, {
|
||||||
|
invoke: async function failStep() {
|
||||||
|
throw new Error(
|
||||||
|
`Failed to do something after creating payment sessions`
|
||||||
|
)
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
const region = await regionModule.create({
|
||||||
|
currency_code: "usd",
|
||||||
|
name: "US",
|
||||||
|
})
|
||||||
|
|
||||||
|
let paymentCollection =
|
||||||
|
await paymentModule.createPaymentCollections({
|
||||||
|
currency_code: "usd",
|
||||||
|
amount: 1000,
|
||||||
|
region_id: region.id,
|
||||||
|
})
|
||||||
|
|
||||||
|
const { errors } = await workflow.run({
|
||||||
|
input: {
|
||||||
|
payment_collection_id: paymentCollection.id,
|
||||||
|
provider_id: "pp_system_default",
|
||||||
|
context: {},
|
||||||
|
data: {},
|
||||||
|
},
|
||||||
|
throwOnError: false,
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(errors).toEqual([
|
||||||
|
{
|
||||||
|
action: "throw",
|
||||||
|
handlerType: "invoke",
|
||||||
|
error: new Error(
|
||||||
|
`Failed to do something after creating payment sessions`
|
||||||
|
),
|
||||||
|
},
|
||||||
|
])
|
||||||
|
|
||||||
|
const sessions = await paymentModule.listPaymentSessions({
|
||||||
|
payment_collection_id: paymentCollection.id,
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(sessions).toHaveLength(0)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
let paymentCollection = await paymentModule.createPaymentCollections({
|
|
||||||
currency_code: "usd",
|
|
||||||
amount: 1000,
|
|
||||||
region_id: region.id,
|
|
||||||
})
|
|
||||||
|
|
||||||
const { errors } = await workflow.run({
|
|
||||||
input: {
|
|
||||||
payment_collection_id: paymentCollection.id,
|
|
||||||
provider_id: "pp_system_default",
|
|
||||||
context: {},
|
|
||||||
data: {},
|
|
||||||
},
|
|
||||||
throwOnError: false,
|
|
||||||
})
|
|
||||||
|
|
||||||
expect(errors).toEqual([
|
|
||||||
{
|
|
||||||
action: "throw",
|
|
||||||
handlerType: "invoke",
|
|
||||||
error: new Error(
|
|
||||||
`Failed to do something after creating payment sessions`
|
|
||||||
),
|
|
||||||
},
|
|
||||||
])
|
|
||||||
|
|
||||||
const sessions = await paymentModule.listPaymentSessions({
|
|
||||||
payment_collection_id: paymentCollection.id,
|
|
||||||
})
|
|
||||||
|
|
||||||
expect(sessions).toHaveLength(0)
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
},
|
||||||
})
|
})
|
||||||
@@ -1,74 +1,60 @@
|
|||||||
import { ModuleRegistrationName, Modules } from "@medusajs/modules-sdk"
|
import { ModuleRegistrationName, Modules } from "@medusajs/modules-sdk"
|
||||||
import { IRegionModuleService } from "@medusajs/types"
|
import { IRegionModuleService } from "@medusajs/types"
|
||||||
import path from "path"
|
import { medusaIntegrationTestRunner } from "medusa-test-utils/dist"
|
||||||
import { startBootstrapApp } from "../../../environment-helpers/bootstrap-app"
|
|
||||||
import { useApi } from "../../../environment-helpers/use-api"
|
|
||||||
import { getContainer } from "../../../environment-helpers/use-container"
|
|
||||||
import { initDb, useDb } from "../../../environment-helpers/use-db"
|
|
||||||
|
|
||||||
jest.setTimeout(50000)
|
jest.setTimeout(50000)
|
||||||
|
|
||||||
const env = { MEDUSA_FF_MEDUSA_V2: true }
|
const env = { MEDUSA_FF_MEDUSA_V2: true }
|
||||||
|
|
||||||
describe("Payments", () => {
|
medusaIntegrationTestRunner({
|
||||||
let dbConnection
|
env,
|
||||||
let appContainer
|
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||||
let shutdownServer
|
describe("Payments", () => {
|
||||||
let regionService: IRegionModuleService
|
let appContainer
|
||||||
let remoteLink
|
let regionService: IRegionModuleService
|
||||||
|
let remoteLink
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
const cwd = path.resolve(path.join(__dirname, "..", ".."))
|
appContainer = getContainer()
|
||||||
dbConnection = await initDb({ cwd, env } as any)
|
regionService = appContainer.resolve(ModuleRegistrationName.REGION)
|
||||||
shutdownServer = await startBootstrapApp({ cwd, env })
|
remoteLink = appContainer.resolve("remoteLink")
|
||||||
appContainer = getContainer()
|
})
|
||||||
regionService = appContainer.resolve(ModuleRegistrationName.REGION)
|
|
||||||
remoteLink = appContainer.resolve("remoteLink")
|
|
||||||
})
|
|
||||||
|
|
||||||
afterAll(async () => {
|
it("should list payment providers", async () => {
|
||||||
const db = useDb()
|
const region = await regionService.create({
|
||||||
await db.shutdown()
|
name: "Test Region",
|
||||||
await shutdownServer()
|
currency_code: "usd",
|
||||||
})
|
})
|
||||||
|
|
||||||
afterEach(async () => {
|
let response = await api.get(
|
||||||
const db = useDb()
|
`/store/regions/${region.id}/payment-providers`
|
||||||
await db.teardown()
|
)
|
||||||
})
|
|
||||||
|
|
||||||
it("should list payment providers", async () => {
|
expect(response.status).toEqual(200)
|
||||||
const region = await regionService.create({
|
expect(response.data.payment_providers).toEqual([])
|
||||||
name: "Test Region",
|
|
||||||
currency_code: "usd",
|
await remoteLink.create([
|
||||||
|
{
|
||||||
|
[Modules.REGION]: {
|
||||||
|
region_id: region.id,
|
||||||
|
},
|
||||||
|
[Modules.PAYMENT]: {
|
||||||
|
payment_provider_id: "pp_system_default",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
])
|
||||||
|
|
||||||
|
response = await api.get(
|
||||||
|
`/store/regions/${region.id}/payment-providers`
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(response.status).toEqual(200)
|
||||||
|
expect(response.data.payment_providers).toEqual([
|
||||||
|
expect.objectContaining({
|
||||||
|
id: "pp_system_default",
|
||||||
|
}),
|
||||||
|
])
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
},
|
||||||
const api = useApi() as any
|
|
||||||
let response = await api.get(
|
|
||||||
`/store/regions/${region.id}/payment-providers`
|
|
||||||
)
|
|
||||||
|
|
||||||
expect(response.status).toEqual(200)
|
|
||||||
expect(response.data.payment_providers).toEqual([])
|
|
||||||
|
|
||||||
await remoteLink.create([
|
|
||||||
{
|
|
||||||
[Modules.REGION]: {
|
|
||||||
region_id: region.id,
|
|
||||||
},
|
|
||||||
[Modules.PAYMENT]: {
|
|
||||||
payment_provider_id: "pp_system_default",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
])
|
|
||||||
|
|
||||||
response = await api.get(`/store/regions/${region.id}/payment-providers`)
|
|
||||||
|
|
||||||
expect(response.status).toEqual(200)
|
|
||||||
expect(response.data.payment_providers).toEqual([
|
|
||||||
expect.objectContaining({
|
|
||||||
id: "pp_system_default",
|
|
||||||
}),
|
|
||||||
])
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
+188
-204
@@ -1,6 +1,3 @@
|
|||||||
import { useApi } from "../../../../environment-helpers/use-api"
|
|
||||||
import { getContainer } from "../../../../environment-helpers/use-container"
|
|
||||||
import { initDb, useDb } from "../../../../environment-helpers/use-db"
|
|
||||||
import {
|
import {
|
||||||
simpleProductFactory,
|
simpleProductFactory,
|
||||||
simpleRegionFactory,
|
simpleRegionFactory,
|
||||||
@@ -11,11 +8,10 @@ import {
|
|||||||
PriceListStatus,
|
PriceListStatus,
|
||||||
PriceListType,
|
PriceListType,
|
||||||
} from "@medusajs/types"
|
} from "@medusajs/types"
|
||||||
import path from "path"
|
|
||||||
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
|
|
||||||
import adminSeeder from "../../../../helpers/admin-seeder"
|
import adminSeeder from "../../../../helpers/admin-seeder"
|
||||||
import { createDefaultRuleTypes } from "../../../helpers/create-default-rule-types"
|
import { createDefaultRuleTypes } from "../../../helpers/create-default-rule-types"
|
||||||
import { createVariantPriceSet } from "../../../helpers/create-variant-price-set"
|
import { createVariantPriceSet } from "../../../helpers/create-variant-price-set"
|
||||||
|
import { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||||
|
|
||||||
jest.setTimeout(50000)
|
jest.setTimeout(50000)
|
||||||
|
|
||||||
@@ -29,205 +25,193 @@ const env = {
|
|||||||
MEDUSA_FF_MEDUSA_V2: true,
|
MEDUSA_FF_MEDUSA_V2: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
describe.skip("POST /admin/price-lists/:id/prices/batch", () => {
|
medusaIntegrationTestRunner({
|
||||||
let dbConnection
|
env,
|
||||||
let appContainer
|
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||||
let shutdownServer
|
describe.skip("POST /admin/price-lists/:id/prices/batch", () => {
|
||||||
let product
|
let appContainer
|
||||||
let variant
|
let product
|
||||||
let pricingModuleService: IPricingModuleService
|
let variant
|
||||||
|
let pricingModuleService: IPricingModuleService
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
|
appContainer = getContainer()
|
||||||
dbConnection = await initDb({ cwd, env } as any)
|
pricingModuleService = appContainer.resolve("pricingModuleService")
|
||||||
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)
|
|
||||||
|
|
||||||
await simpleRegionFactory(dbConnection, {
|
|
||||||
id: "test-region",
|
|
||||||
name: "Test Region",
|
|
||||||
currency_code: "usd",
|
|
||||||
tax_rate: 0,
|
|
||||||
})
|
|
||||||
|
|
||||||
product = await simpleProductFactory(dbConnection, {
|
|
||||||
id: "test-product-with-variant",
|
|
||||||
variants: [
|
|
||||||
{
|
|
||||||
options: [{ option_id: "test-product-option-1", value: "test" }],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
options: [
|
|
||||||
{
|
|
||||||
id: "test-product-option-1",
|
|
||||||
title: "Test option 1",
|
|
||||||
},
|
|
||||||
],
|
|
||||||
})
|
|
||||||
|
|
||||||
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([
|
|
||||||
{
|
|
||||||
title: "test price list",
|
|
||||||
description: "test",
|
|
||||||
ends_at: new Date().toISOString(),
|
|
||||||
starts_at: new Date().toISOString(),
|
|
||||||
status: PriceListStatus.ACTIVE,
|
|
||||||
type: PriceListType.OVERRIDE,
|
|
||||||
},
|
|
||||||
])
|
|
||||||
|
|
||||||
await createVariantPriceSet({
|
|
||||||
container: appContainer,
|
|
||||||
variantId: variant.id,
|
|
||||||
prices: [
|
|
||||||
{
|
|
||||||
amount: 3000,
|
|
||||||
currency_code: "usd",
|
|
||||||
},
|
|
||||||
],
|
|
||||||
})
|
|
||||||
|
|
||||||
const api = useApi() as any
|
|
||||||
const data = {
|
|
||||||
prices: [
|
|
||||||
{
|
|
||||||
variant_id: variant.id,
|
|
||||||
amount: 5000,
|
|
||||||
currency_code: "usd",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
amount: 6000,
|
|
||||||
region_id: "test-region",
|
|
||||||
variant_id: variant.id,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
}
|
|
||||||
|
|
||||||
await api.post(
|
|
||||||
`admin/price-lists/${priceList.id}/prices/batch`,
|
|
||||||
data,
|
|
||||||
adminHeaders
|
|
||||||
)
|
|
||||||
|
|
||||||
const response = await api.get(
|
|
||||||
`/admin/price-lists/${priceList.id}`,
|
|
||||||
adminHeaders
|
|
||||||
)
|
|
||||||
|
|
||||||
expect(response.status).toEqual(200)
|
|
||||||
expect(response.data.price_list).toEqual(
|
|
||||||
expect.objectContaining({
|
|
||||||
id: expect.any(String),
|
|
||||||
created_at: expect.any(String),
|
|
||||||
updated_at: expect.any(String),
|
|
||||||
deleted_at: null,
|
|
||||||
name: "test price list",
|
|
||||||
description: "test",
|
|
||||||
type: "override",
|
|
||||||
status: "active",
|
|
||||||
starts_at: expect.any(String),
|
|
||||||
ends_at: expect.any(String),
|
|
||||||
customer_groups: [],
|
|
||||||
prices: [
|
|
||||||
expect.objectContaining({
|
|
||||||
id: expect.any(String),
|
|
||||||
created_at: expect.any(String),
|
|
||||||
updated_at: expect.any(String),
|
|
||||||
deleted_at: null,
|
|
||||||
currency_code: "usd",
|
|
||||||
amount: 5000,
|
|
||||||
min_quantity: null,
|
|
||||||
max_quantity: null,
|
|
||||||
price_list_id: expect.any(String),
|
|
||||||
region_id: null,
|
|
||||||
variant: expect.objectContaining({
|
|
||||||
id: expect.any(String),
|
|
||||||
created_at: expect.any(String),
|
|
||||||
updated_at: expect.any(String),
|
|
||||||
deleted_at: null,
|
|
||||||
title: expect.any(String),
|
|
||||||
product_id: expect.any(String),
|
|
||||||
sku: null,
|
|
||||||
barcode: null,
|
|
||||||
ean: null,
|
|
||||||
upc: null,
|
|
||||||
variant_rank: 0,
|
|
||||||
inventory_quantity: 10,
|
|
||||||
allow_backorder: false,
|
|
||||||
manage_inventory: true,
|
|
||||||
hs_code: null,
|
|
||||||
origin_country: null,
|
|
||||||
mid_code: null,
|
|
||||||
material: null,
|
|
||||||
weight: null,
|
|
||||||
length: null,
|
|
||||||
height: null,
|
|
||||||
width: null,
|
|
||||||
metadata: null,
|
|
||||||
}),
|
|
||||||
variant_id: expect.any(String),
|
|
||||||
}),
|
|
||||||
expect.objectContaining({
|
|
||||||
id: expect.any(String),
|
|
||||||
created_at: expect.any(String),
|
|
||||||
updated_at: expect.any(String),
|
|
||||||
deleted_at: null,
|
|
||||||
currency_code: "usd",
|
|
||||||
amount: 6000,
|
|
||||||
min_quantity: null,
|
|
||||||
max_quantity: null,
|
|
||||||
price_list_id: expect.any(String),
|
|
||||||
region_id: "test-region",
|
|
||||||
variant: expect.objectContaining({
|
|
||||||
id: expect.any(String),
|
|
||||||
created_at: expect.any(String),
|
|
||||||
updated_at: expect.any(String),
|
|
||||||
deleted_at: null,
|
|
||||||
title: expect.any(String),
|
|
||||||
product_id: expect.any(String),
|
|
||||||
sku: null,
|
|
||||||
barcode: null,
|
|
||||||
ean: null,
|
|
||||||
upc: null,
|
|
||||||
variant_rank: 0,
|
|
||||||
inventory_quantity: 10,
|
|
||||||
allow_backorder: false,
|
|
||||||
manage_inventory: true,
|
|
||||||
hs_code: null,
|
|
||||||
origin_country: null,
|
|
||||||
mid_code: null,
|
|
||||||
material: null,
|
|
||||||
weight: null,
|
|
||||||
length: null,
|
|
||||||
height: null,
|
|
||||||
width: null,
|
|
||||||
metadata: null,
|
|
||||||
}),
|
|
||||||
variant_id: expect.any(String),
|
|
||||||
}),
|
|
||||||
],
|
|
||||||
})
|
})
|
||||||
)
|
|
||||||
})
|
beforeEach(async () => {
|
||||||
|
await adminSeeder(dbConnection)
|
||||||
|
await createDefaultRuleTypes(appContainer)
|
||||||
|
|
||||||
|
await simpleRegionFactory(dbConnection, {
|
||||||
|
id: "test-region",
|
||||||
|
name: "Test Region",
|
||||||
|
currency_code: "usd",
|
||||||
|
tax_rate: 0,
|
||||||
|
})
|
||||||
|
|
||||||
|
product = await simpleProductFactory(dbConnection, {
|
||||||
|
id: "test-product-with-variant",
|
||||||
|
variants: [
|
||||||
|
{
|
||||||
|
options: [{ option_id: "test-product-option-1", value: "test" }],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
id: "test-product-option-1",
|
||||||
|
title: "Test option 1",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
})
|
||||||
|
|
||||||
|
variant = product.variants[0]
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should update money amounts if variant id is present in prices", async () => {
|
||||||
|
const [priceList] = await pricingModuleService.createPriceLists([
|
||||||
|
{
|
||||||
|
title: "test price list",
|
||||||
|
description: "test",
|
||||||
|
ends_at: new Date().toISOString(),
|
||||||
|
starts_at: new Date().toISOString(),
|
||||||
|
status: PriceListStatus.ACTIVE,
|
||||||
|
type: PriceListType.OVERRIDE,
|
||||||
|
},
|
||||||
|
])
|
||||||
|
|
||||||
|
await createVariantPriceSet({
|
||||||
|
container: appContainer,
|
||||||
|
variantId: variant.id,
|
||||||
|
prices: [
|
||||||
|
{
|
||||||
|
amount: 3000,
|
||||||
|
currency_code: "usd",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
})
|
||||||
|
|
||||||
|
const data = {
|
||||||
|
prices: [
|
||||||
|
{
|
||||||
|
variant_id: variant.id,
|
||||||
|
amount: 5000,
|
||||||
|
currency_code: "usd",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
amount: 6000,
|
||||||
|
region_id: "test-region",
|
||||||
|
variant_id: variant.id,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}
|
||||||
|
|
||||||
|
await api.post(
|
||||||
|
`admin/price-lists/${priceList.id}/prices/batch`,
|
||||||
|
data,
|
||||||
|
adminHeaders
|
||||||
|
)
|
||||||
|
|
||||||
|
const response = await api.get(
|
||||||
|
`/admin/price-lists/${priceList.id}`,
|
||||||
|
adminHeaders
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(response.status).toEqual(200)
|
||||||
|
expect(response.data.price_list).toEqual(
|
||||||
|
expect.objectContaining({
|
||||||
|
id: expect.any(String),
|
||||||
|
created_at: expect.any(String),
|
||||||
|
updated_at: expect.any(String),
|
||||||
|
deleted_at: null,
|
||||||
|
name: "test price list",
|
||||||
|
description: "test",
|
||||||
|
type: "override",
|
||||||
|
status: "active",
|
||||||
|
starts_at: expect.any(String),
|
||||||
|
ends_at: expect.any(String),
|
||||||
|
customer_groups: [],
|
||||||
|
prices: [
|
||||||
|
expect.objectContaining({
|
||||||
|
id: expect.any(String),
|
||||||
|
created_at: expect.any(String),
|
||||||
|
updated_at: expect.any(String),
|
||||||
|
deleted_at: null,
|
||||||
|
currency_code: "usd",
|
||||||
|
amount: 5000,
|
||||||
|
min_quantity: null,
|
||||||
|
max_quantity: null,
|
||||||
|
price_list_id: expect.any(String),
|
||||||
|
region_id: null,
|
||||||
|
variant: expect.objectContaining({
|
||||||
|
id: expect.any(String),
|
||||||
|
created_at: expect.any(String),
|
||||||
|
updated_at: expect.any(String),
|
||||||
|
deleted_at: null,
|
||||||
|
title: expect.any(String),
|
||||||
|
product_id: expect.any(String),
|
||||||
|
sku: null,
|
||||||
|
barcode: null,
|
||||||
|
ean: null,
|
||||||
|
upc: null,
|
||||||
|
variant_rank: 0,
|
||||||
|
inventory_quantity: 10,
|
||||||
|
allow_backorder: false,
|
||||||
|
manage_inventory: true,
|
||||||
|
hs_code: null,
|
||||||
|
origin_country: null,
|
||||||
|
mid_code: null,
|
||||||
|
material: null,
|
||||||
|
weight: null,
|
||||||
|
length: null,
|
||||||
|
height: null,
|
||||||
|
width: null,
|
||||||
|
metadata: null,
|
||||||
|
}),
|
||||||
|
variant_id: expect.any(String),
|
||||||
|
}),
|
||||||
|
expect.objectContaining({
|
||||||
|
id: expect.any(String),
|
||||||
|
created_at: expect.any(String),
|
||||||
|
updated_at: expect.any(String),
|
||||||
|
deleted_at: null,
|
||||||
|
currency_code: "usd",
|
||||||
|
amount: 6000,
|
||||||
|
min_quantity: null,
|
||||||
|
max_quantity: null,
|
||||||
|
price_list_id: expect.any(String),
|
||||||
|
region_id: "test-region",
|
||||||
|
variant: expect.objectContaining({
|
||||||
|
id: expect.any(String),
|
||||||
|
created_at: expect.any(String),
|
||||||
|
updated_at: expect.any(String),
|
||||||
|
deleted_at: null,
|
||||||
|
title: expect.any(String),
|
||||||
|
product_id: expect.any(String),
|
||||||
|
sku: null,
|
||||||
|
barcode: null,
|
||||||
|
ean: null,
|
||||||
|
upc: null,
|
||||||
|
variant_rank: 0,
|
||||||
|
inventory_quantity: 10,
|
||||||
|
allow_backorder: false,
|
||||||
|
manage_inventory: true,
|
||||||
|
hs_code: null,
|
||||||
|
origin_country: null,
|
||||||
|
mid_code: null,
|
||||||
|
material: null,
|
||||||
|
weight: null,
|
||||||
|
length: null,
|
||||||
|
height: null,
|
||||||
|
width: null,
|
||||||
|
metadata: null,
|
||||||
|
}),
|
||||||
|
variant_id: expect.any(String),
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
})
|
||||||
|
)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
},
|
||||||
})
|
})
|
||||||
@@ -1,6 +1,3 @@
|
|||||||
import { useApi } from "../../../../environment-helpers/use-api"
|
|
||||||
import { getContainer } from "../../../../environment-helpers/use-container"
|
|
||||||
import { initDb, useDb } from "../../../../environment-helpers/use-db"
|
|
||||||
import {
|
import {
|
||||||
simpleCustomerGroupFactory,
|
simpleCustomerGroupFactory,
|
||||||
simpleProductFactory,
|
simpleProductFactory,
|
||||||
@@ -8,11 +5,10 @@ import {
|
|||||||
} from "../../../../factories"
|
} from "../../../../factories"
|
||||||
|
|
||||||
import { IPricingModuleService } from "@medusajs/types"
|
import { IPricingModuleService } from "@medusajs/types"
|
||||||
import path from "path"
|
|
||||||
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
|
|
||||||
import adminSeeder from "../../../../helpers/admin-seeder"
|
import adminSeeder from "../../../../helpers/admin-seeder"
|
||||||
import { createDefaultRuleTypes } from "../../../helpers/create-default-rule-types"
|
import { createDefaultRuleTypes } from "../../../helpers/create-default-rule-types"
|
||||||
import { createVariantPriceSet } from "../../../helpers/create-variant-price-set"
|
import { createVariantPriceSet } from "../../../helpers/create-variant-price-set"
|
||||||
|
import { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||||
|
|
||||||
jest.setTimeout(50000)
|
jest.setTimeout(50000)
|
||||||
|
|
||||||
@@ -26,166 +22,154 @@ const env = {
|
|||||||
MEDUSA_FF_MEDUSA_V2: true,
|
MEDUSA_FF_MEDUSA_V2: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
describe.skip("POST /admin/price-lists", () => {
|
medusaIntegrationTestRunner({
|
||||||
let dbConnection
|
env,
|
||||||
let appContainer
|
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||||
let shutdownServer
|
describe.skip("POST /admin/price-lists", () => {
|
||||||
let product
|
let appContainer
|
||||||
let variant
|
let product
|
||||||
let pricingModuleService: IPricingModuleService
|
let variant
|
||||||
|
let pricingModuleService: IPricingModuleService
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
|
appContainer = getContainer()
|
||||||
dbConnection = await initDb({ cwd, env } as any)
|
pricingModuleService = appContainer.resolve("pricingModuleService")
|
||||||
shutdownServer = await startBootstrapApp({ cwd, env })
|
})
|
||||||
appContainer = getContainer()
|
|
||||||
pricingModuleService = appContainer.resolve("pricingModuleService")
|
|
||||||
})
|
|
||||||
|
|
||||||
afterAll(async () => {
|
beforeEach(async () => {
|
||||||
const db = useDb()
|
await adminSeeder(dbConnection)
|
||||||
await db.shutdown()
|
await createDefaultRuleTypes(appContainer)
|
||||||
await shutdownServer()
|
await simpleCustomerGroupFactory(dbConnection, {
|
||||||
})
|
id: "customer-group-1",
|
||||||
|
name: "Test Group",
|
||||||
|
})
|
||||||
|
|
||||||
beforeEach(async () => {
|
await simpleRegionFactory(dbConnection, {
|
||||||
await adminSeeder(dbConnection)
|
id: "test-region",
|
||||||
await createDefaultRuleTypes(appContainer)
|
name: "Test Region",
|
||||||
await simpleCustomerGroupFactory(dbConnection, {
|
|
||||||
id: "customer-group-1",
|
|
||||||
name: "Test Group",
|
|
||||||
})
|
|
||||||
|
|
||||||
await simpleRegionFactory(dbConnection, {
|
|
||||||
id: "test-region",
|
|
||||||
name: "Test Region",
|
|
||||||
currency_code: "usd",
|
|
||||||
tax_rate: 0,
|
|
||||||
})
|
|
||||||
|
|
||||||
product = await simpleProductFactory(dbConnection, {
|
|
||||||
id: "test-product-with-variant",
|
|
||||||
variants: [
|
|
||||||
{
|
|
||||||
options: [{ option_id: "test-product-option-1", value: "test" }],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
options: [
|
|
||||||
{
|
|
||||||
id: "test-product-option-1",
|
|
||||||
title: "Test option 1",
|
|
||||||
},
|
|
||||||
],
|
|
||||||
})
|
|
||||||
|
|
||||||
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,
|
|
||||||
variantId: variant.id,
|
|
||||||
prices: [
|
|
||||||
{
|
|
||||||
amount: 3000,
|
|
||||||
currency_code: "usd",
|
currency_code: "usd",
|
||||||
},
|
tax_rate: 0,
|
||||||
],
|
})
|
||||||
})
|
|
||||||
|
|
||||||
const api = useApi() as any
|
product = await simpleProductFactory(dbConnection, {
|
||||||
const data = {
|
id: "test-product-with-variant",
|
||||||
name: "test price list",
|
variants: [
|
||||||
description: "test",
|
{
|
||||||
type: "override",
|
options: [{ option_id: "test-product-option-1", value: "test" }],
|
||||||
customer_groups: [{ id: "customer-group-1" }],
|
},
|
||||||
status: "active",
|
],
|
||||||
starts_at: new Date(),
|
options: [
|
||||||
prices: [
|
{
|
||||||
{
|
id: "test-product-option-1",
|
||||||
amount: 400,
|
title: "Test option 1",
|
||||||
variant_id: variant.id,
|
},
|
||||||
currency_code: "usd",
|
],
|
||||||
},
|
})
|
||||||
],
|
|
||||||
}
|
|
||||||
|
|
||||||
const result = await api.post(`admin/price-lists`, data, adminHeaders)
|
variant = product.variants[0]
|
||||||
|
})
|
||||||
|
|
||||||
let response = await api.get(
|
it("should create price list and money amounts", async () => {
|
||||||
`/admin/price-lists/${result.data.price_list.id}`,
|
await createVariantPriceSet({
|
||||||
adminHeaders
|
container: appContainer,
|
||||||
)
|
variantId: variant.id,
|
||||||
|
prices: [
|
||||||
|
{
|
||||||
|
amount: 3000,
|
||||||
|
currency_code: "usd",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
})
|
||||||
|
|
||||||
expect(response.status).toEqual(200)
|
const data = {
|
||||||
expect(response.data.price_list).toEqual(
|
name: "test price list",
|
||||||
expect.objectContaining({
|
description: "test",
|
||||||
id: expect.any(String),
|
type: "override",
|
||||||
created_at: expect.any(String),
|
customer_groups: [{ id: "customer-group-1" }],
|
||||||
updated_at: expect.any(String),
|
status: "active",
|
||||||
deleted_at: null,
|
starts_at: new Date(),
|
||||||
name: "test price list",
|
prices: [
|
||||||
description: "test",
|
{
|
||||||
type: "override",
|
amount: 400,
|
||||||
status: "active",
|
variant_id: variant.id,
|
||||||
starts_at: expect.any(String),
|
currency_code: "usd",
|
||||||
ends_at: null,
|
},
|
||||||
customer_groups: [
|
],
|
||||||
{
|
}
|
||||||
id: expect.any(String),
|
|
||||||
created_at: expect.any(String),
|
const result = await api.post(`admin/price-lists`, data, adminHeaders)
|
||||||
updated_at: expect.any(String),
|
|
||||||
deleted_at: null,
|
let response = await api.get(
|
||||||
name: "Test Group",
|
`/admin/price-lists/${result.data.price_list.id}`,
|
||||||
metadata: null,
|
adminHeaders
|
||||||
},
|
)
|
||||||
],
|
|
||||||
prices: [
|
expect(response.status).toEqual(200)
|
||||||
|
expect(response.data.price_list).toEqual(
|
||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
id: expect.any(String),
|
id: expect.any(String),
|
||||||
created_at: expect.any(String),
|
created_at: expect.any(String),
|
||||||
updated_at: expect.any(String),
|
updated_at: expect.any(String),
|
||||||
deleted_at: null,
|
deleted_at: null,
|
||||||
currency_code: "usd",
|
name: "test price list",
|
||||||
amount: 400,
|
description: "test",
|
||||||
min_quantity: null,
|
type: "override",
|
||||||
max_quantity: null,
|
status: "active",
|
||||||
price_list_id: expect.any(String),
|
starts_at: expect.any(String),
|
||||||
region_id: null,
|
ends_at: null,
|
||||||
variant: expect.objectContaining({
|
customer_groups: [
|
||||||
id: expect.any(String),
|
{
|
||||||
created_at: expect.any(String),
|
id: expect.any(String),
|
||||||
updated_at: expect.any(String),
|
created_at: expect.any(String),
|
||||||
deleted_at: null,
|
updated_at: expect.any(String),
|
||||||
title: expect.any(String),
|
deleted_at: null,
|
||||||
product_id: expect.any(String),
|
name: "Test Group",
|
||||||
sku: null,
|
metadata: null,
|
||||||
barcode: null,
|
},
|
||||||
ean: null,
|
],
|
||||||
upc: null,
|
prices: [
|
||||||
variant_rank: 0,
|
expect.objectContaining({
|
||||||
inventory_quantity: 10,
|
id: expect.any(String),
|
||||||
allow_backorder: false,
|
created_at: expect.any(String),
|
||||||
manage_inventory: true,
|
updated_at: expect.any(String),
|
||||||
hs_code: null,
|
deleted_at: null,
|
||||||
origin_country: null,
|
currency_code: "usd",
|
||||||
mid_code: null,
|
amount: 400,
|
||||||
material: null,
|
min_quantity: null,
|
||||||
weight: null,
|
max_quantity: null,
|
||||||
length: null,
|
price_list_id: expect.any(String),
|
||||||
height: null,
|
region_id: null,
|
||||||
width: null,
|
variant: expect.objectContaining({
|
||||||
metadata: null,
|
id: expect.any(String),
|
||||||
}),
|
created_at: expect.any(String),
|
||||||
variant_id: expect.any(String),
|
updated_at: expect.any(String),
|
||||||
}),
|
deleted_at: null,
|
||||||
],
|
title: expect.any(String),
|
||||||
|
product_id: expect.any(String),
|
||||||
|
sku: null,
|
||||||
|
barcode: null,
|
||||||
|
ean: null,
|
||||||
|
upc: null,
|
||||||
|
variant_rank: 0,
|
||||||
|
inventory_quantity: 10,
|
||||||
|
allow_backorder: false,
|
||||||
|
manage_inventory: true,
|
||||||
|
hs_code: null,
|
||||||
|
origin_country: null,
|
||||||
|
mid_code: null,
|
||||||
|
material: null,
|
||||||
|
weight: null,
|
||||||
|
length: null,
|
||||||
|
height: null,
|
||||||
|
width: null,
|
||||||
|
metadata: null,
|
||||||
|
}),
|
||||||
|
variant_id: expect.any(String),
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
})
|
||||||
|
)
|
||||||
})
|
})
|
||||||
)
|
})
|
||||||
})
|
},
|
||||||
})
|
})
|
||||||
+126
-146
@@ -1,18 +1,13 @@
|
|||||||
import { useApi } from "../../../../environment-helpers/use-api"
|
|
||||||
import { getContainer } from "../../../../environment-helpers/use-container"
|
|
||||||
import { initDb, useDb } from "../../../../environment-helpers/use-db"
|
|
||||||
import {
|
import {
|
||||||
simpleProductFactory,
|
simpleProductFactory,
|
||||||
simpleRegionFactory,
|
simpleRegionFactory,
|
||||||
} from "../../../../factories"
|
} from "../../../../factories"
|
||||||
|
|
||||||
import { IPricingModuleService } from "@medusajs/types"
|
import { IPricingModuleService } from "@medusajs/types"
|
||||||
import path from "path"
|
|
||||||
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
|
|
||||||
import adminSeeder from "../../../../helpers/admin-seeder"
|
import adminSeeder from "../../../../helpers/admin-seeder"
|
||||||
import { createDefaultRuleTypes } from "../../../helpers/create-default-rule-types"
|
import { createDefaultRuleTypes } from "../../../helpers/create-default-rule-types"
|
||||||
import { createVariantPriceSet } from "../../../helpers/create-variant-price-set"
|
import { createVariantPriceSet } from "../../../helpers/create-variant-price-set"
|
||||||
import { AxiosInstance } from "axios"
|
import { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||||
|
|
||||||
jest.setTimeout(50000)
|
jest.setTimeout(50000)
|
||||||
|
|
||||||
@@ -26,155 +21,140 @@ const env = {
|
|||||||
MEDUSA_FF_MEDUSA_V2: true,
|
MEDUSA_FF_MEDUSA_V2: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
describe.skip("DELETE /admin/price-lists/:id/products/:productId/batch", () => {
|
medusaIntegrationTestRunner({
|
||||||
let dbConnection
|
env,
|
||||||
let appContainer
|
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||||
let shutdownServer
|
describe.skip("DELETE /admin/price-lists/:id/products/:productId/batch", () => {
|
||||||
let product
|
let appContainer
|
||||||
let variant1
|
let product
|
||||||
let priceSet
|
let variant1
|
||||||
let priceListId
|
let priceSet
|
||||||
let pricingModuleService: IPricingModuleService
|
let priceListId
|
||||||
|
let pricingModuleService: IPricingModuleService
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
|
appContainer = getContainer()
|
||||||
dbConnection = await initDb({ cwd, env } as any)
|
pricingModuleService = appContainer.resolve("pricingModuleService")
|
||||||
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)
|
|
||||||
|
|
||||||
await simpleRegionFactory(dbConnection, {
|
|
||||||
id: "test-region",
|
|
||||||
name: "Test Region",
|
|
||||||
currency_code: "usd",
|
|
||||||
tax_rate: 0,
|
|
||||||
})
|
|
||||||
|
|
||||||
product = await simpleProductFactory(dbConnection, {
|
|
||||||
id: "test-product-with-variant",
|
|
||||||
variants: [
|
|
||||||
{
|
|
||||||
options: [{ option_id: "test-product-option-1", value: "test" }],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
options: [
|
|
||||||
{
|
|
||||||
id: "test-product-option-1",
|
|
||||||
title: "Test option 1",
|
|
||||||
},
|
|
||||||
],
|
|
||||||
})
|
|
||||||
|
|
||||||
variant1 = product.variants[0]
|
|
||||||
|
|
||||||
priceSet = await createVariantPriceSet({
|
|
||||||
container: appContainer,
|
|
||||||
variantId: variant1.id,
|
|
||||||
prices: [
|
|
||||||
{
|
|
||||||
amount: 3000,
|
|
||||||
currency_code: "usd",
|
|
||||||
},
|
|
||||||
],
|
|
||||||
})
|
|
||||||
|
|
||||||
const data = {
|
|
||||||
name: "test price list",
|
|
||||||
description: "test",
|
|
||||||
type: "override",
|
|
||||||
customer_groups: [],
|
|
||||||
status: "active",
|
|
||||||
prices: [
|
|
||||||
{
|
|
||||||
amount: 400,
|
|
||||||
variant_id: variant1.id,
|
|
||||||
currency_code: "usd",
|
|
||||||
},
|
|
||||||
],
|
|
||||||
}
|
|
||||||
|
|
||||||
const priceListResult = await api.post(
|
|
||||||
`admin/price-lists`,
|
|
||||||
data,
|
|
||||||
adminHeaders
|
|
||||||
)
|
|
||||||
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],
|
|
||||||
})
|
})
|
||||||
expect(priceSetMoneyAmounts.length).toEqual(2)
|
|
||||||
|
|
||||||
const deleteRes = await api.delete(
|
beforeEach(async () => {
|
||||||
`/admin/price-lists/${priceListId}/products/prices/batch`,
|
await adminSeeder(dbConnection)
|
||||||
{
|
await createDefaultRuleTypes(appContainer)
|
||||||
headers: adminHeaders.headers,
|
|
||||||
data: {
|
|
||||||
product_ids: [product.id],
|
|
||||||
},
|
|
||||||
}
|
|
||||||
)
|
|
||||||
expect(deleteRes.status).toEqual(200)
|
|
||||||
|
|
||||||
priceSetMoneyAmounts = await pricingModuleService.listPriceSetMoneyAmounts({
|
await simpleRegionFactory(dbConnection, {
|
||||||
price_set_id: [priceSet.id],
|
id: "test-region",
|
||||||
})
|
name: "Test Region",
|
||||||
|
currency_code: "usd",
|
||||||
|
tax_rate: 0,
|
||||||
|
})
|
||||||
|
|
||||||
expect(priceSetMoneyAmounts.length).toEqual(1)
|
product = await simpleProductFactory(dbConnection, {
|
||||||
expect(priceSetMoneyAmounts).toEqual([
|
id: "test-product-with-variant",
|
||||||
expect.objectContaining({
|
variants: [
|
||||||
price_list: null,
|
{
|
||||||
}),
|
options: [{ option_id: "test-product-option-1", value: "test" }],
|
||||||
])
|
},
|
||||||
})
|
],
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
id: "test-product-option-1",
|
||||||
|
title: "Test option 1",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
})
|
||||||
|
|
||||||
it("should delete prices based on single product id", async () => {
|
variant1 = product.variants[0]
|
||||||
const api = useApi()! as AxiosInstance
|
|
||||||
|
|
||||||
let priceSetMoneyAmounts =
|
priceSet = await createVariantPriceSet({
|
||||||
await pricingModuleService.listPriceSetMoneyAmounts({
|
container: appContainer,
|
||||||
price_set_id: [priceSet.id],
|
variantId: variant1.id,
|
||||||
|
prices: [
|
||||||
|
{
|
||||||
|
amount: 3000,
|
||||||
|
currency_code: "usd",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
})
|
||||||
|
|
||||||
|
const data = {
|
||||||
|
name: "test price list",
|
||||||
|
description: "test",
|
||||||
|
type: "override",
|
||||||
|
customer_groups: [],
|
||||||
|
status: "active",
|
||||||
|
prices: [
|
||||||
|
{
|
||||||
|
amount: 400,
|
||||||
|
variant_id: variant1.id,
|
||||||
|
currency_code: "usd",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}
|
||||||
|
|
||||||
|
const priceListResult = await api.post(
|
||||||
|
`admin/price-lists`,
|
||||||
|
data,
|
||||||
|
adminHeaders
|
||||||
|
)
|
||||||
|
priceListId = priceListResult.data.price_list.id
|
||||||
})
|
})
|
||||||
expect(priceSetMoneyAmounts.length).toEqual(2)
|
|
||||||
|
|
||||||
const deleteRes = await api.delete(
|
it("should delete prices in batch based on product ids", async () => {
|
||||||
`/admin/price-lists/${priceListId}/products/${product.id}/prices`,
|
let priceSetMoneyAmounts =
|
||||||
adminHeaders
|
await pricingModuleService.listPriceSetMoneyAmounts({
|
||||||
)
|
price_set_id: [priceSet.id],
|
||||||
expect(deleteRes.status).toEqual(200)
|
})
|
||||||
|
expect(priceSetMoneyAmounts.length).toEqual(2)
|
||||||
|
|
||||||
priceSetMoneyAmounts = await pricingModuleService.listPriceSetMoneyAmounts({
|
const deleteRes = await api.delete(
|
||||||
price_set_id: [priceSet.id],
|
`/admin/price-lists/${priceListId}/products/prices/batch`,
|
||||||
|
{
|
||||||
|
headers: adminHeaders.headers,
|
||||||
|
data: {
|
||||||
|
product_ids: [product.id],
|
||||||
|
},
|
||||||
|
}
|
||||||
|
)
|
||||||
|
expect(deleteRes.status).toEqual(200)
|
||||||
|
|
||||||
|
priceSetMoneyAmounts =
|
||||||
|
await pricingModuleService.listPriceSetMoneyAmounts({
|
||||||
|
price_set_id: [priceSet.id],
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(priceSetMoneyAmounts.length).toEqual(1)
|
||||||
|
expect(priceSetMoneyAmounts).toEqual([
|
||||||
|
expect.objectContaining({
|
||||||
|
price_list: null,
|
||||||
|
}),
|
||||||
|
])
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should delete prices based on single product id", async () => {
|
||||||
|
let priceSetMoneyAmounts =
|
||||||
|
await pricingModuleService.listPriceSetMoneyAmounts({
|
||||||
|
price_set_id: [priceSet.id],
|
||||||
|
})
|
||||||
|
expect(priceSetMoneyAmounts.length).toEqual(2)
|
||||||
|
|
||||||
|
const deleteRes = await api.delete(
|
||||||
|
`/admin/price-lists/${priceListId}/products/${product.id}/prices`,
|
||||||
|
adminHeaders
|
||||||
|
)
|
||||||
|
expect(deleteRes.status).toEqual(200)
|
||||||
|
|
||||||
|
priceSetMoneyAmounts =
|
||||||
|
await pricingModuleService.listPriceSetMoneyAmounts({
|
||||||
|
price_set_id: [priceSet.id],
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(priceSetMoneyAmounts.length).toEqual(1)
|
||||||
|
expect(priceSetMoneyAmounts).toEqual([
|
||||||
|
expect.objectContaining({
|
||||||
|
price_list: null,
|
||||||
|
}),
|
||||||
|
])
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
},
|
||||||
expect(priceSetMoneyAmounts.length).toEqual(1)
|
|
||||||
expect(priceSetMoneyAmounts).toEqual([
|
|
||||||
expect.objectContaining({
|
|
||||||
price_list: null,
|
|
||||||
}),
|
|
||||||
])
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
+87
-103
@@ -1,17 +1,13 @@
|
|||||||
import { useApi } from "../../../../environment-helpers/use-api"
|
|
||||||
import { getContainer } from "../../../../environment-helpers/use-container"
|
|
||||||
import { initDb, useDb } from "../../../../environment-helpers/use-db"
|
|
||||||
import {
|
import {
|
||||||
simpleProductFactory,
|
simpleProductFactory,
|
||||||
simpleRegionFactory,
|
simpleRegionFactory,
|
||||||
} from "../../../../factories"
|
} from "../../../../factories"
|
||||||
|
|
||||||
import { IPricingModuleService } from "@medusajs/types"
|
import { IPricingModuleService } from "@medusajs/types"
|
||||||
import path from "path"
|
|
||||||
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
|
|
||||||
import adminSeeder from "../../../../helpers/admin-seeder"
|
import adminSeeder from "../../../../helpers/admin-seeder"
|
||||||
import { createDefaultRuleTypes } from "../../../helpers/create-default-rule-types"
|
import { createDefaultRuleTypes } from "../../../helpers/create-default-rule-types"
|
||||||
import { createVariantPriceSet } from "../../../helpers/create-variant-price-set"
|
import { createVariantPriceSet } from "../../../helpers/create-variant-price-set"
|
||||||
|
import { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||||
|
|
||||||
jest.setTimeout(50000)
|
jest.setTimeout(50000)
|
||||||
|
|
||||||
@@ -25,107 +21,95 @@ const env = {
|
|||||||
MEDUSA_FF_MEDUSA_V2: true,
|
MEDUSA_FF_MEDUSA_V2: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
describe.skip("DELETE /admin/price-lists/:id/variants/:variantId/prices", () => {
|
medusaIntegrationTestRunner({
|
||||||
let dbConnection
|
env,
|
||||||
let appContainer
|
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||||
let shutdownServer
|
describe.skip("DELETE /admin/price-lists/:id/variants/:variantId/prices", () => {
|
||||||
let product
|
let appContainer
|
||||||
let variant
|
let product
|
||||||
let pricingModuleService: IPricingModuleService
|
let variant
|
||||||
|
let pricingModuleService: IPricingModuleService
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
|
appContainer = getContainer()
|
||||||
dbConnection = await initDb({ cwd, env } as any)
|
pricingModuleService = appContainer.resolve("pricingModuleService")
|
||||||
shutdownServer = await startBootstrapApp({ cwd, env })
|
})
|
||||||
appContainer = getContainer()
|
|
||||||
pricingModuleService = appContainer.resolve("pricingModuleService")
|
|
||||||
})
|
|
||||||
|
|
||||||
afterAll(async () => {
|
beforeEach(async () => {
|
||||||
const db = useDb()
|
await adminSeeder(dbConnection)
|
||||||
await db.shutdown()
|
await createDefaultRuleTypes(appContainer)
|
||||||
await shutdownServer()
|
|
||||||
})
|
|
||||||
|
|
||||||
beforeEach(async () => {
|
await simpleRegionFactory(dbConnection, {
|
||||||
await adminSeeder(dbConnection)
|
id: "test-region",
|
||||||
await createDefaultRuleTypes(appContainer)
|
name: "Test Region",
|
||||||
|
|
||||||
await simpleRegionFactory(dbConnection, {
|
|
||||||
id: "test-region",
|
|
||||||
name: "Test Region",
|
|
||||||
currency_code: "usd",
|
|
||||||
tax_rate: 0,
|
|
||||||
})
|
|
||||||
|
|
||||||
product = await simpleProductFactory(dbConnection, {
|
|
||||||
id: "test-product-with-variant",
|
|
||||||
variants: [
|
|
||||||
{
|
|
||||||
options: [{ option_id: "test-product-option-1", value: "test" }],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
options: [
|
|
||||||
{
|
|
||||||
id: "test-product-option-1",
|
|
||||||
title: "Test option 1",
|
|
||||||
},
|
|
||||||
],
|
|
||||||
})
|
|
||||||
|
|
||||||
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,
|
|
||||||
variantId: variant.id,
|
|
||||||
prices: [
|
|
||||||
{
|
|
||||||
amount: 3000,
|
|
||||||
currency_code: "usd",
|
currency_code: "usd",
|
||||||
},
|
tax_rate: 0,
|
||||||
],
|
})
|
||||||
|
|
||||||
|
product = await simpleProductFactory(dbConnection, {
|
||||||
|
id: "test-product-with-variant",
|
||||||
|
variants: [
|
||||||
|
{
|
||||||
|
options: [{ option_id: "test-product-option-1", value: "test" }],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
id: "test-product-option-1",
|
||||||
|
title: "Test option 1",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
})
|
||||||
|
|
||||||
|
variant = product.variants[0]
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should delete all prices based on product variant ids", async () => {
|
||||||
|
const priceSet = await createVariantPriceSet({
|
||||||
|
container: appContainer,
|
||||||
|
variantId: variant.id,
|
||||||
|
prices: [
|
||||||
|
{
|
||||||
|
amount: 3000,
|
||||||
|
currency_code: "usd",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
})
|
||||||
|
|
||||||
|
const data = {
|
||||||
|
name: "test price list",
|
||||||
|
description: "test",
|
||||||
|
type: "override",
|
||||||
|
customer_groups: [],
|
||||||
|
status: "active",
|
||||||
|
prices: [
|
||||||
|
{
|
||||||
|
amount: 400,
|
||||||
|
variant_id: variant.id,
|
||||||
|
currency_code: "usd",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = await api.post(`admin/price-lists`, data, adminHeaders)
|
||||||
|
const priceListId = result.data.price_list.id
|
||||||
|
|
||||||
|
let psmas = await pricingModuleService.listPriceSetMoneyAmounts({
|
||||||
|
price_list_id: [priceListId],
|
||||||
|
})
|
||||||
|
expect(psmas.length).toEqual(1)
|
||||||
|
|
||||||
|
const deleteRes = await api.delete(
|
||||||
|
`/admin/price-lists/${priceListId}/variants/${variant.id}/prices`,
|
||||||
|
adminHeaders
|
||||||
|
)
|
||||||
|
expect(deleteRes.status).toEqual(200)
|
||||||
|
|
||||||
|
psmas = await pricingModuleService.listPriceSetMoneyAmounts({
|
||||||
|
price_list_id: [priceListId],
|
||||||
|
})
|
||||||
|
expect(psmas.length).toEqual(0)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
},
|
||||||
const api = useApi() as any
|
|
||||||
const data = {
|
|
||||||
name: "test price list",
|
|
||||||
description: "test",
|
|
||||||
type: "override",
|
|
||||||
customer_groups: [],
|
|
||||||
status: "active",
|
|
||||||
prices: [
|
|
||||||
{
|
|
||||||
amount: 400,
|
|
||||||
variant_id: variant.id,
|
|
||||||
currency_code: "usd",
|
|
||||||
},
|
|
||||||
],
|
|
||||||
}
|
|
||||||
|
|
||||||
const result = await api.post(`admin/price-lists`, data, adminHeaders)
|
|
||||||
const priceListId = result.data.price_list.id
|
|
||||||
|
|
||||||
let psmas = await pricingModuleService.listPriceSetMoneyAmounts({
|
|
||||||
price_list_id: [priceListId],
|
|
||||||
})
|
|
||||||
expect(psmas.length).toEqual(1)
|
|
||||||
|
|
||||||
const deleteRes = await api.delete(
|
|
||||||
`/admin/price-lists/${priceListId}/variants/${variant.id}/prices`,
|
|
||||||
adminHeaders
|
|
||||||
)
|
|
||||||
expect(deleteRes.status).toEqual(200)
|
|
||||||
|
|
||||||
psmas = await pricingModuleService.listPriceSetMoneyAmounts({
|
|
||||||
price_list_id: [priceListId],
|
|
||||||
})
|
|
||||||
expect(psmas.length).toEqual(0)
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
+101
-117
@@ -1,17 +1,13 @@
|
|||||||
import { useApi } from "../../../../environment-helpers/use-api"
|
|
||||||
import { getContainer } from "../../../../environment-helpers/use-container"
|
|
||||||
import { initDb, useDb } from "../../../../environment-helpers/use-db"
|
|
||||||
import {
|
import {
|
||||||
simpleProductFactory,
|
simpleProductFactory,
|
||||||
simpleRegionFactory,
|
simpleRegionFactory,
|
||||||
} from "../../../../factories"
|
} from "../../../../factories"
|
||||||
|
|
||||||
import { IPricingModuleService } from "@medusajs/types"
|
import { IPricingModuleService } from "@medusajs/types"
|
||||||
import path from "path"
|
|
||||||
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
|
|
||||||
import adminSeeder from "../../../../helpers/admin-seeder"
|
import adminSeeder from "../../../../helpers/admin-seeder"
|
||||||
import { createDefaultRuleTypes } from "../../../helpers/create-default-rule-types"
|
import { createDefaultRuleTypes } from "../../../helpers/create-default-rule-types"
|
||||||
import { createVariantPriceSet } from "../../../helpers/create-variant-price-set"
|
import { createVariantPriceSet } from "../../../helpers/create-variant-price-set"
|
||||||
|
import { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||||
|
|
||||||
jest.setTimeout(50000)
|
jest.setTimeout(50000)
|
||||||
|
|
||||||
@@ -25,121 +21,109 @@ const env = {
|
|||||||
MEDUSA_FF_MEDUSA_V2: true,
|
MEDUSA_FF_MEDUSA_V2: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
describe.skip("DELETE /admin/price-lists/:id", () => {
|
medusaIntegrationTestRunner({
|
||||||
let dbConnection
|
env,
|
||||||
let appContainer
|
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||||
let shutdownServer
|
describe.skip("DELETE /admin/price-lists/:id", () => {
|
||||||
let product
|
let appContainer
|
||||||
let variant
|
let product
|
||||||
let pricingModuleService: IPricingModuleService
|
let variant
|
||||||
|
let pricingModuleService: IPricingModuleService
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
|
appContainer = getContainer()
|
||||||
dbConnection = await initDb({ cwd, env } as any)
|
pricingModuleService = appContainer.resolve("pricingModuleService")
|
||||||
shutdownServer = await startBootstrapApp({ cwd, env })
|
})
|
||||||
appContainer = getContainer()
|
|
||||||
pricingModuleService = appContainer.resolve("pricingModuleService")
|
|
||||||
})
|
|
||||||
|
|
||||||
afterAll(async () => {
|
beforeEach(async () => {
|
||||||
const db = useDb()
|
await adminSeeder(dbConnection)
|
||||||
await db.shutdown()
|
await createDefaultRuleTypes(appContainer)
|
||||||
await shutdownServer()
|
|
||||||
})
|
|
||||||
|
|
||||||
beforeEach(async () => {
|
await simpleRegionFactory(dbConnection, {
|
||||||
await adminSeeder(dbConnection)
|
id: "test-region",
|
||||||
await createDefaultRuleTypes(appContainer)
|
name: "Test Region",
|
||||||
|
|
||||||
await simpleRegionFactory(dbConnection, {
|
|
||||||
id: "test-region",
|
|
||||||
name: "Test Region",
|
|
||||||
currency_code: "usd",
|
|
||||||
tax_rate: 0,
|
|
||||||
})
|
|
||||||
|
|
||||||
product = await simpleProductFactory(dbConnection, {
|
|
||||||
id: "test-product-with-variant",
|
|
||||||
variants: [
|
|
||||||
{
|
|
||||||
options: [{ option_id: "test-product-option-1", value: "test" }],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
options: [
|
|
||||||
{
|
|
||||||
id: "test-product-option-1",
|
|
||||||
title: "Test option 1",
|
|
||||||
},
|
|
||||||
],
|
|
||||||
})
|
|
||||||
|
|
||||||
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,
|
|
||||||
variantId: variant.id,
|
|
||||||
prices: [
|
|
||||||
{
|
|
||||||
amount: 3000,
|
|
||||||
currency_code: "usd",
|
currency_code: "usd",
|
||||||
},
|
tax_rate: 0,
|
||||||
],
|
})
|
||||||
|
|
||||||
|
product = await simpleProductFactory(dbConnection, {
|
||||||
|
id: "test-product-with-variant",
|
||||||
|
variants: [
|
||||||
|
{
|
||||||
|
options: [{ option_id: "test-product-option-1", value: "test" }],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
id: "test-product-option-1",
|
||||||
|
title: "Test option 1",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
})
|
||||||
|
|
||||||
|
variant = product.variants[0]
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should delete price list prices by money amount ids", async () => {
|
||||||
|
await createVariantPriceSet({
|
||||||
|
container: appContainer,
|
||||||
|
variantId: variant.id,
|
||||||
|
prices: [
|
||||||
|
{
|
||||||
|
amount: 3000,
|
||||||
|
currency_code: "usd",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
})
|
||||||
|
|
||||||
|
const data = {
|
||||||
|
name: "test price list",
|
||||||
|
description: "test",
|
||||||
|
type: "override",
|
||||||
|
status: "active",
|
||||||
|
prices: [
|
||||||
|
{
|
||||||
|
amount: 400,
|
||||||
|
variant_id: variant.id,
|
||||||
|
currency_code: "usd",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
amount: 4000,
|
||||||
|
variant_id: variant.id,
|
||||||
|
currency_code: "usd",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}
|
||||||
|
|
||||||
|
const res = await api.post(`admin/price-lists`, data, adminHeaders)
|
||||||
|
|
||||||
|
const priceListId = res.data.price_list.id
|
||||||
|
let psmas = await pricingModuleService.listPriceSetMoneyAmounts(
|
||||||
|
{
|
||||||
|
price_list_id: [priceListId],
|
||||||
|
},
|
||||||
|
{ relations: ["money_amount"] }
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(psmas.length).toEqual(2)
|
||||||
|
|
||||||
|
const deletePrice = psmas[0].money_amount
|
||||||
|
const deleteRes = await api.delete(
|
||||||
|
`/admin/price-lists/${priceListId}/prices/batch`,
|
||||||
|
{
|
||||||
|
data: {
|
||||||
|
price_ids: [deletePrice?.id],
|
||||||
|
},
|
||||||
|
...adminHeaders,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
expect(deleteRes.status).toEqual(200)
|
||||||
|
|
||||||
|
psmas = await pricingModuleService.listPriceSetMoneyAmounts({
|
||||||
|
price_list_id: [priceListId],
|
||||||
|
})
|
||||||
|
expect(psmas.length).toEqual(1)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
},
|
||||||
const api = useApi() as any
|
|
||||||
const data = {
|
|
||||||
name: "test price list",
|
|
||||||
description: "test",
|
|
||||||
type: "override",
|
|
||||||
status: "active",
|
|
||||||
prices: [
|
|
||||||
{
|
|
||||||
amount: 400,
|
|
||||||
variant_id: variant.id,
|
|
||||||
currency_code: "usd",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
amount: 4000,
|
|
||||||
variant_id: variant.id,
|
|
||||||
currency_code: "usd",
|
|
||||||
},
|
|
||||||
],
|
|
||||||
}
|
|
||||||
|
|
||||||
const res = await api.post(`admin/price-lists`, data, adminHeaders)
|
|
||||||
|
|
||||||
const priceListId = res.data.price_list.id
|
|
||||||
let psmas = await pricingModuleService.listPriceSetMoneyAmounts(
|
|
||||||
{
|
|
||||||
price_list_id: [priceListId],
|
|
||||||
},
|
|
||||||
{ relations: ["money_amount"] }
|
|
||||||
)
|
|
||||||
|
|
||||||
expect(psmas.length).toEqual(2)
|
|
||||||
|
|
||||||
const deletePrice = psmas[0].money_amount
|
|
||||||
const deleteRes = await api.delete(
|
|
||||||
`/admin/price-lists/${priceListId}/prices/batch`,
|
|
||||||
{
|
|
||||||
data: {
|
|
||||||
price_ids: [deletePrice?.id],
|
|
||||||
},
|
|
||||||
...adminHeaders,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
expect(deleteRes.status).toEqual(200)
|
|
||||||
|
|
||||||
psmas = await pricingModuleService.listPriceSetMoneyAmounts({
|
|
||||||
price_list_id: [priceListId],
|
|
||||||
})
|
|
||||||
expect(psmas.length).toEqual(1)
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
@@ -1,17 +1,13 @@
|
|||||||
import { useApi } from "../../../../environment-helpers/use-api"
|
|
||||||
import { getContainer } from "../../../../environment-helpers/use-container"
|
|
||||||
import { initDb, useDb } from "../../../../environment-helpers/use-db"
|
|
||||||
import {
|
import {
|
||||||
simpleProductFactory,
|
simpleProductFactory,
|
||||||
simpleRegionFactory,
|
simpleRegionFactory,
|
||||||
} from "../../../../factories"
|
} from "../../../../factories"
|
||||||
|
|
||||||
import { IPricingModuleService } from "@medusajs/types"
|
import { IPricingModuleService } from "@medusajs/types"
|
||||||
import path from "path"
|
|
||||||
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
|
|
||||||
import adminSeeder from "../../../../helpers/admin-seeder"
|
import adminSeeder from "../../../../helpers/admin-seeder"
|
||||||
import { createDefaultRuleTypes } from "../../../helpers/create-default-rule-types"
|
import { createDefaultRuleTypes } from "../../../helpers/create-default-rule-types"
|
||||||
import { createVariantPriceSet } from "../../../helpers/create-variant-price-set"
|
import { createVariantPriceSet } from "../../../helpers/create-variant-price-set"
|
||||||
|
import { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||||
|
|
||||||
jest.setTimeout(50000)
|
jest.setTimeout(50000)
|
||||||
|
|
||||||
@@ -25,120 +21,108 @@ const env = {
|
|||||||
MEDUSA_FF_MEDUSA_V2: true,
|
MEDUSA_FF_MEDUSA_V2: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
describe.skip("DELETE /admin/price-lists/:id", () => {
|
medusaIntegrationTestRunner({
|
||||||
let dbConnection
|
env,
|
||||||
let appContainer
|
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||||
let shutdownServer
|
describe.skip("DELETE /admin/price-lists/:id", () => {
|
||||||
let product
|
let appContainer
|
||||||
let variant
|
let product
|
||||||
let pricingModuleService: IPricingModuleService
|
let variant
|
||||||
|
let pricingModuleService: IPricingModuleService
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
|
appContainer = getContainer()
|
||||||
dbConnection = await initDb({ cwd, env } as any)
|
pricingModuleService = appContainer.resolve("pricingModuleService")
|
||||||
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)
|
|
||||||
|
|
||||||
await simpleRegionFactory(dbConnection, {
|
|
||||||
id: "test-region",
|
|
||||||
name: "Test Region",
|
|
||||||
currency_code: "usd",
|
|
||||||
tax_rate: 0,
|
|
||||||
})
|
|
||||||
|
|
||||||
product = await simpleProductFactory(dbConnection, {
|
|
||||||
id: "test-product-with-variant",
|
|
||||||
variants: [
|
|
||||||
{
|
|
||||||
options: [{ option_id: "test-product-option-1", value: "test" }],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
options: [
|
|
||||||
{
|
|
||||||
id: "test-product-option-1",
|
|
||||||
title: "Test option 1",
|
|
||||||
},
|
|
||||||
],
|
|
||||||
})
|
|
||||||
|
|
||||||
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,
|
|
||||||
variantId: variant.id,
|
|
||||||
prices: [
|
|
||||||
{
|
|
||||||
amount: 3000,
|
|
||||||
currency_code: "usd",
|
|
||||||
},
|
|
||||||
],
|
|
||||||
})
|
|
||||||
|
|
||||||
const api = useApi() as any
|
|
||||||
const data = {
|
|
||||||
name: "test price list",
|
|
||||||
description: "test",
|
|
||||||
type: "override",
|
|
||||||
customer_groups: [],
|
|
||||||
status: "active",
|
|
||||||
prices: [
|
|
||||||
{
|
|
||||||
amount: 400,
|
|
||||||
variant_id: variant.id,
|
|
||||||
currency_code: "usd",
|
|
||||||
},
|
|
||||||
],
|
|
||||||
}
|
|
||||||
|
|
||||||
const result = await api.post(`admin/price-lists`, data, adminHeaders)
|
|
||||||
const priceListId = result.data.price_list.id
|
|
||||||
|
|
||||||
const getResponse = await api.get(
|
|
||||||
`/admin/price-lists/${priceListId}`,
|
|
||||||
adminHeaders
|
|
||||||
)
|
|
||||||
expect(getResponse.status).toEqual(200)
|
|
||||||
|
|
||||||
let psmas = await pricingModuleService.listPriceSetMoneyAmounts({
|
|
||||||
price_list_id: [priceListId],
|
|
||||||
})
|
|
||||||
expect(psmas.length).toEqual(1)
|
|
||||||
|
|
||||||
const deleteRes = await api.delete(
|
|
||||||
`/admin/price-lists/${priceListId}`,
|
|
||||||
adminHeaders
|
|
||||||
)
|
|
||||||
expect(deleteRes.status).toEqual(200)
|
|
||||||
|
|
||||||
const afterDelete = await api
|
|
||||||
.get(`/admin/price-lists/${priceListId}`, adminHeaders)
|
|
||||||
.catch((err) => {
|
|
||||||
return err
|
|
||||||
})
|
})
|
||||||
expect(afterDelete.response.status).toEqual(404)
|
|
||||||
|
|
||||||
psmas = await pricingModuleService.listPriceSetMoneyAmounts({
|
beforeEach(async () => {
|
||||||
price_list_id: [priceListId],
|
await adminSeeder(dbConnection)
|
||||||
|
await createDefaultRuleTypes(appContainer)
|
||||||
|
|
||||||
|
await simpleRegionFactory(dbConnection, {
|
||||||
|
id: "test-region",
|
||||||
|
name: "Test Region",
|
||||||
|
currency_code: "usd",
|
||||||
|
tax_rate: 0,
|
||||||
|
})
|
||||||
|
|
||||||
|
product = await simpleProductFactory(dbConnection, {
|
||||||
|
id: "test-product-with-variant",
|
||||||
|
variants: [
|
||||||
|
{
|
||||||
|
options: [{ option_id: "test-product-option-1", value: "test" }],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
id: "test-product-option-1",
|
||||||
|
title: "Test option 1",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
})
|
||||||
|
|
||||||
|
variant = product.variants[0]
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should delete price list and money amounts", async () => {
|
||||||
|
const priceSet = await createVariantPriceSet({
|
||||||
|
container: appContainer,
|
||||||
|
variantId: variant.id,
|
||||||
|
prices: [
|
||||||
|
{
|
||||||
|
amount: 3000,
|
||||||
|
currency_code: "usd",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
})
|
||||||
|
|
||||||
|
const data = {
|
||||||
|
name: "test price list",
|
||||||
|
description: "test",
|
||||||
|
type: "override",
|
||||||
|
customer_groups: [],
|
||||||
|
status: "active",
|
||||||
|
prices: [
|
||||||
|
{
|
||||||
|
amount: 400,
|
||||||
|
variant_id: variant.id,
|
||||||
|
currency_code: "usd",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = await api.post(`admin/price-lists`, data, adminHeaders)
|
||||||
|
const priceListId = result.data.price_list.id
|
||||||
|
|
||||||
|
const getResponse = await api.get(
|
||||||
|
`/admin/price-lists/${priceListId}`,
|
||||||
|
adminHeaders
|
||||||
|
)
|
||||||
|
expect(getResponse.status).toEqual(200)
|
||||||
|
|
||||||
|
let psmas = await pricingModuleService.listPriceSetMoneyAmounts({
|
||||||
|
price_list_id: [priceListId],
|
||||||
|
})
|
||||||
|
expect(psmas.length).toEqual(1)
|
||||||
|
|
||||||
|
const deleteRes = await api.delete(
|
||||||
|
`/admin/price-lists/${priceListId}`,
|
||||||
|
adminHeaders
|
||||||
|
)
|
||||||
|
expect(deleteRes.status).toEqual(200)
|
||||||
|
|
||||||
|
const afterDelete = await api
|
||||||
|
.get(`/admin/price-lists/${priceListId}`, adminHeaders)
|
||||||
|
.catch((err) => {
|
||||||
|
return err
|
||||||
|
})
|
||||||
|
expect(afterDelete.response.status).toEqual(404)
|
||||||
|
|
||||||
|
psmas = await pricingModuleService.listPriceSetMoneyAmounts({
|
||||||
|
price_list_id: [priceListId],
|
||||||
|
})
|
||||||
|
expect(psmas.length).toEqual(0)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
expect(psmas.length).toEqual(0)
|
},
|
||||||
})
|
|
||||||
})
|
})
|
||||||
@@ -1,6 +1,3 @@
|
|||||||
import { useApi } from "../../../../environment-helpers/use-api"
|
|
||||||
import { getContainer } from "../../../../environment-helpers/use-container"
|
|
||||||
import { initDb, useDb } from "../../../../environment-helpers/use-db"
|
|
||||||
import { simpleProductFactory } from "../../../../factories"
|
import { simpleProductFactory } from "../../../../factories"
|
||||||
|
|
||||||
import {
|
import {
|
||||||
@@ -8,10 +5,9 @@ import {
|
|||||||
PriceListStatus,
|
PriceListStatus,
|
||||||
PriceListType,
|
PriceListType,
|
||||||
} from "@medusajs/types"
|
} from "@medusajs/types"
|
||||||
import path from "path"
|
|
||||||
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
|
|
||||||
import adminSeeder from "../../../../helpers/admin-seeder"
|
import adminSeeder from "../../../../helpers/admin-seeder"
|
||||||
import { createVariantPriceSet } from "../../../helpers/create-variant-price-set"
|
import { createVariantPriceSet } from "../../../helpers/create-variant-price-set"
|
||||||
|
import { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||||
|
|
||||||
jest.setTimeout(50000)
|
jest.setTimeout(50000)
|
||||||
|
|
||||||
@@ -25,179 +21,164 @@ const env = {
|
|||||||
MEDUSA_FF_MEDUSA_V2: true,
|
MEDUSA_FF_MEDUSA_V2: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
describe.skip("GET /admin/price-lists/:id", () => {
|
medusaIntegrationTestRunner({
|
||||||
let dbConnection
|
env,
|
||||||
let appContainer
|
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||||
let shutdownServer
|
describe.skip("GET /admin/price-lists/:id", () => {
|
||||||
let product
|
let appContainer
|
||||||
let variant
|
let product
|
||||||
let pricingModuleService: IPricingModuleService
|
let variant
|
||||||
|
let pricingModuleService: IPricingModuleService
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
|
appContainer = getContainer()
|
||||||
dbConnection = await initDb({ cwd, env } as any)
|
pricingModuleService = appContainer.resolve("pricingModuleService")
|
||||||
shutdownServer = await startBootstrapApp({ cwd, env })
|
})
|
||||||
appContainer = getContainer()
|
|
||||||
pricingModuleService = appContainer.resolve("pricingModuleService")
|
|
||||||
})
|
|
||||||
|
|
||||||
afterAll(async () => {
|
beforeEach(async () => {
|
||||||
const db = useDb()
|
await adminSeeder(dbConnection)
|
||||||
await db.shutdown()
|
|
||||||
await shutdownServer()
|
|
||||||
})
|
|
||||||
|
|
||||||
beforeEach(async () => {
|
product = await simpleProductFactory(dbConnection, {
|
||||||
await adminSeeder(dbConnection)
|
id: "test-product-with-variant",
|
||||||
|
variants: [
|
||||||
|
{
|
||||||
|
options: [{ option_id: "test-product-option-1", value: "test" }],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
id: "test-product-option-1",
|
||||||
|
title: "Test option 1",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
})
|
||||||
|
|
||||||
product = await simpleProductFactory(dbConnection, {
|
variant = product.variants[0]
|
||||||
id: "test-product-with-variant",
|
})
|
||||||
variants: [
|
|
||||||
{
|
|
||||||
options: [{ option_id: "test-product-option-1", value: "test" }],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
options: [
|
|
||||||
{
|
|
||||||
id: "test-product-option-1",
|
|
||||||
title: "Test option 1",
|
|
||||||
},
|
|
||||||
],
|
|
||||||
})
|
|
||||||
|
|
||||||
variant = product.variants[0]
|
it("should get price list and its money amounts with variants", async () => {
|
||||||
})
|
const priceSet = await createVariantPriceSet({
|
||||||
|
container: appContainer,
|
||||||
|
variantId: variant.id,
|
||||||
|
prices: [
|
||||||
|
{
|
||||||
|
amount: 3000,
|
||||||
|
currency_code: "usd",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
rules: [],
|
||||||
|
})
|
||||||
|
|
||||||
afterEach(async () => {
|
const [priceList] = await pricingModuleService.createPriceLists([
|
||||||
const db = useDb()
|
|
||||||
await db.teardown()
|
|
||||||
})
|
|
||||||
|
|
||||||
it("should get price list and its money amounts with variants", async () => {
|
|
||||||
const priceSet = await createVariantPriceSet({
|
|
||||||
container: appContainer,
|
|
||||||
variantId: variant.id,
|
|
||||||
prices: [
|
|
||||||
{
|
|
||||||
amount: 3000,
|
|
||||||
currency_code: "usd",
|
|
||||||
},
|
|
||||||
],
|
|
||||||
rules: [],
|
|
||||||
})
|
|
||||||
|
|
||||||
const [priceList] = await pricingModuleService.createPriceLists([
|
|
||||||
{
|
|
||||||
title: "test price list",
|
|
||||||
description: "test",
|
|
||||||
ends_at: new Date(),
|
|
||||||
starts_at: new Date(),
|
|
||||||
status: PriceListStatus.ACTIVE,
|
|
||||||
type: PriceListType.OVERRIDE,
|
|
||||||
prices: [
|
|
||||||
{
|
{
|
||||||
amount: 5000,
|
title: "test price list",
|
||||||
currency_code: "usd",
|
description: "test",
|
||||||
price_set_id: priceSet.id,
|
ends_at: new Date(),
|
||||||
|
starts_at: new Date(),
|
||||||
|
status: PriceListStatus.ACTIVE,
|
||||||
|
type: PriceListType.OVERRIDE,
|
||||||
|
prices: [
|
||||||
|
{
|
||||||
|
amount: 5000,
|
||||||
|
currency_code: "usd",
|
||||||
|
price_set_id: priceSet.id,
|
||||||
|
},
|
||||||
|
],
|
||||||
},
|
},
|
||||||
],
|
])
|
||||||
},
|
|
||||||
])
|
|
||||||
|
|
||||||
await pricingModuleService.createPriceLists([
|
await pricingModuleService.createPriceLists([
|
||||||
{
|
|
||||||
title: "test price list 1",
|
|
||||||
description: "test 1",
|
|
||||||
ends_at: new Date(),
|
|
||||||
starts_at: new Date(),
|
|
||||||
status: PriceListStatus.ACTIVE,
|
|
||||||
type: PriceListType.OVERRIDE,
|
|
||||||
prices: [
|
|
||||||
{
|
{
|
||||||
amount: 5000,
|
title: "test price list 1",
|
||||||
currency_code: "usd",
|
description: "test 1",
|
||||||
price_set_id: priceSet.id,
|
ends_at: new Date(),
|
||||||
|
starts_at: new Date(),
|
||||||
|
status: PriceListStatus.ACTIVE,
|
||||||
|
type: PriceListType.OVERRIDE,
|
||||||
|
prices: [
|
||||||
|
{
|
||||||
|
amount: 5000,
|
||||||
|
currency_code: "usd",
|
||||||
|
price_set_id: priceSet.id,
|
||||||
|
},
|
||||||
|
],
|
||||||
},
|
},
|
||||||
],
|
])
|
||||||
},
|
|
||||||
])
|
|
||||||
|
|
||||||
const api = useApi() as any
|
const response = await api.get(
|
||||||
|
`/admin/price-lists/${priceList.id}`,
|
||||||
|
adminHeaders
|
||||||
|
)
|
||||||
|
|
||||||
const response = await api.get(
|
expect(response.status).toEqual(200)
|
||||||
`/admin/price-lists/${priceList.id}`,
|
expect(response.data.price_list).toEqual(
|
||||||
adminHeaders
|
|
||||||
)
|
|
||||||
|
|
||||||
expect(response.status).toEqual(200)
|
|
||||||
expect(response.data.price_list).toEqual(
|
|
||||||
expect.objectContaining({
|
|
||||||
id: expect.any(String),
|
|
||||||
created_at: expect.any(String),
|
|
||||||
updated_at: expect.any(String),
|
|
||||||
deleted_at: null,
|
|
||||||
name: "test price list",
|
|
||||||
description: "test",
|
|
||||||
type: "override",
|
|
||||||
status: "active",
|
|
||||||
starts_at: expect.any(String),
|
|
||||||
ends_at: expect.any(String),
|
|
||||||
customer_groups: [],
|
|
||||||
prices: [
|
|
||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
id: expect.any(String),
|
id: expect.any(String),
|
||||||
created_at: expect.any(String),
|
created_at: expect.any(String),
|
||||||
updated_at: expect.any(String),
|
updated_at: expect.any(String),
|
||||||
deleted_at: null,
|
deleted_at: null,
|
||||||
currency_code: "usd",
|
name: "test price list",
|
||||||
amount: 5000,
|
description: "test",
|
||||||
min_quantity: null,
|
type: "override",
|
||||||
max_quantity: null,
|
status: "active",
|
||||||
price_list_id: expect.any(String),
|
starts_at: expect.any(String),
|
||||||
region_id: null,
|
ends_at: expect.any(String),
|
||||||
variant: expect.objectContaining({
|
customer_groups: [],
|
||||||
id: expect.any(String),
|
prices: [
|
||||||
created_at: expect.any(String),
|
expect.objectContaining({
|
||||||
updated_at: expect.any(String),
|
id: expect.any(String),
|
||||||
deleted_at: null,
|
created_at: expect.any(String),
|
||||||
title: expect.any(String),
|
updated_at: expect.any(String),
|
||||||
product_id: expect.any(String),
|
deleted_at: null,
|
||||||
sku: null,
|
currency_code: "usd",
|
||||||
barcode: null,
|
amount: 5000,
|
||||||
ean: null,
|
min_quantity: null,
|
||||||
upc: null,
|
max_quantity: null,
|
||||||
variant_rank: 0,
|
price_list_id: expect.any(String),
|
||||||
inventory_quantity: 10,
|
region_id: null,
|
||||||
allow_backorder: false,
|
variant: expect.objectContaining({
|
||||||
manage_inventory: true,
|
id: expect.any(String),
|
||||||
hs_code: null,
|
created_at: expect.any(String),
|
||||||
origin_country: null,
|
updated_at: expect.any(String),
|
||||||
mid_code: null,
|
deleted_at: null,
|
||||||
material: null,
|
title: expect.any(String),
|
||||||
weight: null,
|
product_id: expect.any(String),
|
||||||
length: null,
|
sku: null,
|
||||||
height: null,
|
barcode: null,
|
||||||
width: null,
|
ean: null,
|
||||||
metadata: null,
|
upc: null,
|
||||||
}),
|
variant_rank: 0,
|
||||||
variant_id: expect.any(String),
|
inventory_quantity: 10,
|
||||||
}),
|
allow_backorder: false,
|
||||||
],
|
manage_inventory: true,
|
||||||
|
hs_code: null,
|
||||||
|
origin_country: null,
|
||||||
|
mid_code: null,
|
||||||
|
material: null,
|
||||||
|
weight: null,
|
||||||
|
length: null,
|
||||||
|
height: null,
|
||||||
|
width: null,
|
||||||
|
metadata: null,
|
||||||
|
}),
|
||||||
|
variant_id: expect.any(String),
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
})
|
||||||
|
)
|
||||||
})
|
})
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
it("should throw an error when price list is not found", async () => {
|
it("should throw an error when price list is not found", async () => {
|
||||||
const api = useApi() as any
|
const error = await api
|
||||||
|
.get(`/admin/price-lists/does-not-exist`, adminHeaders)
|
||||||
|
.catch((e) => e)
|
||||||
|
|
||||||
const error = await api
|
expect(error.response.status).toBe(404)
|
||||||
.get(`/admin/price-lists/does-not-exist`, adminHeaders)
|
expect(error.response.data).toEqual({
|
||||||
.catch((e) => e)
|
type: "not_found",
|
||||||
|
message: "Price list with id: does-not-exist was not found",
|
||||||
expect(error.response.status).toBe(404)
|
})
|
||||||
expect(error.response.data).toEqual({
|
})
|
||||||
type: "not_found",
|
|
||||||
message: "Price list with id: does-not-exist was not found",
|
|
||||||
})
|
})
|
||||||
})
|
},
|
||||||
})
|
})
|
||||||
+209
-226
@@ -1,6 +1,3 @@
|
|||||||
import { useApi } from "../../../../environment-helpers/use-api"
|
|
||||||
import { getContainer } from "../../../../environment-helpers/use-container"
|
|
||||||
import { initDb, useDb } from "../../../../environment-helpers/use-db"
|
|
||||||
import { simpleProductFactory } from "../../../../factories"
|
import { simpleProductFactory } from "../../../../factories"
|
||||||
|
|
||||||
import {
|
import {
|
||||||
@@ -8,10 +5,9 @@ import {
|
|||||||
PriceListStatus,
|
PriceListStatus,
|
||||||
PriceListType,
|
PriceListType,
|
||||||
} from "@medusajs/types"
|
} from "@medusajs/types"
|
||||||
import path from "path"
|
|
||||||
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
|
|
||||||
import adminSeeder from "../../../../helpers/admin-seeder"
|
import adminSeeder from "../../../../helpers/admin-seeder"
|
||||||
import { createVariantPriceSet } from "../../../helpers/create-variant-price-set"
|
import { createVariantPriceSet } from "../../../helpers/create-variant-price-set"
|
||||||
|
import { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||||
|
|
||||||
jest.setTimeout(50000)
|
jest.setTimeout(50000)
|
||||||
|
|
||||||
@@ -25,248 +21,235 @@ const env = {
|
|||||||
MEDUSA_FF_MEDUSA_V2: true,
|
MEDUSA_FF_MEDUSA_V2: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
describe.skip("GET /admin/price-lists/:id/products", () => {
|
medusaIntegrationTestRunner({
|
||||||
let dbConnection
|
env,
|
||||||
let appContainer
|
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||||
let shutdownServer
|
describe.skip("GET /admin/price-lists/:id/products", () => {
|
||||||
let product
|
let appContainer
|
||||||
let product2
|
let product
|
||||||
let variant
|
let product2
|
||||||
let pricingModuleService: IPricingModuleService
|
let variant
|
||||||
|
let pricingModuleService: IPricingModuleService
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
|
appContainer = getContainer()
|
||||||
dbConnection = await initDb({ cwd, env } as any)
|
pricingModuleService = appContainer.resolve("pricingModuleService")
|
||||||
shutdownServer = await startBootstrapApp({ cwd, env })
|
})
|
||||||
appContainer = getContainer()
|
|
||||||
pricingModuleService = appContainer.resolve("pricingModuleService")
|
|
||||||
})
|
|
||||||
|
|
||||||
afterAll(async () => {
|
beforeEach(async () => {
|
||||||
const db = useDb()
|
await adminSeeder(dbConnection)
|
||||||
await db.shutdown()
|
|
||||||
await shutdownServer()
|
|
||||||
})
|
|
||||||
|
|
||||||
beforeEach(async () => {
|
product = await simpleProductFactory(dbConnection, {
|
||||||
await adminSeeder(dbConnection)
|
id: "test-product-with-variant",
|
||||||
|
title: "uniquely fun product",
|
||||||
|
variants: [
|
||||||
|
{
|
||||||
|
options: [{ option_id: "test-product-option-1", value: "test" }],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
id: "test-product-option-1",
|
||||||
|
title: "Test option 1",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
})
|
||||||
|
|
||||||
product = await simpleProductFactory(dbConnection, {
|
variant = product.variants[0]
|
||||||
id: "test-product-with-variant",
|
|
||||||
title: "uniquely fun product",
|
|
||||||
variants: [
|
|
||||||
{
|
|
||||||
options: [{ option_id: "test-product-option-1", value: "test" }],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
options: [
|
|
||||||
{
|
|
||||||
id: "test-product-option-1",
|
|
||||||
title: "Test option 1",
|
|
||||||
},
|
|
||||||
],
|
|
||||||
})
|
|
||||||
|
|
||||||
variant = product.variants[0]
|
product2 = await simpleProductFactory(dbConnection, {
|
||||||
|
id: "test-product-with-variant-2",
|
||||||
|
title: "uniquely fun product 2",
|
||||||
|
variants: [
|
||||||
|
{
|
||||||
|
options: [
|
||||||
|
{ option_id: "test-product-option-2", value: "test 2" },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
id: "test-product-option-2",
|
||||||
|
title: "Test option 2",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
product2 = await simpleProductFactory(dbConnection, {
|
it("should list all products in a price list", async () => {
|
||||||
id: "test-product-with-variant-2",
|
const priceSet = await createVariantPriceSet({
|
||||||
title: "uniquely fun product 2",
|
container: appContainer,
|
||||||
variants: [
|
variantId: variant.id,
|
||||||
{
|
prices: [
|
||||||
options: [{ option_id: "test-product-option-2", value: "test 2" }],
|
{
|
||||||
},
|
amount: 3000,
|
||||||
],
|
currency_code: "usd",
|
||||||
options: [
|
},
|
||||||
{
|
],
|
||||||
id: "test-product-option-2",
|
rules: [],
|
||||||
title: "Test option 2",
|
})
|
||||||
},
|
|
||||||
],
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
afterEach(async () => {
|
const [priceList] = await pricingModuleService.createPriceLists([
|
||||||
const db = useDb()
|
|
||||||
await db.teardown()
|
|
||||||
})
|
|
||||||
|
|
||||||
it("should list all products in a price list", async () => {
|
|
||||||
const priceSet = await createVariantPriceSet({
|
|
||||||
container: appContainer,
|
|
||||||
variantId: variant.id,
|
|
||||||
prices: [
|
|
||||||
{
|
|
||||||
amount: 3000,
|
|
||||||
currency_code: "usd",
|
|
||||||
},
|
|
||||||
],
|
|
||||||
rules: [],
|
|
||||||
})
|
|
||||||
|
|
||||||
const [priceList] = await pricingModuleService.createPriceLists([
|
|
||||||
{
|
|
||||||
title: "test price list",
|
|
||||||
description: "test",
|
|
||||||
ends_at: new Date(),
|
|
||||||
starts_at: new Date(),
|
|
||||||
status: PriceListStatus.ACTIVE,
|
|
||||||
type: PriceListType.OVERRIDE,
|
|
||||||
prices: [
|
|
||||||
{
|
{
|
||||||
amount: 5000,
|
title: "test price list",
|
||||||
currency_code: "usd",
|
description: "test",
|
||||||
price_set_id: priceSet.id,
|
ends_at: new Date(),
|
||||||
|
starts_at: new Date(),
|
||||||
|
status: PriceListStatus.ACTIVE,
|
||||||
|
type: PriceListType.OVERRIDE,
|
||||||
|
prices: [
|
||||||
|
{
|
||||||
|
amount: 5000,
|
||||||
|
currency_code: "usd",
|
||||||
|
price_set_id: priceSet.id,
|
||||||
|
},
|
||||||
|
],
|
||||||
},
|
},
|
||||||
],
|
])
|
||||||
},
|
|
||||||
])
|
|
||||||
|
|
||||||
const api = useApi() as any
|
let response = await api.get(
|
||||||
|
`/admin/price-lists/${priceList.id}/products`,
|
||||||
|
adminHeaders
|
||||||
|
)
|
||||||
|
|
||||||
let response = await api.get(
|
expect(response.status).toEqual(200)
|
||||||
`/admin/price-lists/${priceList.id}/products`,
|
expect(response.data.count).toEqual(1)
|
||||||
adminHeaders
|
expect(response.data.products).toEqual([
|
||||||
)
|
expect.objectContaining({
|
||||||
|
id: expect.any(String),
|
||||||
|
title: expect.any(String),
|
||||||
|
handle: expect.any(String),
|
||||||
|
subtitle: null,
|
||||||
|
description: null,
|
||||||
|
is_giftcard: false,
|
||||||
|
status: "draft",
|
||||||
|
thumbnail: null,
|
||||||
|
weight: null,
|
||||||
|
length: null,
|
||||||
|
height: null,
|
||||||
|
width: null,
|
||||||
|
origin_country: null,
|
||||||
|
hs_code: null,
|
||||||
|
mid_code: null,
|
||||||
|
material: null,
|
||||||
|
collection_id: null,
|
||||||
|
collection: null,
|
||||||
|
type_id: null,
|
||||||
|
type: null,
|
||||||
|
discountable: true,
|
||||||
|
external_id: null,
|
||||||
|
created_at: expect.any(String),
|
||||||
|
updated_at: expect.any(String),
|
||||||
|
deleted_at: null,
|
||||||
|
metadata: null,
|
||||||
|
}),
|
||||||
|
])
|
||||||
|
|
||||||
expect(response.status).toEqual(200)
|
response = await api.get(
|
||||||
expect(response.data.count).toEqual(1)
|
`/admin/products?price_list_id[]=${priceList.id}`,
|
||||||
expect(response.data.products).toEqual([
|
adminHeaders
|
||||||
expect.objectContaining({
|
)
|
||||||
id: expect.any(String),
|
|
||||||
title: expect.any(String),
|
|
||||||
handle: expect.any(String),
|
|
||||||
subtitle: null,
|
|
||||||
description: null,
|
|
||||||
is_giftcard: false,
|
|
||||||
status: "draft",
|
|
||||||
thumbnail: null,
|
|
||||||
weight: null,
|
|
||||||
length: null,
|
|
||||||
height: null,
|
|
||||||
width: null,
|
|
||||||
origin_country: null,
|
|
||||||
hs_code: null,
|
|
||||||
mid_code: null,
|
|
||||||
material: null,
|
|
||||||
collection_id: null,
|
|
||||||
collection: null,
|
|
||||||
type_id: null,
|
|
||||||
type: null,
|
|
||||||
discountable: true,
|
|
||||||
external_id: null,
|
|
||||||
created_at: expect.any(String),
|
|
||||||
updated_at: expect.any(String),
|
|
||||||
deleted_at: null,
|
|
||||||
metadata: null,
|
|
||||||
}),
|
|
||||||
])
|
|
||||||
|
|
||||||
response = await api.get(
|
expect(response.status).toEqual(200)
|
||||||
`/admin/products?price_list_id[]=${priceList.id}`,
|
expect(response.data.count).toEqual(1)
|
||||||
adminHeaders
|
expect(response.data.products).toEqual([
|
||||||
)
|
expect.objectContaining({
|
||||||
|
id: expect.any(String),
|
||||||
|
title: expect.any(String),
|
||||||
|
handle: expect.any(String),
|
||||||
|
subtitle: null,
|
||||||
|
description: null,
|
||||||
|
is_giftcard: false,
|
||||||
|
status: "draft",
|
||||||
|
thumbnail: null,
|
||||||
|
weight: null,
|
||||||
|
length: null,
|
||||||
|
height: null,
|
||||||
|
width: null,
|
||||||
|
origin_country: null,
|
||||||
|
hs_code: null,
|
||||||
|
mid_code: null,
|
||||||
|
material: null,
|
||||||
|
collection_id: null,
|
||||||
|
collection: null,
|
||||||
|
type_id: null,
|
||||||
|
type: null,
|
||||||
|
discountable: true,
|
||||||
|
external_id: null,
|
||||||
|
created_at: expect.any(String),
|
||||||
|
updated_at: expect.any(String),
|
||||||
|
deleted_at: null,
|
||||||
|
metadata: null,
|
||||||
|
}),
|
||||||
|
])
|
||||||
|
})
|
||||||
|
|
||||||
expect(response.status).toEqual(200)
|
it("should list all products constrained by search query in a price list", async () => {
|
||||||
expect(response.data.count).toEqual(1)
|
const priceSet = await createVariantPriceSet({
|
||||||
expect(response.data.products).toEqual([
|
container: appContainer,
|
||||||
expect.objectContaining({
|
variantId: variant.id,
|
||||||
id: expect.any(String),
|
prices: [
|
||||||
title: expect.any(String),
|
{
|
||||||
handle: expect.any(String),
|
amount: 3000,
|
||||||
subtitle: null,
|
currency_code: "usd",
|
||||||
description: null,
|
},
|
||||||
is_giftcard: false,
|
],
|
||||||
status: "draft",
|
rules: [],
|
||||||
thumbnail: null,
|
})
|
||||||
weight: null,
|
|
||||||
length: null,
|
|
||||||
height: null,
|
|
||||||
width: null,
|
|
||||||
origin_country: null,
|
|
||||||
hs_code: null,
|
|
||||||
mid_code: null,
|
|
||||||
material: null,
|
|
||||||
collection_id: null,
|
|
||||||
collection: null,
|
|
||||||
type_id: null,
|
|
||||||
type: null,
|
|
||||||
discountable: true,
|
|
||||||
external_id: null,
|
|
||||||
created_at: expect.any(String),
|
|
||||||
updated_at: expect.any(String),
|
|
||||||
deleted_at: null,
|
|
||||||
metadata: null,
|
|
||||||
}),
|
|
||||||
])
|
|
||||||
})
|
|
||||||
|
|
||||||
it("should list all products constrained by search query in a price list", async () => {
|
const [priceList] = await pricingModuleService.createPriceLists([
|
||||||
const priceSet = await createVariantPriceSet({
|
|
||||||
container: appContainer,
|
|
||||||
variantId: variant.id,
|
|
||||||
prices: [
|
|
||||||
{
|
|
||||||
amount: 3000,
|
|
||||||
currency_code: "usd",
|
|
||||||
},
|
|
||||||
],
|
|
||||||
rules: [],
|
|
||||||
})
|
|
||||||
|
|
||||||
const [priceList] = await pricingModuleService.createPriceLists([
|
|
||||||
{
|
|
||||||
title: "test price list",
|
|
||||||
description: "test",
|
|
||||||
ends_at: new Date(),
|
|
||||||
starts_at: new Date(),
|
|
||||||
status: PriceListStatus.ACTIVE,
|
|
||||||
type: PriceListType.OVERRIDE,
|
|
||||||
prices: [
|
|
||||||
{
|
{
|
||||||
amount: 5000,
|
title: "test price list",
|
||||||
currency_code: "usd",
|
description: "test",
|
||||||
price_set_id: priceSet.id,
|
ends_at: new Date(),
|
||||||
|
starts_at: new Date(),
|
||||||
|
status: PriceListStatus.ACTIVE,
|
||||||
|
type: PriceListType.OVERRIDE,
|
||||||
|
prices: [
|
||||||
|
{
|
||||||
|
amount: 5000,
|
||||||
|
currency_code: "usd",
|
||||||
|
price_set_id: priceSet.id,
|
||||||
|
},
|
||||||
|
],
|
||||||
},
|
},
|
||||||
],
|
])
|
||||||
},
|
|
||||||
])
|
|
||||||
|
|
||||||
const api = useApi() as any
|
let response = await api.get(
|
||||||
|
`/admin/price-lists/${priceList.id}/products?q=shouldnotreturnanything`,
|
||||||
|
adminHeaders
|
||||||
|
)
|
||||||
|
|
||||||
let response = await api.get(
|
expect(response.status).toEqual(200)
|
||||||
`/admin/price-lists/${priceList.id}/products?q=shouldnotreturnanything`,
|
expect(response.data.count).toEqual(0)
|
||||||
adminHeaders
|
expect(response.data.products).toEqual([])
|
||||||
)
|
|
||||||
|
|
||||||
expect(response.status).toEqual(200)
|
response = await api.get(
|
||||||
expect(response.data.count).toEqual(0)
|
`/admin/price-lists/${priceList.id}/products?q=uniquely`,
|
||||||
expect(response.data.products).toEqual([])
|
adminHeaders
|
||||||
|
)
|
||||||
|
|
||||||
response = await api.get(
|
expect(response.status).toEqual(200)
|
||||||
`/admin/price-lists/${priceList.id}/products?q=uniquely`,
|
expect(response.data.count).toEqual(1)
|
||||||
adminHeaders
|
expect(response.data.products).toEqual([
|
||||||
)
|
expect.objectContaining({
|
||||||
|
id: expect.any(String),
|
||||||
|
}),
|
||||||
|
])
|
||||||
|
|
||||||
expect(response.status).toEqual(200)
|
response = await api.get(
|
||||||
expect(response.data.count).toEqual(1)
|
`/admin/price-lists/${priceList.id}/products?q=`,
|
||||||
expect(response.data.products).toEqual([
|
adminHeaders
|
||||||
expect.objectContaining({
|
)
|
||||||
id: expect.any(String),
|
|
||||||
}),
|
|
||||||
])
|
|
||||||
|
|
||||||
response = await api.get(
|
expect(response.status).toEqual(200)
|
||||||
`/admin/price-lists/${priceList.id}/products?q=`,
|
expect(response.data.count).toEqual(1)
|
||||||
adminHeaders
|
expect(response.data.products).toEqual([
|
||||||
)
|
expect.objectContaining({
|
||||||
|
id: expect.any(String),
|
||||||
expect(response.status).toEqual(200)
|
}),
|
||||||
expect(response.data.count).toEqual(1)
|
])
|
||||||
expect(response.data.products).toEqual([
|
})
|
||||||
expect.objectContaining({
|
})
|
||||||
id: expect.any(String),
|
},
|
||||||
}),
|
|
||||||
])
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
@@ -1,6 +1,3 @@
|
|||||||
import { useApi } from "../../../../environment-helpers/use-api"
|
|
||||||
import { getContainer } from "../../../../environment-helpers/use-container"
|
|
||||||
import { initDb, useDb } from "../../../../environment-helpers/use-db"
|
|
||||||
import { simpleProductFactory } from "../../../../factories"
|
import { simpleProductFactory } from "../../../../factories"
|
||||||
|
|
||||||
import {
|
import {
|
||||||
@@ -8,10 +5,9 @@ import {
|
|||||||
PriceListStatus,
|
PriceListStatus,
|
||||||
PriceListType,
|
PriceListType,
|
||||||
} from "@medusajs/types"
|
} from "@medusajs/types"
|
||||||
import path from "path"
|
|
||||||
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
|
|
||||||
import adminSeeder from "../../../../helpers/admin-seeder"
|
import adminSeeder from "../../../../helpers/admin-seeder"
|
||||||
import { createVariantPriceSet } from "../../../helpers/create-variant-price-set"
|
import { createVariantPriceSet } from "../../../helpers/create-variant-price-set"
|
||||||
|
import { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||||
|
|
||||||
jest.setTimeout(50000)
|
jest.setTimeout(50000)
|
||||||
|
|
||||||
@@ -25,145 +21,132 @@ const env = {
|
|||||||
MEDUSA_FF_MEDUSA_V2: true,
|
MEDUSA_FF_MEDUSA_V2: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
describe.skip("GET /admin/price-lists", () => {
|
medusaIntegrationTestRunner({
|
||||||
let dbConnection
|
env,
|
||||||
let appContainer
|
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||||
let shutdownServer
|
describe.skip("GET /admin/price-lists", () => {
|
||||||
let product
|
let appContainer
|
||||||
let variant
|
let product
|
||||||
let pricingModuleService: IPricingModuleService
|
let variant
|
||||||
|
let pricingModuleService: IPricingModuleService
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
|
appContainer = getContainer()
|
||||||
dbConnection = await initDb({ cwd, env } as any)
|
pricingModuleService = appContainer.resolve("pricingModuleService")
|
||||||
shutdownServer = await startBootstrapApp({ cwd, env })
|
})
|
||||||
appContainer = getContainer()
|
|
||||||
pricingModuleService = appContainer.resolve("pricingModuleService")
|
|
||||||
})
|
|
||||||
|
|
||||||
afterAll(async () => {
|
beforeEach(async () => {
|
||||||
const db = useDb()
|
await adminSeeder(dbConnection)
|
||||||
await db.shutdown()
|
|
||||||
await shutdownServer()
|
|
||||||
})
|
|
||||||
|
|
||||||
beforeEach(async () => {
|
product = await simpleProductFactory(dbConnection, {
|
||||||
await adminSeeder(dbConnection)
|
id: "test-product-with-variant",
|
||||||
|
variants: [
|
||||||
|
{
|
||||||
|
options: [{ option_id: "test-product-option-1", value: "test" }],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
id: "test-product-option-1",
|
||||||
|
title: "Test option 1",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
})
|
||||||
|
|
||||||
product = await simpleProductFactory(dbConnection, {
|
variant = product.variants[0]
|
||||||
id: "test-product-with-variant",
|
})
|
||||||
variants: [
|
|
||||||
{
|
|
||||||
options: [{ option_id: "test-product-option-1", value: "test" }],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
options: [
|
|
||||||
{
|
|
||||||
id: "test-product-option-1",
|
|
||||||
title: "Test option 1",
|
|
||||||
},
|
|
||||||
],
|
|
||||||
})
|
|
||||||
|
|
||||||
variant = product.variants[0]
|
it("should get price list and its money amounts with variants", async () => {
|
||||||
})
|
const priceSet = await createVariantPriceSet({
|
||||||
|
container: appContainer,
|
||||||
|
variantId: variant.id,
|
||||||
|
prices: [
|
||||||
|
{
|
||||||
|
amount: 3000,
|
||||||
|
currency_code: "usd",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
rules: [],
|
||||||
|
})
|
||||||
|
|
||||||
afterEach(async () => {
|
const [priceList] = await pricingModuleService.createPriceLists([
|
||||||
const db = useDb()
|
|
||||||
await db.teardown()
|
|
||||||
})
|
|
||||||
|
|
||||||
it("should get price list and its money amounts with variants", async () => {
|
|
||||||
const priceSet = await createVariantPriceSet({
|
|
||||||
container: appContainer,
|
|
||||||
variantId: variant.id,
|
|
||||||
prices: [
|
|
||||||
{
|
|
||||||
amount: 3000,
|
|
||||||
currency_code: "usd",
|
|
||||||
},
|
|
||||||
],
|
|
||||||
rules: [],
|
|
||||||
})
|
|
||||||
|
|
||||||
const [priceList] = await pricingModuleService.createPriceLists([
|
|
||||||
{
|
|
||||||
title: "test price list",
|
|
||||||
description: "test",
|
|
||||||
ends_at: new Date(),
|
|
||||||
starts_at: new Date(),
|
|
||||||
status: PriceListStatus.ACTIVE,
|
|
||||||
type: PriceListType.OVERRIDE,
|
|
||||||
prices: [
|
|
||||||
{
|
{
|
||||||
amount: 5000,
|
title: "test price list",
|
||||||
currency_code: "usd",
|
description: "test",
|
||||||
price_set_id: priceSet.id,
|
ends_at: new Date(),
|
||||||
|
starts_at: new Date(),
|
||||||
|
status: PriceListStatus.ACTIVE,
|
||||||
|
type: PriceListType.OVERRIDE,
|
||||||
|
prices: [
|
||||||
|
{
|
||||||
|
amount: 5000,
|
||||||
|
currency_code: "usd",
|
||||||
|
price_set_id: priceSet.id,
|
||||||
|
},
|
||||||
|
],
|
||||||
},
|
},
|
||||||
],
|
])
|
||||||
},
|
|
||||||
])
|
|
||||||
|
|
||||||
const api = useApi() as any
|
const response = await api.get(`/admin/price-lists`, adminHeaders)
|
||||||
|
|
||||||
const response = await api.get(`/admin/price-lists`, adminHeaders)
|
expect(response.status).toEqual(200)
|
||||||
|
expect(response.data.count).toEqual(1)
|
||||||
expect(response.status).toEqual(200)
|
expect(response.data.price_lists).toEqual([
|
||||||
expect(response.data.count).toEqual(1)
|
|
||||||
expect(response.data.price_lists).toEqual([
|
|
||||||
expect.objectContaining({
|
|
||||||
id: expect.any(String),
|
|
||||||
created_at: expect.any(String),
|
|
||||||
updated_at: expect.any(String),
|
|
||||||
deleted_at: null,
|
|
||||||
name: "test price list",
|
|
||||||
description: "test",
|
|
||||||
type: "override",
|
|
||||||
status: "active",
|
|
||||||
starts_at: expect.any(String),
|
|
||||||
ends_at: expect.any(String),
|
|
||||||
customer_groups: [],
|
|
||||||
prices: [
|
|
||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
id: expect.any(String),
|
id: expect.any(String),
|
||||||
created_at: expect.any(String),
|
created_at: expect.any(String),
|
||||||
updated_at: expect.any(String),
|
updated_at: expect.any(String),
|
||||||
deleted_at: null,
|
deleted_at: null,
|
||||||
currency_code: "usd",
|
name: "test price list",
|
||||||
amount: 5000,
|
description: "test",
|
||||||
min_quantity: null,
|
type: "override",
|
||||||
max_quantity: null,
|
status: "active",
|
||||||
price_list_id: expect.any(String),
|
starts_at: expect.any(String),
|
||||||
region_id: null,
|
ends_at: expect.any(String),
|
||||||
variant: expect.objectContaining({
|
customer_groups: [],
|
||||||
id: expect.any(String),
|
prices: [
|
||||||
created_at: expect.any(String),
|
expect.objectContaining({
|
||||||
updated_at: expect.any(String),
|
id: expect.any(String),
|
||||||
deleted_at: null,
|
created_at: expect.any(String),
|
||||||
title: expect.any(String),
|
updated_at: expect.any(String),
|
||||||
product_id: expect.any(String),
|
deleted_at: null,
|
||||||
sku: null,
|
currency_code: "usd",
|
||||||
barcode: null,
|
amount: 5000,
|
||||||
ean: null,
|
min_quantity: null,
|
||||||
upc: null,
|
max_quantity: null,
|
||||||
variant_rank: 0,
|
price_list_id: expect.any(String),
|
||||||
inventory_quantity: 10,
|
region_id: null,
|
||||||
allow_backorder: false,
|
variant: expect.objectContaining({
|
||||||
manage_inventory: true,
|
id: expect.any(String),
|
||||||
hs_code: null,
|
created_at: expect.any(String),
|
||||||
origin_country: null,
|
updated_at: expect.any(String),
|
||||||
mid_code: null,
|
deleted_at: null,
|
||||||
material: null,
|
title: expect.any(String),
|
||||||
weight: null,
|
product_id: expect.any(String),
|
||||||
length: null,
|
sku: null,
|
||||||
height: null,
|
barcode: null,
|
||||||
width: null,
|
ean: null,
|
||||||
metadata: null,
|
upc: null,
|
||||||
}),
|
variant_rank: 0,
|
||||||
variant_id: expect.any(String),
|
inventory_quantity: 10,
|
||||||
|
allow_backorder: false,
|
||||||
|
manage_inventory: true,
|
||||||
|
hs_code: null,
|
||||||
|
origin_country: null,
|
||||||
|
mid_code: null,
|
||||||
|
material: null,
|
||||||
|
weight: null,
|
||||||
|
length: null,
|
||||||
|
height: null,
|
||||||
|
width: null,
|
||||||
|
metadata: null,
|
||||||
|
}),
|
||||||
|
variant_id: expect.any(String),
|
||||||
|
}),
|
||||||
|
],
|
||||||
}),
|
}),
|
||||||
],
|
])
|
||||||
}),
|
})
|
||||||
])
|
})
|
||||||
})
|
},
|
||||||
})
|
})
|
||||||
@@ -1,6 +1,3 @@
|
|||||||
import { useApi } from "../../../../environment-helpers/use-api"
|
|
||||||
import { getContainer } from "../../../../environment-helpers/use-container"
|
|
||||||
import { initDb, useDb } from "../../../../environment-helpers/use-db"
|
|
||||||
import {
|
import {
|
||||||
simpleCustomerGroupFactory,
|
simpleCustomerGroupFactory,
|
||||||
simpleProductFactory,
|
simpleProductFactory,
|
||||||
@@ -12,11 +9,10 @@ import {
|
|||||||
PriceListStatus,
|
PriceListStatus,
|
||||||
PriceListType,
|
PriceListType,
|
||||||
} from "@medusajs/types"
|
} from "@medusajs/types"
|
||||||
import path from "path"
|
|
||||||
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
|
|
||||||
import adminSeeder from "../../../../helpers/admin-seeder"
|
import adminSeeder from "../../../../helpers/admin-seeder"
|
||||||
import { createDefaultRuleTypes } from "../../../helpers/create-default-rule-types"
|
import { createDefaultRuleTypes } from "../../../helpers/create-default-rule-types"
|
||||||
import { createVariantPriceSet } from "../../../helpers/create-variant-price-set"
|
import { createVariantPriceSet } from "../../../helpers/create-variant-price-set"
|
||||||
|
import { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||||
|
|
||||||
jest.setTimeout(50000)
|
jest.setTimeout(50000)
|
||||||
|
|
||||||
@@ -30,251 +26,240 @@ const env = {
|
|||||||
MEDUSA_FF_MEDUSA_V2: true,
|
MEDUSA_FF_MEDUSA_V2: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
describe.skip("POST /admin/price-lists/:id", () => {
|
medusaIntegrationTestRunner({
|
||||||
let dbConnection
|
env,
|
||||||
let appContainer
|
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||||
let shutdownServer
|
describe.skip("POST /admin/price-lists/:id", () => {
|
||||||
let product
|
let appContainer
|
||||||
let variant
|
let product
|
||||||
let variant2
|
let variant
|
||||||
let pricingModuleService: IPricingModuleService
|
let variant2
|
||||||
|
let pricingModuleService: IPricingModuleService
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
|
appContainer = getContainer()
|
||||||
dbConnection = await initDb({ cwd, env } as any)
|
pricingModuleService = appContainer.resolve("pricingModuleService")
|
||||||
shutdownServer = await startBootstrapApp({ cwd, env })
|
})
|
||||||
appContainer = getContainer()
|
|
||||||
pricingModuleService = appContainer.resolve("pricingModuleService")
|
|
||||||
})
|
|
||||||
|
|
||||||
afterAll(async () => {
|
beforeEach(async () => {
|
||||||
const db = useDb()
|
await adminSeeder(dbConnection)
|
||||||
await db.shutdown()
|
await createDefaultRuleTypes(appContainer)
|
||||||
await shutdownServer()
|
await simpleCustomerGroupFactory(dbConnection, {
|
||||||
})
|
id: "customer-group-2",
|
||||||
|
name: "Test Group 2",
|
||||||
|
})
|
||||||
|
|
||||||
beforeEach(async () => {
|
await simpleRegionFactory(dbConnection, {
|
||||||
await adminSeeder(dbConnection)
|
id: "test-region",
|
||||||
await createDefaultRuleTypes(appContainer)
|
name: "Test Region",
|
||||||
await simpleCustomerGroupFactory(dbConnection, {
|
currency_code: "usd",
|
||||||
id: "customer-group-2",
|
tax_rate: 0,
|
||||||
name: "Test Group 2",
|
})
|
||||||
})
|
|
||||||
|
|
||||||
await simpleRegionFactory(dbConnection, {
|
product = await simpleProductFactory(dbConnection, {
|
||||||
id: "test-region",
|
id: "test-product-with-variant",
|
||||||
name: "Test Region",
|
variants: [
|
||||||
currency_code: "usd",
|
{
|
||||||
tax_rate: 0,
|
options: [{ option_id: "test-product-option-1", value: "test" }],
|
||||||
})
|
},
|
||||||
|
{
|
||||||
|
options: [
|
||||||
|
{ option_id: "test-product-option-2", value: "test 2" },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
id: "test-product-option-1",
|
||||||
|
title: "Test option 1",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "test-product-option-2",
|
||||||
|
title: "Test option 2",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
})
|
||||||
|
|
||||||
product = await simpleProductFactory(dbConnection, {
|
variant = product.variants[0]
|
||||||
id: "test-product-with-variant",
|
variant2 = product.variants[1]
|
||||||
variants: [
|
})
|
||||||
{
|
|
||||||
options: [{ option_id: "test-product-option-1", value: "test" }],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
options: [{ option_id: "test-product-option-2", value: "test 2" }],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
options: [
|
|
||||||
{
|
|
||||||
id: "test-product-option-1",
|
|
||||||
title: "Test option 1",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: "test-product-option-2",
|
|
||||||
title: "Test option 2",
|
|
||||||
},
|
|
||||||
],
|
|
||||||
})
|
|
||||||
|
|
||||||
variant = product.variants[0]
|
it("should update price lists successfully with prices", async () => {
|
||||||
variant2 = product.variants[1]
|
const var2PriceSet = await createVariantPriceSet({
|
||||||
})
|
container: appContainer,
|
||||||
|
variantId: variant2.id,
|
||||||
|
prices: [],
|
||||||
|
})
|
||||||
|
|
||||||
afterEach(async () => {
|
const [priceList] = await pricingModuleService.createPriceLists([
|
||||||
const db = useDb()
|
|
||||||
await db.teardown()
|
|
||||||
})
|
|
||||||
|
|
||||||
it("should update price lists successfully with prices", async () => {
|
|
||||||
const var2PriceSet = await createVariantPriceSet({
|
|
||||||
container: appContainer,
|
|
||||||
variantId: variant2.id,
|
|
||||||
prices: [],
|
|
||||||
})
|
|
||||||
|
|
||||||
const [priceList] = await pricingModuleService.createPriceLists([
|
|
||||||
{
|
|
||||||
title: "test price list",
|
|
||||||
description: "test",
|
|
||||||
ends_at: new Date(),
|
|
||||||
starts_at: new Date(),
|
|
||||||
status: PriceListStatus.ACTIVE,
|
|
||||||
type: PriceListType.OVERRIDE,
|
|
||||||
prices: [
|
|
||||||
{
|
{
|
||||||
amount: 3000,
|
title: "test price list",
|
||||||
currency_code: "usd",
|
description: "test",
|
||||||
price_set_id: var2PriceSet.id,
|
ends_at: new Date(),
|
||||||
|
starts_at: new Date(),
|
||||||
|
status: PriceListStatus.ACTIVE,
|
||||||
|
type: PriceListType.OVERRIDE,
|
||||||
|
prices: [
|
||||||
|
{
|
||||||
|
amount: 3000,
|
||||||
|
currency_code: "usd",
|
||||||
|
price_set_id: var2PriceSet.id,
|
||||||
|
},
|
||||||
|
],
|
||||||
},
|
},
|
||||||
],
|
])
|
||||||
},
|
|
||||||
])
|
|
||||||
|
|
||||||
await createVariantPriceSet({
|
await createVariantPriceSet({
|
||||||
container: appContainer,
|
container: appContainer,
|
||||||
variantId: variant.id,
|
variantId: variant.id,
|
||||||
prices: [
|
prices: [
|
||||||
{
|
{
|
||||||
amount: 3000,
|
amount: 3000,
|
||||||
currency_code: "usd",
|
currency_code: "usd",
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
|
|
||||||
const api = useApi() as any
|
const data = {
|
||||||
const data = {
|
name: "new price list name",
|
||||||
name: "new price list name",
|
description: "new price list description",
|
||||||
description: "new price list description",
|
customer_groups: [{ id: "customer-group-2" }],
|
||||||
customer_groups: [{ id: "customer-group-2" }],
|
prices: [
|
||||||
prices: [
|
{
|
||||||
{
|
variant_id: variant.id,
|
||||||
variant_id: variant.id,
|
amount: 5000,
|
||||||
amount: 5000,
|
currency_code: "usd",
|
||||||
currency_code: "usd",
|
},
|
||||||
},
|
{
|
||||||
{
|
id: priceList?.price_set_money_amounts?.[0].money_amount?.id,
|
||||||
id: priceList?.price_set_money_amounts?.[0].money_amount?.id,
|
amount: 6000,
|
||||||
amount: 6000,
|
currency_code: "usd",
|
||||||
currency_code: "usd",
|
variant_id: variant2.id,
|
||||||
variant_id: variant2.id,
|
},
|
||||||
},
|
],
|
||||||
],
|
}
|
||||||
}
|
|
||||||
|
|
||||||
await api.post(`admin/price-lists/${priceList.id}`, data, adminHeaders)
|
await api.post(`admin/price-lists/${priceList.id}`, data, adminHeaders)
|
||||||
|
|
||||||
const response = await api.get(
|
const response = await api.get(
|
||||||
`/admin/price-lists/${priceList.id}`,
|
`/admin/price-lists/${priceList.id}`,
|
||||||
adminHeaders
|
adminHeaders
|
||||||
)
|
)
|
||||||
|
|
||||||
expect(response.status).toEqual(200)
|
expect(response.status).toEqual(200)
|
||||||
expect(response.data.price_list).toEqual(
|
expect(response.data.price_list).toEqual(
|
||||||
expect.objectContaining({
|
|
||||||
id: expect.any(String),
|
|
||||||
created_at: expect.any(String),
|
|
||||||
updated_at: expect.any(String),
|
|
||||||
deleted_at: null,
|
|
||||||
name: "new price list name",
|
|
||||||
description: "new price list description",
|
|
||||||
type: "override",
|
|
||||||
status: "active",
|
|
||||||
starts_at: expect.any(String),
|
|
||||||
ends_at: expect.any(String),
|
|
||||||
customer_groups: [
|
|
||||||
{
|
|
||||||
id: expect.any(String),
|
|
||||||
created_at: expect.any(String),
|
|
||||||
updated_at: expect.any(String),
|
|
||||||
deleted_at: null,
|
|
||||||
name: "Test Group 2",
|
|
||||||
metadata: null,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
prices: expect.arrayContaining([
|
|
||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
id: expect.any(String),
|
id: expect.any(String),
|
||||||
created_at: expect.any(String),
|
created_at: expect.any(String),
|
||||||
updated_at: expect.any(String),
|
updated_at: expect.any(String),
|
||||||
deleted_at: null,
|
deleted_at: null,
|
||||||
currency_code: "usd",
|
name: "new price list name",
|
||||||
amount: 5000,
|
description: "new price list description",
|
||||||
min_quantity: null,
|
type: "override",
|
||||||
max_quantity: null,
|
status: "active",
|
||||||
price_list_id: priceList.id,
|
starts_at: expect.any(String),
|
||||||
region_id: null,
|
ends_at: expect.any(String),
|
||||||
variant: expect.objectContaining({
|
customer_groups: [
|
||||||
id: variant.id,
|
{
|
||||||
}),
|
id: expect.any(String),
|
||||||
variant_id: variant.id,
|
created_at: expect.any(String),
|
||||||
}),
|
updated_at: expect.any(String),
|
||||||
|
deleted_at: null,
|
||||||
|
name: "Test Group 2",
|
||||||
|
metadata: null,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
prices: expect.arrayContaining([
|
||||||
|
expect.objectContaining({
|
||||||
|
id: expect.any(String),
|
||||||
|
created_at: expect.any(String),
|
||||||
|
updated_at: expect.any(String),
|
||||||
|
deleted_at: null,
|
||||||
|
currency_code: "usd",
|
||||||
|
amount: 5000,
|
||||||
|
min_quantity: null,
|
||||||
|
max_quantity: null,
|
||||||
|
price_list_id: priceList.id,
|
||||||
|
region_id: null,
|
||||||
|
variant: expect.objectContaining({
|
||||||
|
id: variant.id,
|
||||||
|
}),
|
||||||
|
variant_id: variant.id,
|
||||||
|
}),
|
||||||
|
expect.objectContaining({
|
||||||
|
id: expect.any(String),
|
||||||
|
created_at: expect.any(String),
|
||||||
|
updated_at: expect.any(String),
|
||||||
|
deleted_at: null,
|
||||||
|
currency_code: "usd",
|
||||||
|
amount: 6000,
|
||||||
|
min_quantity: null,
|
||||||
|
max_quantity: null,
|
||||||
|
price_list_id: priceList.id,
|
||||||
|
region_id: null,
|
||||||
|
variant: expect.objectContaining({
|
||||||
|
id: variant2.id,
|
||||||
|
}),
|
||||||
|
variant_id: variant2.id,
|
||||||
|
}),
|
||||||
|
]),
|
||||||
|
})
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should not delete customer groups if customer_groups is not passed as a param", async () => {
|
||||||
|
await createVariantPriceSet({
|
||||||
|
container: appContainer,
|
||||||
|
variantId: variant2.id,
|
||||||
|
prices: [],
|
||||||
|
})
|
||||||
|
|
||||||
|
const [priceList] = await pricingModuleService.createPriceLists([
|
||||||
|
{
|
||||||
|
title: "test price list",
|
||||||
|
description: "test",
|
||||||
|
status: PriceListStatus.DRAFT,
|
||||||
|
rules: {
|
||||||
|
customer_group_id: ["customer-group-2"],
|
||||||
|
},
|
||||||
|
prices: [],
|
||||||
|
},
|
||||||
|
])
|
||||||
|
|
||||||
|
await createVariantPriceSet({
|
||||||
|
container: appContainer,
|
||||||
|
variantId: variant.id,
|
||||||
|
prices: [],
|
||||||
|
})
|
||||||
|
|
||||||
|
const data = {
|
||||||
|
status: PriceListStatus.ACTIVE,
|
||||||
|
}
|
||||||
|
|
||||||
|
await api.post(`admin/price-lists/${priceList.id}`, data, adminHeaders)
|
||||||
|
|
||||||
|
const response = await api.get(
|
||||||
|
`/admin/price-lists/${priceList.id}`,
|
||||||
|
adminHeaders
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(response.status).toEqual(200)
|
||||||
|
expect(response.data.price_list).toEqual(
|
||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
id: expect.any(String),
|
id: expect.any(String),
|
||||||
created_at: expect.any(String),
|
customer_groups: [
|
||||||
updated_at: expect.any(String),
|
{
|
||||||
deleted_at: null,
|
id: expect.any(String),
|
||||||
currency_code: "usd",
|
created_at: expect.any(String),
|
||||||
amount: 6000,
|
updated_at: expect.any(String),
|
||||||
min_quantity: null,
|
deleted_at: null,
|
||||||
max_quantity: null,
|
name: "Test Group 2",
|
||||||
price_list_id: priceList.id,
|
metadata: null,
|
||||||
region_id: null,
|
},
|
||||||
variant: expect.objectContaining({
|
],
|
||||||
id: variant2.id,
|
})
|
||||||
}),
|
)
|
||||||
variant_id: variant2.id,
|
|
||||||
}),
|
|
||||||
]),
|
|
||||||
})
|
})
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
it("should not delete customer groups if customer_groups is not passed as a param", async () => {
|
|
||||||
await createVariantPriceSet({
|
|
||||||
container: appContainer,
|
|
||||||
variantId: variant2.id,
|
|
||||||
prices: [],
|
|
||||||
})
|
})
|
||||||
|
},
|
||||||
const [priceList] = await pricingModuleService.createPriceLists([
|
|
||||||
{
|
|
||||||
title: "test price list",
|
|
||||||
description: "test",
|
|
||||||
status: PriceListStatus.DRAFT,
|
|
||||||
rules: {
|
|
||||||
customer_group_id: ["customer-group-2"],
|
|
||||||
},
|
|
||||||
prices: [],
|
|
||||||
},
|
|
||||||
])
|
|
||||||
|
|
||||||
await createVariantPriceSet({
|
|
||||||
container: appContainer,
|
|
||||||
variantId: variant.id,
|
|
||||||
prices: [],
|
|
||||||
})
|
|
||||||
|
|
||||||
const api = useApi() as any
|
|
||||||
const data = {
|
|
||||||
status: PriceListStatus.ACTIVE,
|
|
||||||
}
|
|
||||||
|
|
||||||
await api.post(`admin/price-lists/${priceList.id}`, data, adminHeaders)
|
|
||||||
|
|
||||||
const response = await api.get(
|
|
||||||
`/admin/price-lists/${priceList.id}`,
|
|
||||||
adminHeaders
|
|
||||||
)
|
|
||||||
|
|
||||||
expect(response.status).toEqual(200)
|
|
||||||
expect(response.data.price_list).toEqual(
|
|
||||||
expect.objectContaining({
|
|
||||||
id: expect.any(String),
|
|
||||||
customer_groups: [
|
|
||||||
{
|
|
||||||
id: expect.any(String),
|
|
||||||
created_at: expect.any(String),
|
|
||||||
updated_at: expect.any(String),
|
|
||||||
deleted_at: null,
|
|
||||||
name: "Test Group 2",
|
|
||||||
metadata: null,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
})
|
|
||||||
)
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
@@ -1,6 +1,3 @@
|
|||||||
import { useApi } from "../../../../environment-helpers/use-api"
|
|
||||||
import { getContainer } from "../../../../environment-helpers/use-container"
|
|
||||||
import { initDb, useDb } from "../../../../environment-helpers/use-db"
|
|
||||||
import {
|
import {
|
||||||
simpleCustomerFactory,
|
simpleCustomerFactory,
|
||||||
simpleCustomerGroupFactory,
|
simpleCustomerGroupFactory,
|
||||||
@@ -13,12 +10,10 @@ import {
|
|||||||
PriceListStatus,
|
PriceListStatus,
|
||||||
PriceListType,
|
PriceListType,
|
||||||
} from "@medusajs/types"
|
} from "@medusajs/types"
|
||||||
import { AxiosInstance } from "axios"
|
|
||||||
import path from "path"
|
|
||||||
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
|
|
||||||
import adminSeeder from "../../../../helpers/admin-seeder"
|
import adminSeeder from "../../../../helpers/admin-seeder"
|
||||||
import { createDefaultRuleTypes } from "../../../helpers/create-default-rule-types"
|
import { createDefaultRuleTypes } from "../../../helpers/create-default-rule-types"
|
||||||
import { createVariantPriceSet } from "../../../helpers/create-variant-price-set"
|
import { createVariantPriceSet } from "../../../helpers/create-variant-price-set"
|
||||||
|
import { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||||
|
|
||||||
jest.setTimeout(50000)
|
jest.setTimeout(50000)
|
||||||
|
|
||||||
@@ -32,256 +27,239 @@ const env = {
|
|||||||
MEDUSA_FF_MEDUSA_V2: true,
|
MEDUSA_FF_MEDUSA_V2: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
describe.skip("GET /store/products/:id", () => {
|
medusaIntegrationTestRunner({
|
||||||
let dbConnection
|
env,
|
||||||
let appContainer
|
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||||
let shutdownServer
|
describe.skip("GET /store/products/:id", () => {
|
||||||
let product
|
let appContainer
|
||||||
let variant
|
let product
|
||||||
let priceSetId
|
let variant
|
||||||
let pricingModuleService: IPricingModuleService
|
let priceSetId
|
||||||
|
let pricingModuleService: IPricingModuleService
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
|
appContainer = getContainer()
|
||||||
dbConnection = await initDb({ cwd, env } as any)
|
pricingModuleService = appContainer.resolve("pricingModuleService")
|
||||||
shutdownServer = await startBootstrapApp({ cwd, env })
|
})
|
||||||
appContainer = getContainer()
|
|
||||||
pricingModuleService = appContainer.resolve("pricingModuleService")
|
|
||||||
})
|
|
||||||
|
|
||||||
afterAll(async () => {
|
beforeEach(async () => {
|
||||||
const db = useDb()
|
await adminSeeder(dbConnection)
|
||||||
await db.shutdown()
|
await createDefaultRuleTypes(appContainer)
|
||||||
await shutdownServer()
|
|
||||||
})
|
|
||||||
|
|
||||||
beforeEach(async () => {
|
await simpleRegionFactory(dbConnection, {
|
||||||
await adminSeeder(dbConnection)
|
id: "test-region",
|
||||||
await createDefaultRuleTypes(appContainer)
|
name: "Test Region",
|
||||||
|
|
||||||
await simpleRegionFactory(dbConnection, {
|
|
||||||
id: "test-region",
|
|
||||||
name: "Test Region",
|
|
||||||
currency_code: "usd",
|
|
||||||
tax_rate: 0,
|
|
||||||
})
|
|
||||||
|
|
||||||
product = await simpleProductFactory(dbConnection, {
|
|
||||||
id: "test-product-with-variant",
|
|
||||||
status: "published",
|
|
||||||
variants: [
|
|
||||||
{
|
|
||||||
options: [{ option_id: "test-product-option-1", value: "test" }],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
options: [
|
|
||||||
{
|
|
||||||
id: "test-product-option-1",
|
|
||||||
title: "Test option 1",
|
|
||||||
},
|
|
||||||
],
|
|
||||||
})
|
|
||||||
|
|
||||||
variant = product.variants[0]
|
|
||||||
|
|
||||||
const priceSet = await createVariantPriceSet({
|
|
||||||
container: appContainer,
|
|
||||||
variantId: variant.id,
|
|
||||||
prices: [
|
|
||||||
{
|
|
||||||
amount: 3000,
|
|
||||||
currency_code: "usd",
|
currency_code: "usd",
|
||||||
},
|
tax_rate: 0,
|
||||||
{
|
})
|
||||||
amount: 4000,
|
|
||||||
currency_code: "usd",
|
|
||||||
},
|
|
||||||
],
|
|
||||||
rules: [],
|
|
||||||
})
|
|
||||||
|
|
||||||
priceSetId = priceSet.id
|
product = await simpleProductFactory(dbConnection, {
|
||||||
})
|
id: "test-product-with-variant",
|
||||||
|
status: "published",
|
||||||
|
variants: [
|
||||||
|
{
|
||||||
|
options: [{ option_id: "test-product-option-1", value: "test" }],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
id: "test-product-option-1",
|
||||||
|
title: "Test option 1",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
})
|
||||||
|
|
||||||
afterEach(async () => {
|
variant = product.variants[0]
|
||||||
const db = useDb()
|
|
||||||
await db.teardown()
|
|
||||||
})
|
|
||||||
|
|
||||||
it("should get product and its prices from price-list created through the price list workflow", async () => {
|
const priceSet = await createVariantPriceSet({
|
||||||
const api = useApi()! as AxiosInstance
|
container: appContainer,
|
||||||
|
variantId: variant.id,
|
||||||
|
prices: [
|
||||||
|
{
|
||||||
|
amount: 3000,
|
||||||
|
currency_code: "usd",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
amount: 4000,
|
||||||
|
currency_code: "usd",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
rules: [],
|
||||||
|
})
|
||||||
|
|
||||||
const priceListResponse = await api.post(
|
priceSetId = priceSet.id
|
||||||
`/admin/price-lists`,
|
|
||||||
{
|
|
||||||
name: "test price list",
|
|
||||||
description: "test",
|
|
||||||
status: PriceListStatus.ACTIVE,
|
|
||||||
type: PriceListType.SALE,
|
|
||||||
prices: [
|
|
||||||
{
|
|
||||||
amount: 2500,
|
|
||||||
currency_code: "usd",
|
|
||||||
variant_id: variant.id,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
adminHeaders
|
|
||||||
)
|
|
||||||
|
|
||||||
let response = await api.get(
|
|
||||||
`/store/products/${product.id}?currency_code=usd`
|
|
||||||
)
|
|
||||||
|
|
||||||
expect(response.status).toEqual(200)
|
|
||||||
expect(response.data.product.variants[0].prices).toHaveLength(2)
|
|
||||||
expect(response.data.product.variants[0].prices).toEqual([
|
|
||||||
expect.objectContaining({
|
|
||||||
currency_code: "usd",
|
|
||||||
amount: 3000,
|
|
||||||
min_quantity: null,
|
|
||||||
max_quantity: null,
|
|
||||||
price_list_id: null,
|
|
||||||
}),
|
|
||||||
expect.objectContaining({
|
|
||||||
currency_code: "usd",
|
|
||||||
amount: 2500,
|
|
||||||
min_quantity: null,
|
|
||||||
max_quantity: null,
|
|
||||||
price_list_id: priceListResponse.data.price_list.id,
|
|
||||||
}),
|
|
||||||
])
|
|
||||||
expect(response.data.product.variants[0]).toEqual(
|
|
||||||
expect.objectContaining({
|
|
||||||
original_price: 3000,
|
|
||||||
calculated_price: 2500,
|
|
||||||
calculated_price_type: "sale",
|
|
||||||
})
|
})
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
it("should not list prices from price-list with customer groups if not logged in", async () => {
|
it("should get product and its prices from price-list created through the price list workflow", async () => {
|
||||||
const api = useApi()! as AxiosInstance
|
const priceListResponse = await api.post(
|
||||||
|
`/admin/price-lists`,
|
||||||
const { id: customerGroupId } = await simpleCustomerGroupFactory(
|
|
||||||
dbConnection
|
|
||||||
)
|
|
||||||
|
|
||||||
const priceListResponse = await api.post(
|
|
||||||
`/admin/price-lists`,
|
|
||||||
{
|
|
||||||
name: "test price list",
|
|
||||||
description: "test",
|
|
||||||
status: PriceListStatus.ACTIVE,
|
|
||||||
type: PriceListType.SALE,
|
|
||||||
prices: [
|
|
||||||
{
|
{
|
||||||
amount: 2500,
|
name: "test price list",
|
||||||
currency_code: "usd",
|
description: "test",
|
||||||
variant_id: variant.id,
|
status: PriceListStatus.ACTIVE,
|
||||||
|
type: PriceListType.SALE,
|
||||||
|
prices: [
|
||||||
|
{
|
||||||
|
amount: 2500,
|
||||||
|
currency_code: "usd",
|
||||||
|
variant_id: variant.id,
|
||||||
|
},
|
||||||
|
],
|
||||||
},
|
},
|
||||||
],
|
adminHeaders
|
||||||
customer_groups: [{ id: customerGroupId }],
|
)
|
||||||
},
|
|
||||||
adminHeaders
|
|
||||||
)
|
|
||||||
|
|
||||||
let response = await api.get(
|
let response = await api.get(
|
||||||
`/store/products/${product.id}?currency_code=usd`
|
`/store/products/${product.id}?currency_code=usd`
|
||||||
)
|
)
|
||||||
|
|
||||||
expect(response.status).toEqual(200)
|
expect(response.status).toEqual(200)
|
||||||
expect(response.data.product.variants[0].prices).toEqual([
|
expect(response.data.product.variants[0].prices).toHaveLength(2)
|
||||||
expect.objectContaining({
|
expect(response.data.product.variants[0].prices).toEqual([
|
||||||
currency_code: "usd",
|
expect.objectContaining({
|
||||||
amount: 3000,
|
currency_code: "usd",
|
||||||
min_quantity: null,
|
amount: 3000,
|
||||||
max_quantity: null,
|
min_quantity: null,
|
||||||
price_list_id: null,
|
max_quantity: null,
|
||||||
}),
|
price_list_id: null,
|
||||||
])
|
}),
|
||||||
expect(response.data.product.variants[0]).toEqual(
|
expect.objectContaining({
|
||||||
expect.objectContaining({
|
currency_code: "usd",
|
||||||
original_price: 3000,
|
amount: 2500,
|
||||||
calculated_price: 3000,
|
min_quantity: null,
|
||||||
calculated_price_type: null,
|
max_quantity: null,
|
||||||
|
price_list_id: priceListResponse.data.price_list.id,
|
||||||
|
}),
|
||||||
|
])
|
||||||
|
expect(response.data.product.variants[0]).toEqual(
|
||||||
|
expect.objectContaining({
|
||||||
|
original_price: 3000,
|
||||||
|
calculated_price: 2500,
|
||||||
|
calculated_price_type: "sale",
|
||||||
|
})
|
||||||
|
)
|
||||||
})
|
})
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
it("should list prices from price-list with customer groups", async () => {
|
it("should not list prices from price-list with customer groups if not logged in", async () => {
|
||||||
const api = useApi()! as AxiosInstance
|
const { id: customerGroupId } = await simpleCustomerGroupFactory(
|
||||||
|
dbConnection
|
||||||
|
)
|
||||||
|
|
||||||
await simpleCustomerFactory(dbConnection, {
|
const priceListResponse = await api.post(
|
||||||
id: "test-customer-5-pl",
|
`/admin/price-lists`,
|
||||||
email: "test5@email-pl.com",
|
|
||||||
first_name: "John",
|
|
||||||
last_name: "Deere",
|
|
||||||
password_hash:
|
|
||||||
"c2NyeXB0AAEAAAABAAAAAVMdaddoGjwU1TafDLLlBKnOTQga7P2dbrfgf3fB+rCD/cJOMuGzAvRdKutbYkVpuJWTU39P7OpuWNkUVoEETOVLMJafbI8qs8Qx/7jMQXkN", // password matching "test"
|
|
||||||
has_account: true,
|
|
||||||
groups: [{ id: "customer-group-1" }],
|
|
||||||
})
|
|
||||||
|
|
||||||
const authResponse = await api.post("/store/auth", {
|
|
||||||
email: "test5@email-pl.com",
|
|
||||||
password: "test",
|
|
||||||
})
|
|
||||||
|
|
||||||
const [authCookie] = authResponse.headers["set-cookie"][0].split(";")
|
|
||||||
|
|
||||||
const priceListResponse = await api.post(
|
|
||||||
`/admin/price-lists`,
|
|
||||||
{
|
|
||||||
name: "test price list",
|
|
||||||
description: "test",
|
|
||||||
status: PriceListStatus.ACTIVE,
|
|
||||||
type: PriceListType.SALE,
|
|
||||||
prices: [
|
|
||||||
{
|
{
|
||||||
amount: 2500,
|
name: "test price list",
|
||||||
currency_code: "usd",
|
description: "test",
|
||||||
variant_id: variant.id,
|
status: PriceListStatus.ACTIVE,
|
||||||
|
type: PriceListType.SALE,
|
||||||
|
prices: [
|
||||||
|
{
|
||||||
|
amount: 2500,
|
||||||
|
currency_code: "usd",
|
||||||
|
variant_id: variant.id,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
customer_groups: [{ id: customerGroupId }],
|
||||||
},
|
},
|
||||||
],
|
adminHeaders
|
||||||
customer_groups: [{ id: "customer-group-1" }],
|
)
|
||||||
},
|
|
||||||
adminHeaders
|
|
||||||
)
|
|
||||||
|
|
||||||
let response = await api.get(
|
let response = await api.get(
|
||||||
`/store/products/${product.id}?currency_code=usd`,
|
`/store/products/${product.id}?currency_code=usd`
|
||||||
{
|
)
|
||||||
headers: {
|
|
||||||
Cookie: authCookie,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
expect(response.status).toEqual(200)
|
expect(response.status).toEqual(200)
|
||||||
expect(response.data.product.variants[0].prices).toHaveLength(2)
|
expect(response.data.product.variants[0].prices).toEqual([
|
||||||
expect(response.data.product.variants[0].prices).toEqual([
|
expect.objectContaining({
|
||||||
expect.objectContaining({
|
currency_code: "usd",
|
||||||
currency_code: "usd",
|
amount: 3000,
|
||||||
amount: 3000,
|
min_quantity: null,
|
||||||
min_quantity: null,
|
max_quantity: null,
|
||||||
max_quantity: null,
|
price_list_id: null,
|
||||||
price_list_id: null,
|
}),
|
||||||
}),
|
])
|
||||||
expect.objectContaining({
|
expect(response.data.product.variants[0]).toEqual(
|
||||||
currency_code: "usd",
|
expect.objectContaining({
|
||||||
amount: 2500,
|
original_price: 3000,
|
||||||
min_quantity: null,
|
calculated_price: 3000,
|
||||||
max_quantity: null,
|
calculated_price_type: null,
|
||||||
price_list_id: priceListResponse.data.price_list.id,
|
})
|
||||||
}),
|
)
|
||||||
])
|
|
||||||
expect(response.data.product.variants[0]).toEqual(
|
|
||||||
expect.objectContaining({
|
|
||||||
original_price: 3000,
|
|
||||||
calculated_price: 2500,
|
|
||||||
calculated_price_type: "sale",
|
|
||||||
})
|
})
|
||||||
)
|
|
||||||
})
|
it("should list prices from price-list with customer groups", async () => {
|
||||||
|
await simpleCustomerFactory(dbConnection, {
|
||||||
|
id: "test-customer-5-pl",
|
||||||
|
email: "test5@email-pl.com",
|
||||||
|
first_name: "John",
|
||||||
|
last_name: "Deere",
|
||||||
|
password_hash:
|
||||||
|
"c2NyeXB0AAEAAAABAAAAAVMdaddoGjwU1TafDLLlBKnOTQga7P2dbrfgf3fB+rCD/cJOMuGzAvRdKutbYkVpuJWTU39P7OpuWNkUVoEETOVLMJafbI8qs8Qx/7jMQXkN", // password matching "test"
|
||||||
|
has_account: true,
|
||||||
|
groups: [{ id: "customer-group-1" }],
|
||||||
|
})
|
||||||
|
|
||||||
|
const authResponse = await api.post("/store/auth", {
|
||||||
|
email: "test5@email-pl.com",
|
||||||
|
password: "test",
|
||||||
|
})
|
||||||
|
|
||||||
|
const [authCookie] = authResponse.headers["set-cookie"][0].split(";")
|
||||||
|
|
||||||
|
const priceListResponse = await api.post(
|
||||||
|
`/admin/price-lists`,
|
||||||
|
{
|
||||||
|
name: "test price list",
|
||||||
|
description: "test",
|
||||||
|
status: PriceListStatus.ACTIVE,
|
||||||
|
type: PriceListType.SALE,
|
||||||
|
prices: [
|
||||||
|
{
|
||||||
|
amount: 2500,
|
||||||
|
currency_code: "usd",
|
||||||
|
variant_id: variant.id,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
customer_groups: [{ id: "customer-group-1" }],
|
||||||
|
},
|
||||||
|
adminHeaders
|
||||||
|
)
|
||||||
|
|
||||||
|
let response = await api.get(
|
||||||
|
`/store/products/${product.id}?currency_code=usd`,
|
||||||
|
{
|
||||||
|
headers: {
|
||||||
|
Cookie: authCookie,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(response.status).toEqual(200)
|
||||||
|
expect(response.data.product.variants[0].prices).toHaveLength(2)
|
||||||
|
expect(response.data.product.variants[0].prices).toEqual([
|
||||||
|
expect.objectContaining({
|
||||||
|
currency_code: "usd",
|
||||||
|
amount: 3000,
|
||||||
|
min_quantity: null,
|
||||||
|
max_quantity: null,
|
||||||
|
price_list_id: null,
|
||||||
|
}),
|
||||||
|
expect.objectContaining({
|
||||||
|
currency_code: "usd",
|
||||||
|
amount: 2500,
|
||||||
|
min_quantity: null,
|
||||||
|
max_quantity: null,
|
||||||
|
price_list_id: priceListResponse.data.price_list.id,
|
||||||
|
}),
|
||||||
|
])
|
||||||
|
expect(response.data.product.variants[0]).toEqual(
|
||||||
|
expect.objectContaining({
|
||||||
|
original_price: 3000,
|
||||||
|
calculated_price: 2500,
|
||||||
|
calculated_price_type: "sale",
|
||||||
|
})
|
||||||
|
)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
},
|
||||||
})
|
})
|
||||||
@@ -1,14 +1,9 @@
|
|||||||
import { useApi } from "../../../environment-helpers/use-api"
|
|
||||||
import { initDb, useDb } from "../../../environment-helpers/use-db"
|
|
||||||
import { simpleCartFactory, simpleRegionFactory } from "../../../factories"
|
import { simpleCartFactory, simpleRegionFactory } from "../../../factories"
|
||||||
|
|
||||||
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||||
import { AxiosInstance } from "axios"
|
|
||||||
import path from "path"
|
|
||||||
import { startBootstrapApp } from "../../../environment-helpers/bootstrap-app"
|
|
||||||
import { getContainer } from "../../../environment-helpers/use-container"
|
|
||||||
import adminSeeder from "../../../helpers/admin-seeder"
|
import adminSeeder from "../../../helpers/admin-seeder"
|
||||||
import { createDefaultRuleTypes } from "../../helpers/create-default-rule-types"
|
import { createDefaultRuleTypes } from "../../helpers/create-default-rule-types"
|
||||||
|
import { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||||
|
|
||||||
jest.setTimeout(5000000)
|
jest.setTimeout(5000000)
|
||||||
|
|
||||||
@@ -28,109 +23,106 @@ const env = {
|
|||||||
MEDUSA_FF_MEDUSA_V2: true,
|
MEDUSA_FF_MEDUSA_V2: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
describe.skip("Link Modules", () => {
|
medusaIntegrationTestRunner({
|
||||||
let medusaContainer
|
env,
|
||||||
let dbConnection
|
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||||
let shutdownServer
|
describe.skip("Link Modules", () => {
|
||||||
|
let medusaContainer
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
const cwd = path.resolve(path.join(__dirname, "..", ".."))
|
medusaContainer = getContainer()
|
||||||
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)
|
|
||||||
await simpleRegionFactory(dbConnection, {
|
|
||||||
id: "region-1",
|
|
||||||
currency_code: "usd",
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
describe("get product price", () => {
|
|
||||||
let ruleType
|
|
||||||
let priceSet
|
|
||||||
let productId
|
|
||||||
const cartId = "test-cart"
|
|
||||||
beforeEach(async () => {
|
|
||||||
const pricingModuleService = medusaContainer.resolve(
|
|
||||||
ModuleRegistrationName.PRICING
|
|
||||||
)
|
|
||||||
const api = useApi()! as AxiosInstance
|
|
||||||
|
|
||||||
await simpleCartFactory(dbConnection, { id: cartId, region: "region-1" })
|
|
||||||
|
|
||||||
const payload = {
|
|
||||||
title: "Test",
|
|
||||||
description: "test-product-description",
|
|
||||||
images: ["test-image.png", "test-image-2.png"],
|
|
||||||
variants: [
|
|
||||||
{
|
|
||||||
title: "Test variant",
|
|
||||||
prices: [],
|
|
||||||
options: [],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
}
|
|
||||||
|
|
||||||
const response = await api.post("/admin/products", payload, adminHeaders)
|
|
||||||
|
|
||||||
productId = response.data.product.id
|
|
||||||
const variant = response.data.product.variants[0]
|
|
||||||
|
|
||||||
ruleType = await pricingModuleService.createRuleTypes([
|
|
||||||
{ name: "region_id", rule_attribute: "region_id" },
|
|
||||||
])
|
|
||||||
|
|
||||||
priceSet = await pricingModuleService.create({
|
|
||||||
rules: [{ rule_attribute: "region_id" }],
|
|
||||||
prices: [
|
|
||||||
{
|
|
||||||
amount: 1000,
|
|
||||||
currency_code: "usd",
|
|
||||||
rules: { region_id: "region-1" },
|
|
||||||
},
|
|
||||||
{
|
|
||||||
amount: 900,
|
|
||||||
currency_code: "usd",
|
|
||||||
rules: { region_id: "region-2" },
|
|
||||||
},
|
|
||||||
],
|
|
||||||
})
|
})
|
||||||
|
beforeEach(async () => {
|
||||||
const remoteLink = medusaContainer.resolve("remoteLink") as any
|
await createDefaultRuleTypes(medusaContainer)
|
||||||
|
await adminSeeder(dbConnection)
|
||||||
await remoteLink.create({
|
await simpleRegionFactory(dbConnection, {
|
||||||
productService: {
|
id: "region-1",
|
||||||
variant_id: variant.id,
|
|
||||||
},
|
|
||||||
pricingService: {
|
|
||||||
price_set_id: priceSet.id,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
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}`
|
|
||||||
)
|
|
||||||
|
|
||||||
expect(response.data.product.variants[0].prices).toEqual([
|
|
||||||
expect.objectContaining({
|
|
||||||
amount: 1000,
|
|
||||||
currency_code: "usd",
|
currency_code: "usd",
|
||||||
}),
|
})
|
||||||
])
|
})
|
||||||
|
|
||||||
|
describe("get product price", () => {
|
||||||
|
let ruleType
|
||||||
|
let priceSet
|
||||||
|
let productId
|
||||||
|
const cartId = "test-cart"
|
||||||
|
beforeEach(async () => {
|
||||||
|
const pricingModuleService = medusaContainer.resolve(
|
||||||
|
ModuleRegistrationName.PRICING
|
||||||
|
)
|
||||||
|
|
||||||
|
await simpleCartFactory(dbConnection, {
|
||||||
|
id: cartId,
|
||||||
|
region: "region-1",
|
||||||
|
})
|
||||||
|
|
||||||
|
const payload = {
|
||||||
|
title: "Test",
|
||||||
|
description: "test-product-description",
|
||||||
|
images: ["test-image.png", "test-image-2.png"],
|
||||||
|
variants: [
|
||||||
|
{
|
||||||
|
title: "Test variant",
|
||||||
|
prices: [],
|
||||||
|
options: [],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}
|
||||||
|
|
||||||
|
const response = await api.post(
|
||||||
|
"/admin/products",
|
||||||
|
payload,
|
||||||
|
adminHeaders
|
||||||
|
)
|
||||||
|
|
||||||
|
productId = response.data.product.id
|
||||||
|
const variant = response.data.product.variants[0]
|
||||||
|
|
||||||
|
ruleType = await pricingModuleService.createRuleTypes([
|
||||||
|
{ name: "region_id", rule_attribute: "region_id" },
|
||||||
|
])
|
||||||
|
|
||||||
|
priceSet = await pricingModuleService.create({
|
||||||
|
rules: [{ rule_attribute: "region_id" }],
|
||||||
|
prices: [
|
||||||
|
{
|
||||||
|
amount: 1000,
|
||||||
|
currency_code: "usd",
|
||||||
|
rules: { region_id: "region-1" },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
amount: 900,
|
||||||
|
currency_code: "usd",
|
||||||
|
rules: { region_id: "region-2" },
|
||||||
|
},
|
||||||
|
],
|
||||||
|
})
|
||||||
|
|
||||||
|
const remoteLink = medusaContainer.resolve("remoteLink") as any
|
||||||
|
|
||||||
|
await remoteLink.create({
|
||||||
|
productService: {
|
||||||
|
variant_id: variant.id,
|
||||||
|
},
|
||||||
|
pricingService: {
|
||||||
|
price_set_id: priceSet.id,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it("Should get prices declared in pricing module", async () => {
|
||||||
|
const response = await api.get(
|
||||||
|
`/store/products/${productId}?cart_id=${cartId}`
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(response.data.product.variants[0].prices).toEqual([
|
||||||
|
expect.objectContaining({
|
||||||
|
amount: 1000,
|
||||||
|
currency_code: "usd",
|
||||||
|
}),
|
||||||
|
])
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
},
|
||||||
})
|
})
|
||||||
+151
-165
@@ -1,17 +1,12 @@
|
|||||||
import { PricingModuleService } from "@medusajs/pricing"
|
import { PricingModuleService } from "@medusajs/pricing"
|
||||||
import { ProductModuleService } from "@medusajs/product"
|
import { ProductModuleService } from "@medusajs/product"
|
||||||
import { AxiosInstance } from "axios"
|
|
||||||
import path from "path"
|
|
||||||
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
|
|
||||||
import { useApi } from "../../../../environment-helpers/use-api"
|
|
||||||
import { getContainer } from "../../../../environment-helpers/use-container"
|
|
||||||
import { initDb, useDb } from "../../../../environment-helpers/use-db"
|
|
||||||
import {
|
import {
|
||||||
simpleProductFactory,
|
simpleProductFactory,
|
||||||
simpleRegionFactory,
|
simpleRegionFactory,
|
||||||
} from "../../../../factories"
|
} from "../../../../factories"
|
||||||
import adminSeeder from "../../../../helpers/admin-seeder"
|
import adminSeeder from "../../../../helpers/admin-seeder"
|
||||||
import { createDefaultRuleTypes } from "../../../helpers/create-default-rule-types"
|
import { createDefaultRuleTypes } from "../../../helpers/create-default-rule-types"
|
||||||
|
import { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||||
|
|
||||||
jest.setTimeout(50000)
|
jest.setTimeout(50000)
|
||||||
|
|
||||||
@@ -25,180 +20,171 @@ const env = {
|
|||||||
MEDUSA_FF_MEDUSA_V2: true,
|
MEDUSA_FF_MEDUSA_V2: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
describe.skip("POST /admin/products/:id/variants", () => {
|
medusaIntegrationTestRunner({
|
||||||
let dbConnection
|
env,
|
||||||
let appContainer
|
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||||
let shutdownServer
|
describe.skip("POST /admin/products/:id/variants", () => {
|
||||||
let product
|
let appContainer
|
||||||
let variant
|
let product
|
||||||
|
let variant
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
|
appContainer = getContainer()
|
||||||
dbConnection = await initDb({ cwd, env } as any)
|
})
|
||||||
shutdownServer = await startBootstrapApp({ cwd, env })
|
|
||||||
appContainer = getContainer()
|
|
||||||
})
|
|
||||||
|
|
||||||
afterAll(async () => {
|
beforeEach(async () => {
|
||||||
const db = useDb()
|
await adminSeeder(dbConnection)
|
||||||
await db.shutdown()
|
await createDefaultRuleTypes(appContainer)
|
||||||
await shutdownServer()
|
|
||||||
})
|
|
||||||
|
|
||||||
beforeEach(async () => {
|
await simpleRegionFactory(dbConnection, {
|
||||||
await adminSeeder(dbConnection)
|
id: "test-region",
|
||||||
await createDefaultRuleTypes(appContainer)
|
name: "Test Region",
|
||||||
|
|
||||||
await simpleRegionFactory(dbConnection, {
|
|
||||||
id: "test-region",
|
|
||||||
name: "Test Region",
|
|
||||||
currency_code: "usd",
|
|
||||||
tax_rate: 0,
|
|
||||||
})
|
|
||||||
|
|
||||||
product = await simpleProductFactory(dbConnection, {
|
|
||||||
id: "test-product-with-variant",
|
|
||||||
variants: [
|
|
||||||
{
|
|
||||||
options: [{ option_id: "test-product-option-1", value: "test" }],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
options: [
|
|
||||||
{
|
|
||||||
id: "test-product-option-1",
|
|
||||||
title: "Test option 1",
|
|
||||||
},
|
|
||||||
],
|
|
||||||
})
|
|
||||||
|
|
||||||
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: [
|
|
||||||
{
|
|
||||||
amount: 66600,
|
|
||||||
region_id: "test-region",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
amount: 55500,
|
|
||||||
currency_code: "usd",
|
currency_code: "usd",
|
||||||
region_id: null,
|
tax_rate: 0,
|
||||||
},
|
})
|
||||||
],
|
|
||||||
material: "boo",
|
|
||||||
mid_code: "234asdfadsf",
|
|
||||||
hs_code: "asdfasdf234",
|
|
||||||
origin_country: "DE",
|
|
||||||
sku: "asdf",
|
|
||||||
ean: "234",
|
|
||||||
upc: "234",
|
|
||||||
barcode: "asdf",
|
|
||||||
inventory_quantity: 234,
|
|
||||||
manage_inventory: true,
|
|
||||||
allow_backorder: true,
|
|
||||||
weight: 234,
|
|
||||||
width: 234,
|
|
||||||
height: 234,
|
|
||||||
length: 234,
|
|
||||||
metadata: { asdf: "asdf" },
|
|
||||||
options: [{ option_id: "test-product-option-1", value: "test option" }],
|
|
||||||
}
|
|
||||||
|
|
||||||
let response = await api.post(
|
product = await simpleProductFactory(dbConnection, {
|
||||||
`/admin/products/${product.id}/variants`,
|
id: "test-product-with-variant",
|
||||||
data,
|
variants: [
|
||||||
adminHeaders
|
{
|
||||||
)
|
options: [{ option_id: "test-product-option-1", value: "test" }],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
id: "test-product-option-1",
|
||||||
|
title: "Test option 1",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
})
|
||||||
|
|
||||||
expect(response.status).toEqual(200)
|
variant = product.variants[0]
|
||||||
expect(response.data.product).toEqual(
|
})
|
||||||
expect.objectContaining({
|
|
||||||
id: expect.any(String),
|
it("should create a product variant with its price sets and prices through the workflow", async () => {
|
||||||
variants: expect.arrayContaining([
|
const data = {
|
||||||
|
title: "test variant create",
|
||||||
|
prices: [
|
||||||
|
{
|
||||||
|
amount: 66600,
|
||||||
|
region_id: "test-region",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
amount: 55500,
|
||||||
|
currency_code: "usd",
|
||||||
|
region_id: null,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
material: "boo",
|
||||||
|
mid_code: "234asdfadsf",
|
||||||
|
hs_code: "asdfasdf234",
|
||||||
|
origin_country: "DE",
|
||||||
|
sku: "asdf",
|
||||||
|
ean: "234",
|
||||||
|
upc: "234",
|
||||||
|
barcode: "asdf",
|
||||||
|
inventory_quantity: 234,
|
||||||
|
manage_inventory: true,
|
||||||
|
allow_backorder: true,
|
||||||
|
weight: 234,
|
||||||
|
width: 234,
|
||||||
|
height: 234,
|
||||||
|
length: 234,
|
||||||
|
metadata: { asdf: "asdf" },
|
||||||
|
options: [
|
||||||
|
{ option_id: "test-product-option-1", value: "test option" },
|
||||||
|
],
|
||||||
|
}
|
||||||
|
|
||||||
|
let response = await api.post(
|
||||||
|
`/admin/products/${product.id}/variants`,
|
||||||
|
data,
|
||||||
|
adminHeaders
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(response.status).toEqual(200)
|
||||||
|
expect(response.data.product).toEqual(
|
||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
id: expect.any(String),
|
id: expect.any(String),
|
||||||
title: "test variant create",
|
variants: expect.arrayContaining([
|
||||||
prices: expect.arrayContaining([
|
|
||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
amount: 66600,
|
id: expect.any(String),
|
||||||
currency_code: "usd",
|
title: "test variant create",
|
||||||
region_id: "test-region",
|
prices: expect.arrayContaining([
|
||||||
}),
|
expect.objectContaining({
|
||||||
expect.objectContaining({
|
amount: 66600,
|
||||||
amount: 55500,
|
currency_code: "usd",
|
||||||
currency_code: "usd",
|
region_id: "test-region",
|
||||||
|
}),
|
||||||
|
expect.objectContaining({
|
||||||
|
amount: 55500,
|
||||||
|
currency_code: "usd",
|
||||||
|
}),
|
||||||
|
]),
|
||||||
}),
|
}),
|
||||||
]),
|
]),
|
||||||
}),
|
})
|
||||||
]),
|
)
|
||||||
})
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
it("should compensate creating product variants when error throws in future step", async () => {
|
|
||||||
jest
|
|
||||||
.spyOn(PricingModuleService.prototype, "create")
|
|
||||||
.mockImplementation(() => {
|
|
||||||
throw new Error("Random Error")
|
|
||||||
})
|
})
|
||||||
|
|
||||||
const productSpy = jest.spyOn(
|
it("should compensate creating product variants when error throws in future step", async () => {
|
||||||
ProductModuleService.prototype,
|
jest
|
||||||
"deleteVariants"
|
.spyOn(PricingModuleService.prototype, "create")
|
||||||
)
|
.mockImplementation(() => {
|
||||||
|
throw new Error("Random Error")
|
||||||
|
})
|
||||||
|
|
||||||
const api = useApi()! as AxiosInstance
|
const productSpy = jest.spyOn(
|
||||||
const data = {
|
ProductModuleService.prototype,
|
||||||
title: "test variant create",
|
"deleteVariants"
|
||||||
prices: [
|
)
|
||||||
{
|
|
||||||
amount: 66600,
|
|
||||||
region_id: "test-region",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
amount: 55500,
|
|
||||||
currency_code: "usd",
|
|
||||||
region_id: null,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
material: "boo",
|
|
||||||
mid_code: "234asdfadsf",
|
|
||||||
hs_code: "asdfasdf234",
|
|
||||||
origin_country: "DE",
|
|
||||||
sku: "asdf",
|
|
||||||
ean: "234",
|
|
||||||
upc: "234",
|
|
||||||
barcode: "asdf",
|
|
||||||
inventory_quantity: 234,
|
|
||||||
manage_inventory: true,
|
|
||||||
allow_backorder: true,
|
|
||||||
weight: 234,
|
|
||||||
width: 234,
|
|
||||||
height: 234,
|
|
||||||
length: 234,
|
|
||||||
metadata: { asdf: "asdf" },
|
|
||||||
options: [{ option_id: "test-product-option-1", value: "test option" }],
|
|
||||||
}
|
|
||||||
|
|
||||||
await api
|
const data = {
|
||||||
.post(`/admin/products/${product.id}/variants`, data, adminHeaders)
|
title: "test variant create",
|
||||||
.catch((e) => e)
|
prices: [
|
||||||
|
{
|
||||||
|
amount: 66600,
|
||||||
|
region_id: "test-region",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
amount: 55500,
|
||||||
|
currency_code: "usd",
|
||||||
|
region_id: null,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
material: "boo",
|
||||||
|
mid_code: "234asdfadsf",
|
||||||
|
hs_code: "asdfasdf234",
|
||||||
|
origin_country: "DE",
|
||||||
|
sku: "asdf",
|
||||||
|
ean: "234",
|
||||||
|
upc: "234",
|
||||||
|
barcode: "asdf",
|
||||||
|
inventory_quantity: 234,
|
||||||
|
manage_inventory: true,
|
||||||
|
allow_backorder: true,
|
||||||
|
weight: 234,
|
||||||
|
width: 234,
|
||||||
|
height: 234,
|
||||||
|
length: 234,
|
||||||
|
metadata: { asdf: "asdf" },
|
||||||
|
options: [
|
||||||
|
{ option_id: "test-product-option-1", value: "test option" },
|
||||||
|
],
|
||||||
|
}
|
||||||
|
|
||||||
expect(productSpy).toBeCalledWith([expect.any(String)])
|
await api
|
||||||
|
.post(`/admin/products/${product.id}/variants`, data, adminHeaders)
|
||||||
|
.catch((e) => e)
|
||||||
|
|
||||||
const getProductResponse = await api.get(
|
expect(productSpy).toBeCalledWith([expect.any(String)])
|
||||||
`/admin/products/${product.id}`,
|
|
||||||
adminHeaders
|
const getProductResponse = await api.get(
|
||||||
)
|
`/admin/products/${product.id}`,
|
||||||
expect(getProductResponse.data.product.variants).toHaveLength(1)
|
adminHeaders
|
||||||
})
|
)
|
||||||
|
expect(getProductResponse.data.product.variants).toHaveLength(1)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
},
|
||||||
})
|
})
|
||||||
@@ -1,18 +1,5 @@
|
|||||||
import path from "path"
|
|
||||||
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
|
|
||||||
import { useApi } from "../../../../environment-helpers/use-api"
|
|
||||||
import { initDb, useDb } from "../../../../environment-helpers/use-db"
|
|
||||||
|
|
||||||
import productSeeder from "../../../../helpers/product-seeder"
|
|
||||||
|
|
||||||
import { AxiosInstance } from "axios"
|
|
||||||
import { getContainer } from "../../../../environment-helpers/use-container"
|
|
||||||
import {
|
|
||||||
simpleProductFactory,
|
|
||||||
simpleSalesChannelFactory,
|
|
||||||
} from "../../../../factories"
|
|
||||||
import { createDefaultRuleTypes } from "../../../helpers/create-default-rule-types"
|
|
||||||
import { createAdminUser } from "../../../helpers/create-admin-user"
|
import { createAdminUser } from "../../../helpers/create-admin-user"
|
||||||
|
import { medusaIntegrationTestRunner } from "medusa-test-utils/dist"
|
||||||
|
|
||||||
jest.setTimeout(50000)
|
jest.setTimeout(50000)
|
||||||
|
|
||||||
@@ -26,469 +13,448 @@ const env = {
|
|||||||
MEDUSA_FF_MEDUSA_V2: true,
|
MEDUSA_FF_MEDUSA_V2: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
describe("/admin/products", () => {
|
medusaIntegrationTestRunner({
|
||||||
let dbConnection
|
env,
|
||||||
let shutdownServer
|
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||||
let medusaContainer
|
describe("/admin/products", () => {
|
||||||
|
let medusaContainer
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
|
medusaContainer = getContainer()
|
||||||
dbConnection = await initDb({ cwd, env })
|
})
|
||||||
shutdownServer = await startBootstrapApp({ cwd, env })
|
|
||||||
medusaContainer = getContainer()
|
|
||||||
})
|
|
||||||
|
|
||||||
afterAll(async () => {
|
beforeEach(async () => {
|
||||||
const db = useDb()
|
await createAdminUser(dbConnection, adminHeaders, medusaContainer)
|
||||||
await db.shutdown()
|
|
||||||
await shutdownServer()
|
|
||||||
})
|
|
||||||
|
|
||||||
describe("POST /admin/products", () => {
|
// await productSeeder(dbConnection)
|
||||||
beforeEach(async () => {
|
// await createDefaultRuleTypes(medusaContainer)
|
||||||
await createAdminUser(dbConnection, adminHeaders)
|
// await simpleSalesChannelFactory(dbConnection, {
|
||||||
|
// name: "Default channel",
|
||||||
|
// id: "default-channel",
|
||||||
|
// is_default: true,
|
||||||
|
// })
|
||||||
|
})
|
||||||
|
|
||||||
// await productSeeder(dbConnection)
|
describe("POST /admin/products", () => {
|
||||||
// await createDefaultRuleTypes(medusaContainer)
|
it("should create a product", async () => {
|
||||||
// await simpleSalesChannelFactory(dbConnection, {
|
const payload = {
|
||||||
// name: "Default channel",
|
title: "Test",
|
||||||
// id: "default-channel",
|
description: "test-product-description",
|
||||||
// is_default: true,
|
// 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" }],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}
|
||||||
|
|
||||||
afterEach(async () => {
|
const response = await api
|
||||||
const db = useDb()
|
.post("/admin/products", payload, adminHeaders)
|
||||||
await db.teardown()
|
.catch((err) => {
|
||||||
})
|
console.log(err)
|
||||||
|
})
|
||||||
|
|
||||||
it("should create a product", async () => {
|
expect(response?.status).toEqual(200)
|
||||||
const api = useApi()! as AxiosInstance
|
expect(response?.data.product).toEqual(
|
||||||
|
|
||||||
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",
|
|
||||||
// profile_id: expect.stringMatching(/^sp_*/),
|
|
||||||
thumbnail: "test-image.png",
|
|
||||||
created_at: expect.any(String),
|
|
||||||
updated_at: expect.any(String),
|
|
||||||
})
|
|
||||||
)
|
|
||||||
|
|
||||||
expect(response?.data.product.images).toEqual(
|
|
||||||
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),
|
|
||||||
}),
|
|
||||||
])
|
|
||||||
)
|
|
||||||
|
|
||||||
console.log(response?.data.product)
|
|
||||||
|
|
||||||
expect(response?.data.product.variants).toEqual(
|
|
||||||
expect.arrayContaining([
|
|
||||||
expect.objectContaining({
|
|
||||||
id: expect.stringMatching(/^variant_*/),
|
|
||||||
title: "Test variant",
|
|
||||||
// product_id: expect.stringMatching(/^prod_*/),
|
|
||||||
updated_at: expect.any(String),
|
|
||||||
created_at: expect.any(String),
|
|
||||||
// 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_*/),
|
|
||||||
// }),
|
|
||||||
// ]),
|
|
||||||
}),
|
|
||||||
])
|
|
||||||
)
|
|
||||||
|
|
||||||
expect(response?.data.product.options).toEqual(
|
|
||||||
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),
|
|
||||||
}),
|
|
||||||
])
|
|
||||||
)
|
|
||||||
|
|
||||||
// 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),
|
|
||||||
// }),
|
|
||||||
})
|
|
||||||
|
|
||||||
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}?fields=title,variants.title`,
|
|
||||||
adminHeaders
|
|
||||||
)
|
|
||||||
.catch((err) => {
|
|
||||||
console.log(err)
|
|
||||||
})
|
|
||||||
|
|
||||||
expect(response?.data.product).toEqual(
|
|
||||||
expect.objectContaining({
|
|
||||||
title: "Test product - 1",
|
|
||||||
variants: [
|
|
||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
title: "Test variant 1",
|
id: expect.stringMatching(/^prod_*/),
|
||||||
}),
|
title: "Test",
|
||||||
|
discountable: true,
|
||||||
|
is_giftcard: false,
|
||||||
|
handle: "test",
|
||||||
|
status: "draft",
|
||||||
|
// profile_id: expect.stringMatching(/^sp_*/),
|
||||||
|
thumbnail: "test-image.png",
|
||||||
|
created_at: expect.any(String),
|
||||||
|
updated_at: expect.any(String),
|
||||||
|
})
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(response?.data.product.images).toEqual(
|
||||||
|
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),
|
||||||
|
}),
|
||||||
|
])
|
||||||
|
)
|
||||||
|
|
||||||
|
console.log(response?.data.product)
|
||||||
|
|
||||||
|
expect(response?.data.product.variants).toEqual(
|
||||||
|
expect.arrayContaining([
|
||||||
|
expect.objectContaining({
|
||||||
|
id: expect.stringMatching(/^variant_*/),
|
||||||
|
title: "Test variant",
|
||||||
|
// product_id: expect.stringMatching(/^prod_*/),
|
||||||
|
updated_at: expect.any(String),
|
||||||
|
created_at: expect.any(String),
|
||||||
|
// 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_*/),
|
||||||
|
// }),
|
||||||
|
// ]),
|
||||||
|
}),
|
||||||
|
])
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(response?.data.product.options).toEqual(
|
||||||
|
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),
|
||||||
|
}),
|
||||||
|
])
|
||||||
|
)
|
||||||
|
|
||||||
|
// 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),
|
||||||
|
// }),
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should create a product that is not discountable", async () => {
|
||||||
|
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({
|
expect.objectContaining({
|
||||||
title: "Test variant 2",
|
discountable: false,
|
||||||
}),
|
})
|
||||||
],
|
)
|
||||||
})
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
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)
|
it("should sets the variant ranks when creating a product", async () => {
|
||||||
|
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" }],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}
|
||||||
|
|
||||||
expect(response?.data.product).toEqual(
|
const creationResponse = await api
|
||||||
expect.objectContaining({
|
.post("/admin/products", payload, adminHeaders)
|
||||||
title: "Test Giftcard",
|
.catch((err) => {
|
||||||
discountable: false,
|
console.log(err)
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(creationResponse?.status).toEqual(200)
|
||||||
|
|
||||||
|
const productId = creationResponse?.data.product.id
|
||||||
|
|
||||||
|
const response = await api
|
||||||
|
.get(
|
||||||
|
`/admin/products/${productId}?fields=title,variants.title`,
|
||||||
|
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 variants with inventory items", async () => {
|
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(
|
const response = await api
|
||||||
`/admin/products`,
|
.post("/admin/products", payload, adminHeaders)
|
||||||
{
|
.catch((err) => {
|
||||||
title: "Test product - 1",
|
console.log(err)
|
||||||
description: "test-product-description 1",
|
})
|
||||||
// type: { value: "test-type 1" },
|
|
||||||
images: ["test-image.png", "test-image-2.png"],
|
expect(response?.status).toEqual(200)
|
||||||
// collection_id: "test-collection",
|
|
||||||
// tags: [{ value: "123" }, { value: "456" }],
|
expect(response?.data.product).toEqual(
|
||||||
options: [{ title: "size" }, { title: "color" }],
|
expect.objectContaining({
|
||||||
variants: [
|
title: "Test Giftcard",
|
||||||
|
discountable: false,
|
||||||
|
})
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should create variants with inventory items", async () => {
|
||||||
|
const response = await api.post(
|
||||||
|
`/admin/products`,
|
||||||
{
|
{
|
||||||
title: "Test variant 1",
|
title: "Test product - 1",
|
||||||
inventory_quantity: 10,
|
description: "test-product-description 1",
|
||||||
// prices: [{ currency_code: "usd", amount: 100 }],
|
// type: { value: "test-type 1" },
|
||||||
// options: [{ value: "large" }, { value: "green" }],
|
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" }],
|
||||||
|
},
|
||||||
|
],
|
||||||
},
|
},
|
||||||
{
|
adminHeaders
|
||||||
title: "Test variant 2",
|
)
|
||||||
inventory_quantity: 10,
|
|
||||||
// prices: [{ currency_code: "usd", amount: 100 }],
|
|
||||||
// options: [{ value: "large" }, { value: "green" }],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
adminHeaders
|
|
||||||
)
|
|
||||||
|
|
||||||
expect(response.status).toEqual(200)
|
expect(response.status).toEqual(200)
|
||||||
|
|
||||||
// const variantIds = response.data.product.variants.map(
|
// const variantIds = response.data.product.variants.map(
|
||||||
// (v: { id: string }) => v.id
|
// (v: { id: string }) => v.id
|
||||||
// )
|
// )
|
||||||
|
|
||||||
// const variantInventoryService = medusaContainer.resolve(
|
// const variantInventoryService = medusaContainer.resolve(
|
||||||
// "productVariantInventoryService"
|
// "productVariantInventoryService"
|
||||||
// )
|
// )
|
||||||
// const inventory = await variantInventoryService.listByVariant(variantIds)
|
// const inventory = await variantInventoryService.listByVariant(variantIds)
|
||||||
|
|
||||||
// expect(inventory).toHaveLength(2)
|
// expect(inventory).toHaveLength(2)
|
||||||
// expect(inventory).toContainEqual(
|
// expect(inventory).toContainEqual(
|
||||||
// expect.objectContaining({
|
// expect.objectContaining({
|
||||||
// variant_id: variantIds[0],
|
// variant_id: variantIds[0],
|
||||||
// required_quantity: 1,
|
// required_quantity: 1,
|
||||||
// })
|
// })
|
||||||
// )
|
// )
|
||||||
// expect(inventory).toContainEqual(
|
// expect(inventory).toContainEqual(
|
||||||
// expect.objectContaining({
|
// expect.objectContaining({
|
||||||
// variant_id: variantIds[1],
|
// variant_id: variantIds[1],
|
||||||
// required_quantity: 1,
|
// required_quantity: 1,
|
||||||
// })
|
// })
|
||||||
// )
|
// )
|
||||||
|
})
|
||||||
|
|
||||||
|
// it("should create prices with region_id and currency_code context", async () => {
|
||||||
|
// const api = useApi()! as AxiosInstance
|
||||||
|
|
||||||
|
// const data = {
|
||||||
|
// title: "test product",
|
||||||
|
// options: [{ title: "test-option" }],
|
||||||
|
// variants: [
|
||||||
|
// {
|
||||||
|
// title: "test variant",
|
||||||
|
// prices: [
|
||||||
|
// {
|
||||||
|
// amount: 66600,
|
||||||
|
// region_id: "test-region",
|
||||||
|
// },
|
||||||
|
// {
|
||||||
|
// amount: 55500,
|
||||||
|
// currency_code: "usd",
|
||||||
|
// },
|
||||||
|
// ],
|
||||||
|
// options: [{ value: "test-option" }],
|
||||||
|
// },
|
||||||
|
// ],
|
||||||
|
// }
|
||||||
|
|
||||||
|
// let response = await api.post(
|
||||||
|
// "/admin/products?relations=variants.prices",
|
||||||
|
// data,
|
||||||
|
// adminHeaders
|
||||||
|
// )
|
||||||
|
|
||||||
|
// expect(response.status).toEqual(200)
|
||||||
|
// expect(response.data).toEqual({
|
||||||
|
// product: expect.objectContaining({
|
||||||
|
// id: expect.any(String),
|
||||||
|
// title: "test product",
|
||||||
|
// variants: expect.arrayContaining([
|
||||||
|
// expect.objectContaining({
|
||||||
|
// id: expect.any(String),
|
||||||
|
// title: "test variant",
|
||||||
|
// prices: expect.arrayContaining([
|
||||||
|
// expect.objectContaining({
|
||||||
|
// amount: 66600,
|
||||||
|
// currency_code: "usd",
|
||||||
|
// }),
|
||||||
|
// expect.objectContaining({
|
||||||
|
// amount: 55500,
|
||||||
|
// currency_code: "usd",
|
||||||
|
// }),
|
||||||
|
// ]),
|
||||||
|
// }),
|
||||||
|
// ]),
|
||||||
|
// }),
|
||||||
|
// })
|
||||||
|
|
||||||
|
// const pricingModuleService: IPricingModuleService = appContainer.resolve(
|
||||||
|
// "pricingModuleService"
|
||||||
|
// )
|
||||||
|
|
||||||
|
// const [_, count] = await pricingModuleService.listAndCount()
|
||||||
|
// expect(count).toEqual(1)
|
||||||
|
// })
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
},
|
||||||
// it("should create prices with region_id and currency_code context", async () => {
|
|
||||||
// const api = useApi()! as AxiosInstance
|
|
||||||
|
|
||||||
// const data = {
|
|
||||||
// title: "test product",
|
|
||||||
// options: [{ title: "test-option" }],
|
|
||||||
// variants: [
|
|
||||||
// {
|
|
||||||
// title: "test variant",
|
|
||||||
// prices: [
|
|
||||||
// {
|
|
||||||
// amount: 66600,
|
|
||||||
// region_id: "test-region",
|
|
||||||
// },
|
|
||||||
// {
|
|
||||||
// amount: 55500,
|
|
||||||
// currency_code: "usd",
|
|
||||||
// },
|
|
||||||
// ],
|
|
||||||
// options: [{ value: "test-option" }],
|
|
||||||
// },
|
|
||||||
// ],
|
|
||||||
// }
|
|
||||||
|
|
||||||
// let response = await api.post(
|
|
||||||
// "/admin/products?relations=variants.prices",
|
|
||||||
// data,
|
|
||||||
// adminHeaders
|
|
||||||
// )
|
|
||||||
|
|
||||||
// expect(response.status).toEqual(200)
|
|
||||||
// expect(response.data).toEqual({
|
|
||||||
// product: expect.objectContaining({
|
|
||||||
// id: expect.any(String),
|
|
||||||
// title: "test product",
|
|
||||||
// variants: expect.arrayContaining([
|
|
||||||
// expect.objectContaining({
|
|
||||||
// id: expect.any(String),
|
|
||||||
// title: "test variant",
|
|
||||||
// prices: expect.arrayContaining([
|
|
||||||
// expect.objectContaining({
|
|
||||||
// amount: 66600,
|
|
||||||
// currency_code: "usd",
|
|
||||||
// }),
|
|
||||||
// expect.objectContaining({
|
|
||||||
// amount: 55500,
|
|
||||||
// currency_code: "usd",
|
|
||||||
// }),
|
|
||||||
// ]),
|
|
||||||
// }),
|
|
||||||
// ]),
|
|
||||||
// }),
|
|
||||||
// })
|
|
||||||
|
|
||||||
// const pricingModuleService: IPricingModuleService = appContainer.resolve(
|
|
||||||
// "pricingModuleService"
|
|
||||||
// )
|
|
||||||
|
|
||||||
// const [_, count] = await pricingModuleService.listAndCount()
|
|
||||||
// expect(count).toEqual(1)
|
|
||||||
// })
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
@@ -24,6 +24,10 @@ const env: Record<any, any> = {
|
|||||||
|
|
||||||
jest.setTimeout(180000)
|
jest.setTimeout(180000)
|
||||||
|
|
||||||
|
// TODO SEE to use new test runner medusaIntegrationTestRunner({
|
||||||
|
// env,
|
||||||
|
// testSuite: ({ dbConnection, getContainer, api }) => {})
|
||||||
|
|
||||||
describe.skip("Batch job of product-export type", () => {
|
describe.skip("Batch job of product-export type", () => {
|
||||||
let medusaProcess
|
let medusaProcess
|
||||||
let dbConnection
|
let dbConnection
|
||||||
|
|||||||
@@ -56,6 +56,10 @@ const env: Record<any, any> = {
|
|||||||
MEDUSA_FF_MEDUSA_V2: true,
|
MEDUSA_FF_MEDUSA_V2: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO SEE to use new test runner medusaIntegrationTestRunner({
|
||||||
|
// env,
|
||||||
|
// testSuite: ({ dbConnection, getContainer, api }) => {})
|
||||||
|
|
||||||
describe.skip("Product import batch job", () => {
|
describe.skip("Product import batch job", () => {
|
||||||
let dbConnection
|
let dbConnection
|
||||||
let shutdownServer
|
let shutdownServer
|
||||||
|
|||||||
@@ -0,0 +1,659 @@
|
|||||||
|
import path from "path"
|
||||||
|
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
|
||||||
|
import { useApi } from "../../../../environment-helpers/use-api"
|
||||||
|
import { initDb, useDb } from "../../../../environment-helpers/use-db"
|
||||||
|
|
||||||
|
import adminSeeder from "../../../../helpers/admin-seeder"
|
||||||
|
import productSeeder from "../../../../helpers/product-seeder"
|
||||||
|
|
||||||
|
import { Modules, ModulesDefinition } from "@medusajs/modules-sdk"
|
||||||
|
import { MedusaV2Flag } from "@medusajs/utils"
|
||||||
|
import { AxiosInstance } from "axios"
|
||||||
|
import { getContainer } from "../../../../environment-helpers/use-container"
|
||||||
|
import {
|
||||||
|
simpleProductFactory,
|
||||||
|
simpleSalesChannelFactory,
|
||||||
|
} from "../../../../factories"
|
||||||
|
import { createDefaultRuleTypes } from "../../../helpers/create-default-rule-types"
|
||||||
|
|
||||||
|
jest.setTimeout(50000)
|
||||||
|
|
||||||
|
const adminHeaders = {
|
||||||
|
headers: {
|
||||||
|
"x-medusa-access-token": "test_token",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
const env = {
|
||||||
|
MEDUSA_FF_MEDUSA_V2: true,
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO SEE to use new test runner medusaIntegrationTestRunner({
|
||||||
|
// env,
|
||||||
|
// testSuite: ({ dbConnection, getContainer, api }) => {})
|
||||||
|
|
||||||
|
describe.skip("/admin/products", () => {
|
||||||
|
let dbConnection
|
||||||
|
let shutdownServer
|
||||||
|
let medusaContainer
|
||||||
|
|
||||||
|
beforeAll(async () => {
|
||||||
|
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
|
||||||
|
dbConnection = await initDb({ cwd, env })
|
||||||
|
shutdownServer = await startBootstrapApp({ cwd, env })
|
||||||
|
medusaContainer = getContainer()
|
||||||
|
})
|
||||||
|
|
||||||
|
afterAll(async () => {
|
||||||
|
const db = useDb()
|
||||||
|
await db.shutdown()
|
||||||
|
await shutdownServer()
|
||||||
|
})
|
||||||
|
|
||||||
|
it("Should have loaded the product module", function () {
|
||||||
|
const productRegistrationName =
|
||||||
|
ModulesDefinition[Modules.PRODUCT].registrationName
|
||||||
|
expect(
|
||||||
|
medusaContainer.hasRegistration(productRegistrationName)
|
||||||
|
).toBeTruthy()
|
||||||
|
})
|
||||||
|
|
||||||
|
it("Should have enabled workflows feature flag", function () {
|
||||||
|
const flagRouter = medusaContainer.resolve("featureFlagRouter")
|
||||||
|
|
||||||
|
const workflowsFlag = flagRouter.isFeatureEnabled(MedusaV2Flag.key)
|
||||||
|
|
||||||
|
expect(workflowsFlag).toBe(true)
|
||||||
|
})
|
||||||
|
|
||||||
|
describe("POST /admin/products", () => {
|
||||||
|
beforeEach(async () => {
|
||||||
|
await productSeeder(dbConnection)
|
||||||
|
await adminSeeder(dbConnection)
|
||||||
|
await createDefaultRuleTypes(medusaContainer)
|
||||||
|
|
||||||
|
await simpleSalesChannelFactory(dbConnection, {
|
||||||
|
name: "Default channel",
|
||||||
|
id: "default-channel",
|
||||||
|
is_default: true,
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
afterEach(async () => {
|
||||||
|
const db = useDb()
|
||||||
|
await db.teardown()
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should create a product", async () => {
|
||||||
|
const api = useApi()! as AxiosInstance
|
||||||
|
|
||||||
|
const payload = {
|
||||||
|
title: "Test",
|
||||||
|
description: "test-product-description",
|
||||||
|
type: { value: "test-type" },
|
||||||
|
images: ["test-image.png", "test-image-2.png"],
|
||||||
|
collection_id: "test-collection",
|
||||||
|
tags: [{ value: "123" }, { value: "456" }],
|
||||||
|
options: [{ title: "size" }, { title: "color" }],
|
||||||
|
variants: [
|
||||||
|
{
|
||||||
|
title: "Test variant",
|
||||||
|
inventory_quantity: 10,
|
||||||
|
prices: [
|
||||||
|
{
|
||||||
|
currency_code: "usd",
|
||||||
|
amount: 100,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
currency_code: "eur",
|
||||||
|
amount: 45,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
currency_code: "dkk",
|
||||||
|
amount: 30,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
options: [{ value: "large" }, { value: "green" }],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}
|
||||||
|
|
||||||
|
const response = await api
|
||||||
|
.post("/admin/products", payload, adminHeaders)
|
||||||
|
.catch((err) => {
|
||||||
|
console.log(err)
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(response?.status).toEqual(200)
|
||||||
|
expect(response?.data.product).toEqual(
|
||||||
|
expect.objectContaining({
|
||||||
|
id: expect.stringMatching(/^prod_*/),
|
||||||
|
title: "Test",
|
||||||
|
discountable: true,
|
||||||
|
is_giftcard: false,
|
||||||
|
handle: "test",
|
||||||
|
status: "draft",
|
||||||
|
created_at: expect.any(String),
|
||||||
|
updated_at: expect.any(String),
|
||||||
|
profile_id: expect.stringMatching(/^sp_*/),
|
||||||
|
images: expect.arrayContaining([
|
||||||
|
expect.objectContaining({
|
||||||
|
id: expect.any(String),
|
||||||
|
url: "test-image.png",
|
||||||
|
created_at: expect.any(String),
|
||||||
|
updated_at: expect.any(String),
|
||||||
|
}),
|
||||||
|
expect.objectContaining({
|
||||||
|
id: expect.any(String),
|
||||||
|
url: "test-image-2.png",
|
||||||
|
created_at: expect.any(String),
|
||||||
|
updated_at: expect.any(String),
|
||||||
|
}),
|
||||||
|
]),
|
||||||
|
thumbnail: "test-image.png",
|
||||||
|
tags: expect.arrayContaining([
|
||||||
|
expect.objectContaining({
|
||||||
|
id: expect.any(String),
|
||||||
|
value: "123",
|
||||||
|
created_at: expect.any(String),
|
||||||
|
updated_at: expect.any(String),
|
||||||
|
}),
|
||||||
|
expect.objectContaining({
|
||||||
|
id: expect.any(String),
|
||||||
|
value: "456",
|
||||||
|
created_at: expect.any(String),
|
||||||
|
updated_at: expect.any(String),
|
||||||
|
}),
|
||||||
|
]),
|
||||||
|
type: expect.objectContaining({
|
||||||
|
value: "test-type",
|
||||||
|
created_at: expect.any(String),
|
||||||
|
updated_at: expect.any(String),
|
||||||
|
}),
|
||||||
|
collection: expect.objectContaining({
|
||||||
|
id: "test-collection",
|
||||||
|
title: "Test collection",
|
||||||
|
created_at: expect.any(String),
|
||||||
|
updated_at: expect.any(String),
|
||||||
|
}),
|
||||||
|
options: expect.arrayContaining([
|
||||||
|
expect.objectContaining({
|
||||||
|
id: expect.stringMatching(/^opt_*/),
|
||||||
|
product_id: expect.stringMatching(/^prod_*/),
|
||||||
|
title: "size",
|
||||||
|
created_at: expect.any(String),
|
||||||
|
updated_at: expect.any(String),
|
||||||
|
}),
|
||||||
|
expect.objectContaining({
|
||||||
|
id: expect.stringMatching(/^opt_*/),
|
||||||
|
product_id: expect.stringMatching(/^prod_*/),
|
||||||
|
title: "color",
|
||||||
|
created_at: expect.any(String),
|
||||||
|
updated_at: expect.any(String),
|
||||||
|
}),
|
||||||
|
]),
|
||||||
|
variants: expect.arrayContaining([
|
||||||
|
expect.objectContaining({
|
||||||
|
id: expect.stringMatching(/^variant_*/),
|
||||||
|
product_id: expect.stringMatching(/^prod_*/),
|
||||||
|
updated_at: expect.any(String),
|
||||||
|
created_at: expect.any(String),
|
||||||
|
title: "Test variant",
|
||||||
|
prices: expect.arrayContaining([
|
||||||
|
expect.objectContaining({
|
||||||
|
id: expect.stringMatching(/^ma_*/),
|
||||||
|
currency_code: "usd",
|
||||||
|
amount: 100,
|
||||||
|
// TODO: enable this in the Pricing Module PR
|
||||||
|
// created_at: expect.any(String),
|
||||||
|
// updated_at: expect.any(String),
|
||||||
|
// variant_id: expect.stringMatching(/^variant_*/),
|
||||||
|
}),
|
||||||
|
expect.objectContaining({
|
||||||
|
id: expect.stringMatching(/^ma_*/),
|
||||||
|
currency_code: "eur",
|
||||||
|
amount: 45,
|
||||||
|
// TODO: enable this in the Pricing Module PR
|
||||||
|
// created_at: expect.any(String),
|
||||||
|
// updated_at: expect.any(String),
|
||||||
|
// variant_id: expect.stringMatching(/^variant_*/),
|
||||||
|
}),
|
||||||
|
expect.objectContaining({
|
||||||
|
id: expect.stringMatching(/^ma_*/),
|
||||||
|
currency_code: "dkk",
|
||||||
|
amount: 30,
|
||||||
|
// TODO: enable this in the Pricing Module PR
|
||||||
|
// created_at: expect.any(String),
|
||||||
|
// updated_at: expect.any(String),
|
||||||
|
// variant_id: expect.stringMatching(/^variant_*/),
|
||||||
|
}),
|
||||||
|
]),
|
||||||
|
options: expect.arrayContaining([
|
||||||
|
expect.objectContaining({
|
||||||
|
value: "large",
|
||||||
|
created_at: expect.any(String),
|
||||||
|
updated_at: expect.any(String),
|
||||||
|
variant_id: expect.stringMatching(/^variant_*/),
|
||||||
|
option_id: expect.stringMatching(/^opt_*/),
|
||||||
|
id: expect.stringMatching(/^optval_*/),
|
||||||
|
}),
|
||||||
|
expect.objectContaining({
|
||||||
|
value: "green",
|
||||||
|
created_at: expect.any(String),
|
||||||
|
updated_at: expect.any(String),
|
||||||
|
variant_id: expect.stringMatching(/^variant_*/),
|
||||||
|
option_id: expect.stringMatching(/^opt_*/),
|
||||||
|
id: expect.stringMatching(/^optval_*/),
|
||||||
|
}),
|
||||||
|
]),
|
||||||
|
}),
|
||||||
|
]),
|
||||||
|
})
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should create a product that is not discountable", async () => {
|
||||||
|
const api = useApi()! as AxiosInstance
|
||||||
|
|
||||||
|
const payload = {
|
||||||
|
title: "Test",
|
||||||
|
discountable: false,
|
||||||
|
description: "test-product-description",
|
||||||
|
type: { value: "test-type" },
|
||||||
|
images: ["test-image.png", "test-image-2.png"],
|
||||||
|
collection_id: "test-collection",
|
||||||
|
tags: [{ value: "123" }, { value: "456" }],
|
||||||
|
options: [{ title: "size" }, { title: "color" }],
|
||||||
|
variants: [
|
||||||
|
{
|
||||||
|
title: "Test variant",
|
||||||
|
inventory_quantity: 10,
|
||||||
|
prices: [{ currency_code: "usd", amount: 100 }],
|
||||||
|
options: [{ value: "large" }, { value: "green" }],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}
|
||||||
|
|
||||||
|
const response = await api
|
||||||
|
.post("/admin/products", payload, adminHeaders)
|
||||||
|
.catch((err) => {
|
||||||
|
console.log(err)
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(response?.status).toEqual(200)
|
||||||
|
expect(response?.data.product).toEqual(
|
||||||
|
expect.objectContaining({
|
||||||
|
discountable: false,
|
||||||
|
})
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should sets the variant ranks when creating a product", async () => {
|
||||||
|
const api = useApi()! as AxiosInstance
|
||||||
|
|
||||||
|
const payload = {
|
||||||
|
title: "Test product - 1",
|
||||||
|
description: "test-product-description 1",
|
||||||
|
type: { value: "test-type 1" },
|
||||||
|
images: ["test-image.png", "test-image-2.png"],
|
||||||
|
collection_id: "test-collection",
|
||||||
|
tags: [{ value: "123" }, { value: "456" }],
|
||||||
|
options: [{ title: "size" }, { title: "color" }],
|
||||||
|
variants: [
|
||||||
|
{
|
||||||
|
title: "Test variant 1",
|
||||||
|
inventory_quantity: 10,
|
||||||
|
prices: [{ currency_code: "usd", amount: 100 }],
|
||||||
|
options: [{ value: "large" }, { value: "green" }],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: "Test variant 2",
|
||||||
|
inventory_quantity: 10,
|
||||||
|
prices: [{ currency_code: "usd", amount: 100 }],
|
||||||
|
options: [{ value: "large" }, { value: "green" }],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}
|
||||||
|
|
||||||
|
const creationResponse = await api
|
||||||
|
.post("/admin/products", payload, adminHeaders)
|
||||||
|
.catch((err) => {
|
||||||
|
console.log(err)
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(creationResponse?.status).toEqual(200)
|
||||||
|
|
||||||
|
const productId = creationResponse?.data.product.id
|
||||||
|
|
||||||
|
const response = await api
|
||||||
|
.get(`/admin/products/${productId}`, adminHeaders)
|
||||||
|
.catch((err) => {
|
||||||
|
console.log(err)
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(response?.data.product).toEqual(
|
||||||
|
expect.objectContaining({
|
||||||
|
title: "Test product - 1",
|
||||||
|
variants: [
|
||||||
|
expect.objectContaining({
|
||||||
|
title: "Test variant 1",
|
||||||
|
}),
|
||||||
|
expect.objectContaining({
|
||||||
|
title: "Test variant 2",
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
})
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should create a giftcard", async () => {
|
||||||
|
const api = useApi()! as AxiosInstance
|
||||||
|
|
||||||
|
const payload = {
|
||||||
|
title: "Test Giftcard",
|
||||||
|
is_giftcard: true,
|
||||||
|
description: "test-giftcard-description",
|
||||||
|
options: [{ title: "Denominations" }],
|
||||||
|
variants: [
|
||||||
|
{
|
||||||
|
title: "Test variant",
|
||||||
|
prices: [{ currency_code: "usd", amount: 100 }],
|
||||||
|
options: [{ value: "100" }],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}
|
||||||
|
|
||||||
|
const response = await api
|
||||||
|
.post("/admin/products", payload, adminHeaders)
|
||||||
|
.catch((err) => {
|
||||||
|
console.log(err)
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(response?.status).toEqual(200)
|
||||||
|
|
||||||
|
expect(response?.data.product).toEqual(
|
||||||
|
expect.objectContaining({
|
||||||
|
title: "Test Giftcard",
|
||||||
|
discountable: false,
|
||||||
|
})
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should create variants with inventory items", async () => {
|
||||||
|
const api = useApi()! as AxiosInstance
|
||||||
|
|
||||||
|
const response = await api.post(
|
||||||
|
`/admin/products`,
|
||||||
|
{
|
||||||
|
title: "Test product - 1",
|
||||||
|
description: "test-product-description 1",
|
||||||
|
type: { value: "test-type 1" },
|
||||||
|
images: ["test-image.png", "test-image-2.png"],
|
||||||
|
collection_id: "test-collection",
|
||||||
|
tags: [{ value: "123" }, { value: "456" }],
|
||||||
|
options: [{ title: "size" }, { title: "color" }],
|
||||||
|
variants: [
|
||||||
|
{
|
||||||
|
title: "Test variant 1",
|
||||||
|
inventory_quantity: 10,
|
||||||
|
prices: [{ currency_code: "usd", amount: 100 }],
|
||||||
|
options: [{ value: "large" }, { value: "green" }],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: "Test variant 2",
|
||||||
|
inventory_quantity: 10,
|
||||||
|
prices: [{ currency_code: "usd", amount: 100 }],
|
||||||
|
options: [{ value: "large" }, { value: "green" }],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{ headers: { "x-medusa-access-token": "test_token" } }
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(response.status).toEqual(200)
|
||||||
|
|
||||||
|
const variantIds = response.data.product.variants.map(
|
||||||
|
(v: { id: string }) => v.id
|
||||||
|
)
|
||||||
|
|
||||||
|
const variantInventoryService = medusaContainer.resolve(
|
||||||
|
"productVariantInventoryService"
|
||||||
|
)
|
||||||
|
const inventory = await variantInventoryService.listByVariant(variantIds)
|
||||||
|
|
||||||
|
expect(inventory).toHaveLength(2)
|
||||||
|
expect(inventory).toContainEqual(
|
||||||
|
expect.objectContaining({
|
||||||
|
variant_id: variantIds[0],
|
||||||
|
required_quantity: 1,
|
||||||
|
})
|
||||||
|
)
|
||||||
|
expect(inventory).toContainEqual(
|
||||||
|
expect.objectContaining({
|
||||||
|
variant_id: variantIds[1],
|
||||||
|
required_quantity: 1,
|
||||||
|
})
|
||||||
|
)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe("POST /admin/products/:id", () => {
|
||||||
|
const toUpdateWithSalesChannels = "to-update-with-sales-channels"
|
||||||
|
const toUpdateWithVariants = "to-update-with-variants"
|
||||||
|
const toUpdate = "to-update"
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
await productSeeder(dbConnection)
|
||||||
|
await adminSeeder(dbConnection)
|
||||||
|
await createDefaultRuleTypes(medusaContainer)
|
||||||
|
|
||||||
|
await simpleSalesChannelFactory(dbConnection, {
|
||||||
|
name: "Default channel",
|
||||||
|
id: "default-channel",
|
||||||
|
is_default: true,
|
||||||
|
})
|
||||||
|
|
||||||
|
await simpleSalesChannelFactory(dbConnection, {
|
||||||
|
name: "Channel 3",
|
||||||
|
id: "channel-3",
|
||||||
|
is_default: true,
|
||||||
|
})
|
||||||
|
|
||||||
|
await simpleProductFactory(dbConnection, {
|
||||||
|
title: "To update product",
|
||||||
|
id: toUpdate,
|
||||||
|
})
|
||||||
|
|
||||||
|
await simpleProductFactory(dbConnection, {
|
||||||
|
title: "To update product with channels",
|
||||||
|
id: toUpdateWithSalesChannels,
|
||||||
|
sales_channels: [
|
||||||
|
{ name: "channel 1", id: "channel-1" },
|
||||||
|
{ name: "channel 2", id: "channel-2" },
|
||||||
|
],
|
||||||
|
})
|
||||||
|
|
||||||
|
await simpleSalesChannelFactory(dbConnection, {
|
||||||
|
name: "To be added",
|
||||||
|
id: "to-be-added",
|
||||||
|
})
|
||||||
|
|
||||||
|
await simpleProductFactory(dbConnection, {
|
||||||
|
title: "To update product with variants",
|
||||||
|
id: toUpdateWithVariants,
|
||||||
|
variants: [
|
||||||
|
{
|
||||||
|
id: "variant-1",
|
||||||
|
title: "Variant 1",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "variant-2",
|
||||||
|
title: "Variant 2",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
afterEach(async () => {
|
||||||
|
const db = useDb()
|
||||||
|
await db.teardown()
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should do a basic product update", async () => {
|
||||||
|
const api = useApi()! as AxiosInstance
|
||||||
|
|
||||||
|
const payload = {
|
||||||
|
title: "New title",
|
||||||
|
description: "test-product-description",
|
||||||
|
}
|
||||||
|
|
||||||
|
const response = await api
|
||||||
|
.post(`/admin/products/${toUpdate}`, payload, adminHeaders)
|
||||||
|
.catch((err) => {
|
||||||
|
console.log(err)
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(response?.status).toEqual(200)
|
||||||
|
expect(response?.data.product).toEqual(
|
||||||
|
expect.objectContaining({
|
||||||
|
id: toUpdate,
|
||||||
|
title: "New title",
|
||||||
|
description: "test-product-description",
|
||||||
|
})
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should update product and also update a variant and create a variant", async () => {
|
||||||
|
const api = useApi()! as AxiosInstance
|
||||||
|
|
||||||
|
const payload = {
|
||||||
|
title: "New title",
|
||||||
|
description: "test-product-description",
|
||||||
|
variants: [
|
||||||
|
{
|
||||||
|
id: "variant-1",
|
||||||
|
title: "Variant 1 updated",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: "Variant 3",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}
|
||||||
|
|
||||||
|
const response = await api
|
||||||
|
.post(`/admin/products/${toUpdateWithVariants}`, payload, adminHeaders)
|
||||||
|
.catch((err) => {
|
||||||
|
console.log(err)
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(response?.status).toEqual(200)
|
||||||
|
expect(response?.data.product).toEqual(
|
||||||
|
expect.objectContaining({
|
||||||
|
id: toUpdateWithVariants,
|
||||||
|
title: "New title",
|
||||||
|
description: "test-product-description",
|
||||||
|
variants: expect.arrayContaining([
|
||||||
|
expect.objectContaining({
|
||||||
|
id: "variant-1",
|
||||||
|
title: "Variant 1 updated",
|
||||||
|
}),
|
||||||
|
expect.objectContaining({
|
||||||
|
title: "Variant 3",
|
||||||
|
}),
|
||||||
|
]),
|
||||||
|
})
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should update product's sales channels", async () => {
|
||||||
|
const api = useApi()! as AxiosInstance
|
||||||
|
|
||||||
|
const payload = {
|
||||||
|
title: "New title",
|
||||||
|
description: "test-product-description",
|
||||||
|
sales_channels: [{ id: "channel-2" }, { id: "channel-3" }],
|
||||||
|
}
|
||||||
|
|
||||||
|
const response = await api
|
||||||
|
.post(
|
||||||
|
`/admin/products/${toUpdateWithSalesChannels}?expand=sales_channels`,
|
||||||
|
payload,
|
||||||
|
adminHeaders
|
||||||
|
)
|
||||||
|
.catch((err) => {
|
||||||
|
console.log(err)
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(response?.status).toEqual(200)
|
||||||
|
expect(response?.data.product).toEqual(
|
||||||
|
expect.objectContaining({
|
||||||
|
id: toUpdateWithSalesChannels,
|
||||||
|
sales_channels: [
|
||||||
|
expect.objectContaining({ id: "channel-2" }),
|
||||||
|
expect.objectContaining({ id: "channel-3" }),
|
||||||
|
],
|
||||||
|
})
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should update inventory when variants are updated", async () => {
|
||||||
|
const api = useApi()! as AxiosInstance
|
||||||
|
|
||||||
|
const variantInventoryService = medusaContainer.resolve(
|
||||||
|
"productVariantInventoryService"
|
||||||
|
)
|
||||||
|
|
||||||
|
const payload = {
|
||||||
|
title: "New title",
|
||||||
|
description: "test-product-description",
|
||||||
|
variants: [
|
||||||
|
{
|
||||||
|
id: "variant-1",
|
||||||
|
title: "Variant 1 updated",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: "Variant 3",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}
|
||||||
|
|
||||||
|
const response = await api
|
||||||
|
.post(`/admin/products/${toUpdateWithVariants}`, payload, adminHeaders)
|
||||||
|
.catch((err) => {
|
||||||
|
console.log(err)
|
||||||
|
})
|
||||||
|
|
||||||
|
let inventory = await variantInventoryService.listInventoryItemsByVariant(
|
||||||
|
"variant-2"
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(response?.status).toEqual(200)
|
||||||
|
expect(response?.data.product).toEqual(
|
||||||
|
expect.objectContaining({
|
||||||
|
id: toUpdateWithVariants,
|
||||||
|
title: "New title",
|
||||||
|
description: "test-product-description",
|
||||||
|
variants: expect.arrayContaining([
|
||||||
|
expect.objectContaining({
|
||||||
|
id: "variant-1",
|
||||||
|
title: "Variant 1 updated",
|
||||||
|
}),
|
||||||
|
expect.objectContaining({
|
||||||
|
title: "Variant 3",
|
||||||
|
}),
|
||||||
|
]),
|
||||||
|
})
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(inventory).toEqual([]) // no inventory items for removed variant
|
||||||
|
|
||||||
|
inventory = await variantInventoryService.listInventoryItemsByVariant(
|
||||||
|
response?.data.product.variants.find((v) => v.title === "Variant 3").id
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(inventory).toEqual([
|
||||||
|
expect.objectContaining({ id: expect.any(String) }),
|
||||||
|
])
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
@@ -1,17 +1,16 @@
|
|||||||
import { initDb, useDb } from "../../../../environment-helpers/use-db"
|
import {initDb, useDb} from "../../../../environment-helpers/use-db"
|
||||||
import {
|
import {simpleProductFactory, simpleRegionFactory,} from "../../../../factories"
|
||||||
simpleProductFactory,
|
|
||||||
simpleRegionFactory,
|
|
||||||
} from "../../../../factories"
|
|
||||||
|
|
||||||
import { AxiosInstance } from "axios"
|
import {AxiosInstance} from "axios"
|
||||||
import adminSeeder from "../../../../helpers/admin-seeder"
|
import adminSeeder from "../../../../helpers/admin-seeder"
|
||||||
import { createDefaultRuleTypes } from "../../../helpers/create-default-rule-types"
|
import {
|
||||||
import { createVariantPriceSet } from "../../../helpers/create-variant-price-set"
|
createDefaultRuleTypes
|
||||||
import { getContainer } from "../../../../environment-helpers/use-container"
|
} 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 path from "path"
|
||||||
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
|
import {startBootstrapApp} from "../../../../environment-helpers/bootstrap-app"
|
||||||
import { useApi } from "../../../../environment-helpers/use-api"
|
import {useApi} from "../../../../environment-helpers/use-api"
|
||||||
|
|
||||||
jest.setTimeout(50000)
|
jest.setTimeout(50000)
|
||||||
|
|
||||||
@@ -25,6 +24,10 @@ const env = {
|
|||||||
MEDUSA_FF_MEDUSA_V2: true,
|
MEDUSA_FF_MEDUSA_V2: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO SEE to use new test runner medusaIntegrationTestRunner({
|
||||||
|
// env,
|
||||||
|
// testSuite: ({ dbConnection, getContainer, api }) => {})
|
||||||
|
|
||||||
describe.skip("POST /admin/products/:id/variants/:id", () => {
|
describe.skip("POST /admin/products/:id/variants/:id", () => {
|
||||||
let dbConnection
|
let dbConnection
|
||||||
let appContainer
|
let appContainer
|
||||||
|
|||||||
@@ -23,6 +23,10 @@ const env = {
|
|||||||
MEDUSA_FF_MEDUSA_V2: true,
|
MEDUSA_FF_MEDUSA_V2: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO SEE to use new test runner medusaIntegrationTestRunner({
|
||||||
|
// env,
|
||||||
|
// testSuite: ({ dbConnection, getContainer, api }) => {})
|
||||||
|
|
||||||
describe.skip("POST /admin/products/:id", () => {
|
describe.skip("POST /admin/products/:id", () => {
|
||||||
let dbConnection
|
let dbConnection
|
||||||
let appContainer
|
let appContainer
|
||||||
|
|||||||
@@ -1,12 +1,7 @@
|
|||||||
import { initDb, useDb } from "../../../../environment-helpers/use-db"
|
|
||||||
|
|
||||||
import { IPromotionModuleService } from "@medusajs/types"
|
import { IPromotionModuleService } from "@medusajs/types"
|
||||||
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||||
import { createAdminUser } from "../../../helpers/create-admin-user"
|
import { createAdminUser } from "../../../helpers/create-admin-user"
|
||||||
import { getContainer } from "../../../../environment-helpers/use-container"
|
import { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||||
import path from "path"
|
|
||||||
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
|
|
||||||
import { useApi } from "../../../../environment-helpers/use-api"
|
|
||||||
|
|
||||||
jest.setTimeout(50000)
|
jest.setTimeout(50000)
|
||||||
|
|
||||||
@@ -15,184 +10,169 @@ const adminHeaders = {
|
|||||||
headers: { "x-medusa-access-token": "test_token" },
|
headers: { "x-medusa-access-token": "test_token" },
|
||||||
}
|
}
|
||||||
|
|
||||||
describe("POST /admin/campaigns", () => {
|
medusaIntegrationTestRunner({
|
||||||
let dbConnection
|
env,
|
||||||
let appContainer
|
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||||
let shutdownServer
|
describe("POST /admin/campaigns", () => {
|
||||||
let promotionModuleService: IPromotionModuleService
|
let appContainer
|
||||||
|
let promotionModuleService: IPromotionModuleService
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
|
appContainer = getContainer()
|
||||||
dbConnection = await initDb({ cwd, env } as any)
|
promotionModuleService = appContainer.resolve(
|
||||||
shutdownServer = await startBootstrapApp({ cwd, env })
|
ModuleRegistrationName.PROMOTION
|
||||||
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()
|
|
||||||
})
|
|
||||||
|
|
||||||
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)
|
|
||||||
|
|
||||||
expect(response.status).toEqual(400)
|
|
||||||
expect(response.data.message).toEqual(
|
|
||||||
"name must be a string, name should not be empty"
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
it("should create a campaign successfully", async () => {
|
|
||||||
const createdPromotion = await promotionModuleService.create({
|
|
||||||
code: "TEST",
|
|
||||||
type: "standard",
|
|
||||||
})
|
|
||||||
|
|
||||||
const api = useApi() as any
|
|
||||||
const response = await api.post(
|
|
||||||
`/admin/campaigns`,
|
|
||||||
{
|
|
||||||
name: "test",
|
|
||||||
campaign_identifier: "test",
|
|
||||||
starts_at: new Date("01/01/2024").toISOString(),
|
|
||||||
ends_at: new Date("01/01/2029").toISOString(),
|
|
||||||
promotions: [{ id: createdPromotion.id }],
|
|
||||||
budget: {
|
|
||||||
limit: 1000,
|
|
||||||
type: "usage",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
adminHeaders
|
|
||||||
)
|
|
||||||
|
|
||||||
expect(response.status).toEqual(200)
|
|
||||||
expect(response.data.campaign).toEqual(
|
|
||||||
expect.objectContaining({
|
|
||||||
id: expect.any(String),
|
|
||||||
name: "test",
|
|
||||||
campaign_identifier: "test",
|
|
||||||
starts_at: expect.any(String),
|
|
||||||
ends_at: expect.any(String),
|
|
||||||
budget: expect.objectContaining({
|
|
||||||
limit: 1000,
|
|
||||||
type: "usage",
|
|
||||||
}),
|
|
||||||
promotions: [
|
|
||||||
expect.objectContaining({
|
|
||||||
id: createdPromotion.id,
|
|
||||||
}),
|
|
||||||
],
|
|
||||||
})
|
})
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
it("should create 3 campaigns in parallel and have the context passed as argument when calling createCampaigns with different transactionId", async () => {
|
beforeEach(async () => {
|
||||||
const parallelPromotion = await promotionModuleService.create({
|
await createAdminUser(dbConnection, adminHeaders, appContainer)
|
||||||
code: "PARALLEL",
|
})
|
||||||
type: "standard",
|
|
||||||
})
|
|
||||||
|
|
||||||
const spyCreateCampaigns = jest.spyOn(
|
it("should throw an error if required params are not passed", async () => {
|
||||||
promotionModuleService.constructor.prototype,
|
const { response } = await api
|
||||||
"createCampaigns"
|
.post(`/admin/campaigns`, {}, adminHeaders)
|
||||||
)
|
.catch((e) => e)
|
||||||
|
|
||||||
const api = useApi() as any
|
expect(response.status).toEqual(400)
|
||||||
|
expect(response.data.message).toEqual(
|
||||||
|
"name must be a string, name should not be empty"
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
const a = async () => {
|
it("should create a campaign successfully", async () => {
|
||||||
return await api.post(
|
const createdPromotion = await promotionModuleService.create({
|
||||||
`/admin/campaigns`,
|
code: "TEST",
|
||||||
{
|
type: "standard",
|
||||||
name: "camp_1",
|
})
|
||||||
campaign_identifier: "camp_1",
|
|
||||||
starts_at: new Date("01/01/2024").toISOString(),
|
const response = await api.post(
|
||||||
ends_at: new Date("01/02/2024").toISOString(),
|
`/admin/campaigns`,
|
||||||
promotions: [{ id: parallelPromotion.id }],
|
{
|
||||||
budget: {
|
name: "test",
|
||||||
limit: 1000,
|
campaign_identifier: "test",
|
||||||
type: "usage",
|
starts_at: new Date("01/01/2024").toISOString(),
|
||||||
|
ends_at: new Date("01/01/2029").toISOString(),
|
||||||
|
promotions: [{ id: createdPromotion.id }],
|
||||||
|
budget: {
|
||||||
|
limit: 1000,
|
||||||
|
type: "usage",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
adminHeaders
|
||||||
adminHeaders
|
)
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
const b = async () => {
|
expect(response.status).toEqual(200)
|
||||||
return await api.post(
|
expect(response.data.campaign).toEqual(
|
||||||
`/admin/campaigns`,
|
expect.objectContaining({
|
||||||
{
|
id: expect.any(String),
|
||||||
name: "camp_2",
|
name: "test",
|
||||||
campaign_identifier: "camp_2",
|
campaign_identifier: "test",
|
||||||
starts_at: new Date("01/02/2024").toISOString(),
|
starts_at: expect.any(String),
|
||||||
ends_at: new Date("01/03/2029").toISOString(),
|
ends_at: expect.any(String),
|
||||||
promotions: [{ id: parallelPromotion.id }],
|
budget: expect.objectContaining({
|
||||||
budget: {
|
limit: 1000,
|
||||||
limit: 500,
|
type: "usage",
|
||||||
type: "usage",
|
}),
|
||||||
},
|
promotions: [
|
||||||
},
|
expect.objectContaining({
|
||||||
adminHeaders
|
id: createdPromotion.id,
|
||||||
)
|
}),
|
||||||
}
|
],
|
||||||
|
})
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
const c = async () => {
|
it("should create 3 campaigns in parallel and have the context passed as argument when calling createCampaigns with different transactionId", async () => {
|
||||||
return await api.post(
|
const parallelPromotion = await promotionModuleService.create({
|
||||||
`/admin/campaigns`,
|
code: "PARALLEL",
|
||||||
{
|
type: "standard",
|
||||||
name: "camp_3",
|
})
|
||||||
campaign_identifier: "camp_3",
|
|
||||||
starts_at: new Date("01/03/2024").toISOString(),
|
const spyCreateCampaigns = jest.spyOn(
|
||||||
ends_at: new Date("01/04/2029").toISOString(),
|
promotionModuleService.constructor.prototype,
|
||||||
promotions: [{ id: parallelPromotion.id }],
|
"createCampaigns"
|
||||||
budget: {
|
)
|
||||||
limit: 250,
|
|
||||||
type: "usage",
|
const a = async () => {
|
||||||
},
|
return await api.post(
|
||||||
},
|
`/admin/campaigns`,
|
||||||
{
|
{
|
||||||
headers: {
|
name: "camp_1",
|
||||||
...adminHeaders.headers,
|
campaign_identifier: "camp_1",
|
||||||
"x-request-id": "my-custom-request-id",
|
starts_at: new Date("01/01/2024").toISOString(),
|
||||||
},
|
ends_at: new Date("01/02/2024").toISOString(),
|
||||||
|
promotions: [{ id: parallelPromotion.id }],
|
||||||
|
budget: {
|
||||||
|
limit: 1000,
|
||||||
|
type: "usage",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
adminHeaders
|
||||||
|
)
|
||||||
}
|
}
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
await Promise.all([a(), b(), c()])
|
const b = async () => {
|
||||||
|
return await api.post(
|
||||||
|
`/admin/campaigns`,
|
||||||
|
{
|
||||||
|
name: "camp_2",
|
||||||
|
campaign_identifier: "camp_2",
|
||||||
|
starts_at: new Date("01/02/2024").toISOString(),
|
||||||
|
ends_at: new Date("01/03/2029").toISOString(),
|
||||||
|
promotions: [{ id: parallelPromotion.id }],
|
||||||
|
budget: {
|
||||||
|
limit: 500,
|
||||||
|
type: "usage",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
adminHeaders
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
expect(spyCreateCampaigns).toHaveBeenCalledTimes(3)
|
const c = async () => {
|
||||||
expect(spyCreateCampaigns.mock.calls[0][1].__type).toBe("MedusaContext")
|
return await api.post(
|
||||||
|
`/admin/campaigns`,
|
||||||
|
{
|
||||||
|
name: "camp_3",
|
||||||
|
campaign_identifier: "camp_3",
|
||||||
|
starts_at: new Date("01/03/2024").toISOString(),
|
||||||
|
ends_at: new Date("01/04/2029").toISOString(),
|
||||||
|
promotions: [{ id: parallelPromotion.id }],
|
||||||
|
budget: {
|
||||||
|
limit: 250,
|
||||||
|
type: "usage",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
headers: {
|
||||||
|
...adminHeaders.headers,
|
||||||
|
"x-request-id": "my-custom-request-id",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
const distinctTransactionId = [
|
await Promise.all([a(), b(), c()])
|
||||||
...new Set(
|
|
||||||
spyCreateCampaigns.mock.calls.map((call) => call[1].transactionId)
|
|
||||||
),
|
|
||||||
]
|
|
||||||
expect(distinctTransactionId).toHaveLength(3)
|
|
||||||
|
|
||||||
const distinctRequestId = [
|
expect(spyCreateCampaigns).toHaveBeenCalledTimes(3)
|
||||||
...new Set(
|
expect(spyCreateCampaigns.mock.calls[0][1].__type).toBe("MedusaContext")
|
||||||
spyCreateCampaigns.mock.calls.map((call) => call[1].requestId)
|
|
||||||
),
|
|
||||||
]
|
|
||||||
|
|
||||||
expect(distinctRequestId).toHaveLength(3)
|
const distinctTransactionId = [
|
||||||
expect(distinctRequestId).toContain("my-custom-request-id")
|
...new Set(
|
||||||
})
|
spyCreateCampaigns.mock.calls.map((call) => call[1].transactionId)
|
||||||
|
),
|
||||||
|
]
|
||||||
|
expect(distinctTransactionId).toHaveLength(3)
|
||||||
|
|
||||||
|
const distinctRequestId = [
|
||||||
|
...new Set(
|
||||||
|
spyCreateCampaigns.mock.calls.map((call) => call[1].requestId)
|
||||||
|
),
|
||||||
|
]
|
||||||
|
|
||||||
|
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 { IPromotionModuleService } from "@medusajs/types"
|
||||||
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||||
import { PromotionType } from "@medusajs/utils"
|
import { PromotionType } from "@medusajs/utils"
|
||||||
import { createAdminUser } from "../../../helpers/create-admin-user"
|
import { createAdminUser } from "../../../helpers/create-admin-user"
|
||||||
import { getContainer } from "../../../../environment-helpers/use-container"
|
import { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||||
import path from "path"
|
|
||||||
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
|
|
||||||
import { useApi } from "../../../../environment-helpers/use-api"
|
|
||||||
|
|
||||||
jest.setTimeout(50000)
|
jest.setTimeout(50000)
|
||||||
|
|
||||||
@@ -16,158 +11,71 @@ const adminHeaders = {
|
|||||||
headers: { "x-medusa-access-token": "test_token" },
|
headers: { "x-medusa-access-token": "test_token" },
|
||||||
}
|
}
|
||||||
|
|
||||||
describe("POST /admin/promotions", () => {
|
medusaIntegrationTestRunner({
|
||||||
let dbConnection
|
env,
|
||||||
let appContainer
|
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||||
let shutdownServer
|
describe("POST /admin/promotions", () => {
|
||||||
let promotionModuleService: IPromotionModuleService
|
let appContainer
|
||||||
|
let promotionModuleService: IPromotionModuleService
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
|
appContainer = getContainer()
|
||||||
dbConnection = await initDb({ cwd, env } as any)
|
promotionModuleService = appContainer.resolve(
|
||||||
shutdownServer = await startBootstrapApp({ cwd, env })
|
ModuleRegistrationName.PROMOTION
|
||||||
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()
|
|
||||||
})
|
|
||||||
|
|
||||||
it("should throw an error if required params are not passed", async () => {
|
|
||||||
const api = useApi() as any
|
|
||||||
const { response } = await api
|
|
||||||
.post(
|
|
||||||
`/admin/promotions`,
|
|
||||||
{
|
|
||||||
type: PromotionType.STANDARD,
|
|
||||||
},
|
|
||||||
adminHeaders
|
|
||||||
)
|
|
||||||
.catch((e) => e)
|
|
||||||
|
|
||||||
expect(response.status).toEqual(400)
|
|
||||||
expect(response.data.message).toEqual(
|
|
||||||
"code must be a string, code should not be empty, application_method should not be empty"
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
it("should create a standard promotion successfully", async () => {
|
|
||||||
const api = useApi() as any
|
|
||||||
const response = await api.post(
|
|
||||||
`/admin/promotions`,
|
|
||||||
{
|
|
||||||
code: "TEST",
|
|
||||||
type: PromotionType.STANDARD,
|
|
||||||
is_automatic: true,
|
|
||||||
campaign: {
|
|
||||||
name: "test",
|
|
||||||
campaign_identifier: "test-1",
|
|
||||||
budget: {
|
|
||||||
type: "usage",
|
|
||||||
limit: 100,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
application_method: {
|
|
||||||
target_type: "items",
|
|
||||||
type: "fixed",
|
|
||||||
allocation: "each",
|
|
||||||
value: "100",
|
|
||||||
max_quantity: 100,
|
|
||||||
target_rules: [
|
|
||||||
{
|
|
||||||
attribute: "test.test",
|
|
||||||
operator: "eq",
|
|
||||||
values: ["test1", "test2"],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
rules: [
|
|
||||||
{
|
|
||||||
attribute: "test.test",
|
|
||||||
operator: "eq",
|
|
||||||
values: ["test1", "test2"],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
adminHeaders
|
|
||||||
)
|
|
||||||
|
|
||||||
expect(response.status).toEqual(200)
|
|
||||||
expect(response.data.promotion).toEqual(
|
|
||||||
expect.objectContaining({
|
|
||||||
id: expect.any(String),
|
|
||||||
code: "TEST",
|
|
||||||
type: "standard",
|
|
||||||
is_automatic: true,
|
|
||||||
campaign: expect.objectContaining({
|
|
||||||
name: "test",
|
|
||||||
campaign_identifier: "test-1",
|
|
||||||
budget: expect.objectContaining({
|
|
||||||
type: "usage",
|
|
||||||
limit: 100,
|
|
||||||
}),
|
|
||||||
}),
|
|
||||||
application_method: expect.objectContaining({
|
|
||||||
value: 100,
|
|
||||||
max_quantity: 100,
|
|
||||||
type: "fixed",
|
|
||||||
target_type: "items",
|
|
||||||
allocation: "each",
|
|
||||||
target_rules: [
|
|
||||||
expect.objectContaining({
|
|
||||||
operator: "eq",
|
|
||||||
attribute: "test.test",
|
|
||||||
values: expect.arrayContaining([
|
|
||||||
expect.objectContaining({ value: "test1" }),
|
|
||||||
expect.objectContaining({ value: "test2" }),
|
|
||||||
]),
|
|
||||||
}),
|
|
||||||
],
|
|
||||||
}),
|
|
||||||
rules: [
|
|
||||||
expect.objectContaining({
|
|
||||||
operator: "eq",
|
|
||||||
attribute: "test.test",
|
|
||||||
values: expect.arrayContaining([
|
|
||||||
expect.objectContaining({ value: "test1" }),
|
|
||||||
expect.objectContaining({ value: "test2" }),
|
|
||||||
]),
|
|
||||||
}),
|
|
||||||
],
|
|
||||||
})
|
})
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
it("should throw an error if buy_rules params are not passed", async () => {
|
beforeEach(async () => {
|
||||||
const api = useApi() as any
|
await createAdminUser(dbConnection, adminHeaders, appContainer)
|
||||||
const { response } = await api
|
})
|
||||||
.post(
|
|
||||||
`/admin/promotions`,
|
it("should throw an error if required params are not passed", async () => {
|
||||||
{
|
const { response } = await api
|
||||||
code: "TEST",
|
.post(
|
||||||
type: PromotionType.BUYGET,
|
`/admin/promotions`,
|
||||||
is_automatic: true,
|
{
|
||||||
application_method: {
|
type: PromotionType.STANDARD,
|
||||||
target_type: "items",
|
},
|
||||||
type: "fixed",
|
adminHeaders
|
||||||
allocation: "each",
|
)
|
||||||
value: "100",
|
.catch((e) => e)
|
||||||
max_quantity: 100,
|
|
||||||
target_rules: [
|
expect(response.status).toEqual(400)
|
||||||
|
expect(response.data.message).toEqual(
|
||||||
|
"code must be a string, code should not be empty, application_method should not be empty"
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should create a standard promotion successfully", async () => {
|
||||||
|
const response = await api.post(
|
||||||
|
`/admin/promotions`,
|
||||||
|
{
|
||||||
|
code: "TEST",
|
||||||
|
type: PromotionType.STANDARD,
|
||||||
|
is_automatic: true,
|
||||||
|
campaign: {
|
||||||
|
name: "test",
|
||||||
|
campaign_identifier: "test-1",
|
||||||
|
budget: {
|
||||||
|
type: "usage",
|
||||||
|
limit: 100,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
application_method: {
|
||||||
|
target_type: "items",
|
||||||
|
type: "fixed",
|
||||||
|
allocation: "each",
|
||||||
|
value: "100",
|
||||||
|
max_quantity: 100,
|
||||||
|
target_rules: [
|
||||||
|
{
|
||||||
|
attribute: "test.test",
|
||||||
|
operator: "eq",
|
||||||
|
values: ["test1", "test2"],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
rules: [
|
||||||
{
|
{
|
||||||
attribute: "test.test",
|
attribute: "test.test",
|
||||||
operator: "eq",
|
operator: "eq",
|
||||||
@@ -175,40 +83,174 @@ describe("POST /admin/promotions", () => {
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
rules: [
|
adminHeaders
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(response.status).toEqual(200)
|
||||||
|
expect(response.data.promotion).toEqual(
|
||||||
|
expect.objectContaining({
|
||||||
|
id: expect.any(String),
|
||||||
|
code: "TEST",
|
||||||
|
type: "standard",
|
||||||
|
is_automatic: true,
|
||||||
|
campaign: expect.objectContaining({
|
||||||
|
name: "test",
|
||||||
|
campaign_identifier: "test-1",
|
||||||
|
budget: expect.objectContaining({
|
||||||
|
type: "usage",
|
||||||
|
limit: 100,
|
||||||
|
}),
|
||||||
|
}),
|
||||||
|
application_method: expect.objectContaining({
|
||||||
|
value: 100,
|
||||||
|
max_quantity: 100,
|
||||||
|
type: "fixed",
|
||||||
|
target_type: "items",
|
||||||
|
allocation: "each",
|
||||||
|
target_rules: [
|
||||||
|
expect.objectContaining({
|
||||||
|
operator: "eq",
|
||||||
|
attribute: "test.test",
|
||||||
|
values: expect.arrayContaining([
|
||||||
|
expect.objectContaining({ value: "test1" }),
|
||||||
|
expect.objectContaining({ value: "test2" }),
|
||||||
|
]),
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
rules: [
|
||||||
|
expect.objectContaining({
|
||||||
|
operator: "eq",
|
||||||
|
attribute: "test.test",
|
||||||
|
values: expect.arrayContaining([
|
||||||
|
expect.objectContaining({ value: "test1" }),
|
||||||
|
expect.objectContaining({ value: "test2" }),
|
||||||
|
]),
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
})
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should throw an error if buy_rules params are not passed", async () => {
|
||||||
|
const { response } = await api
|
||||||
|
.post(
|
||||||
|
`/admin/promotions`,
|
||||||
{
|
{
|
||||||
attribute: "test.test",
|
code: "TEST",
|
||||||
operator: "eq",
|
type: PromotionType.BUYGET,
|
||||||
values: ["test1", "test2"],
|
is_automatic: true,
|
||||||
|
application_method: {
|
||||||
|
target_type: "items",
|
||||||
|
type: "fixed",
|
||||||
|
allocation: "each",
|
||||||
|
value: "100",
|
||||||
|
max_quantity: 100,
|
||||||
|
target_rules: [
|
||||||
|
{
|
||||||
|
attribute: "test.test",
|
||||||
|
operator: "eq",
|
||||||
|
values: ["test1", "test2"],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
rules: [
|
||||||
|
{
|
||||||
|
attribute: "test.test",
|
||||||
|
operator: "eq",
|
||||||
|
values: ["test1", "test2"],
|
||||||
|
},
|
||||||
|
],
|
||||||
},
|
},
|
||||||
],
|
adminHeaders
|
||||||
},
|
)
|
||||||
adminHeaders
|
.catch((e) => e)
|
||||||
)
|
|
||||||
.catch((e) => e)
|
|
||||||
|
|
||||||
expect(response.status).toEqual(400)
|
expect(response.status).toEqual(400)
|
||||||
expect(response.data.message).toEqual(
|
expect(response.data.message).toEqual(
|
||||||
"Buy rules are required for buyget promotion type"
|
"Buy rules are required for buyget promotion type"
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should throw an error if buy_rules params are not passed", async () => {
|
it("should throw an error if buy_rules params are not passed", async () => {
|
||||||
const api = useApi() as any
|
const { response } = await api
|
||||||
const { response } = await api
|
.post(
|
||||||
.post(
|
`/admin/promotions`,
|
||||||
`/admin/promotions`,
|
{
|
||||||
{
|
code: "TEST",
|
||||||
code: "TEST",
|
type: PromotionType.BUYGET,
|
||||||
type: PromotionType.BUYGET,
|
is_automatic: true,
|
||||||
is_automatic: true,
|
application_method: {
|
||||||
application_method: {
|
target_type: "items",
|
||||||
target_type: "items",
|
type: "fixed",
|
||||||
type: "fixed",
|
allocation: "each",
|
||||||
allocation: "each",
|
value: "100",
|
||||||
value: "100",
|
max_quantity: 100,
|
||||||
max_quantity: 100,
|
buy_rules: [
|
||||||
buy_rules: [
|
{
|
||||||
|
attribute: "test.test",
|
||||||
|
operator: "eq",
|
||||||
|
values: ["test1", "test2"],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
rules: [
|
||||||
|
{
|
||||||
|
attribute: "test.test",
|
||||||
|
operator: "eq",
|
||||||
|
values: ["test1", "test2"],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
adminHeaders
|
||||||
|
)
|
||||||
|
.catch((e) => e)
|
||||||
|
|
||||||
|
expect(response.status).toEqual(400)
|
||||||
|
expect(response.data.message).toEqual(
|
||||||
|
"Target rules are required for buyget promotion type"
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should create a buyget promotion successfully", async () => {
|
||||||
|
const response = await api.post(
|
||||||
|
`/admin/promotions`,
|
||||||
|
{
|
||||||
|
code: "TEST",
|
||||||
|
type: PromotionType.BUYGET,
|
||||||
|
is_automatic: true,
|
||||||
|
campaign: {
|
||||||
|
name: "test",
|
||||||
|
campaign_identifier: "test-1",
|
||||||
|
budget: {
|
||||||
|
type: "usage",
|
||||||
|
limit: 100,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
application_method: {
|
||||||
|
target_type: "items",
|
||||||
|
type: "fixed",
|
||||||
|
allocation: "each",
|
||||||
|
value: "100",
|
||||||
|
max_quantity: 100,
|
||||||
|
apply_to_quantity: 1,
|
||||||
|
buy_rules_min_quantity: 1,
|
||||||
|
target_rules: [
|
||||||
|
{
|
||||||
|
attribute: "test.test",
|
||||||
|
operator: "eq",
|
||||||
|
values: ["test1", "test2"],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
buy_rules: [
|
||||||
|
{
|
||||||
|
attribute: "test.test",
|
||||||
|
operator: "eq",
|
||||||
|
values: ["test1", "test2"],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
rules: [
|
||||||
{
|
{
|
||||||
attribute: "test.test",
|
attribute: "test.test",
|
||||||
operator: "eq",
|
operator: "eq",
|
||||||
@@ -216,129 +258,66 @@ describe("POST /admin/promotions", () => {
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
rules: [
|
adminHeaders
|
||||||
{
|
)
|
||||||
attribute: "test.test",
|
|
||||||
operator: "eq",
|
|
||||||
values: ["test1", "test2"],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
adminHeaders
|
|
||||||
)
|
|
||||||
.catch((e) => e)
|
|
||||||
|
|
||||||
expect(response.status).toEqual(400)
|
expect(response.status).toEqual(200)
|
||||||
expect(response.data.message).toEqual(
|
expect(response.data.promotion).toEqual(
|
||||||
"Target rules are required for buyget promotion type"
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
it("should create a buyget promotion successfully", async () => {
|
|
||||||
const api = useApi() as any
|
|
||||||
const response = await api.post(
|
|
||||||
`/admin/promotions`,
|
|
||||||
{
|
|
||||||
code: "TEST",
|
|
||||||
type: PromotionType.BUYGET,
|
|
||||||
is_automatic: true,
|
|
||||||
campaign: {
|
|
||||||
name: "test",
|
|
||||||
campaign_identifier: "test-1",
|
|
||||||
budget: {
|
|
||||||
type: "usage",
|
|
||||||
limit: 100,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
application_method: {
|
|
||||||
target_type: "items",
|
|
||||||
type: "fixed",
|
|
||||||
allocation: "each",
|
|
||||||
value: "100",
|
|
||||||
max_quantity: 100,
|
|
||||||
apply_to_quantity: 1,
|
|
||||||
buy_rules_min_quantity: 1,
|
|
||||||
target_rules: [
|
|
||||||
{
|
|
||||||
attribute: "test.test",
|
|
||||||
operator: "eq",
|
|
||||||
values: ["test1", "test2"],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
buy_rules: [
|
|
||||||
{
|
|
||||||
attribute: "test.test",
|
|
||||||
operator: "eq",
|
|
||||||
values: ["test1", "test2"],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
rules: [
|
|
||||||
{
|
|
||||||
attribute: "test.test",
|
|
||||||
operator: "eq",
|
|
||||||
values: ["test1", "test2"],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
adminHeaders
|
|
||||||
)
|
|
||||||
|
|
||||||
expect(response.status).toEqual(200)
|
|
||||||
expect(response.data.promotion).toEqual(
|
|
||||||
expect.objectContaining({
|
|
||||||
id: expect.any(String),
|
|
||||||
code: "TEST",
|
|
||||||
type: "buyget",
|
|
||||||
is_automatic: true,
|
|
||||||
campaign: expect.objectContaining({
|
|
||||||
name: "test",
|
|
||||||
campaign_identifier: "test-1",
|
|
||||||
budget: expect.objectContaining({
|
|
||||||
type: "usage",
|
|
||||||
limit: 100,
|
|
||||||
}),
|
|
||||||
}),
|
|
||||||
application_method: expect.objectContaining({
|
|
||||||
value: 100,
|
|
||||||
max_quantity: 100,
|
|
||||||
type: "fixed",
|
|
||||||
target_type: "items",
|
|
||||||
allocation: "each",
|
|
||||||
apply_to_quantity: 1,
|
|
||||||
buy_rules_min_quantity: 1,
|
|
||||||
target_rules: [
|
|
||||||
expect.objectContaining({
|
|
||||||
operator: "eq",
|
|
||||||
attribute: "test.test",
|
|
||||||
values: expect.arrayContaining([
|
|
||||||
expect.objectContaining({ value: "test1" }),
|
|
||||||
expect.objectContaining({ value: "test2" }),
|
|
||||||
]),
|
|
||||||
}),
|
|
||||||
],
|
|
||||||
buy_rules: [
|
|
||||||
expect.objectContaining({
|
|
||||||
operator: "eq",
|
|
||||||
attribute: "test.test",
|
|
||||||
values: expect.arrayContaining([
|
|
||||||
expect.objectContaining({ value: "test1" }),
|
|
||||||
expect.objectContaining({ value: "test2" }),
|
|
||||||
]),
|
|
||||||
}),
|
|
||||||
],
|
|
||||||
}),
|
|
||||||
rules: [
|
|
||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
operator: "eq",
|
id: expect.any(String),
|
||||||
attribute: "test.test",
|
code: "TEST",
|
||||||
values: expect.arrayContaining([
|
type: "buyget",
|
||||||
expect.objectContaining({ value: "test1" }),
|
is_automatic: true,
|
||||||
expect.objectContaining({ value: "test2" }),
|
campaign: expect.objectContaining({
|
||||||
]),
|
name: "test",
|
||||||
}),
|
campaign_identifier: "test-1",
|
||||||
],
|
budget: expect.objectContaining({
|
||||||
|
type: "usage",
|
||||||
|
limit: 100,
|
||||||
|
}),
|
||||||
|
}),
|
||||||
|
application_method: expect.objectContaining({
|
||||||
|
value: 100,
|
||||||
|
max_quantity: 100,
|
||||||
|
type: "fixed",
|
||||||
|
target_type: "items",
|
||||||
|
allocation: "each",
|
||||||
|
apply_to_quantity: 1,
|
||||||
|
buy_rules_min_quantity: 1,
|
||||||
|
target_rules: [
|
||||||
|
expect.objectContaining({
|
||||||
|
operator: "eq",
|
||||||
|
attribute: "test.test",
|
||||||
|
values: expect.arrayContaining([
|
||||||
|
expect.objectContaining({ value: "test1" }),
|
||||||
|
expect.objectContaining({ value: "test2" }),
|
||||||
|
]),
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
buy_rules: [
|
||||||
|
expect.objectContaining({
|
||||||
|
operator: "eq",
|
||||||
|
attribute: "test.test",
|
||||||
|
values: expect.arrayContaining([
|
||||||
|
expect.objectContaining({ value: "test1" }),
|
||||||
|
expect.objectContaining({ value: "test2" }),
|
||||||
|
]),
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
rules: [
|
||||||
|
expect.objectContaining({
|
||||||
|
operator: "eq",
|
||||||
|
attribute: "test.test",
|
||||||
|
values: expect.arrayContaining([
|
||||||
|
expect.objectContaining({ value: "test1" }),
|
||||||
|
expect.objectContaining({ value: "test2" }),
|
||||||
|
]),
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
})
|
||||||
|
)
|
||||||
})
|
})
|
||||||
)
|
})
|
||||||
})
|
},
|
||||||
})
|
})
|
||||||
@@ -1,12 +1,7 @@
|
|||||||
import { initDb, useDb } from "../../../../environment-helpers/use-db"
|
|
||||||
|
|
||||||
import { IPromotionModuleService } from "@medusajs/types"
|
import { IPromotionModuleService } from "@medusajs/types"
|
||||||
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||||
import { createAdminUser } from "../../../helpers/create-admin-user"
|
import { createAdminUser } from "../../../helpers/create-admin-user"
|
||||||
import { getContainer } from "../../../../environment-helpers/use-container"
|
import { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||||
import path from "path"
|
|
||||||
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
|
|
||||||
import { useApi } from "../../../../environment-helpers/use-api"
|
|
||||||
|
|
||||||
jest.setTimeout(50000)
|
jest.setTimeout(50000)
|
||||||
|
|
||||||
@@ -15,59 +10,47 @@ const adminHeaders = {
|
|||||||
headers: { "x-medusa-access-token": "test_token" },
|
headers: { "x-medusa-access-token": "test_token" },
|
||||||
}
|
}
|
||||||
|
|
||||||
describe("DELETE /admin/campaigns/:id", () => {
|
medusaIntegrationTestRunner({
|
||||||
let dbConnection
|
env,
|
||||||
let appContainer
|
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||||
let shutdownServer
|
describe("DELETE /admin/campaigns/:id", () => {
|
||||||
let promotionModuleService: IPromotionModuleService
|
let appContainer
|
||||||
|
let promotionModuleService: IPromotionModuleService
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
|
appContainer = getContainer()
|
||||||
dbConnection = await initDb({ cwd, env } as any)
|
promotionModuleService = appContainer.resolve(
|
||||||
shutdownServer = await startBootstrapApp({ cwd, env })
|
ModuleRegistrationName.PROMOTION
|
||||||
appContainer = getContainer()
|
)
|
||||||
promotionModuleService = appContainer.resolve(
|
})
|
||||||
ModuleRegistrationName.PROMOTION
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
afterAll(async () => {
|
beforeEach(async () => {
|
||||||
const db = useDb()
|
await createAdminUser(dbConnection, adminHeaders, appContainer)
|
||||||
await db.shutdown()
|
})
|
||||||
await shutdownServer()
|
|
||||||
})
|
|
||||||
|
|
||||||
beforeEach(async () => {
|
it("should delete campaign successfully", async () => {
|
||||||
await createAdminUser(dbConnection, adminHeaders)
|
const [createdCampaign] = await promotionModuleService.createCampaigns([
|
||||||
})
|
{
|
||||||
|
name: "test",
|
||||||
|
campaign_identifier: "test",
|
||||||
|
starts_at: new Date("01/01/2024"),
|
||||||
|
ends_at: new Date("01/01/2025"),
|
||||||
|
},
|
||||||
|
])
|
||||||
|
|
||||||
afterEach(async () => {
|
const deleteRes = await api.delete(
|
||||||
const db = useDb()
|
`/admin/campaigns/${createdCampaign.id}`,
|
||||||
await db.teardown()
|
adminHeaders
|
||||||
})
|
)
|
||||||
|
|
||||||
it("should delete campaign successfully", async () => {
|
expect(deleteRes.status).toEqual(200)
|
||||||
const [createdCampaign] = await promotionModuleService.createCampaigns([
|
|
||||||
{
|
|
||||||
name: "test",
|
|
||||||
campaign_identifier: "test",
|
|
||||||
starts_at: new Date("01/01/2024"),
|
|
||||||
ends_at: new Date("01/01/2025"),
|
|
||||||
},
|
|
||||||
])
|
|
||||||
|
|
||||||
const api = useApi() as any
|
const campaigns = await promotionModuleService.listCampaigns({
|
||||||
const deleteRes = await api.delete(
|
id: [createdCampaign.id],
|
||||||
`/admin/campaigns/${createdCampaign.id}`,
|
})
|
||||||
adminHeaders
|
|
||||||
)
|
|
||||||
|
|
||||||
expect(deleteRes.status).toEqual(200)
|
expect(campaigns.length).toEqual(0)
|
||||||
|
})
|
||||||
const campaigns = await promotionModuleService.listCampaigns({
|
|
||||||
id: [createdCampaign.id],
|
|
||||||
})
|
})
|
||||||
|
},
|
||||||
expect(campaigns.length).toEqual(0)
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
@@ -1,12 +1,7 @@
|
|||||||
import { initDb, useDb } from "../../../../environment-helpers/use-db"
|
|
||||||
|
|
||||||
import { IPromotionModuleService } from "@medusajs/types"
|
import { IPromotionModuleService } from "@medusajs/types"
|
||||||
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||||
import { createAdminUser } from "../../../helpers/create-admin-user"
|
import { createAdminUser } from "../../../helpers/create-admin-user"
|
||||||
import { getContainer } from "../../../../environment-helpers/use-container"
|
import { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||||
import path from "path"
|
|
||||||
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
|
|
||||||
import { useApi } from "../../../../environment-helpers/use-api"
|
|
||||||
|
|
||||||
jest.setTimeout(50000)
|
jest.setTimeout(50000)
|
||||||
|
|
||||||
@@ -15,60 +10,48 @@ const adminHeaders = {
|
|||||||
headers: { "x-medusa-access-token": "test_token" },
|
headers: { "x-medusa-access-token": "test_token" },
|
||||||
}
|
}
|
||||||
|
|
||||||
describe("DELETE /admin/promotions/:id", () => {
|
medusaIntegrationTestRunner({
|
||||||
let dbConnection
|
env,
|
||||||
let appContainer
|
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||||
let shutdownServer
|
describe("DELETE /admin/promotions/:id", () => {
|
||||||
let promotionModuleService: IPromotionModuleService
|
let appContainer
|
||||||
|
let promotionModuleService: IPromotionModuleService
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
|
appContainer = getContainer()
|
||||||
dbConnection = await initDb({ cwd, env } as any)
|
promotionModuleService = appContainer.resolve(
|
||||||
shutdownServer = await startBootstrapApp({ cwd, env })
|
ModuleRegistrationName.PROMOTION
|
||||||
appContainer = getContainer()
|
)
|
||||||
promotionModuleService = appContainer.resolve(
|
})
|
||||||
ModuleRegistrationName.PROMOTION
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
afterAll(async () => {
|
beforeEach(async () => {
|
||||||
const db = useDb()
|
await createAdminUser(dbConnection, adminHeaders, appContainer)
|
||||||
await db.shutdown()
|
})
|
||||||
await shutdownServer()
|
|
||||||
})
|
|
||||||
|
|
||||||
beforeEach(async () => {
|
it("should delete promotion successfully", async () => {
|
||||||
await createAdminUser(dbConnection, adminHeaders)
|
const createdPromotion = await promotionModuleService.create({
|
||||||
})
|
code: "TEST",
|
||||||
|
type: "standard",
|
||||||
|
application_method: {
|
||||||
|
type: "fixed",
|
||||||
|
target_type: "order",
|
||||||
|
value: "100",
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
afterEach(async () => {
|
const deleteRes = await api.delete(
|
||||||
const db = useDb()
|
`/admin/promotions/${createdPromotion.id}`,
|
||||||
await db.teardown()
|
adminHeaders
|
||||||
})
|
)
|
||||||
|
|
||||||
it("should delete promotion successfully", async () => {
|
expect(deleteRes.status).toEqual(200)
|
||||||
const createdPromotion = await promotionModuleService.create({
|
|
||||||
code: "TEST",
|
const promotions = await promotionModuleService.list({
|
||||||
type: "standard",
|
id: [createdPromotion.id],
|
||||||
application_method: {
|
})
|
||||||
type: "fixed",
|
|
||||||
target_type: "order",
|
expect(promotions.length).toEqual(0)
|
||||||
value: "100",
|
})
|
||||||
},
|
|
||||||
})
|
})
|
||||||
|
},
|
||||||
const api = useApi() as any
|
|
||||||
const deleteRes = await api.delete(
|
|
||||||
`/admin/promotions/${createdPromotion.id}`,
|
|
||||||
adminHeaders
|
|
||||||
)
|
|
||||||
|
|
||||||
expect(deleteRes.status).toEqual(200)
|
|
||||||
|
|
||||||
const promotions = await promotionModuleService.list({
|
|
||||||
id: [createdPromotion.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 { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||||
import { IPromotionModuleService } from "@medusajs/types"
|
import { IPromotionModuleService } from "@medusajs/types"
|
||||||
import { CampaignBudgetType } from "@medusajs/utils"
|
import { CampaignBudgetType } from "@medusajs/utils"
|
||||||
import path from "path"
|
|
||||||
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
|
|
||||||
import { useApi } from "../../../../environment-helpers/use-api"
|
|
||||||
import { getContainer } from "../../../../environment-helpers/use-container"
|
|
||||||
import { createAdminUser } from "../../../helpers/create-admin-user"
|
import { createAdminUser } from "../../../helpers/create-admin-user"
|
||||||
|
import { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||||
|
|
||||||
jest.setTimeout(50000)
|
jest.setTimeout(50000)
|
||||||
|
|
||||||
@@ -47,140 +42,127 @@ const adminHeaders = {
|
|||||||
headers: { "x-medusa-access-token": "test_token" },
|
headers: { "x-medusa-access-token": "test_token" },
|
||||||
}
|
}
|
||||||
|
|
||||||
describe("GET /admin/campaigns", () => {
|
medusaIntegrationTestRunner({
|
||||||
let dbConnection
|
env,
|
||||||
let appContainer
|
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||||
let shutdownServer
|
describe("GET /admin/campaigns", () => {
|
||||||
let promotionModuleService: IPromotionModuleService
|
let appContainer
|
||||||
|
let promotionModuleService: IPromotionModuleService
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
|
appContainer = getContainer()
|
||||||
dbConnection = await initDb({ cwd, env } as any)
|
promotionModuleService = appContainer.resolve(
|
||||||
shutdownServer = await startBootstrapApp({ cwd, env })
|
ModuleRegistrationName.PROMOTION
|
||||||
appContainer = getContainer()
|
)
|
||||||
promotionModuleService = appContainer.resolve(
|
})
|
||||||
ModuleRegistrationName.PROMOTION
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
afterAll(async () => {
|
beforeEach(async () => {
|
||||||
const db = useDb()
|
await createAdminUser(dbConnection, adminHeaders, appContainer)
|
||||||
await db.shutdown()
|
await promotionModuleService.createCampaigns(campaignsData)
|
||||||
await shutdownServer()
|
})
|
||||||
})
|
|
||||||
|
|
||||||
beforeEach(async () => {
|
it("should get all campaigns and its count", async () => {
|
||||||
await createAdminUser(dbConnection, adminHeaders)
|
const response = await api.get(`/admin/campaigns`, adminHeaders)
|
||||||
await promotionModuleService.createCampaigns(campaignsData)
|
|
||||||
})
|
|
||||||
|
|
||||||
afterEach(async () => {
|
expect(response.status).toEqual(200)
|
||||||
const db = useDb()
|
expect(response.data.count).toEqual(2)
|
||||||
await db.teardown()
|
expect(response.data.campaigns).toEqual(
|
||||||
})
|
expect.arrayContaining([
|
||||||
|
expect.objectContaining({
|
||||||
|
id: expect.any(String),
|
||||||
|
name: "campaign 1",
|
||||||
|
description: "test description",
|
||||||
|
currency: "USD",
|
||||||
|
campaign_identifier: "test-1",
|
||||||
|
starts_at: expect.any(String),
|
||||||
|
ends_at: expect.any(String),
|
||||||
|
budget: {
|
||||||
|
id: expect.any(String),
|
||||||
|
campaign: expect.any(Object),
|
||||||
|
type: "spend",
|
||||||
|
limit: 1000,
|
||||||
|
used: 0,
|
||||||
|
raw_limit: {
|
||||||
|
precision: 20,
|
||||||
|
value: "1000",
|
||||||
|
},
|
||||||
|
raw_used: {
|
||||||
|
precision: 20,
|
||||||
|
value: "0",
|
||||||
|
},
|
||||||
|
created_at: expect.any(String),
|
||||||
|
updated_at: expect.any(String),
|
||||||
|
deleted_at: null,
|
||||||
|
},
|
||||||
|
created_at: expect.any(String),
|
||||||
|
updated_at: expect.any(String),
|
||||||
|
deleted_at: null,
|
||||||
|
}),
|
||||||
|
expect.objectContaining({
|
||||||
|
id: expect.any(String),
|
||||||
|
name: "campaign 2",
|
||||||
|
description: "test description",
|
||||||
|
currency: "USD",
|
||||||
|
campaign_identifier: "test-2",
|
||||||
|
starts_at: expect.any(String),
|
||||||
|
ends_at: expect.any(String),
|
||||||
|
budget: {
|
||||||
|
id: expect.any(String),
|
||||||
|
campaign: expect.any(Object),
|
||||||
|
type: "usage",
|
||||||
|
limit: 1000,
|
||||||
|
used: 0,
|
||||||
|
raw_limit: {
|
||||||
|
precision: 20,
|
||||||
|
value: "1000",
|
||||||
|
},
|
||||||
|
raw_used: {
|
||||||
|
precision: 20,
|
||||||
|
value: "0",
|
||||||
|
},
|
||||||
|
created_at: expect.any(String),
|
||||||
|
updated_at: expect.any(String),
|
||||||
|
deleted_at: null,
|
||||||
|
},
|
||||||
|
created_at: expect.any(String),
|
||||||
|
updated_at: expect.any(String),
|
||||||
|
deleted_at: null,
|
||||||
|
}),
|
||||||
|
])
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
it("should get all campaigns and its count", async () => {
|
it("should get all campaigns and its count filtered", async () => {
|
||||||
const api = useApi() as any
|
const response = await api.get(
|
||||||
const response = await api.get(`/admin/campaigns`, adminHeaders)
|
`/admin/campaigns?fields=name,created_at,budget.id`,
|
||||||
|
adminHeaders
|
||||||
|
)
|
||||||
|
|
||||||
expect(response.status).toEqual(200)
|
expect(response.status).toEqual(200)
|
||||||
expect(response.data.count).toEqual(2)
|
expect(response.data.count).toEqual(2)
|
||||||
expect(response.data.campaigns).toEqual(
|
expect(response.data.campaigns).toEqual(
|
||||||
expect.arrayContaining([
|
expect.arrayContaining([
|
||||||
expect.objectContaining({
|
{
|
||||||
id: expect.any(String),
|
id: expect.any(String),
|
||||||
name: "campaign 1",
|
name: "campaign 1",
|
||||||
description: "test description",
|
created_at: expect.any(String),
|
||||||
currency: "USD",
|
budget: {
|
||||||
campaign_identifier: "test-1",
|
id: expect.any(String),
|
||||||
starts_at: expect.any(String),
|
campaign: expect.any(Object),
|
||||||
ends_at: expect.any(String),
|
},
|
||||||
budget: {
|
|
||||||
id: expect.any(String),
|
|
||||||
campaign: expect.any(Object),
|
|
||||||
type: "spend",
|
|
||||||
limit: 1000,
|
|
||||||
used: 0,
|
|
||||||
raw_limit: {
|
|
||||||
precision: 20,
|
|
||||||
value: "1000",
|
|
||||||
},
|
},
|
||||||
raw_used: {
|
{
|
||||||
precision: 20,
|
id: expect.any(String),
|
||||||
value: "0",
|
name: "campaign 2",
|
||||||
|
created_at: expect.any(String),
|
||||||
|
budget: {
|
||||||
|
id: expect.any(String),
|
||||||
|
campaign: expect.any(Object),
|
||||||
|
},
|
||||||
},
|
},
|
||||||
created_at: expect.any(String),
|
])
|
||||||
updated_at: expect.any(String),
|
)
|
||||||
deleted_at: null,
|
})
|
||||||
},
|
})
|
||||||
created_at: expect.any(String),
|
},
|
||||||
updated_at: expect.any(String),
|
|
||||||
deleted_at: null,
|
|
||||||
}),
|
|
||||||
expect.objectContaining({
|
|
||||||
id: expect.any(String),
|
|
||||||
name: "campaign 2",
|
|
||||||
description: "test description",
|
|
||||||
currency: "USD",
|
|
||||||
campaign_identifier: "test-2",
|
|
||||||
starts_at: expect.any(String),
|
|
||||||
ends_at: expect.any(String),
|
|
||||||
budget: {
|
|
||||||
id: expect.any(String),
|
|
||||||
campaign: expect.any(Object),
|
|
||||||
type: "usage",
|
|
||||||
limit: 1000,
|
|
||||||
used: 0,
|
|
||||||
raw_limit: {
|
|
||||||
precision: 20,
|
|
||||||
value: "1000",
|
|
||||||
},
|
|
||||||
raw_used: {
|
|
||||||
precision: 20,
|
|
||||||
value: "0",
|
|
||||||
},
|
|
||||||
created_at: expect.any(String),
|
|
||||||
updated_at: expect.any(String),
|
|
||||||
deleted_at: null,
|
|
||||||
},
|
|
||||||
created_at: expect.any(String),
|
|
||||||
updated_at: expect.any(String),
|
|
||||||
deleted_at: null,
|
|
||||||
}),
|
|
||||||
])
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
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
|
|
||||||
)
|
|
||||||
|
|
||||||
expect(response.status).toEqual(200)
|
|
||||||
expect(response.data.count).toEqual(2)
|
|
||||||
expect(response.data.campaigns).toEqual(
|
|
||||||
expect.arrayContaining([
|
|
||||||
{
|
|
||||||
id: expect.any(String),
|
|
||||||
name: "campaign 1",
|
|
||||||
created_at: expect.any(String),
|
|
||||||
budget: {
|
|
||||||
id: expect.any(String),
|
|
||||||
campaign: expect.any(Object),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: expect.any(String),
|
|
||||||
name: "campaign 2",
|
|
||||||
created_at: expect.any(String),
|
|
||||||
budget: {
|
|
||||||
id: expect.any(String),
|
|
||||||
campaign: expect.any(Object),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
])
|
|
||||||
)
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
@@ -1,13 +1,8 @@
|
|||||||
import { initDb, useDb } from "../../../../environment-helpers/use-db"
|
|
||||||
|
|
||||||
import { IPromotionModuleService } from "@medusajs/types"
|
import { IPromotionModuleService } from "@medusajs/types"
|
||||||
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||||
import { PromotionType } from "@medusajs/utils"
|
import { PromotionType } from "@medusajs/utils"
|
||||||
import { createAdminUser } from "../../../helpers/create-admin-user"
|
import { createAdminUser } from "../../../helpers/create-admin-user"
|
||||||
import { getContainer } from "../../../../environment-helpers/use-container"
|
import { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||||
import path from "path"
|
|
||||||
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
|
|
||||||
import { useApi } from "../../../../environment-helpers/use-api"
|
|
||||||
|
|
||||||
jest.setTimeout(50000)
|
jest.setTimeout(50000)
|
||||||
|
|
||||||
@@ -16,110 +11,97 @@ const adminHeaders = {
|
|||||||
headers: { "x-medusa-access-token": "test_token" },
|
headers: { "x-medusa-access-token": "test_token" },
|
||||||
}
|
}
|
||||||
|
|
||||||
describe("GET /admin/promotions", () => {
|
medusaIntegrationTestRunner({
|
||||||
let dbConnection
|
env,
|
||||||
let appContainer
|
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||||
let shutdownServer
|
describe("GET /admin/promotions", () => {
|
||||||
let promotionModuleService: IPromotionModuleService
|
let appContainer
|
||||||
|
let promotionModuleService: IPromotionModuleService
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
|
appContainer = getContainer()
|
||||||
dbConnection = await initDb({ cwd, env } as any)
|
promotionModuleService = appContainer.resolve(
|
||||||
shutdownServer = await startBootstrapApp({ cwd, env })
|
ModuleRegistrationName.PROMOTION
|
||||||
appContainer = getContainer()
|
)
|
||||||
promotionModuleService = appContainer.resolve(
|
})
|
||||||
ModuleRegistrationName.PROMOTION
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
afterAll(async () => {
|
beforeEach(async () => {
|
||||||
const db = useDb()
|
await createAdminUser(dbConnection, adminHeaders, appContainer)
|
||||||
await db.shutdown()
|
})
|
||||||
await shutdownServer()
|
|
||||||
})
|
|
||||||
|
|
||||||
beforeEach(async () => {
|
it("should get all promotions and its count", async () => {
|
||||||
await createAdminUser(dbConnection, adminHeaders)
|
await promotionModuleService.create([
|
||||||
})
|
{
|
||||||
|
code: "TEST",
|
||||||
|
type: PromotionType.STANDARD,
|
||||||
|
application_method: {
|
||||||
|
type: "fixed",
|
||||||
|
target_type: "order",
|
||||||
|
value: "100",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
])
|
||||||
|
|
||||||
afterEach(async () => {
|
const response = await api.get(`/admin/promotions`, adminHeaders)
|
||||||
const db = useDb()
|
|
||||||
await db.teardown()
|
|
||||||
})
|
|
||||||
|
|
||||||
it("should get all promotions and its count", async () => {
|
expect(response.status).toEqual(200)
|
||||||
await promotionModuleService.create([
|
expect(response.data.count).toEqual(1)
|
||||||
{
|
expect(response.data.promotions).toEqual([
|
||||||
code: "TEST",
|
expect.objectContaining({
|
||||||
type: PromotionType.STANDARD,
|
id: expect.any(String),
|
||||||
application_method: {
|
code: "TEST",
|
||||||
type: "fixed",
|
campaign: null,
|
||||||
target_type: "order",
|
is_automatic: false,
|
||||||
value: "100",
|
type: "standard",
|
||||||
},
|
created_at: expect.any(String),
|
||||||
},
|
updated_at: expect.any(String),
|
||||||
])
|
deleted_at: null,
|
||||||
|
application_method: expect.objectContaining({
|
||||||
|
id: expect.any(String),
|
||||||
|
value: 100,
|
||||||
|
type: "fixed",
|
||||||
|
target_type: "order",
|
||||||
|
allocation: null,
|
||||||
|
created_at: expect.any(String),
|
||||||
|
updated_at: expect.any(String),
|
||||||
|
deleted_at: null,
|
||||||
|
}),
|
||||||
|
}),
|
||||||
|
])
|
||||||
|
})
|
||||||
|
|
||||||
const api = useApi() as any
|
it("should get all promotions and its count filtered", async () => {
|
||||||
const response = await api.get(`/admin/promotions`, adminHeaders)
|
const [createdPromotion] = await promotionModuleService.create([
|
||||||
|
{
|
||||||
|
code: "TEST",
|
||||||
|
type: PromotionType.STANDARD,
|
||||||
|
application_method: {
|
||||||
|
type: "fixed",
|
||||||
|
target_type: "order",
|
||||||
|
value: "100",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
])
|
||||||
|
|
||||||
expect(response.status).toEqual(200)
|
const response = await api.get(
|
||||||
expect(response.data.count).toEqual(1)
|
`/admin/promotions?fields=code,created_at,application_method.id`,
|
||||||
expect(response.data.promotions).toEqual([
|
adminHeaders
|
||||||
expect.objectContaining({
|
)
|
||||||
id: expect.any(String),
|
|
||||||
code: "TEST",
|
|
||||||
campaign: null,
|
|
||||||
is_automatic: false,
|
|
||||||
type: "standard",
|
|
||||||
created_at: expect.any(String),
|
|
||||||
updated_at: expect.any(String),
|
|
||||||
deleted_at: null,
|
|
||||||
application_method: expect.objectContaining({
|
|
||||||
id: expect.any(String),
|
|
||||||
value: 100,
|
|
||||||
type: "fixed",
|
|
||||||
target_type: "order",
|
|
||||||
allocation: null,
|
|
||||||
created_at: expect.any(String),
|
|
||||||
updated_at: expect.any(String),
|
|
||||||
deleted_at: null,
|
|
||||||
}),
|
|
||||||
}),
|
|
||||||
])
|
|
||||||
})
|
|
||||||
|
|
||||||
it("should get all promotions and its count filtered", async () => {
|
expect(response.status).toEqual(200)
|
||||||
const [createdPromotion] = await promotionModuleService.create([
|
expect(response.data.count).toEqual(1)
|
||||||
{
|
expect(response.data.promotions).toEqual([
|
||||||
code: "TEST",
|
{
|
||||||
type: PromotionType.STANDARD,
|
id: expect.any(String),
|
||||||
application_method: {
|
code: "TEST",
|
||||||
type: "fixed",
|
created_at: expect.any(String),
|
||||||
target_type: "order",
|
application_method: {
|
||||||
value: "100",
|
id: expect.any(String),
|
||||||
},
|
promotion: expect.any(Object),
|
||||||
},
|
},
|
||||||
])
|
},
|
||||||
|
])
|
||||||
const api = useApi() as any
|
})
|
||||||
const response = await api.get(
|
})
|
||||||
`/admin/promotions?fields=code,created_at,application_method.id`,
|
},
|
||||||
adminHeaders
|
|
||||||
)
|
|
||||||
|
|
||||||
expect(response.status).toEqual(200)
|
|
||||||
expect(response.data.count).toEqual(1)
|
|
||||||
expect(response.data.promotions).toEqual([
|
|
||||||
{
|
|
||||||
id: expect.any(String),
|
|
||||||
code: "TEST",
|
|
||||||
created_at: expect.any(String),
|
|
||||||
application_method: {
|
|
||||||
id: expect.any(String),
|
|
||||||
promotion: expect.any(Object),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
])
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
@@ -1,13 +1,8 @@
|
|||||||
import { initDb, useDb } from "../../../../environment-helpers/use-db"
|
|
||||||
|
|
||||||
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||||
import { IPromotionModuleService } from "@medusajs/types"
|
import { IPromotionModuleService } from "@medusajs/types"
|
||||||
import { CampaignBudgetType } from "@medusajs/utils"
|
import { CampaignBudgetType } from "@medusajs/utils"
|
||||||
import path from "path"
|
|
||||||
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
|
|
||||||
import { useApi } from "../../../../environment-helpers/use-api"
|
|
||||||
import { getContainer } from "../../../../environment-helpers/use-container"
|
|
||||||
import { createAdminUser } from "../../../helpers/create-admin-user"
|
import { createAdminUser } from "../../../helpers/create-admin-user"
|
||||||
|
import { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||||
|
|
||||||
jest.setTimeout(50000)
|
jest.setTimeout(50000)
|
||||||
|
|
||||||
@@ -30,112 +25,94 @@ const adminHeaders = {
|
|||||||
headers: { "x-medusa-access-token": "test_token" },
|
headers: { "x-medusa-access-token": "test_token" },
|
||||||
}
|
}
|
||||||
|
|
||||||
describe("GET /admin/campaigns", () => {
|
medusaIntegrationTestRunner({
|
||||||
let dbConnection
|
env,
|
||||||
let appContainer
|
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||||
let shutdownServer
|
describe("GET /admin/campaigns", () => {
|
||||||
let promotionModuleService: IPromotionModuleService
|
let appContainer
|
||||||
|
let promotionModuleService: IPromotionModuleService
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
|
appContainer = getContainer()
|
||||||
dbConnection = await initDb({ cwd, env } as any)
|
promotionModuleService = appContainer.resolve(
|
||||||
shutdownServer = await startBootstrapApp({ cwd, env })
|
ModuleRegistrationName.PROMOTION
|
||||||
appContainer = getContainer()
|
)
|
||||||
promotionModuleService = appContainer.resolve(
|
})
|
||||||
ModuleRegistrationName.PROMOTION
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
afterAll(async () => {
|
beforeEach(async () => {
|
||||||
const db = useDb()
|
await createAdminUser(dbConnection, adminHeaders, appContainer)
|
||||||
await db.shutdown()
|
})
|
||||||
await shutdownServer()
|
|
||||||
})
|
|
||||||
|
|
||||||
beforeEach(async () => {
|
it("should throw an error if id does not exist", async () => {
|
||||||
await createAdminUser(dbConnection, adminHeaders)
|
const { response } = await api
|
||||||
})
|
.get(`/admin/campaigns/does-not-exist`, adminHeaders)
|
||||||
|
.catch((e) => e)
|
||||||
|
|
||||||
afterEach(async () => {
|
expect(response.status).toEqual(404)
|
||||||
const db = useDb()
|
expect(response.data.message).toEqual(
|
||||||
await db.teardown()
|
"Campaign with id: does-not-exist was not found"
|
||||||
})
|
)
|
||||||
|
})
|
||||||
|
|
||||||
let campaigns
|
it("should get the requested campaign", async () => {
|
||||||
|
const createdCampaign = await promotionModuleService.createCampaigns(
|
||||||
|
campaignData
|
||||||
|
)
|
||||||
|
|
||||||
beforeEach(async () => {})
|
const response = await api.get(
|
||||||
|
`/admin/campaigns/${createdCampaign.id}`,
|
||||||
|
adminHeaders
|
||||||
|
)
|
||||||
|
|
||||||
it("should throw an error if id does not exist", async () => {
|
expect(response.status).toEqual(200)
|
||||||
const api = useApi() as any
|
expect(response.data.campaign).toEqual({
|
||||||
const { response } = await api
|
id: expect.any(String),
|
||||||
.get(`/admin/campaigns/does-not-exist`, adminHeaders)
|
name: "campaign 1",
|
||||||
.catch((e) => e)
|
description: "test description",
|
||||||
|
currency: "USD",
|
||||||
|
campaign_identifier: "test-1",
|
||||||
|
starts_at: expect.any(String),
|
||||||
|
ends_at: expect.any(String),
|
||||||
|
budget: {
|
||||||
|
id: expect.any(String),
|
||||||
|
campaign: expect.any(Object),
|
||||||
|
type: "spend",
|
||||||
|
limit: 1000,
|
||||||
|
raw_limit: {
|
||||||
|
precision: 20,
|
||||||
|
value: "1000",
|
||||||
|
},
|
||||||
|
raw_used: {
|
||||||
|
precision: 20,
|
||||||
|
value: "0",
|
||||||
|
},
|
||||||
|
used: 0,
|
||||||
|
created_at: expect.any(String),
|
||||||
|
updated_at: expect.any(String),
|
||||||
|
deleted_at: null,
|
||||||
|
},
|
||||||
|
created_at: expect.any(String),
|
||||||
|
updated_at: expect.any(String),
|
||||||
|
deleted_at: null,
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
expect(response.status).toEqual(404)
|
it("should get the requested campaign with filtered fields and relations", async () => {
|
||||||
expect(response.data.message).toEqual(
|
const createdCampaign = await promotionModuleService.createCampaigns(
|
||||||
"Campaign with id: does-not-exist was not found"
|
campaignData
|
||||||
)
|
)
|
||||||
})
|
|
||||||
|
|
||||||
it("should get the requested campaign", async () => {
|
const response = await api.get(
|
||||||
const createdCampaign = await promotionModuleService.createCampaigns(
|
`/admin/campaigns/${createdCampaign.id}?fields=name&expand=`,
|
||||||
campaignData
|
adminHeaders
|
||||||
)
|
)
|
||||||
|
|
||||||
const api = useApi() as any
|
expect(response.status).toEqual(200)
|
||||||
const response = await api.get(
|
expect(response.data.campaign).toEqual({
|
||||||
`/admin/campaigns/${createdCampaign.id}`,
|
id: expect.any(String),
|
||||||
adminHeaders
|
name: "campaign 1",
|
||||||
)
|
})
|
||||||
|
})
|
||||||
expect(response.status).toEqual(200)
|
|
||||||
expect(response.data.campaign).toEqual({
|
|
||||||
id: expect.any(String),
|
|
||||||
name: "campaign 1",
|
|
||||||
description: "test description",
|
|
||||||
currency: "USD",
|
|
||||||
campaign_identifier: "test-1",
|
|
||||||
starts_at: expect.any(String),
|
|
||||||
ends_at: expect.any(String),
|
|
||||||
budget: {
|
|
||||||
id: expect.any(String),
|
|
||||||
campaign: expect.any(Object),
|
|
||||||
type: "spend",
|
|
||||||
limit: 1000,
|
|
||||||
raw_limit: {
|
|
||||||
precision: 20,
|
|
||||||
value: "1000",
|
|
||||||
},
|
|
||||||
raw_used: {
|
|
||||||
precision: 20,
|
|
||||||
value: "0",
|
|
||||||
},
|
|
||||||
used: 0,
|
|
||||||
created_at: expect.any(String),
|
|
||||||
updated_at: expect.any(String),
|
|
||||||
deleted_at: null,
|
|
||||||
},
|
|
||||||
created_at: expect.any(String),
|
|
||||||
updated_at: expect.any(String),
|
|
||||||
deleted_at: null,
|
|
||||||
})
|
})
|
||||||
})
|
},
|
||||||
|
|
||||||
it("should get the requested campaign with filtered fields and relations", async () => {
|
|
||||||
const createdCampaign = await promotionModuleService.createCampaigns(
|
|
||||||
campaignData
|
|
||||||
)
|
|
||||||
|
|
||||||
const api = useApi() as any
|
|
||||||
const response = await api.get(
|
|
||||||
`/admin/campaigns/${createdCampaign.id}?fields=name&expand=`,
|
|
||||||
adminHeaders
|
|
||||||
)
|
|
||||||
|
|
||||||
expect(response.status).toEqual(200)
|
|
||||||
expect(response.data.campaign).toEqual({
|
|
||||||
id: expect.any(String),
|
|
||||||
name: "campaign 1",
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
@@ -1,13 +1,8 @@
|
|||||||
import { initDb, useDb } from "../../../../environment-helpers/use-db"
|
|
||||||
|
|
||||||
import { IPromotionModuleService } from "@medusajs/types"
|
import { IPromotionModuleService } from "@medusajs/types"
|
||||||
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||||
import { PromotionType } from "@medusajs/utils"
|
import { PromotionType } from "@medusajs/utils"
|
||||||
import { createAdminUser } from "../../../helpers/create-admin-user"
|
import { createAdminUser } from "../../../helpers/create-admin-user"
|
||||||
import { getContainer } from "../../../../environment-helpers/use-container"
|
import { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||||
import path from "path"
|
|
||||||
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
|
|
||||||
import { useApi } from "../../../../environment-helpers/use-api"
|
|
||||||
|
|
||||||
jest.setTimeout(50000)
|
jest.setTimeout(50000)
|
||||||
|
|
||||||
@@ -16,114 +11,100 @@ const adminHeaders = {
|
|||||||
headers: { "x-medusa-access-token": "test_token" },
|
headers: { "x-medusa-access-token": "test_token" },
|
||||||
}
|
}
|
||||||
|
|
||||||
describe("GET /admin/promotions", () => {
|
medusaIntegrationTestRunner({
|
||||||
let dbConnection
|
env,
|
||||||
let appContainer
|
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||||
let shutdownServer
|
describe("GET /admin/promotions", () => {
|
||||||
let promotionModuleService: IPromotionModuleService
|
let appContainer
|
||||||
|
let promotionModuleService: IPromotionModuleService
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
|
appContainer = getContainer()
|
||||||
dbConnection = await initDb({ cwd, env } as any)
|
promotionModuleService = appContainer.resolve(
|
||||||
shutdownServer = await startBootstrapApp({ cwd, env })
|
ModuleRegistrationName.PROMOTION
|
||||||
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()
|
|
||||||
})
|
|
||||||
|
|
||||||
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)
|
|
||||||
|
|
||||||
expect(response.status).toEqual(404)
|
|
||||||
expect(response.data.message).toEqual(
|
|
||||||
"Promotion with id: does-not-exist was not found"
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
it("should get the requested promotion", async () => {
|
|
||||||
const createdPromotion = await promotionModuleService.create({
|
|
||||||
code: "TEST",
|
|
||||||
type: PromotionType.STANDARD,
|
|
||||||
application_method: {
|
|
||||||
type: "fixed",
|
|
||||||
target_type: "order",
|
|
||||||
value: "100",
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
const api = useApi() as any
|
|
||||||
const response = await api.get(
|
|
||||||
`/admin/promotions/${createdPromotion.id}`,
|
|
||||||
adminHeaders
|
|
||||||
)
|
|
||||||
|
|
||||||
expect(response.status).toEqual(200)
|
|
||||||
expect(response.data.promotion).toEqual(
|
|
||||||
expect.objectContaining({
|
|
||||||
id: expect.any(String),
|
|
||||||
code: "TEST",
|
|
||||||
campaign: null,
|
|
||||||
is_automatic: false,
|
|
||||||
type: "standard",
|
|
||||||
created_at: expect.any(String),
|
|
||||||
updated_at: expect.any(String),
|
|
||||||
deleted_at: null,
|
|
||||||
application_method: expect.objectContaining({
|
|
||||||
id: expect.any(String),
|
|
||||||
promotion: expect.any(Object),
|
|
||||||
value: 100,
|
|
||||||
type: "fixed",
|
|
||||||
target_type: "order",
|
|
||||||
max_quantity: 0,
|
|
||||||
allocation: null,
|
|
||||||
created_at: expect.any(String),
|
|
||||||
updated_at: expect.any(String),
|
|
||||||
deleted_at: null,
|
|
||||||
}),
|
|
||||||
})
|
})
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
it("should get the requested promotion with filtered fields and relations", async () => {
|
beforeEach(async () => {
|
||||||
const createdPromotion = await promotionModuleService.create({
|
await createAdminUser(dbConnection, adminHeaders, appContainer)
|
||||||
code: "TEST",
|
})
|
||||||
type: PromotionType.STANDARD,
|
|
||||||
application_method: {
|
it("should throw an error if id does not exist", async () => {
|
||||||
type: "fixed",
|
const { response } = await api
|
||||||
target_type: "order",
|
.get(`/admin/promotions/does-not-exist`, adminHeaders)
|
||||||
value: "100",
|
.catch((e) => e)
|
||||||
},
|
|
||||||
|
expect(response.status).toEqual(404)
|
||||||
|
expect(response.data.message).toEqual(
|
||||||
|
"Promotion with id: does-not-exist was not found"
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should get the requested promotion", async () => {
|
||||||
|
const createdPromotion = await promotionModuleService.create({
|
||||||
|
code: "TEST",
|
||||||
|
type: PromotionType.STANDARD,
|
||||||
|
application_method: {
|
||||||
|
type: "fixed",
|
||||||
|
target_type: "order",
|
||||||
|
value: "100",
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
const response = await api.get(
|
||||||
|
`/admin/promotions/${createdPromotion.id}`,
|
||||||
|
adminHeaders
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(response.status).toEqual(200)
|
||||||
|
expect(response.data.promotion).toEqual(
|
||||||
|
expect.objectContaining({
|
||||||
|
id: expect.any(String),
|
||||||
|
code: "TEST",
|
||||||
|
campaign: null,
|
||||||
|
is_automatic: false,
|
||||||
|
type: "standard",
|
||||||
|
created_at: expect.any(String),
|
||||||
|
updated_at: expect.any(String),
|
||||||
|
deleted_at: null,
|
||||||
|
application_method: expect.objectContaining({
|
||||||
|
id: expect.any(String),
|
||||||
|
promotion: expect.any(Object),
|
||||||
|
value: 100,
|
||||||
|
type: "fixed",
|
||||||
|
target_type: "order",
|
||||||
|
max_quantity: 0,
|
||||||
|
allocation: null,
|
||||||
|
created_at: expect.any(String),
|
||||||
|
updated_at: expect.any(String),
|
||||||
|
deleted_at: null,
|
||||||
|
}),
|
||||||
|
})
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should get the requested promotion with filtered fields and relations", async () => {
|
||||||
|
const createdPromotion = await promotionModuleService.create({
|
||||||
|
code: "TEST",
|
||||||
|
type: PromotionType.STANDARD,
|
||||||
|
application_method: {
|
||||||
|
type: "fixed",
|
||||||
|
target_type: "order",
|
||||||
|
value: "100",
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
const response = await api.get(
|
||||||
|
`/admin/promotions/${createdPromotion.id}?fields=id,code&expand=`,
|
||||||
|
adminHeaders
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(response.status).toEqual(200)
|
||||||
|
expect(response.data.promotion).toEqual({
|
||||||
|
id: expect.any(String),
|
||||||
|
code: "TEST",
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
},
|
||||||
const api = useApi() as any
|
|
||||||
const response = await api.get(
|
|
||||||
`/admin/promotions/${createdPromotion.id}?fields=id,code&expand=`,
|
|
||||||
adminHeaders
|
|
||||||
)
|
|
||||||
|
|
||||||
expect(response.status).toEqual(200)
|
|
||||||
expect(response.data.promotion).toEqual({
|
|
||||||
id: expect.any(String),
|
|
||||||
code: "TEST",
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
@@ -1,12 +1,7 @@
|
|||||||
import { initDb, useDb } from "../../../../environment-helpers/use-db"
|
|
||||||
|
|
||||||
import { IPromotionModuleService } from "@medusajs/types"
|
import { IPromotionModuleService } from "@medusajs/types"
|
||||||
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||||
import { createAdminUser } from "../../../helpers/create-admin-user"
|
import { createAdminUser } from "../../../helpers/create-admin-user"
|
||||||
import { getContainer } from "../../../../environment-helpers/use-container"
|
import { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||||
import path from "path"
|
|
||||||
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
|
|
||||||
import { useApi } from "../../../../environment-helpers/use-api"
|
|
||||||
|
|
||||||
jest.setTimeout(50000)
|
jest.setTimeout(50000)
|
||||||
|
|
||||||
@@ -15,104 +10,91 @@ const adminHeaders = {
|
|||||||
headers: { "x-medusa-access-token": "test_token" },
|
headers: { "x-medusa-access-token": "test_token" },
|
||||||
}
|
}
|
||||||
|
|
||||||
describe("POST /admin/campaigns/:id", () => {
|
medusaIntegrationTestRunner({
|
||||||
let dbConnection
|
env,
|
||||||
let appContainer
|
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||||
let shutdownServer
|
describe("POST /admin/campaigns/:id", () => {
|
||||||
let promotionModuleService: IPromotionModuleService
|
let appContainer
|
||||||
|
let promotionModuleService: IPromotionModuleService
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
|
appContainer = getContainer()
|
||||||
dbConnection = await initDb({ cwd, env } as any)
|
promotionModuleService = appContainer.resolve(
|
||||||
shutdownServer = await startBootstrapApp({ cwd, env })
|
ModuleRegistrationName.PROMOTION
|
||||||
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()
|
|
||||||
})
|
|
||||||
|
|
||||||
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)
|
|
||||||
|
|
||||||
expect(response.status).toEqual(404)
|
|
||||||
expect(response.data.message).toEqual(
|
|
||||||
`Campaign with id "does-not-exist" not found`
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
it("should update a campaign successfully", async () => {
|
|
||||||
const createdPromotion = await promotionModuleService.create({
|
|
||||||
code: "TEST",
|
|
||||||
type: "standard",
|
|
||||||
})
|
|
||||||
|
|
||||||
const createdPromotion2 = await promotionModuleService.create({
|
|
||||||
code: "TEST_2",
|
|
||||||
type: "standard",
|
|
||||||
})
|
|
||||||
|
|
||||||
const createdCampaign = await promotionModuleService.createCampaigns({
|
|
||||||
name: "test",
|
|
||||||
campaign_identifier: "test",
|
|
||||||
starts_at: new Date("01/01/2024").toISOString(),
|
|
||||||
ends_at: new Date("01/01/2029").toISOString(),
|
|
||||||
promotions: [{ id: createdPromotion.id }],
|
|
||||||
budget: {
|
|
||||||
limit: 1000,
|
|
||||||
type: "usage",
|
|
||||||
used: 10,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
const api = useApi() as any
|
|
||||||
const response = await api.post(
|
|
||||||
`/admin/campaigns/${createdCampaign.id}`,
|
|
||||||
{
|
|
||||||
name: "test-2",
|
|
||||||
campaign_identifier: "test-2",
|
|
||||||
budget: {
|
|
||||||
limit: 2000,
|
|
||||||
},
|
|
||||||
promotions: [{ id: createdPromotion2.id }],
|
|
||||||
},
|
|
||||||
adminHeaders
|
|
||||||
)
|
|
||||||
|
|
||||||
expect(response.status).toEqual(200)
|
|
||||||
expect(response.data.campaign).toEqual(
|
|
||||||
expect.objectContaining({
|
|
||||||
id: expect.any(String),
|
|
||||||
name: "test-2",
|
|
||||||
campaign_identifier: "test-2",
|
|
||||||
budget: expect.objectContaining({
|
|
||||||
limit: 2000,
|
|
||||||
type: "usage",
|
|
||||||
used: 10,
|
|
||||||
}),
|
|
||||||
promotions: [
|
|
||||||
expect.objectContaining({
|
|
||||||
id: createdPromotion2.id,
|
|
||||||
}),
|
|
||||||
],
|
|
||||||
})
|
})
|
||||||
)
|
|
||||||
})
|
beforeEach(async () => {
|
||||||
|
await createAdminUser(dbConnection, adminHeaders, appContainer)
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should throw an error if id does not exist", async () => {
|
||||||
|
const { response } = await api
|
||||||
|
.post(`/admin/campaigns/does-not-exist`, {}, adminHeaders)
|
||||||
|
.catch((e) => e)
|
||||||
|
|
||||||
|
expect(response.status).toEqual(404)
|
||||||
|
expect(response.data.message).toEqual(
|
||||||
|
`Campaign with id "does-not-exist" not found`
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should update a campaign successfully", async () => {
|
||||||
|
const createdPromotion = await promotionModuleService.create({
|
||||||
|
code: "TEST",
|
||||||
|
type: "standard",
|
||||||
|
})
|
||||||
|
|
||||||
|
const createdPromotion2 = await promotionModuleService.create({
|
||||||
|
code: "TEST_2",
|
||||||
|
type: "standard",
|
||||||
|
})
|
||||||
|
|
||||||
|
const createdCampaign = await promotionModuleService.createCampaigns({
|
||||||
|
name: "test",
|
||||||
|
campaign_identifier: "test",
|
||||||
|
starts_at: new Date("01/01/2024").toISOString(),
|
||||||
|
ends_at: new Date("01/01/2029").toISOString(),
|
||||||
|
promotions: [{ id: createdPromotion.id }],
|
||||||
|
budget: {
|
||||||
|
limit: 1000,
|
||||||
|
type: "usage",
|
||||||
|
used: 10,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
const response = await api.post(
|
||||||
|
`/admin/campaigns/${createdCampaign.id}`,
|
||||||
|
{
|
||||||
|
name: "test-2",
|
||||||
|
campaign_identifier: "test-2",
|
||||||
|
budget: {
|
||||||
|
limit: 2000,
|
||||||
|
},
|
||||||
|
promotions: [{ id: createdPromotion2.id }],
|
||||||
|
},
|
||||||
|
adminHeaders
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(response.status).toEqual(200)
|
||||||
|
expect(response.data.campaign).toEqual(
|
||||||
|
expect.objectContaining({
|
||||||
|
id: expect.any(String),
|
||||||
|
name: "test-2",
|
||||||
|
campaign_identifier: "test-2",
|
||||||
|
budget: expect.objectContaining({
|
||||||
|
limit: 2000,
|
||||||
|
type: "usage",
|
||||||
|
used: 10,
|
||||||
|
}),
|
||||||
|
promotions: [
|
||||||
|
expect.objectContaining({
|
||||||
|
id: createdPromotion2.id,
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
})
|
||||||
|
)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
},
|
||||||
})
|
})
|
||||||
@@ -1,13 +1,8 @@
|
|||||||
import { initDb, useDb } from "../../../../environment-helpers/use-db"
|
|
||||||
|
|
||||||
import { IPromotionModuleService } from "@medusajs/types"
|
import { IPromotionModuleService } from "@medusajs/types"
|
||||||
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||||
import { PromotionType } from "@medusajs/utils"
|
import { PromotionType } from "@medusajs/utils"
|
||||||
import { createAdminUser } from "../../../helpers/create-admin-user"
|
import { createAdminUser } from "../../../helpers/create-admin-user"
|
||||||
import { getContainer } from "../../../../environment-helpers/use-container"
|
import { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||||
import path from "path"
|
|
||||||
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
|
|
||||||
import { useApi } from "../../../../environment-helpers/use-api"
|
|
||||||
|
|
||||||
jest.setTimeout(50000)
|
jest.setTimeout(50000)
|
||||||
|
|
||||||
@@ -16,177 +11,161 @@ const adminHeaders = {
|
|||||||
headers: { "x-medusa-access-token": "test_token" },
|
headers: { "x-medusa-access-token": "test_token" },
|
||||||
}
|
}
|
||||||
|
|
||||||
describe("POST /admin/promotions/:id", () => {
|
medusaIntegrationTestRunner({
|
||||||
let dbConnection
|
env,
|
||||||
let appContainer
|
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||||
let shutdownServer
|
describe("POST /admin/promotions/:id", () => {
|
||||||
let promotionModuleService: IPromotionModuleService
|
let appContainer
|
||||||
|
let promotionModuleService: IPromotionModuleService
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
|
appContainer = getContainer()
|
||||||
dbConnection = await initDb({ cwd, env } as any)
|
promotionModuleService = appContainer.resolve(
|
||||||
shutdownServer = await startBootstrapApp({ cwd, env })
|
ModuleRegistrationName.PROMOTION
|
||||||
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()
|
|
||||||
})
|
|
||||||
|
|
||||||
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`,
|
|
||||||
{ type: PromotionType.STANDARD },
|
|
||||||
adminHeaders
|
|
||||||
)
|
|
||||||
.catch((e) => e)
|
|
||||||
|
|
||||||
expect(response.status).toEqual(404)
|
|
||||||
expect(response.data.message).toEqual(
|
|
||||||
`Promotion with id "does-not-exist" not found`
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
it("should throw an error when both campaign and campaign_id params are passed", async () => {
|
|
||||||
const createdPromotion = await promotionModuleService.create({
|
|
||||||
code: "TEST",
|
|
||||||
type: PromotionType.STANDARD,
|
|
||||||
is_automatic: true,
|
|
||||||
application_method: {
|
|
||||||
target_type: "items",
|
|
||||||
type: "fixed",
|
|
||||||
allocation: "each",
|
|
||||||
value: "100",
|
|
||||||
max_quantity: 100,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
const api = useApi() as any
|
|
||||||
|
|
||||||
const { response } = await api
|
|
||||||
.post(
|
|
||||||
`/admin/promotions/${createdPromotion.id}`,
|
|
||||||
{
|
|
||||||
campaign: {
|
|
||||||
name: "test campaign",
|
|
||||||
},
|
|
||||||
campaign_id: "test",
|
|
||||||
},
|
|
||||||
adminHeaders
|
|
||||||
)
|
|
||||||
.catch((e) => e)
|
|
||||||
|
|
||||||
expect(response.status).toEqual(400)
|
|
||||||
expect(response.data.message).toContain(
|
|
||||||
`Failed XOR relation between "campaign_id" and "campaign"`
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
it("should update a promotion successfully", async () => {
|
|
||||||
const createdPromotion = await promotionModuleService.create({
|
|
||||||
code: "TEST",
|
|
||||||
type: PromotionType.STANDARD,
|
|
||||||
is_automatic: true,
|
|
||||||
application_method: {
|
|
||||||
target_type: "items",
|
|
||||||
type: "fixed",
|
|
||||||
allocation: "each",
|
|
||||||
value: "100",
|
|
||||||
max_quantity: 100,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
const api = useApi() as any
|
|
||||||
const response = await api.post(
|
|
||||||
`/admin/promotions/${createdPromotion.id}`,
|
|
||||||
{
|
|
||||||
code: "TEST_TWO",
|
|
||||||
application_method: {
|
|
||||||
value: "200",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
adminHeaders
|
|
||||||
)
|
|
||||||
|
|
||||||
expect(response.status).toEqual(200)
|
|
||||||
expect(response.data.promotion).toEqual(
|
|
||||||
expect.objectContaining({
|
|
||||||
id: expect.any(String),
|
|
||||||
code: "TEST_TWO",
|
|
||||||
application_method: expect.objectContaining({
|
|
||||||
value: 200,
|
|
||||||
}),
|
|
||||||
})
|
})
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
it("should update a buyget promotion successfully", async () => {
|
beforeEach(async () => {
|
||||||
const createdPromotion = await promotionModuleService.create({
|
await createAdminUser(dbConnection, adminHeaders, appContainer)
|
||||||
code: "PROMOTION_TEST",
|
|
||||||
type: PromotionType.BUYGET,
|
|
||||||
application_method: {
|
|
||||||
type: "fixed",
|
|
||||||
target_type: "items",
|
|
||||||
allocation: "across",
|
|
||||||
value: "100",
|
|
||||||
apply_to_quantity: 1,
|
|
||||||
buy_rules_min_quantity: 1,
|
|
||||||
buy_rules: [
|
|
||||||
{
|
|
||||||
attribute: "product_collection.id",
|
|
||||||
operator: "eq",
|
|
||||||
values: ["pcol_towel"],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
target_rules: [
|
|
||||||
{
|
|
||||||
attribute: "product.id",
|
|
||||||
operator: "eq",
|
|
||||||
values: "prod_mat",
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
const api = useApi() as any
|
|
||||||
const response = await api.post(
|
|
||||||
`/admin/promotions/${createdPromotion.id}`,
|
|
||||||
{
|
|
||||||
code: "TEST_TWO",
|
|
||||||
application_method: {
|
|
||||||
value: "200",
|
|
||||||
buy_rules_min_quantity: 6,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
adminHeaders
|
|
||||||
)
|
|
||||||
|
|
||||||
expect(response.status).toEqual(200)
|
|
||||||
expect(response.data.promotion).toEqual(
|
|
||||||
expect.objectContaining({
|
|
||||||
id: expect.any(String),
|
|
||||||
code: "TEST_TWO",
|
|
||||||
application_method: expect.objectContaining({
|
|
||||||
value: 200,
|
|
||||||
buy_rules_min_quantity: 6,
|
|
||||||
}),
|
|
||||||
})
|
})
|
||||||
)
|
|
||||||
})
|
it("should throw an error if id does not exist", async () => {
|
||||||
|
const { response } = await api
|
||||||
|
.post(
|
||||||
|
`/admin/promotions/does-not-exist`,
|
||||||
|
{ type: PromotionType.STANDARD },
|
||||||
|
adminHeaders
|
||||||
|
)
|
||||||
|
.catch((e) => e)
|
||||||
|
|
||||||
|
expect(response.status).toEqual(404)
|
||||||
|
expect(response.data.message).toEqual(
|
||||||
|
`Promotion with id "does-not-exist" not found`
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should throw an error when both campaign and campaign_id params are passed", async () => {
|
||||||
|
const createdPromotion = await promotionModuleService.create({
|
||||||
|
code: "TEST",
|
||||||
|
type: PromotionType.STANDARD,
|
||||||
|
is_automatic: true,
|
||||||
|
application_method: {
|
||||||
|
target_type: "items",
|
||||||
|
type: "fixed",
|
||||||
|
allocation: "each",
|
||||||
|
value: "100",
|
||||||
|
max_quantity: 100,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
const { response } = await api
|
||||||
|
.post(
|
||||||
|
`/admin/promotions/${createdPromotion.id}`,
|
||||||
|
{
|
||||||
|
campaign: {
|
||||||
|
name: "test campaign",
|
||||||
|
},
|
||||||
|
campaign_id: "test",
|
||||||
|
},
|
||||||
|
adminHeaders
|
||||||
|
)
|
||||||
|
.catch((e) => e)
|
||||||
|
|
||||||
|
expect(response.status).toEqual(400)
|
||||||
|
expect(response.data.message).toContain(
|
||||||
|
`Failed XOR relation between "campaign_id" and "campaign"`
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should update a promotion successfully", async () => {
|
||||||
|
const createdPromotion = await promotionModuleService.create({
|
||||||
|
code: "TEST",
|
||||||
|
type: PromotionType.STANDARD,
|
||||||
|
is_automatic: true,
|
||||||
|
application_method: {
|
||||||
|
target_type: "items",
|
||||||
|
type: "fixed",
|
||||||
|
allocation: "each",
|
||||||
|
value: "100",
|
||||||
|
max_quantity: 100,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
const response = await api.post(
|
||||||
|
`/admin/promotions/${createdPromotion.id}`,
|
||||||
|
{
|
||||||
|
code: "TEST_TWO",
|
||||||
|
application_method: {
|
||||||
|
value: "200",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
adminHeaders
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(response.status).toEqual(200)
|
||||||
|
expect(response.data.promotion).toEqual(
|
||||||
|
expect.objectContaining({
|
||||||
|
id: expect.any(String),
|
||||||
|
code: "TEST_TWO",
|
||||||
|
application_method: expect.objectContaining({
|
||||||
|
value: 200,
|
||||||
|
}),
|
||||||
|
})
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should update a buyget promotion successfully", async () => {
|
||||||
|
const createdPromotion = await promotionModuleService.create({
|
||||||
|
code: "PROMOTION_TEST",
|
||||||
|
type: PromotionType.BUYGET,
|
||||||
|
application_method: {
|
||||||
|
type: "fixed",
|
||||||
|
target_type: "items",
|
||||||
|
allocation: "across",
|
||||||
|
value: "100",
|
||||||
|
apply_to_quantity: 1,
|
||||||
|
buy_rules_min_quantity: 1,
|
||||||
|
buy_rules: [
|
||||||
|
{
|
||||||
|
attribute: "product_collection.id",
|
||||||
|
operator: "eq",
|
||||||
|
values: ["pcol_towel"],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
target_rules: [
|
||||||
|
{
|
||||||
|
attribute: "product.id",
|
||||||
|
operator: "eq",
|
||||||
|
values: "prod_mat",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
const response = await api.post(
|
||||||
|
`/admin/promotions/${createdPromotion.id}`,
|
||||||
|
{
|
||||||
|
code: "TEST_TWO",
|
||||||
|
application_method: {
|
||||||
|
value: "200",
|
||||||
|
buy_rules_min_quantity: 6,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
adminHeaders
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(response.status).toEqual(200)
|
||||||
|
expect(response.data.promotion).toEqual(
|
||||||
|
expect.objectContaining({
|
||||||
|
id: expect.any(String),
|
||||||
|
code: "TEST_TWO",
|
||||||
|
application_method: expect.objectContaining({
|
||||||
|
value: 200,
|
||||||
|
buy_rules_min_quantity: 6,
|
||||||
|
}),
|
||||||
|
})
|
||||||
|
)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
},
|
||||||
})
|
})
|
||||||
@@ -1,11 +1,7 @@
|
|||||||
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||||
import { IRegionModuleService } from "@medusajs/types"
|
import { IRegionModuleService } from "@medusajs/types"
|
||||||
import path from "path"
|
|
||||||
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
|
|
||||||
import { useApi } from "../../../../environment-helpers/use-api"
|
|
||||||
import { getContainer } from "../../../../environment-helpers/use-container"
|
|
||||||
import { initDb, useDb } from "../../../../environment-helpers/use-db"
|
|
||||||
import { createAdminUser } from "../../../helpers/create-admin-user"
|
import { createAdminUser } from "../../../helpers/create-admin-user"
|
||||||
|
import { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||||
|
|
||||||
jest.setTimeout(50000)
|
jest.setTimeout(50000)
|
||||||
|
|
||||||
@@ -14,210 +10,206 @@ const adminHeaders = {
|
|||||||
headers: { "x-medusa-access-token": "test_token" },
|
headers: { "x-medusa-access-token": "test_token" },
|
||||||
}
|
}
|
||||||
|
|
||||||
describe("Regions - Admin", () => {
|
medusaIntegrationTestRunner({
|
||||||
let dbConnection
|
env,
|
||||||
let appContainer
|
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||||
let shutdownServer
|
describe("Regions - Admin", () => {
|
||||||
let service: IRegionModuleService
|
let appContainer
|
||||||
|
let service: IRegionModuleService
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
|
appContainer = getContainer()
|
||||||
dbConnection = await initDb({ cwd, env } as any)
|
service = appContainer.resolve(ModuleRegistrationName.REGION)
|
||||||
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)
|
|
||||||
})
|
|
||||||
|
|
||||||
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`,
|
|
||||||
{
|
|
||||||
name: "Test Region",
|
|
||||||
currency_code: "usd",
|
|
||||||
countries: ["us", "ca"],
|
|
||||||
metadata: { foo: "bar" },
|
|
||||||
},
|
|
||||||
adminHeaders
|
|
||||||
)
|
|
||||||
|
|
||||||
expect(created.status).toEqual(200)
|
|
||||||
expect(created.data.region).toEqual(
|
|
||||||
expect.objectContaining({
|
|
||||||
id: created.data.region.id,
|
|
||||||
name: "Test Region",
|
|
||||||
currency_code: "usd",
|
|
||||||
metadata: { foo: "bar" },
|
|
||||||
})
|
})
|
||||||
)
|
|
||||||
expect(created.data.region.countries.map((c) => c.iso_2)).toEqual([
|
|
||||||
"us",
|
|
||||||
"ca",
|
|
||||||
])
|
|
||||||
|
|
||||||
const updated = await api.post(
|
beforeEach(async () => {
|
||||||
`/admin/regions/${created.data.region.id}`,
|
await createAdminUser(dbConnection, adminHeaders, appContainer)
|
||||||
{
|
|
||||||
name: "United States",
|
|
||||||
currency_code: "usd",
|
|
||||||
countries: ["us"],
|
|
||||||
metadata: { foo: "baz" },
|
|
||||||
},
|
|
||||||
adminHeaders
|
|
||||||
)
|
|
||||||
|
|
||||||
expect(updated.status).toEqual(200)
|
|
||||||
expect(updated.data.region).toEqual(
|
|
||||||
expect.objectContaining({
|
|
||||||
id: updated.data.region.id,
|
|
||||||
name: "United States",
|
|
||||||
currency_code: "usd",
|
|
||||||
metadata: { foo: "baz" },
|
|
||||||
})
|
})
|
||||||
)
|
|
||||||
expect(updated.data.region.countries.map((c) => c.iso_2)).toEqual(["us"])
|
|
||||||
|
|
||||||
const deleted = await api.delete(
|
afterEach(async () => {
|
||||||
`/admin/regions/${updated.data.region.id}`,
|
// TODO: Once teardown doesn't skip constraint checks and cascades, we can remove this
|
||||||
adminHeaders
|
const existingRegions = await service.list({})
|
||||||
)
|
await service.delete(existingRegions.map((r) => r.id))
|
||||||
|
})
|
||||||
|
|
||||||
expect(deleted.status).toEqual(200)
|
it("should create, update, and delete a region", async () => {
|
||||||
expect(deleted.data).toEqual({
|
const created = await api.post(
|
||||||
id: updated.data.region.id,
|
`/admin/regions`,
|
||||||
object: "region",
|
{
|
||||||
deleted: true,
|
name: "Test Region",
|
||||||
})
|
currency_code: "usd",
|
||||||
|
countries: ["us", "ca"],
|
||||||
|
metadata: { foo: "bar" },
|
||||||
|
},
|
||||||
|
adminHeaders
|
||||||
|
)
|
||||||
|
|
||||||
const deletedRegion = await service.retrieve(updated.data.region.id, {
|
expect(created.status).toEqual(200)
|
||||||
withDeleted: true,
|
expect(created.data.region).toEqual(
|
||||||
})
|
expect.objectContaining({
|
||||||
|
id: created.data.region.id,
|
||||||
|
name: "Test Region",
|
||||||
|
currency_code: "usd",
|
||||||
|
metadata: { foo: "bar" },
|
||||||
|
})
|
||||||
|
)
|
||||||
|
expect(created.data.region.countries.map((c) => c.iso_2)).toEqual([
|
||||||
|
"us",
|
||||||
|
"ca",
|
||||||
|
])
|
||||||
|
|
||||||
// @ts-ignore
|
const updated = await api.post(
|
||||||
expect(deletedRegion.deleted_at).toBeTruthy()
|
`/admin/regions/${created.data.region.id}`,
|
||||||
})
|
{
|
||||||
|
name: "United States",
|
||||||
|
currency_code: "usd",
|
||||||
|
countries: ["us"],
|
||||||
|
metadata: { foo: "baz" },
|
||||||
|
},
|
||||||
|
adminHeaders
|
||||||
|
)
|
||||||
|
|
||||||
it("should throw on missing required properties in create", async () => {
|
expect(updated.status).toEqual(200)
|
||||||
const api = useApi() as any
|
expect(updated.data.region).toEqual(
|
||||||
const err = await api
|
expect.objectContaining({
|
||||||
.post(`/admin/regions`, {}, adminHeaders)
|
id: updated.data.region.id,
|
||||||
.catch((e) => e)
|
name: "United States",
|
||||||
|
currency_code: "usd",
|
||||||
|
metadata: { foo: "baz" },
|
||||||
|
})
|
||||||
|
)
|
||||||
|
expect(updated.data.region.countries.map((c) => c.iso_2)).toEqual([
|
||||||
|
"us",
|
||||||
|
])
|
||||||
|
|
||||||
expect(err.response.status).toEqual(400)
|
const deleted = await api.delete(
|
||||||
expect(err.response.data.message).toEqual(
|
`/admin/regions/${updated.data.region.id}`,
|
||||||
"name must be a string, currency_code must be a string"
|
adminHeaders
|
||||||
)
|
)
|
||||||
})
|
|
||||||
|
|
||||||
it("should throw on unknown properties in create", async () => {
|
expect(deleted.status).toEqual(200)
|
||||||
const api = useApi() as any
|
expect(deleted.data).toEqual({
|
||||||
const error = await api
|
id: updated.data.region.id,
|
||||||
.post(
|
object: "region",
|
||||||
`/admin/regions`,
|
deleted: true,
|
||||||
{
|
})
|
||||||
foo: "bar",
|
|
||||||
currency_code: "usd",
|
const deletedRegion = await service.retrieve(updated.data.region.id, {
|
||||||
|
withDeleted: true,
|
||||||
|
})
|
||||||
|
|
||||||
|
// @ts-ignore
|
||||||
|
expect(deletedRegion.deleted_at).toBeTruthy()
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should throw on missing required properties in create", async () => {
|
||||||
|
const err = await api
|
||||||
|
.post(`/admin/regions`, {}, adminHeaders)
|
||||||
|
.catch((e) => e)
|
||||||
|
|
||||||
|
expect(err.response.status).toEqual(400)
|
||||||
|
expect(err.response.data.message).toEqual(
|
||||||
|
"name must be a string, currency_code must be a string"
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should throw on unknown properties in create", async () => {
|
||||||
|
const error = await api
|
||||||
|
.post(
|
||||||
|
`/admin/regions`,
|
||||||
|
{
|
||||||
|
foo: "bar",
|
||||||
|
currency_code: "usd",
|
||||||
|
name: "Test Region",
|
||||||
|
},
|
||||||
|
adminHeaders
|
||||||
|
)
|
||||||
|
.catch((e) => e)
|
||||||
|
|
||||||
|
expect(error.response.status).toEqual(400)
|
||||||
|
expect(error.response.data.message).toEqual(
|
||||||
|
"property foo should not exist"
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should throw on unknown properties in update", async () => {
|
||||||
|
const created = await service.create({
|
||||||
name: "Test Region",
|
name: "Test Region",
|
||||||
},
|
|
||||||
adminHeaders
|
|
||||||
)
|
|
||||||
.catch((e) => e)
|
|
||||||
|
|
||||||
expect(error.response.status).toEqual(400)
|
|
||||||
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",
|
|
||||||
})
|
|
||||||
|
|
||||||
const error = await api
|
|
||||||
.post(
|
|
||||||
`/admin/regions/${created.id}`,
|
|
||||||
{
|
|
||||||
foo: "bar",
|
|
||||||
currency_code: "usd",
|
currency_code: "usd",
|
||||||
name: "Test Region",
|
})
|
||||||
},
|
|
||||||
adminHeaders
|
|
||||||
)
|
|
||||||
.catch((e) => e)
|
|
||||||
|
|
||||||
expect(error.response.status).toEqual(400)
|
const error = await api
|
||||||
expect(error.response.data.message).toEqual("property foo should not exist")
|
.post(
|
||||||
})
|
`/admin/regions/${created.id}`,
|
||||||
|
{
|
||||||
|
foo: "bar",
|
||||||
|
currency_code: "usd",
|
||||||
|
name: "Test Region",
|
||||||
|
},
|
||||||
|
adminHeaders
|
||||||
|
)
|
||||||
|
.catch((e) => e)
|
||||||
|
|
||||||
it("should get all regions and count", async () => {
|
expect(error.response.status).toEqual(400)
|
||||||
await service.create([
|
expect(error.response.data.message).toEqual(
|
||||||
{
|
"property foo should not exist"
|
||||||
name: "Test",
|
)
|
||||||
currency_code: "usd",
|
|
||||||
countries: ["jp"],
|
|
||||||
metadata: { foo: "bar" },
|
|
||||||
},
|
|
||||||
])
|
|
||||||
|
|
||||||
const api = useApi() as any
|
|
||||||
const response = await api.get(`/admin/regions`, adminHeaders)
|
|
||||||
|
|
||||||
expect(response.status).toEqual(200)
|
|
||||||
expect(response.data.regions).toEqual([
|
|
||||||
expect.objectContaining({
|
|
||||||
id: expect.any(String),
|
|
||||||
name: "Test",
|
|
||||||
currency_code: "usd",
|
|
||||||
metadata: { foo: "bar" },
|
|
||||||
}),
|
|
||||||
])
|
|
||||||
expect(response.data.regions[0].countries.map((c) => c.iso_2)).toEqual([
|
|
||||||
"jp",
|
|
||||||
])
|
|
||||||
})
|
|
||||||
|
|
||||||
it("should get a region", async () => {
|
|
||||||
const [region] = await service.create([
|
|
||||||
{
|
|
||||||
name: "Test",
|
|
||||||
currency_code: "usd",
|
|
||||||
countries: ["jp"],
|
|
||||||
metadata: { foo: "bar" },
|
|
||||||
},
|
|
||||||
])
|
|
||||||
|
|
||||||
const api = useApi() as any
|
|
||||||
const response = await api.get(`/admin/regions/${region.id}`, adminHeaders)
|
|
||||||
|
|
||||||
expect(response.status).toEqual(200)
|
|
||||||
expect(response.data.region).toEqual(
|
|
||||||
expect.objectContaining({
|
|
||||||
id: region.id,
|
|
||||||
name: "Test",
|
|
||||||
currency_code: "usd",
|
|
||||||
metadata: { foo: "bar" },
|
|
||||||
})
|
})
|
||||||
)
|
|
||||||
expect(response.data.region.countries.map((c) => c.iso_2)).toEqual(["jp"])
|
it("should get all regions and count", async () => {
|
||||||
})
|
await service.create([
|
||||||
|
{
|
||||||
|
name: "Test",
|
||||||
|
currency_code: "usd",
|
||||||
|
countries: ["jp"],
|
||||||
|
metadata: { foo: "bar" },
|
||||||
|
},
|
||||||
|
])
|
||||||
|
|
||||||
|
const response = await api.get(`/admin/regions`, adminHeaders)
|
||||||
|
|
||||||
|
expect(response.status).toEqual(200)
|
||||||
|
expect(response.data.regions).toEqual([
|
||||||
|
expect.objectContaining({
|
||||||
|
id: expect.any(String),
|
||||||
|
name: "Test",
|
||||||
|
currency_code: "usd",
|
||||||
|
metadata: { foo: "bar" },
|
||||||
|
}),
|
||||||
|
])
|
||||||
|
expect(response.data.regions[0].countries.map((c) => c.iso_2)).toEqual([
|
||||||
|
"jp",
|
||||||
|
])
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should get a region", async () => {
|
||||||
|
const [region] = await service.create([
|
||||||
|
{
|
||||||
|
name: "Test",
|
||||||
|
currency_code: "usd",
|
||||||
|
countries: ["jp"],
|
||||||
|
metadata: { foo: "bar" },
|
||||||
|
},
|
||||||
|
])
|
||||||
|
|
||||||
|
const response = await api.get(
|
||||||
|
`/admin/regions/${region.id}`,
|
||||||
|
adminHeaders
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(response.status).toEqual(200)
|
||||||
|
expect(response.data.region).toEqual(
|
||||||
|
expect.objectContaining({
|
||||||
|
id: region.id,
|
||||||
|
name: "Test",
|
||||||
|
currency_code: "usd",
|
||||||
|
metadata: { foo: "bar" },
|
||||||
|
})
|
||||||
|
)
|
||||||
|
expect(response.data.region.countries.map((c) => c.iso_2)).toEqual([
|
||||||
|
"jp",
|
||||||
|
])
|
||||||
|
})
|
||||||
|
})
|
||||||
|
},
|
||||||
})
|
})
|
||||||
@@ -1,12 +1,7 @@
|
|||||||
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||||
import { IStoreModuleService } from "@medusajs/types"
|
import { IStoreModuleService } from "@medusajs/types"
|
||||||
import path from "path"
|
|
||||||
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
|
|
||||||
import { useApi } from "../../../../environment-helpers/use-api"
|
|
||||||
import { getContainer } from "../../../../environment-helpers/use-container"
|
|
||||||
import { initDb, useDb } from "../../../../environment-helpers/use-db"
|
|
||||||
import { DataSource } from "typeorm"
|
|
||||||
import { createAdminUser } from "../../../helpers/create-admin-user"
|
import { createAdminUser } from "../../../helpers/create-admin-user"
|
||||||
|
import { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||||
|
|
||||||
jest.setTimeout(50000)
|
jest.setTimeout(50000)
|
||||||
|
|
||||||
@@ -15,68 +10,56 @@ const adminHeaders = {
|
|||||||
headers: { "x-medusa-access-token": "test_token" },
|
headers: { "x-medusa-access-token": "test_token" },
|
||||||
}
|
}
|
||||||
|
|
||||||
describe("Store - Admin", () => {
|
medusaIntegrationTestRunner({
|
||||||
let dbConnection: DataSource
|
env,
|
||||||
let appContainer
|
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||||
let shutdownServer
|
describe("Store - Admin", () => {
|
||||||
let service: IStoreModuleService
|
let appContainer
|
||||||
|
let service: IStoreModuleService
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
|
appContainer = getContainer()
|
||||||
dbConnection = await initDb({ cwd, env } as any)
|
service = appContainer.resolve(ModuleRegistrationName.STORE)
|
||||||
shutdownServer = await startBootstrapApp({ cwd, env })
|
})
|
||||||
appContainer = getContainer()
|
|
||||||
service = appContainer.resolve(ModuleRegistrationName.STORE)
|
|
||||||
})
|
|
||||||
|
|
||||||
afterAll(async () => {
|
beforeEach(async () => {
|
||||||
const db = useDb()
|
await createAdminUser(dbConnection, adminHeaders, appContainer)
|
||||||
await db.shutdown()
|
})
|
||||||
await shutdownServer()
|
|
||||||
})
|
|
||||||
|
|
||||||
beforeEach(async () => {
|
it("should correctly implement the entire lifecycle of a store", async () => {
|
||||||
await createAdminUser(dbConnection, adminHeaders)
|
const createdStore = await service.create({
|
||||||
})
|
name: "Test store",
|
||||||
|
supported_currency_codes: ["usd"],
|
||||||
|
})
|
||||||
|
|
||||||
afterEach(async () => {
|
expect(createdStore).toEqual(
|
||||||
const db = useDb()
|
expect.objectContaining({
|
||||||
await db.teardown()
|
id: createdStore.id,
|
||||||
})
|
supported_currency_codes: ["usd"],
|
||||||
|
name: "Test store",
|
||||||
|
})
|
||||||
|
)
|
||||||
|
|
||||||
it("should correctly implement the entire lifecycle of a store", async () => {
|
const updated = await api.post(
|
||||||
const api = useApi() as any
|
`/admin/stores/${createdStore.id}`,
|
||||||
const createdStore = await service.create({
|
{
|
||||||
name: "Test store",
|
name: "Updated store",
|
||||||
supported_currency_codes: ["usd"],
|
},
|
||||||
|
adminHeaders
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(updated.status).toEqual(200)
|
||||||
|
expect(updated.data.store).toEqual(
|
||||||
|
expect.objectContaining({
|
||||||
|
id: createdStore.id,
|
||||||
|
name: "Updated store",
|
||||||
|
})
|
||||||
|
)
|
||||||
|
|
||||||
|
await service.delete(createdStore.id)
|
||||||
|
const listedStores = await api.get(`/admin/stores`, adminHeaders)
|
||||||
|
expect(listedStores.data.stores).toHaveLength(0)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
},
|
||||||
expect(createdStore).toEqual(
|
|
||||||
expect.objectContaining({
|
|
||||||
id: createdStore.id,
|
|
||||||
supported_currency_codes: ["usd"],
|
|
||||||
name: "Test store",
|
|
||||||
})
|
|
||||||
)
|
|
||||||
|
|
||||||
const updated = await api.post(
|
|
||||||
`/admin/stores/${createdStore.id}`,
|
|
||||||
{
|
|
||||||
name: "Updated store",
|
|
||||||
},
|
|
||||||
adminHeaders
|
|
||||||
)
|
|
||||||
|
|
||||||
expect(updated.status).toEqual(200)
|
|
||||||
expect(updated.data.store).toEqual(
|
|
||||||
expect.objectContaining({
|
|
||||||
id: createdStore.id,
|
|
||||||
name: "Updated store",
|
|
||||||
})
|
|
||||||
)
|
|
||||||
|
|
||||||
await service.delete(createdStore.id)
|
|
||||||
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 { ITaxModuleService } from "@medusajs/types"
|
||||||
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||||
|
|
||||||
import { createAdminUser } from "../../../helpers/create-admin-user"
|
import { createAdminUser } from "../../../helpers/create-admin-user"
|
||||||
import { initDb, useDb } from "../../../../environment-helpers/use-db"
|
import { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||||
import { getContainer } from "../../../../environment-helpers/use-container"
|
|
||||||
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
|
|
||||||
import { useApi } from "../../../../environment-helpers/use-api"
|
|
||||||
|
|
||||||
jest.setTimeout(50000)
|
jest.setTimeout(50000)
|
||||||
|
|
||||||
@@ -15,497 +11,499 @@ const adminHeaders = {
|
|||||||
headers: { "x-medusa-access-token": "test_token" },
|
headers: { "x-medusa-access-token": "test_token" },
|
||||||
}
|
}
|
||||||
|
|
||||||
describe("Taxes - Admin", () => {
|
medusaIntegrationTestRunner({
|
||||||
let dbConnection
|
env,
|
||||||
let appContainer
|
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||||
let shutdownServer
|
describe("Taxes - Admin", () => {
|
||||||
let service: ITaxModuleService
|
let appContainer
|
||||||
|
let service: ITaxModuleService
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
|
appContainer = getContainer()
|
||||||
dbConnection = await initDb({ cwd, env } as any)
|
service = appContainer.resolve(ModuleRegistrationName.TAX)
|
||||||
shutdownServer = await startBootstrapApp({ cwd, env })
|
})
|
||||||
appContainer = getContainer()
|
|
||||||
service = appContainer.resolve(ModuleRegistrationName.TAX)
|
|
||||||
})
|
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
await createAdminUser(dbConnection, adminHeaders)
|
await createAdminUser(dbConnection, adminHeaders, appContainer)
|
||||||
})
|
})
|
||||||
|
|
||||||
afterAll(async () => {
|
it("can retrieve a tax rate", async () => {
|
||||||
const db = useDb()
|
const region = await service.createTaxRegions({
|
||||||
await db.shutdown()
|
country_code: "us",
|
||||||
await shutdownServer()
|
})
|
||||||
})
|
const rate = await service.create({
|
||||||
|
tax_region_id: region.id,
|
||||||
|
code: "test",
|
||||||
|
rate: 2.5,
|
||||||
|
name: "Test Rate",
|
||||||
|
})
|
||||||
|
|
||||||
afterEach(async () => {
|
const response = await api.get(
|
||||||
const db = useDb()
|
`/admin/tax-rates/${rate.id}`,
|
||||||
await db.teardown()
|
adminHeaders
|
||||||
})
|
)
|
||||||
|
|
||||||
it("can retrieve a tax rate", async () => {
|
expect(response.status).toEqual(200)
|
||||||
const region = await service.createTaxRegions({
|
expect(response.data).toEqual({
|
||||||
country_code: "us",
|
tax_rate: {
|
||||||
})
|
id: rate.id,
|
||||||
const rate = await service.create({
|
code: "test",
|
||||||
tax_region_id: region.id,
|
rate: 2.5,
|
||||||
code: "test",
|
name: "Test Rate",
|
||||||
rate: 2.5,
|
metadata: null,
|
||||||
name: "Test Rate",
|
tax_region_id: region.id,
|
||||||
})
|
is_default: false,
|
||||||
|
is_combinable: false,
|
||||||
|
created_at: expect.any(String),
|
||||||
|
updated_at: expect.any(String),
|
||||||
|
deleted_at: null,
|
||||||
|
created_by: null,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
const api = useApi() as any
|
it("can create a tax region with rates and rules", async () => {
|
||||||
const response = await api.get(`/admin/tax-rates/${rate.id}`, adminHeaders)
|
const regionRes = await api.post(
|
||||||
|
`/admin/tax-regions`,
|
||||||
|
{
|
||||||
|
country_code: "us",
|
||||||
|
default_tax_rate: {
|
||||||
|
code: "default",
|
||||||
|
rate: 2,
|
||||||
|
name: "default rate",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
adminHeaders
|
||||||
|
)
|
||||||
|
|
||||||
expect(response.status).toEqual(200)
|
const usRegionId = regionRes.data.tax_region.id
|
||||||
expect(response.data).toEqual({
|
|
||||||
tax_rate: {
|
|
||||||
id: rate.id,
|
|
||||||
code: "test",
|
|
||||||
rate: 2.5,
|
|
||||||
name: "Test Rate",
|
|
||||||
metadata: null,
|
|
||||||
tax_region_id: region.id,
|
|
||||||
is_default: false,
|
|
||||||
is_combinable: false,
|
|
||||||
created_at: expect.any(String),
|
|
||||||
updated_at: expect.any(String),
|
|
||||||
deleted_at: null,
|
|
||||||
created_by: null,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
it("can create a tax region with rates and rules", async () => {
|
expect(regionRes.status).toEqual(200)
|
||||||
const api = useApi() as any
|
expect(regionRes.data).toEqual({
|
||||||
const regionRes = await api.post(
|
tax_region: {
|
||||||
`/admin/tax-regions`,
|
id: expect.any(String),
|
||||||
{
|
country_code: "us",
|
||||||
country_code: "us",
|
parent_id: null,
|
||||||
default_tax_rate: {
|
province_code: null,
|
||||||
code: "default",
|
created_at: expect.any(String),
|
||||||
rate: 2,
|
updated_at: expect.any(String),
|
||||||
name: "default rate",
|
deleted_at: null,
|
||||||
},
|
created_by: "admin_user",
|
||||||
},
|
provider_id: null,
|
||||||
adminHeaders
|
metadata: null,
|
||||||
)
|
},
|
||||||
|
})
|
||||||
|
|
||||||
const usRegionId = regionRes.data.tax_region.id
|
const rateRes = await api.post(
|
||||||
|
`/admin/tax-rates`,
|
||||||
|
{
|
||||||
|
tax_region_id: usRegionId,
|
||||||
|
code: "RATE2",
|
||||||
|
name: "another rate",
|
||||||
|
rate: 10,
|
||||||
|
rules: [{ reference: "product", reference_id: "prod_1234" }],
|
||||||
|
},
|
||||||
|
adminHeaders
|
||||||
|
)
|
||||||
|
|
||||||
expect(regionRes.status).toEqual(200)
|
expect(rateRes.status).toEqual(200)
|
||||||
expect(regionRes.data).toEqual({
|
expect(rateRes.data).toEqual({
|
||||||
tax_region: {
|
tax_rate: {
|
||||||
id: expect.any(String),
|
id: expect.any(String),
|
||||||
country_code: "us",
|
code: "RATE2",
|
||||||
parent_id: null,
|
rate: 10,
|
||||||
province_code: null,
|
name: "another rate",
|
||||||
created_at: expect.any(String),
|
is_default: false,
|
||||||
updated_at: expect.any(String),
|
metadata: null,
|
||||||
deleted_at: null,
|
tax_region_id: usRegionId,
|
||||||
created_by: "admin_user",
|
created_at: expect.any(String),
|
||||||
provider_id: null,
|
updated_at: expect.any(String),
|
||||||
metadata: null,
|
deleted_at: null,
|
||||||
},
|
created_by: "admin_user",
|
||||||
})
|
is_combinable: false,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
const rateRes = await api.post(
|
const provRegRes = await api.post(
|
||||||
`/admin/tax-rates`,
|
`/admin/tax-regions`,
|
||||||
{
|
{
|
||||||
tax_region_id: usRegionId,
|
country_code: "US",
|
||||||
code: "RATE2",
|
parent_id: usRegionId,
|
||||||
name: "another rate",
|
province_code: "cA",
|
||||||
rate: 10,
|
},
|
||||||
rules: [{ reference: "product", reference_id: "prod_1234" }],
|
adminHeaders
|
||||||
},
|
)
|
||||||
adminHeaders
|
|
||||||
)
|
|
||||||
|
|
||||||
expect(rateRes.status).toEqual(200)
|
expect(provRegRes.status).toEqual(200)
|
||||||
expect(rateRes.data).toEqual({
|
expect(provRegRes.data).toEqual({
|
||||||
tax_rate: {
|
tax_region: {
|
||||||
id: expect.any(String),
|
id: expect.any(String),
|
||||||
code: "RATE2",
|
country_code: "us",
|
||||||
rate: 10,
|
parent_id: usRegionId,
|
||||||
name: "another rate",
|
province_code: "ca",
|
||||||
is_default: false,
|
created_at: expect.any(String),
|
||||||
metadata: null,
|
updated_at: expect.any(String),
|
||||||
tax_region_id: usRegionId,
|
deleted_at: null,
|
||||||
created_at: expect.any(String),
|
created_by: "admin_user",
|
||||||
updated_at: expect.any(String),
|
metadata: null,
|
||||||
deleted_at: null,
|
provider_id: null,
|
||||||
created_by: "admin_user",
|
},
|
||||||
is_combinable: false,
|
})
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
const provRegRes = await api.post(
|
const defRes = await api.post(
|
||||||
`/admin/tax-regions`,
|
`/admin/tax-rates`,
|
||||||
{
|
{
|
||||||
country_code: "US",
|
tax_region_id: provRegRes.data.tax_region.id,
|
||||||
parent_id: usRegionId,
|
code: "DEFAULT",
|
||||||
province_code: "cA",
|
name: "DEFAULT",
|
||||||
},
|
rate: 10,
|
||||||
adminHeaders
|
is_default: true,
|
||||||
)
|
},
|
||||||
|
adminHeaders
|
||||||
|
)
|
||||||
|
|
||||||
expect(provRegRes.status).toEqual(200)
|
const listRes = await api.get(`/admin/tax-rates`, adminHeaders)
|
||||||
expect(provRegRes.data).toEqual({
|
|
||||||
tax_region: {
|
|
||||||
id: expect.any(String),
|
|
||||||
country_code: "us",
|
|
||||||
parent_id: usRegionId,
|
|
||||||
province_code: "ca",
|
|
||||||
created_at: expect.any(String),
|
|
||||||
updated_at: expect.any(String),
|
|
||||||
deleted_at: null,
|
|
||||||
created_by: "admin_user",
|
|
||||||
metadata: null,
|
|
||||||
provider_id: null,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
const defRes = await api.post(
|
expect(listRes.status).toEqual(200)
|
||||||
`/admin/tax-rates`,
|
expect(listRes.data.tax_rates).toEqual(
|
||||||
{
|
expect.arrayContaining([
|
||||||
tax_region_id: provRegRes.data.tax_region.id,
|
expect.objectContaining({
|
||||||
code: "DEFAULT",
|
id: rateRes.data.tax_rate.id,
|
||||||
name: "DEFAULT",
|
code: "RATE2",
|
||||||
rate: 10,
|
rate: 10,
|
||||||
is_default: true,
|
name: "another rate",
|
||||||
},
|
is_default: false,
|
||||||
adminHeaders
|
metadata: null,
|
||||||
)
|
tax_region_id: usRegionId,
|
||||||
|
created_at: expect.any(String),
|
||||||
|
updated_at: expect.any(String),
|
||||||
|
deleted_at: null,
|
||||||
|
created_by: "admin_user",
|
||||||
|
}),
|
||||||
|
expect.objectContaining({ id: defRes.data.tax_rate.id }),
|
||||||
|
expect.objectContaining({
|
||||||
|
tax_region_id: usRegionId,
|
||||||
|
is_default: true,
|
||||||
|
rate: 2,
|
||||||
|
}),
|
||||||
|
])
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
const listRes = await api.get(`/admin/tax-rates`, adminHeaders)
|
it("can create a tax rate and update it", async () => {
|
||||||
|
const regionRes = await api.post(
|
||||||
|
`/admin/tax-regions`,
|
||||||
|
{
|
||||||
|
country_code: "us",
|
||||||
|
default_tax_rate: {
|
||||||
|
code: "default",
|
||||||
|
rate: 2,
|
||||||
|
name: "default rate",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
adminHeaders
|
||||||
|
)
|
||||||
|
|
||||||
expect(listRes.status).toEqual(200)
|
const usRegionId = regionRes.data.tax_region.id
|
||||||
expect(listRes.data.tax_rates).toEqual(
|
|
||||||
expect.arrayContaining([
|
expect(regionRes.status).toEqual(200)
|
||||||
expect.objectContaining({
|
expect(regionRes.data).toEqual({
|
||||||
|
tax_region: {
|
||||||
|
id: expect.any(String),
|
||||||
|
country_code: "us",
|
||||||
|
parent_id: null,
|
||||||
|
province_code: null,
|
||||||
|
created_at: expect.any(String),
|
||||||
|
updated_at: expect.any(String),
|
||||||
|
deleted_at: null,
|
||||||
|
created_by: "admin_user",
|
||||||
|
provider_id: null,
|
||||||
|
metadata: null,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
const rateRes = await api.post(
|
||||||
|
`/admin/tax-rates`,
|
||||||
|
{
|
||||||
|
tax_region_id: usRegionId,
|
||||||
|
code: "RATE2",
|
||||||
|
name: "another rate",
|
||||||
|
rate: 10,
|
||||||
|
rules: [{ reference: "product", reference_id: "prod_1234" }],
|
||||||
|
},
|
||||||
|
adminHeaders
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(rateRes.status).toEqual(200)
|
||||||
|
expect(rateRes.data).toEqual({
|
||||||
|
tax_rate: {
|
||||||
|
id: expect.any(String),
|
||||||
|
code: "RATE2",
|
||||||
|
rate: 10,
|
||||||
|
name: "another rate",
|
||||||
|
is_default: false,
|
||||||
|
metadata: null,
|
||||||
|
tax_region_id: usRegionId,
|
||||||
|
created_at: expect.any(String),
|
||||||
|
updated_at: expect.any(String),
|
||||||
|
deleted_at: null,
|
||||||
|
created_by: "admin_user",
|
||||||
|
is_combinable: false,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
const updateRes = await api.post(
|
||||||
|
`/admin/tax-rates/${rateRes.data.tax_rate.id}`,
|
||||||
|
{
|
||||||
|
code: "updatedcode",
|
||||||
|
rate: 12,
|
||||||
|
is_combinable: true,
|
||||||
|
name: "Another Name",
|
||||||
|
metadata: { you: "know it" },
|
||||||
|
},
|
||||||
|
adminHeaders
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(updateRes.status).toEqual(200)
|
||||||
|
expect(updateRes.data).toEqual({
|
||||||
|
tax_rate: {
|
||||||
|
id: expect.any(String),
|
||||||
|
code: "updatedcode",
|
||||||
|
rate: 12,
|
||||||
|
name: "Another Name",
|
||||||
|
is_default: false,
|
||||||
|
metadata: { you: "know it" },
|
||||||
|
tax_region_id: usRegionId,
|
||||||
|
deleted_at: null,
|
||||||
|
created_at: expect.any(String),
|
||||||
|
updated_at: expect.any(String),
|
||||||
|
created_by: "admin_user",
|
||||||
|
is_combinable: true,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it("can create a tax rate and delete it", async () => {
|
||||||
|
const regionRes = await api.post(
|
||||||
|
`/admin/tax-regions`,
|
||||||
|
{
|
||||||
|
country_code: "us",
|
||||||
|
default_tax_rate: {
|
||||||
|
code: "default",
|
||||||
|
rate: 2,
|
||||||
|
name: "default rate",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
adminHeaders
|
||||||
|
)
|
||||||
|
|
||||||
|
const usRegionId = regionRes.data.tax_region.id
|
||||||
|
|
||||||
|
const rateRes = await api.post(
|
||||||
|
`/admin/tax-rates`,
|
||||||
|
{
|
||||||
|
tax_region_id: usRegionId,
|
||||||
|
code: "RATE2",
|
||||||
|
name: "another rate",
|
||||||
|
rate: 10,
|
||||||
|
rules: [{ reference: "product", reference_id: "prod_1234" }],
|
||||||
|
},
|
||||||
|
adminHeaders
|
||||||
|
)
|
||||||
|
|
||||||
|
const deleteRes = await api.delete(
|
||||||
|
`/admin/tax-rates/${rateRes.data.tax_rate.id}`,
|
||||||
|
adminHeaders
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(deleteRes.status).toEqual(200)
|
||||||
|
expect(deleteRes.data).toEqual({
|
||||||
id: rateRes.data.tax_rate.id,
|
id: rateRes.data.tax_rate.id,
|
||||||
code: "RATE2",
|
object: "tax_rate",
|
||||||
rate: 10,
|
deleted: true,
|
||||||
name: "another rate",
|
})
|
||||||
is_default: false,
|
|
||||||
metadata: null,
|
|
||||||
tax_region_id: usRegionId,
|
|
||||||
created_at: expect.any(String),
|
|
||||||
updated_at: expect.any(String),
|
|
||||||
deleted_at: null,
|
|
||||||
created_by: "admin_user",
|
|
||||||
}),
|
|
||||||
expect.objectContaining({ id: defRes.data.tax_rate.id }),
|
|
||||||
expect.objectContaining({
|
|
||||||
tax_region_id: usRegionId,
|
|
||||||
is_default: true,
|
|
||||||
rate: 2,
|
|
||||||
}),
|
|
||||||
])
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
it("can create a tax rate and update it", async () => {
|
const rates = await service.list(
|
||||||
const api = useApi() as any
|
{ id: rateRes.data.tax_rate.id },
|
||||||
const regionRes = await api.post(
|
{ withDeleted: true }
|
||||||
`/admin/tax-regions`,
|
)
|
||||||
{
|
expect(rates.length).toEqual(1)
|
||||||
country_code: "us",
|
expect(rates[0].deleted_at).not.toBeNull()
|
||||||
default_tax_rate: { code: "default", rate: 2, name: "default rate" },
|
})
|
||||||
},
|
|
||||||
adminHeaders
|
|
||||||
)
|
|
||||||
|
|
||||||
const usRegionId = regionRes.data.tax_region.id
|
it("can create a tax region and delete it", async () => {
|
||||||
|
const regionRes = await api.post(
|
||||||
|
`/admin/tax-regions`,
|
||||||
|
{
|
||||||
|
country_code: "us",
|
||||||
|
default_tax_rate: {
|
||||||
|
code: "default",
|
||||||
|
rate: 2,
|
||||||
|
name: "default rate",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
adminHeaders
|
||||||
|
)
|
||||||
|
|
||||||
expect(regionRes.status).toEqual(200)
|
const usRegionId = regionRes.data.tax_region.id
|
||||||
expect(regionRes.data).toEqual({
|
|
||||||
tax_region: {
|
const deleteRes = await api.delete(
|
||||||
id: expect.any(String),
|
`/admin/tax-regions/${usRegionId}`,
|
||||||
country_code: "us",
|
adminHeaders
|
||||||
parent_id: null,
|
)
|
||||||
province_code: null,
|
|
||||||
created_at: expect.any(String),
|
expect(deleteRes.status).toEqual(200)
|
||||||
updated_at: expect.any(String),
|
expect(deleteRes.data).toEqual({
|
||||||
deleted_at: null,
|
id: usRegionId,
|
||||||
created_by: "admin_user",
|
object: "tax_region",
|
||||||
provider_id: null,
|
deleted: true,
|
||||||
metadata: null,
|
})
|
||||||
},
|
|
||||||
|
const rates = await service.listTaxRegions(
|
||||||
|
{ id: usRegionId },
|
||||||
|
{ withDeleted: true }
|
||||||
|
)
|
||||||
|
expect(rates.length).toEqual(1)
|
||||||
|
expect(rates[0].deleted_at).not.toBeNull()
|
||||||
|
})
|
||||||
|
|
||||||
|
it("can create a tax rate add rules and remove them", async () => {
|
||||||
|
const regionRes = await api.post(
|
||||||
|
`/admin/tax-regions`,
|
||||||
|
{
|
||||||
|
country_code: "us",
|
||||||
|
default_tax_rate: {
|
||||||
|
code: "default",
|
||||||
|
rate: 2,
|
||||||
|
name: "default rate",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
adminHeaders
|
||||||
|
)
|
||||||
|
|
||||||
|
const usRegionId = regionRes.data.tax_region.id
|
||||||
|
const rateRes = await api.post(
|
||||||
|
`/admin/tax-rates`,
|
||||||
|
{
|
||||||
|
tax_region_id: usRegionId,
|
||||||
|
code: "RATE2",
|
||||||
|
name: "another rate",
|
||||||
|
rate: 10,
|
||||||
|
rules: [{ reference: "product", reference_id: "prod_1234" }],
|
||||||
|
},
|
||||||
|
adminHeaders
|
||||||
|
)
|
||||||
|
const rateId = rateRes.data.tax_rate.id
|
||||||
|
let rules = await service.listTaxRateRules({ tax_rate_id: rateId })
|
||||||
|
|
||||||
|
expect(rules).toEqual([
|
||||||
|
{
|
||||||
|
id: expect.any(String),
|
||||||
|
tax_rate_id: rateId,
|
||||||
|
reference: "product",
|
||||||
|
reference_id: "prod_1234",
|
||||||
|
created_by: "admin_user",
|
||||||
|
created_at: expect.any(Date),
|
||||||
|
updated_at: expect.any(Date),
|
||||||
|
deleted_at: null,
|
||||||
|
tax_rate: { id: rateId },
|
||||||
|
metadata: null,
|
||||||
|
},
|
||||||
|
])
|
||||||
|
|
||||||
|
await api.post(
|
||||||
|
`/admin/tax-rates/${rateId}/rules`,
|
||||||
|
{
|
||||||
|
reference: "product",
|
||||||
|
reference_id: "prod_1111",
|
||||||
|
},
|
||||||
|
adminHeaders
|
||||||
|
)
|
||||||
|
|
||||||
|
await api.post(
|
||||||
|
`/admin/tax-rates/${rateId}/rules`,
|
||||||
|
{
|
||||||
|
reference: "product",
|
||||||
|
reference_id: "prod_2222",
|
||||||
|
},
|
||||||
|
adminHeaders
|
||||||
|
)
|
||||||
|
rules = await service.listTaxRateRules({ tax_rate_id: rateId })
|
||||||
|
expect(rules).toEqual(
|
||||||
|
expect.arrayContaining([
|
||||||
|
expect.objectContaining({
|
||||||
|
tax_rate_id: rateId,
|
||||||
|
reference: "product",
|
||||||
|
reference_id: "prod_1234",
|
||||||
|
created_by: "admin_user",
|
||||||
|
}),
|
||||||
|
expect.objectContaining({
|
||||||
|
tax_rate_id: rateId,
|
||||||
|
reference: "product",
|
||||||
|
reference_id: "prod_1111",
|
||||||
|
created_by: "admin_user",
|
||||||
|
}),
|
||||||
|
expect.objectContaining({
|
||||||
|
tax_rate_id: rateId,
|
||||||
|
reference: "product",
|
||||||
|
reference_id: "prod_2222",
|
||||||
|
created_by: "admin_user",
|
||||||
|
}),
|
||||||
|
])
|
||||||
|
)
|
||||||
|
|
||||||
|
const toDeleteId = rules.find((r) => r.reference_id === "prod_1111")!.id
|
||||||
|
await api.delete(
|
||||||
|
`/admin/tax-rates/${rateId}/rules/${toDeleteId}`,
|
||||||
|
adminHeaders
|
||||||
|
)
|
||||||
|
|
||||||
|
rules = await service.listTaxRateRules({ tax_rate_id: rateId })
|
||||||
|
expect(rules.length).toEqual(2)
|
||||||
|
|
||||||
|
await api.post(
|
||||||
|
`/admin/tax-rates/${rateId}`,
|
||||||
|
{
|
||||||
|
rules: [
|
||||||
|
{ reference: "product", reference_id: "prod_3333" },
|
||||||
|
{ reference: "product", reference_id: "prod_4444" },
|
||||||
|
{ reference: "product", reference_id: "prod_5555" },
|
||||||
|
{ reference: "product", reference_id: "prod_6666" },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
adminHeaders
|
||||||
|
)
|
||||||
|
rules = await service.listTaxRateRules({ tax_rate_id: rateId })
|
||||||
|
expect(rules.length).toEqual(4)
|
||||||
|
expect(rules).toEqual(
|
||||||
|
expect.arrayContaining([
|
||||||
|
expect.objectContaining({
|
||||||
|
tax_rate_id: rateId,
|
||||||
|
reference: "product",
|
||||||
|
reference_id: "prod_3333",
|
||||||
|
created_by: "admin_user",
|
||||||
|
}),
|
||||||
|
expect.objectContaining({
|
||||||
|
tax_rate_id: rateId,
|
||||||
|
reference: "product",
|
||||||
|
reference_id: "prod_4444",
|
||||||
|
created_by: "admin_user",
|
||||||
|
}),
|
||||||
|
expect.objectContaining({
|
||||||
|
tax_rate_id: rateId,
|
||||||
|
reference: "product",
|
||||||
|
reference_id: "prod_5555",
|
||||||
|
created_by: "admin_user",
|
||||||
|
}),
|
||||||
|
expect.objectContaining({
|
||||||
|
tax_rate_id: rateId,
|
||||||
|
reference: "product",
|
||||||
|
reference_id: "prod_6666",
|
||||||
|
created_by: "admin_user",
|
||||||
|
}),
|
||||||
|
])
|
||||||
|
)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
},
|
||||||
const rateRes = await api.post(
|
|
||||||
`/admin/tax-rates`,
|
|
||||||
{
|
|
||||||
tax_region_id: usRegionId,
|
|
||||||
code: "RATE2",
|
|
||||||
name: "another rate",
|
|
||||||
rate: 10,
|
|
||||||
rules: [{ reference: "product", reference_id: "prod_1234" }],
|
|
||||||
},
|
|
||||||
adminHeaders
|
|
||||||
)
|
|
||||||
|
|
||||||
expect(rateRes.status).toEqual(200)
|
|
||||||
expect(rateRes.data).toEqual({
|
|
||||||
tax_rate: {
|
|
||||||
id: expect.any(String),
|
|
||||||
code: "RATE2",
|
|
||||||
rate: 10,
|
|
||||||
name: "another rate",
|
|
||||||
is_default: false,
|
|
||||||
metadata: null,
|
|
||||||
tax_region_id: usRegionId,
|
|
||||||
created_at: expect.any(String),
|
|
||||||
updated_at: expect.any(String),
|
|
||||||
deleted_at: null,
|
|
||||||
created_by: "admin_user",
|
|
||||||
is_combinable: false,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
const updateRes = await api.post(
|
|
||||||
`/admin/tax-rates/${rateRes.data.tax_rate.id}`,
|
|
||||||
{
|
|
||||||
code: "updatedcode",
|
|
||||||
rate: 12,
|
|
||||||
is_combinable: true,
|
|
||||||
name: "Another Name",
|
|
||||||
metadata: { you: "know it" },
|
|
||||||
},
|
|
||||||
adminHeaders
|
|
||||||
)
|
|
||||||
|
|
||||||
expect(updateRes.status).toEqual(200)
|
|
||||||
expect(updateRes.data).toEqual({
|
|
||||||
tax_rate: {
|
|
||||||
id: expect.any(String),
|
|
||||||
code: "updatedcode",
|
|
||||||
rate: 12,
|
|
||||||
name: "Another Name",
|
|
||||||
is_default: false,
|
|
||||||
metadata: { you: "know it" },
|
|
||||||
tax_region_id: usRegionId,
|
|
||||||
deleted_at: null,
|
|
||||||
created_at: expect.any(String),
|
|
||||||
updated_at: expect.any(String),
|
|
||||||
created_by: "admin_user",
|
|
||||||
is_combinable: true,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
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" },
|
|
||||||
},
|
|
||||||
adminHeaders
|
|
||||||
)
|
|
||||||
|
|
||||||
const usRegionId = regionRes.data.tax_region.id
|
|
||||||
|
|
||||||
const rateRes = await api.post(
|
|
||||||
`/admin/tax-rates`,
|
|
||||||
{
|
|
||||||
tax_region_id: usRegionId,
|
|
||||||
code: "RATE2",
|
|
||||||
name: "another rate",
|
|
||||||
rate: 10,
|
|
||||||
rules: [{ reference: "product", reference_id: "prod_1234" }],
|
|
||||||
},
|
|
||||||
adminHeaders
|
|
||||||
)
|
|
||||||
|
|
||||||
const deleteRes = await api.delete(
|
|
||||||
`/admin/tax-rates/${rateRes.data.tax_rate.id}`,
|
|
||||||
adminHeaders
|
|
||||||
)
|
|
||||||
|
|
||||||
expect(deleteRes.status).toEqual(200)
|
|
||||||
expect(deleteRes.data).toEqual({
|
|
||||||
id: rateRes.data.tax_rate.id,
|
|
||||||
object: "tax_rate",
|
|
||||||
deleted: true,
|
|
||||||
})
|
|
||||||
|
|
||||||
const rates = await service.list(
|
|
||||||
{ id: rateRes.data.tax_rate.id },
|
|
||||||
{ withDeleted: true }
|
|
||||||
)
|
|
||||||
expect(rates.length).toEqual(1)
|
|
||||||
expect(rates[0].deleted_at).not.toBeNull()
|
|
||||||
})
|
|
||||||
|
|
||||||
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" },
|
|
||||||
},
|
|
||||||
adminHeaders
|
|
||||||
)
|
|
||||||
|
|
||||||
const usRegionId = regionRes.data.tax_region.id
|
|
||||||
|
|
||||||
const deleteRes = await api.delete(
|
|
||||||
`/admin/tax-regions/${usRegionId}`,
|
|
||||||
adminHeaders
|
|
||||||
)
|
|
||||||
|
|
||||||
expect(deleteRes.status).toEqual(200)
|
|
||||||
expect(deleteRes.data).toEqual({
|
|
||||||
id: usRegionId,
|
|
||||||
object: "tax_region",
|
|
||||||
deleted: true,
|
|
||||||
})
|
|
||||||
|
|
||||||
const rates = await service.listTaxRegions(
|
|
||||||
{ id: usRegionId },
|
|
||||||
{ withDeleted: true }
|
|
||||||
)
|
|
||||||
expect(rates.length).toEqual(1)
|
|
||||||
expect(rates[0].deleted_at).not.toBeNull()
|
|
||||||
})
|
|
||||||
|
|
||||||
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" },
|
|
||||||
},
|
|
||||||
adminHeaders
|
|
||||||
)
|
|
||||||
|
|
||||||
const usRegionId = regionRes.data.tax_region.id
|
|
||||||
const rateRes = await api.post(
|
|
||||||
`/admin/tax-rates`,
|
|
||||||
{
|
|
||||||
tax_region_id: usRegionId,
|
|
||||||
code: "RATE2",
|
|
||||||
name: "another rate",
|
|
||||||
rate: 10,
|
|
||||||
rules: [{ reference: "product", reference_id: "prod_1234" }],
|
|
||||||
},
|
|
||||||
adminHeaders
|
|
||||||
)
|
|
||||||
const rateId = rateRes.data.tax_rate.id
|
|
||||||
let rules = await service.listTaxRateRules({ tax_rate_id: rateId })
|
|
||||||
|
|
||||||
expect(rules).toEqual([
|
|
||||||
{
|
|
||||||
id: expect.any(String),
|
|
||||||
tax_rate_id: rateId,
|
|
||||||
reference: "product",
|
|
||||||
reference_id: "prod_1234",
|
|
||||||
created_by: "admin_user",
|
|
||||||
created_at: expect.any(Date),
|
|
||||||
updated_at: expect.any(Date),
|
|
||||||
deleted_at: null,
|
|
||||||
tax_rate: { id: rateId },
|
|
||||||
metadata: null,
|
|
||||||
},
|
|
||||||
])
|
|
||||||
|
|
||||||
await api.post(
|
|
||||||
`/admin/tax-rates/${rateId}/rules`,
|
|
||||||
{
|
|
||||||
reference: "product",
|
|
||||||
reference_id: "prod_1111",
|
|
||||||
},
|
|
||||||
adminHeaders
|
|
||||||
)
|
|
||||||
|
|
||||||
await api.post(
|
|
||||||
`/admin/tax-rates/${rateId}/rules`,
|
|
||||||
{
|
|
||||||
reference: "product",
|
|
||||||
reference_id: "prod_2222",
|
|
||||||
},
|
|
||||||
adminHeaders
|
|
||||||
)
|
|
||||||
rules = await service.listTaxRateRules({ tax_rate_id: rateId })
|
|
||||||
expect(rules).toEqual(
|
|
||||||
expect.arrayContaining([
|
|
||||||
expect.objectContaining({
|
|
||||||
tax_rate_id: rateId,
|
|
||||||
reference: "product",
|
|
||||||
reference_id: "prod_1234",
|
|
||||||
created_by: "admin_user",
|
|
||||||
}),
|
|
||||||
expect.objectContaining({
|
|
||||||
tax_rate_id: rateId,
|
|
||||||
reference: "product",
|
|
||||||
reference_id: "prod_1111",
|
|
||||||
created_by: "admin_user",
|
|
||||||
}),
|
|
||||||
expect.objectContaining({
|
|
||||||
tax_rate_id: rateId,
|
|
||||||
reference: "product",
|
|
||||||
reference_id: "prod_2222",
|
|
||||||
created_by: "admin_user",
|
|
||||||
}),
|
|
||||||
])
|
|
||||||
)
|
|
||||||
|
|
||||||
const toDeleteId = rules.find((r) => r.reference_id === "prod_1111")!.id
|
|
||||||
await api.delete(
|
|
||||||
`/admin/tax-rates/${rateId}/rules/${toDeleteId}`,
|
|
||||||
adminHeaders
|
|
||||||
)
|
|
||||||
|
|
||||||
rules = await service.listTaxRateRules({ tax_rate_id: rateId })
|
|
||||||
expect(rules.length).toEqual(2)
|
|
||||||
|
|
||||||
await api.post(
|
|
||||||
`/admin/tax-rates/${rateId}`,
|
|
||||||
{
|
|
||||||
rules: [
|
|
||||||
{ reference: "product", reference_id: "prod_3333" },
|
|
||||||
{ reference: "product", reference_id: "prod_4444" },
|
|
||||||
{ reference: "product", reference_id: "prod_5555" },
|
|
||||||
{ reference: "product", reference_id: "prod_6666" },
|
|
||||||
],
|
|
||||||
},
|
|
||||||
adminHeaders
|
|
||||||
)
|
|
||||||
rules = await service.listTaxRateRules({ tax_rate_id: rateId })
|
|
||||||
expect(rules.length).toEqual(4)
|
|
||||||
expect(rules).toEqual(
|
|
||||||
expect.arrayContaining([
|
|
||||||
expect.objectContaining({
|
|
||||||
tax_rate_id: rateId,
|
|
||||||
reference: "product",
|
|
||||||
reference_id: "prod_3333",
|
|
||||||
created_by: "admin_user",
|
|
||||||
}),
|
|
||||||
expect.objectContaining({
|
|
||||||
tax_rate_id: rateId,
|
|
||||||
reference: "product",
|
|
||||||
reference_id: "prod_4444",
|
|
||||||
created_by: "admin_user",
|
|
||||||
}),
|
|
||||||
expect.objectContaining({
|
|
||||||
tax_rate_id: rateId,
|
|
||||||
reference: "product",
|
|
||||||
reference_id: "prod_5555",
|
|
||||||
created_by: "admin_user",
|
|
||||||
}),
|
|
||||||
expect.objectContaining({
|
|
||||||
tax_rate_id: rateId,
|
|
||||||
reference: "product",
|
|
||||||
reference_id: "prod_6666",
|
|
||||||
created_by: "admin_user",
|
|
||||||
}),
|
|
||||||
])
|
|
||||||
)
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
@@ -1,18 +1,12 @@
|
|||||||
import path from "path"
|
|
||||||
import { ITaxModuleService } from "@medusajs/types"
|
import { ITaxModuleService } from "@medusajs/types"
|
||||||
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||||
|
|
||||||
import { createAdminUser } from "../../../helpers/create-admin-user"
|
import { createAdminUser } from "../../../helpers/create-admin-user"
|
||||||
import { initDb, useDb } from "../../../../environment-helpers/use-db"
|
|
||||||
import { getContainer } from "../../../../environment-helpers/use-container"
|
|
||||||
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
|
|
||||||
import { useApi } from "../../../../environment-helpers/use-api"
|
|
||||||
import {
|
import {
|
||||||
createTaxRateRulesStepId,
|
createTaxRateRulesStepId,
|
||||||
maybeSetTaxRateRulesStepId,
|
|
||||||
updateTaxRatesStepId,
|
|
||||||
updateTaxRatesWorkflow,
|
updateTaxRatesWorkflow,
|
||||||
} from "@medusajs/core-flows"
|
} from "@medusajs/core-flows"
|
||||||
|
import { medusaIntegrationTestRunner } from "medusa-test-utils/dist"
|
||||||
|
|
||||||
jest.setTimeout(50000)
|
jest.setTimeout(50000)
|
||||||
|
|
||||||
@@ -21,189 +15,178 @@ const adminHeaders = {
|
|||||||
headers: { "x-medusa-access-token": "test_token" },
|
headers: { "x-medusa-access-token": "test_token" },
|
||||||
}
|
}
|
||||||
|
|
||||||
describe("Taxes - Workflow", () => {
|
medusaIntegrationTestRunner({
|
||||||
let dbConnection
|
env,
|
||||||
let appContainer
|
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||||
let shutdownServer
|
describe("Taxes - Workflow", () => {
|
||||||
let service: ITaxModuleService
|
let appContainer
|
||||||
|
let service: ITaxModuleService
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
|
appContainer = getContainer()
|
||||||
dbConnection = await initDb({ cwd, env } as any)
|
service = appContainer.resolve(ModuleRegistrationName.TAX)
|
||||||
shutdownServer = await startBootstrapApp({ cwd, env })
|
})
|
||||||
appContainer = getContainer()
|
|
||||||
service = appContainer.resolve(ModuleRegistrationName.TAX)
|
|
||||||
})
|
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
await createAdminUser(dbConnection, adminHeaders)
|
await createAdminUser(dbConnection, adminHeaders)
|
||||||
})
|
})
|
||||||
|
|
||||||
afterAll(async () => {
|
it("compensates rules correctly", async () => {
|
||||||
const db = useDb()
|
const taxRegion = await service.createTaxRegions({
|
||||||
await db.shutdown()
|
country_code: "us",
|
||||||
await shutdownServer()
|
})
|
||||||
})
|
|
||||||
|
|
||||||
afterEach(async () => {
|
const [rateOne, rateTwo] = await service.create([
|
||||||
const db = useDb()
|
{
|
||||||
await db.teardown()
|
tax_region_id: taxRegion.id,
|
||||||
})
|
rate: 10,
|
||||||
|
code: "standard",
|
||||||
|
name: "Standard",
|
||||||
|
rules: [
|
||||||
|
{ reference: "shipping", reference_id: "shipping_12354" },
|
||||||
|
{ reference: "shipping", reference_id: "shipping_11111" },
|
||||||
|
{ reference: "shipping", reference_id: "shipping_22222" },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
tax_region_id: taxRegion.id,
|
||||||
|
rate: 2,
|
||||||
|
code: "reduced",
|
||||||
|
name: "Reduced",
|
||||||
|
rules: [
|
||||||
|
{ reference: "product", reference_id: "product_12354" },
|
||||||
|
{ reference: "product", reference_id: "product_11111" },
|
||||||
|
{ reference: "product", reference_id: "product_22222" },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
])
|
||||||
|
|
||||||
it("compensates rules correctly", async () => {
|
const workflow = updateTaxRatesWorkflow(appContainer)
|
||||||
const taxRegion = await service.createTaxRegions({
|
|
||||||
country_code: "us",
|
workflow.appendAction("throw", createTaxRateRulesStepId, {
|
||||||
|
invoke: async function failStep() {
|
||||||
|
throw new Error(`Failed to update`)
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
await workflow.run({
|
||||||
|
input: {
|
||||||
|
selector: { tax_region_id: taxRegion.id },
|
||||||
|
update: {
|
||||||
|
rate: 2,
|
||||||
|
rules: [
|
||||||
|
{ reference: "product", reference_id: "product_12354" },
|
||||||
|
{ reference: "shipping", reference_id: "shipping_12354" },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
throwOnError: false,
|
||||||
|
})
|
||||||
|
|
||||||
|
const taxRateRules = await service.listTaxRateRules({
|
||||||
|
tax_rate: { tax_region_id: taxRegion.id },
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(taxRateRules.length).toEqual(6)
|
||||||
|
expect(taxRateRules).toEqual(
|
||||||
|
expect.arrayContaining([
|
||||||
|
expect.objectContaining({
|
||||||
|
tax_rate_id: rateOne.id,
|
||||||
|
reference_id: "shipping_12354",
|
||||||
|
}),
|
||||||
|
expect.objectContaining({
|
||||||
|
tax_rate_id: rateOne.id,
|
||||||
|
reference_id: "shipping_11111",
|
||||||
|
}),
|
||||||
|
expect.objectContaining({
|
||||||
|
tax_rate_id: rateOne.id,
|
||||||
|
reference_id: "shipping_22222",
|
||||||
|
}),
|
||||||
|
expect.objectContaining({
|
||||||
|
tax_rate_id: rateTwo.id,
|
||||||
|
reference_id: "product_12354",
|
||||||
|
}),
|
||||||
|
expect.objectContaining({
|
||||||
|
tax_rate_id: rateTwo.id,
|
||||||
|
reference_id: "product_11111",
|
||||||
|
}),
|
||||||
|
expect.objectContaining({
|
||||||
|
tax_rate_id: rateTwo.id,
|
||||||
|
reference_id: "product_22222",
|
||||||
|
}),
|
||||||
|
])
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
it("creates rules correctly", async () => {
|
||||||
|
const taxRegion = await service.createTaxRegions({
|
||||||
|
country_code: "us",
|
||||||
|
})
|
||||||
|
|
||||||
|
const [rateOne, rateTwo] = await service.create([
|
||||||
|
{
|
||||||
|
tax_region_id: taxRegion.id,
|
||||||
|
rate: 10,
|
||||||
|
code: "standard",
|
||||||
|
name: "Standard",
|
||||||
|
rules: [
|
||||||
|
{ reference: "shipping", reference_id: "shipping_12354" },
|
||||||
|
{ reference: "shipping", reference_id: "shipping_11111" },
|
||||||
|
{ reference: "shipping", reference_id: "shipping_22222" },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
tax_region_id: taxRegion.id,
|
||||||
|
rate: 2,
|
||||||
|
code: "reduced",
|
||||||
|
name: "Reduced",
|
||||||
|
rules: [
|
||||||
|
{ reference: "product", reference_id: "product_12354" },
|
||||||
|
{ reference: "product", reference_id: "product_11111" },
|
||||||
|
{ reference: "product", reference_id: "product_22222" },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
])
|
||||||
|
|
||||||
|
await updateTaxRatesWorkflow(appContainer).run({
|
||||||
|
input: {
|
||||||
|
selector: { tax_region_id: taxRegion.id },
|
||||||
|
update: {
|
||||||
|
rate: 2,
|
||||||
|
rules: [
|
||||||
|
{ reference: "product", reference_id: "product_12354" },
|
||||||
|
{ reference: "shipping", reference_id: "shipping_12354" },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
const taxRateRules = await service.listTaxRateRules({
|
||||||
|
tax_rate: { tax_region_id: taxRegion.id },
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(taxRateRules.length).toEqual(4)
|
||||||
|
expect(taxRateRules).toEqual(
|
||||||
|
expect.arrayContaining([
|
||||||
|
expect.objectContaining({
|
||||||
|
tax_rate_id: rateOne.id,
|
||||||
|
reference_id: "shipping_12354",
|
||||||
|
}),
|
||||||
|
expect.objectContaining({
|
||||||
|
tax_rate_id: rateTwo.id,
|
||||||
|
reference_id: "shipping_12354",
|
||||||
|
}),
|
||||||
|
expect.objectContaining({
|
||||||
|
tax_rate_id: rateOne.id,
|
||||||
|
reference_id: "product_12354",
|
||||||
|
}),
|
||||||
|
expect.objectContaining({
|
||||||
|
tax_rate_id: rateTwo.id,
|
||||||
|
reference_id: "product_12354",
|
||||||
|
}),
|
||||||
|
])
|
||||||
|
)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
},
|
||||||
const [rateOne, rateTwo] = await service.create([
|
|
||||||
{
|
|
||||||
tax_region_id: taxRegion.id,
|
|
||||||
rate: 10,
|
|
||||||
code: "standard",
|
|
||||||
name: "Standard",
|
|
||||||
rules: [
|
|
||||||
{ reference: "shipping", reference_id: "shipping_12354" },
|
|
||||||
{ reference: "shipping", reference_id: "shipping_11111" },
|
|
||||||
{ reference: "shipping", reference_id: "shipping_22222" },
|
|
||||||
],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
tax_region_id: taxRegion.id,
|
|
||||||
rate: 2,
|
|
||||||
code: "reduced",
|
|
||||||
name: "Reduced",
|
|
||||||
rules: [
|
|
||||||
{ reference: "product", reference_id: "product_12354" },
|
|
||||||
{ reference: "product", reference_id: "product_11111" },
|
|
||||||
{ reference: "product", reference_id: "product_22222" },
|
|
||||||
],
|
|
||||||
},
|
|
||||||
])
|
|
||||||
|
|
||||||
const workflow = updateTaxRatesWorkflow(appContainer)
|
|
||||||
|
|
||||||
workflow.appendAction("throw", createTaxRateRulesStepId, {
|
|
||||||
invoke: async function failStep() {
|
|
||||||
throw new Error(`Failed to update`)
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
await workflow.run({
|
|
||||||
input: {
|
|
||||||
selector: { tax_region_id: taxRegion.id },
|
|
||||||
update: {
|
|
||||||
rate: 2,
|
|
||||||
rules: [
|
|
||||||
{ reference: "product", reference_id: "product_12354" },
|
|
||||||
{ reference: "shipping", reference_id: "shipping_12354" },
|
|
||||||
],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
throwOnError: false,
|
|
||||||
})
|
|
||||||
|
|
||||||
const taxRateRules = await service.listTaxRateRules({
|
|
||||||
tax_rate: { tax_region_id: taxRegion.id },
|
|
||||||
})
|
|
||||||
|
|
||||||
expect(taxRateRules.length).toEqual(6)
|
|
||||||
expect(taxRateRules).toEqual(
|
|
||||||
expect.arrayContaining([
|
|
||||||
expect.objectContaining({
|
|
||||||
tax_rate_id: rateOne.id,
|
|
||||||
reference_id: "shipping_12354",
|
|
||||||
}),
|
|
||||||
expect.objectContaining({
|
|
||||||
tax_rate_id: rateOne.id,
|
|
||||||
reference_id: "shipping_11111",
|
|
||||||
}),
|
|
||||||
expect.objectContaining({
|
|
||||||
tax_rate_id: rateOne.id,
|
|
||||||
reference_id: "shipping_22222",
|
|
||||||
}),
|
|
||||||
expect.objectContaining({
|
|
||||||
tax_rate_id: rateTwo.id,
|
|
||||||
reference_id: "product_12354",
|
|
||||||
}),
|
|
||||||
expect.objectContaining({
|
|
||||||
tax_rate_id: rateTwo.id,
|
|
||||||
reference_id: "product_11111",
|
|
||||||
}),
|
|
||||||
expect.objectContaining({
|
|
||||||
tax_rate_id: rateTwo.id,
|
|
||||||
reference_id: "product_22222",
|
|
||||||
}),
|
|
||||||
])
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
it("creates rules correctly", async () => {
|
|
||||||
const taxRegion = await service.createTaxRegions({
|
|
||||||
country_code: "us",
|
|
||||||
})
|
|
||||||
|
|
||||||
const [rateOne, rateTwo] = await service.create([
|
|
||||||
{
|
|
||||||
tax_region_id: taxRegion.id,
|
|
||||||
rate: 10,
|
|
||||||
code: "standard",
|
|
||||||
name: "Standard",
|
|
||||||
rules: [
|
|
||||||
{ reference: "shipping", reference_id: "shipping_12354" },
|
|
||||||
{ reference: "shipping", reference_id: "shipping_11111" },
|
|
||||||
{ reference: "shipping", reference_id: "shipping_22222" },
|
|
||||||
],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
tax_region_id: taxRegion.id,
|
|
||||||
rate: 2,
|
|
||||||
code: "reduced",
|
|
||||||
name: "Reduced",
|
|
||||||
rules: [
|
|
||||||
{ reference: "product", reference_id: "product_12354" },
|
|
||||||
{ reference: "product", reference_id: "product_11111" },
|
|
||||||
{ reference: "product", reference_id: "product_22222" },
|
|
||||||
],
|
|
||||||
},
|
|
||||||
])
|
|
||||||
|
|
||||||
await updateTaxRatesWorkflow(appContainer).run({
|
|
||||||
input: {
|
|
||||||
selector: { tax_region_id: taxRegion.id },
|
|
||||||
update: {
|
|
||||||
rate: 2,
|
|
||||||
rules: [
|
|
||||||
{ reference: "product", reference_id: "product_12354" },
|
|
||||||
{ reference: "shipping", reference_id: "shipping_12354" },
|
|
||||||
],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
const taxRateRules = await service.listTaxRateRules({
|
|
||||||
tax_rate: { tax_region_id: taxRegion.id },
|
|
||||||
})
|
|
||||||
|
|
||||||
expect(taxRateRules.length).toEqual(4)
|
|
||||||
expect(taxRateRules).toEqual(
|
|
||||||
expect.arrayContaining([
|
|
||||||
expect.objectContaining({
|
|
||||||
tax_rate_id: rateOne.id,
|
|
||||||
reference_id: "shipping_12354",
|
|
||||||
}),
|
|
||||||
expect.objectContaining({
|
|
||||||
tax_rate_id: rateTwo.id,
|
|
||||||
reference_id: "shipping_12354",
|
|
||||||
}),
|
|
||||||
expect.objectContaining({
|
|
||||||
tax_rate_id: rateOne.id,
|
|
||||||
reference_id: "product_12354",
|
|
||||||
}),
|
|
||||||
expect.objectContaining({
|
|
||||||
tax_rate_id: rateTwo.id,
|
|
||||||
reference_id: "product_12354",
|
|
||||||
}),
|
|
||||||
])
|
|
||||||
)
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
@@ -1,10 +1,5 @@
|
|||||||
import { initDb, useDb } from "../../../environment-helpers/use-db"
|
|
||||||
|
|
||||||
import { AxiosInstance } from "axios"
|
|
||||||
import { createAdminUser } from "../../helpers/create-admin-user"
|
import { createAdminUser } from "../../helpers/create-admin-user"
|
||||||
import path from "path"
|
import { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||||
import { startBootstrapApp } from "../../../environment-helpers/bootstrap-app"
|
|
||||||
import { useApi } from "../../../environment-helpers/use-api"
|
|
||||||
|
|
||||||
jest.setTimeout(50000)
|
jest.setTimeout(50000)
|
||||||
|
|
||||||
@@ -13,43 +8,26 @@ const adminHeaders = {
|
|||||||
headers: { "x-medusa-access-token": "test_token" },
|
headers: { "x-medusa-access-token": "test_token" },
|
||||||
}
|
}
|
||||||
|
|
||||||
describe("POST /admin/users", () => {
|
medusaIntegrationTestRunner({
|
||||||
let dbConnection
|
env,
|
||||||
let shutdownServer
|
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||||
|
describe("POST /admin/users", () => {
|
||||||
|
beforeEach(async () => {
|
||||||
|
await createAdminUser(dbConnection, adminHeaders, getContainer())
|
||||||
|
})
|
||||||
|
|
||||||
beforeAll(async () => {
|
it("create a user", async () => {
|
||||||
const cwd = path.resolve(path.join(__dirname, "..", ".."))
|
const body = {
|
||||||
dbConnection = await initDb({ cwd, env } as any)
|
email: "test_member@test.com",
|
||||||
shutdownServer = await startBootstrapApp({ cwd, env })
|
}
|
||||||
})
|
|
||||||
|
|
||||||
beforeEach(async () => {
|
const response = await api.post(`/admin/users`, body, adminHeaders)
|
||||||
await createAdminUser(dbConnection, adminHeaders)
|
|
||||||
})
|
|
||||||
|
|
||||||
afterAll(async () => {
|
expect(response.status).toEqual(200)
|
||||||
const db = useDb()
|
expect(response.data).toEqual({
|
||||||
await db.shutdown()
|
user: expect.objectContaining(body),
|
||||||
await shutdownServer()
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
afterEach(async () => {
|
|
||||||
const db = useDb()
|
|
||||||
await db.teardown()
|
|
||||||
})
|
|
||||||
|
|
||||||
it("create a user", async () => {
|
|
||||||
const api = useApi()! as AxiosInstance
|
|
||||||
|
|
||||||
const body = {
|
|
||||||
email: "test_member@test.com",
|
|
||||||
}
|
|
||||||
|
|
||||||
const response = await api.post(`/admin/users`, body, adminHeaders)
|
|
||||||
|
|
||||||
expect(response.status).toEqual(200)
|
|
||||||
expect(response.data).toEqual({
|
|
||||||
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 { IUserModuleService } from "@medusajs/types"
|
||||||
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||||
import { createAdminUser } from "../../helpers/create-admin-user"
|
import { createAdminUser } from "../../helpers/create-admin-user"
|
||||||
import { getContainer } from "../../../environment-helpers/use-container"
|
import { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||||
import path from "path"
|
|
||||||
import { startBootstrapApp } from "../../../environment-helpers/bootstrap-app"
|
|
||||||
import { useApi } from "../../../environment-helpers/use-api"
|
|
||||||
|
|
||||||
jest.setTimeout(50000)
|
jest.setTimeout(50000)
|
||||||
|
|
||||||
@@ -16,56 +10,46 @@ const adminHeaders = {
|
|||||||
headers: { "x-medusa-access-token": "test_token" },
|
headers: { "x-medusa-access-token": "test_token" },
|
||||||
}
|
}
|
||||||
|
|
||||||
describe("DELETE /admin/users/:id", () => {
|
medusaIntegrationTestRunner({
|
||||||
let dbConnection
|
env,
|
||||||
let appContainer
|
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||||
let shutdownServer
|
describe("DELETE /admin/users/:id", () => {
|
||||||
let userModuleService: IUserModuleService
|
let appContainer
|
||||||
|
let userModuleService: IUserModuleService
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
const cwd = path.resolve(path.join(__dirname, "..", ".."))
|
appContainer = getContainer()
|
||||||
dbConnection = await initDb({ cwd, env } as any)
|
userModuleService = appContainer.resolve(ModuleRegistrationName.USER)
|
||||||
shutdownServer = await startBootstrapApp({ cwd, env })
|
})
|
||||||
appContainer = getContainer()
|
|
||||||
userModuleService = appContainer.resolve(ModuleRegistrationName.USER)
|
|
||||||
})
|
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
await createAdminUser(dbConnection, adminHeaders)
|
await createAdminUser(dbConnection, adminHeaders, appContainer)
|
||||||
})
|
})
|
||||||
|
|
||||||
afterAll(async () => {
|
it("should delete a single user", async () => {
|
||||||
const db = useDb()
|
const user = await userModuleService.create({
|
||||||
await db.shutdown()
|
email: "member@test.com",
|
||||||
await shutdownServer()
|
})
|
||||||
})
|
|
||||||
|
|
||||||
afterEach(async () => {
|
const response = await api.delete(
|
||||||
const db = useDb()
|
`/admin/users/${user.id}`,
|
||||||
await db.teardown()
|
adminHeaders
|
||||||
})
|
)
|
||||||
|
|
||||||
it("should delete a single user", async () => {
|
expect(response.status).toEqual(200)
|
||||||
const user = await userModuleService.create({
|
expect(response.data).toEqual({
|
||||||
email: "member@test.com",
|
id: user.id,
|
||||||
|
object: "user",
|
||||||
|
deleted: true,
|
||||||
|
})
|
||||||
|
|
||||||
|
const { response: deletedResponse } = await api
|
||||||
|
.get(`/admin/users/${user.id}`, adminHeaders)
|
||||||
|
.catch((e) => e)
|
||||||
|
|
||||||
|
expect(deletedResponse.status).toEqual(404)
|
||||||
|
expect(deletedResponse.data.type).toEqual("not_found")
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
},
|
||||||
const api = useApi()! as AxiosInstance
|
|
||||||
|
|
||||||
const response = await api.delete(`/admin/users/${user.id}`, adminHeaders)
|
|
||||||
|
|
||||||
expect(response.status).toEqual(200)
|
|
||||||
expect(response.data).toEqual({
|
|
||||||
id: user.id,
|
|
||||||
object: "user",
|
|
||||||
deleted: true,
|
|
||||||
})
|
|
||||||
|
|
||||||
const { response: deletedResponse } = await api
|
|
||||||
.get(`/admin/users/${user.id}`, adminHeaders)
|
|
||||||
.catch((e) => e)
|
|
||||||
|
|
||||||
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 { createAdminUser } from "../../helpers/create-admin-user"
|
||||||
|
import { medusaIntegrationTestRunner } from "medusa-test-utils/dist"
|
||||||
|
|
||||||
jest.setTimeout(50000)
|
jest.setTimeout(50000)
|
||||||
|
|
||||||
@@ -13,39 +8,22 @@ const adminHeaders = {
|
|||||||
headers: { "x-medusa-access-token": "test_token" },
|
headers: { "x-medusa-access-token": "test_token" },
|
||||||
}
|
}
|
||||||
|
|
||||||
describe("POST /admin/users/me", () => {
|
medusaIntegrationTestRunner({
|
||||||
let dbConnection
|
env,
|
||||||
let shutdownServer
|
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||||
|
describe("POST /admin/users/me", () => {
|
||||||
|
beforeEach(async () => {
|
||||||
|
await createAdminUser(dbConnection, adminHeaders)
|
||||||
|
})
|
||||||
|
|
||||||
beforeAll(async () => {
|
it("gets the current user", async () => {
|
||||||
const cwd = path.resolve(path.join(__dirname, "..", ".."))
|
const response = await api.get(`/admin/users/me`, adminHeaders)
|
||||||
dbConnection = await initDb({ cwd, env } as any)
|
|
||||||
shutdownServer = await startBootstrapApp({ cwd, env })
|
|
||||||
})
|
|
||||||
|
|
||||||
beforeEach(async () => {
|
expect(response.status).toEqual(200)
|
||||||
await createAdminUser(dbConnection, adminHeaders)
|
expect(response.data).toEqual({
|
||||||
})
|
user: expect.objectContaining({ id: "admin_user" }),
|
||||||
|
})
|
||||||
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)
|
|
||||||
expect(response.data).toEqual({
|
|
||||||
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 { IUserModuleService } from "@medusajs/types"
|
||||||
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||||
import { createAdminUser } from "../../helpers/create-admin-user"
|
import { createAdminUser } from "../../helpers/create-admin-user"
|
||||||
import { getContainer } from "../../../environment-helpers/use-container"
|
import { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||||
import path from "path"
|
|
||||||
import { startBootstrapApp } from "../../../environment-helpers/bootstrap-app"
|
|
||||||
import { useApi } from "../../../environment-helpers/use-api"
|
|
||||||
|
|
||||||
jest.setTimeout(50000)
|
jest.setTimeout(50000)
|
||||||
|
|
||||||
@@ -16,57 +10,44 @@ const adminHeaders = {
|
|||||||
headers: { "x-medusa-access-token": "test_token" },
|
headers: { "x-medusa-access-token": "test_token" },
|
||||||
}
|
}
|
||||||
|
|
||||||
describe("GET /admin/users", () => {
|
medusaIntegrationTestRunner({
|
||||||
let dbConnection
|
env,
|
||||||
let appContainer
|
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||||
let shutdownServer
|
describe("GET /admin/users", () => {
|
||||||
let userModuleService: IUserModuleService
|
let appContainer
|
||||||
|
let userModuleService: IUserModuleService
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
const cwd = path.resolve(path.join(__dirname, "..", ".."))
|
appContainer = getContainer()
|
||||||
dbConnection = await initDb({ cwd, env } as any)
|
userModuleService = appContainer.resolve(ModuleRegistrationName.USER)
|
||||||
shutdownServer = await startBootstrapApp({ cwd, env })
|
})
|
||||||
appContainer = getContainer()
|
|
||||||
userModuleService = appContainer.resolve(ModuleRegistrationName.USER)
|
|
||||||
})
|
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
await createAdminUser(dbConnection, adminHeaders)
|
await createAdminUser(dbConnection, adminHeaders, appContainer)
|
||||||
})
|
})
|
||||||
|
|
||||||
afterAll(async () => {
|
it("should list users", async () => {
|
||||||
const db = useDb()
|
await userModuleService.create([
|
||||||
await db.shutdown()
|
{
|
||||||
await shutdownServer()
|
email: "member@test.com",
|
||||||
})
|
},
|
||||||
|
])
|
||||||
|
|
||||||
afterEach(async () => {
|
const response = await api.get(`/admin/users`, adminHeaders)
|
||||||
const db = useDb()
|
|
||||||
await db.teardown()
|
|
||||||
})
|
|
||||||
|
|
||||||
it("should list users", async () => {
|
expect(response.status).toEqual(200)
|
||||||
await userModuleService.create([
|
expect(response.data).toEqual({
|
||||||
{
|
users: expect.arrayContaining([
|
||||||
email: "member@test.com",
|
expect.objectContaining({
|
||||||
},
|
email: "admin@medusa.js",
|
||||||
])
|
}),
|
||||||
|
expect.objectContaining({ email: "member@test.com" }),
|
||||||
const api = useApi()! as AxiosInstance
|
]),
|
||||||
|
count: 2,
|
||||||
const response = await api.get(`/admin/users`, adminHeaders)
|
offset: 0,
|
||||||
|
limit: 50,
|
||||||
expect(response.status).toEqual(200)
|
})
|
||||||
expect(response.data).toEqual({
|
})
|
||||||
users: expect.arrayContaining([
|
|
||||||
expect.objectContaining({
|
|
||||||
email: "admin@medusa.js",
|
|
||||||
}),
|
|
||||||
expect.objectContaining({ email: "member@test.com" }),
|
|
||||||
]),
|
|
||||||
count: 2,
|
|
||||||
offset: 0,
|
|
||||||
limit: 50,
|
|
||||||
})
|
})
|
||||||
})
|
},
|
||||||
})
|
})
|
||||||
@@ -1,13 +1,7 @@
|
|||||||
import { initDb, useDb } from "../../../environment-helpers/use-db"
|
|
||||||
|
|
||||||
import { AxiosInstance } from "axios"
|
|
||||||
import { IUserModuleService } from "@medusajs/types"
|
import { IUserModuleService } from "@medusajs/types"
|
||||||
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||||
import { createAdminUser } from "../../helpers/create-admin-user"
|
import { createAdminUser } from "../../helpers/create-admin-user"
|
||||||
import { getContainer } from "../../../environment-helpers/use-container"
|
import { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||||
import path from "path"
|
|
||||||
import { startBootstrapApp } from "../../../environment-helpers/bootstrap-app"
|
|
||||||
import { useApi } from "../../../environment-helpers/use-api"
|
|
||||||
|
|
||||||
jest.setTimeout(50000)
|
jest.setTimeout(50000)
|
||||||
|
|
||||||
@@ -16,47 +10,34 @@ const adminHeaders = {
|
|||||||
headers: { "x-medusa-access-token": "test_token" },
|
headers: { "x-medusa-access-token": "test_token" },
|
||||||
}
|
}
|
||||||
|
|
||||||
describe("GET /admin/users/:id", () => {
|
medusaIntegrationTestRunner({
|
||||||
let dbConnection
|
env,
|
||||||
let appContainer
|
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||||
let shutdownServer
|
describe("GET /admin/users/:id", () => {
|
||||||
let userModuleService: IUserModuleService
|
let appContainer
|
||||||
|
let userModuleService: IUserModuleService
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
const cwd = path.resolve(path.join(__dirname, "..", ".."))
|
appContainer = getContainer()
|
||||||
dbConnection = await initDb({ cwd, env } as any)
|
userModuleService = appContainer.resolve(ModuleRegistrationName.USER)
|
||||||
shutdownServer = await startBootstrapApp({ cwd, env })
|
})
|
||||||
appContainer = getContainer()
|
|
||||||
userModuleService = appContainer.resolve(ModuleRegistrationName.USER)
|
|
||||||
})
|
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
await createAdminUser(dbConnection, adminHeaders)
|
await createAdminUser(dbConnection, adminHeaders, appContainer)
|
||||||
})
|
})
|
||||||
|
|
||||||
afterAll(async () => {
|
it("should retrieve a single user", async () => {
|
||||||
const db = useDb()
|
const user = await userModuleService.create({
|
||||||
await db.shutdown()
|
email: "member@test.com",
|
||||||
await shutdownServer()
|
})
|
||||||
})
|
|
||||||
|
|
||||||
afterEach(async () => {
|
const response = await api.get(`/admin/users/${user.id}`, adminHeaders)
|
||||||
const db = useDb()
|
|
||||||
await db.teardown()
|
|
||||||
})
|
|
||||||
|
|
||||||
it("should retrieve a single user", async () => {
|
expect(response.status).toEqual(200)
|
||||||
const user = await userModuleService.create({
|
expect(response.data.user).toEqual(
|
||||||
email: "member@test.com",
|
expect.objectContaining({ email: "member@test.com" })
|
||||||
|
)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
},
|
||||||
const api = useApi()! as AxiosInstance
|
|
||||||
|
|
||||||
const response = await api.get(`/admin/users/${user.id}`, adminHeaders)
|
|
||||||
|
|
||||||
expect(response.status).toEqual(200)
|
|
||||||
expect(response.data.user).toEqual(
|
|
||||||
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 { IUserModuleService } from "@medusajs/types"
|
||||||
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||||
import { createAdminUser } from "../../helpers/create-admin-user"
|
import { createAdminUser } from "../../helpers/create-admin-user"
|
||||||
import { getContainer } from "../../../environment-helpers/use-container"
|
import { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||||
import path from "path"
|
|
||||||
import { startBootstrapApp } from "../../../environment-helpers/bootstrap-app"
|
|
||||||
import { useApi } from "../../../environment-helpers/use-api"
|
|
||||||
|
|
||||||
jest.setTimeout(50000)
|
jest.setTimeout(50000)
|
||||||
|
|
||||||
@@ -16,53 +10,40 @@ const adminHeaders = {
|
|||||||
headers: { "x-medusa-access-token": "test_token" },
|
headers: { "x-medusa-access-token": "test_token" },
|
||||||
}
|
}
|
||||||
|
|
||||||
describe("POST /admin/users/:id", () => {
|
medusaIntegrationTestRunner({
|
||||||
let dbConnection
|
env,
|
||||||
let appContainer
|
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||||
let shutdownServer
|
describe("POST /admin/users/:id", () => {
|
||||||
let userModuleService: IUserModuleService
|
let appContainer
|
||||||
|
let userModuleService: IUserModuleService
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
const cwd = path.resolve(path.join(__dirname, "..", ".."))
|
appContainer = getContainer()
|
||||||
dbConnection = await initDb({ cwd, env } as any)
|
userModuleService = appContainer.resolve(ModuleRegistrationName.USER)
|
||||||
shutdownServer = await startBootstrapApp({ cwd, env })
|
})
|
||||||
appContainer = getContainer()
|
|
||||||
userModuleService = appContainer.resolve(ModuleRegistrationName.USER)
|
|
||||||
})
|
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
await createAdminUser(dbConnection, adminHeaders)
|
await createAdminUser(dbConnection, adminHeaders, appContainer)
|
||||||
})
|
})
|
||||||
|
|
||||||
afterAll(async () => {
|
it("should update a single user", async () => {
|
||||||
const db = useDb()
|
const user = await userModuleService.create({
|
||||||
await db.shutdown()
|
email: "member@test.com",
|
||||||
await shutdownServer()
|
})
|
||||||
})
|
|
||||||
|
|
||||||
afterEach(async () => {
|
const body = {
|
||||||
const db = useDb()
|
first_name: "John",
|
||||||
await db.teardown()
|
last_name: "Doe",
|
||||||
})
|
}
|
||||||
|
const response = await api.post(
|
||||||
|
`/admin/users/${user.id}`,
|
||||||
|
body,
|
||||||
|
adminHeaders
|
||||||
|
)
|
||||||
|
|
||||||
it("should update a single user", async () => {
|
expect(response.status).toEqual(200)
|
||||||
const user = await userModuleService.create({
|
expect(response.data.user).toEqual(expect.objectContaining(body))
|
||||||
email: "member@test.com",
|
})
|
||||||
})
|
})
|
||||||
|
},
|
||||||
const api = useApi()! as AxiosInstance
|
|
||||||
|
|
||||||
const body = {
|
|
||||||
first_name: "John",
|
|
||||||
last_name: "Doe",
|
|
||||||
}
|
|
||||||
const response = await api.post(
|
|
||||||
`/admin/users/${user.id}`,
|
|
||||||
body,
|
|
||||||
adminHeaders
|
|
||||||
)
|
|
||||||
|
|
||||||
expect(response.status).toEqual(200)
|
|
||||||
expect(response.data.user).toEqual(expect.objectContaining(body))
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
@@ -4,6 +4,7 @@ jest.setTimeout(5000000)
|
|||||||
|
|
||||||
const env = {
|
const env = {
|
||||||
MEDUSA_FF_MEDUSA_V2: false,
|
MEDUSA_FF_MEDUSA_V2: false,
|
||||||
|
MEDUSA_FF_SALES_CHANNELS: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
workflowEngineTestSuite(env, { force_modules_migration: true })
|
workflowEngineTestSuite(env, { force_modules_migration: true })
|
||||||
@@ -4,266 +4,257 @@ import {
|
|||||||
StepResponse,
|
StepResponse,
|
||||||
WorkflowData,
|
WorkflowData,
|
||||||
} from "@medusajs/workflows-sdk"
|
} from "@medusajs/workflows-sdk"
|
||||||
import { initDb, useDb } from "../../../environment-helpers/use-db"
|
|
||||||
|
|
||||||
import { AxiosInstance } from "axios"
|
|
||||||
import adminSeeder from "../../../helpers/admin-seeder"
|
|
||||||
import { createAdminUser } from "../../helpers/create-admin-user"
|
import { createAdminUser } from "../../helpers/create-admin-user"
|
||||||
import { getContainer } from "../../../environment-helpers/use-container"
|
import { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||||
import path from "path"
|
|
||||||
import { startBootstrapApp } from "../../../environment-helpers/bootstrap-app"
|
|
||||||
import { useApi } from "../../../environment-helpers/use-api"
|
|
||||||
|
|
||||||
export const workflowEngineTestSuite = (env, extraParams = {}) => {
|
export const workflowEngineTestSuite = (
|
||||||
|
env,
|
||||||
|
extraParams: { force_modules_migration?: boolean } = {}
|
||||||
|
) => {
|
||||||
const adminHeaders = {
|
const adminHeaders = {
|
||||||
headers: {
|
headers: {
|
||||||
"x-medusa-access-token": "test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
describe("Workflow Engine API", () => {
|
return medusaIntegrationTestRunner({
|
||||||
let medusaContainer
|
env,
|
||||||
let dbConnection
|
force_modules_migration: extraParams.force_modules_migration,
|
||||||
let shutdownServer
|
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||||
|
describe("Workflow Engine API", () => {
|
||||||
|
let medusaContainer
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(() => {
|
||||||
const cwd = path.resolve(path.join(__dirname, "..", ".."))
|
medusaContainer = getContainer()
|
||||||
dbConnection = await initDb({ cwd, env, ...extraParams } as any)
|
})
|
||||||
shutdownServer = await startBootstrapApp({ cwd, env })
|
|
||||||
medusaContainer = getContainer()
|
|
||||||
|
|
||||||
await createAdminUser(dbConnection, adminHeaders)
|
beforeEach(async () => {
|
||||||
})
|
await createAdminUser(dbConnection, adminHeaders, medusaContainer)
|
||||||
|
})
|
||||||
|
|
||||||
afterAll(async () => {
|
describe("running workflows", () => {
|
||||||
const db = useDb()
|
beforeAll(async () => {
|
||||||
await db.shutdown()
|
const step1 = createStep(
|
||||||
await shutdownServer()
|
{
|
||||||
})
|
name: "my-step",
|
||||||
|
|
||||||
describe("running workflows", () => {
|
|
||||||
beforeAll(async () => {
|
|
||||||
const step1 = createStep(
|
|
||||||
{
|
|
||||||
name: "my-step",
|
|
||||||
},
|
|
||||||
async (input: { initial: string }) => {
|
|
||||||
return new StepResponse({
|
|
||||||
result: input.initial,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
)
|
|
||||||
const step2 = createStep(
|
|
||||||
{
|
|
||||||
name: "my-step-async",
|
|
||||||
async: true,
|
|
||||||
},
|
|
||||||
async () => {}
|
|
||||||
)
|
|
||||||
|
|
||||||
createWorkflow(
|
|
||||||
{
|
|
||||||
name: "my-workflow-name",
|
|
||||||
retentionTime: 1000,
|
|
||||||
},
|
|
||||||
function (input: WorkflowData<{ initial: string }>) {
|
|
||||||
step1(input)
|
|
||||||
return step2()
|
|
||||||
}
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
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`,
|
|
||||||
{
|
|
||||||
input: {
|
|
||||||
initial: "abc",
|
|
||||||
},
|
},
|
||||||
},
|
async (input: { initial: string }) => {
|
||||||
adminHeaders
|
return new StepResponse({
|
||||||
)
|
result: input.initial,
|
||||||
}
|
})
|
||||||
|
}
|
||||||
const executions = await api.get(
|
)
|
||||||
`/admin/workflows-executions`,
|
const step2 = createStep(
|
||||||
adminHeaders
|
{
|
||||||
)
|
name: "my-step-async",
|
||||||
|
async: true,
|
||||||
expect(executions.data.count).toEqual(3)
|
|
||||||
expect(executions.data.workflow_executions.length).toEqual(3)
|
|
||||||
expect(executions.data.workflow_executions[0]).toEqual({
|
|
||||||
workflow_id: "my-workflow-name",
|
|
||||||
transaction_id: expect.any(String),
|
|
||||||
id: expect.any(String),
|
|
||||||
state: "invoking",
|
|
||||||
created_at: expect.any(String),
|
|
||||||
updated_at: expect.any(String),
|
|
||||||
deleted_at: null,
|
|
||||||
})
|
|
||||||
|
|
||||||
const retrivedById = await api.get(
|
|
||||||
`/admin/workflows-executions/` +
|
|
||||||
executions.data.workflow_executions[0].id,
|
|
||||||
adminHeaders
|
|
||||||
)
|
|
||||||
expect(retrivedById.data.workflow_execution).toEqual(
|
|
||||||
expect.objectContaining(executions.data.workflow_executions[0])
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
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`,
|
|
||||||
{
|
|
||||||
input: {
|
|
||||||
initial: "abc",
|
|
||||||
},
|
},
|
||||||
transaction_id: "transaction_" + (i + 1),
|
async () => {}
|
||||||
},
|
)
|
||||||
adminHeaders
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
const executions = await api.get(
|
createWorkflow(
|
||||||
`/admin/workflows-executions?transaction_id[]=transaction_1&transaction_id[]=transaction_2`,
|
{
|
||||||
adminHeaders
|
name: "my-workflow-name",
|
||||||
)
|
retentionTime: 1000,
|
||||||
|
},
|
||||||
|
function (input: WorkflowData<{ initial: string }>) {
|
||||||
|
step1(input)
|
||||||
|
return step2()
|
||||||
|
}
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
expect(executions.data.count).toEqual(2)
|
it("Should list all workflows in execution or completed and retrieve them by id", async () => {
|
||||||
expect(executions.data.workflow_executions.length).toEqual(2)
|
for (let i = 3; i--; ) {
|
||||||
expect(executions.data.workflow_executions[0]).toEqual({
|
await api.post(
|
||||||
workflow_id: "my-workflow-name",
|
`/admin/workflows-executions/my-workflow-name/run`,
|
||||||
transaction_id: expect.stringMatching(/transaction_1|transaction_2/),
|
{
|
||||||
id: expect.any(String),
|
input: {
|
||||||
state: "invoking",
|
initial: "abc",
|
||||||
created_at: expect.any(String),
|
|
||||||
updated_at: expect.any(String),
|
|
||||||
deleted_at: null,
|
|
||||||
})
|
|
||||||
expect(executions.data.workflow_executions[1]).toEqual({
|
|
||||||
workflow_id: "my-workflow-name",
|
|
||||||
transaction_id: expect.stringMatching(/transaction_1|transaction_2/),
|
|
||||||
id: expect.any(String),
|
|
||||||
state: "invoking",
|
|
||||||
created_at: expect.any(String),
|
|
||||||
updated_at: expect.any(String),
|
|
||||||
deleted_at: null,
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
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`,
|
|
||||||
{
|
|
||||||
input: {
|
|
||||||
initial: "abc",
|
|
||||||
},
|
|
||||||
transaction_id: "trx_123",
|
|
||||||
},
|
|
||||||
adminHeaders
|
|
||||||
)
|
|
||||||
|
|
||||||
expect(wf.data).toEqual({
|
|
||||||
acknowledgement: {
|
|
||||||
transactionId: "trx_123",
|
|
||||||
workflowId: "my-workflow-name",
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
const execution = await api.get(
|
|
||||||
`/admin/workflows-executions/my-workflow-name/trx_123`,
|
|
||||||
adminHeaders
|
|
||||||
)
|
|
||||||
|
|
||||||
expect(execution.data).toEqual({
|
|
||||||
workflow_execution: expect.objectContaining({
|
|
||||||
workflow_id: "my-workflow-name",
|
|
||||||
transaction_id: "trx_123",
|
|
||||||
id: expect.any(String),
|
|
||||||
state: "invoking",
|
|
||||||
execution: expect.objectContaining({
|
|
||||||
hasAsyncSteps: true,
|
|
||||||
hasFailedSteps: false,
|
|
||||||
hasSkippedSteps: false,
|
|
||||||
hasWaitingSteps: false,
|
|
||||||
hasRevertedSteps: false,
|
|
||||||
}),
|
|
||||||
context: expect.objectContaining({
|
|
||||||
data: expect.objectContaining({
|
|
||||||
invoke: {
|
|
||||||
"my-step": {
|
|
||||||
__type: "Symbol(WorkflowWorkflowData)",
|
|
||||||
output: {
|
|
||||||
__type: "Symbol(WorkflowStepResponse)",
|
|
||||||
output: {
|
|
||||||
result: "abc",
|
|
||||||
},
|
|
||||||
compensateInput: {
|
|
||||||
result: "abc",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
payload: {
|
adminHeaders
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
const executions = await api.get(
|
||||||
|
`/admin/workflows-executions`,
|
||||||
|
adminHeaders
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(executions.data.count).toEqual(3)
|
||||||
|
expect(executions.data.workflow_executions.length).toEqual(3)
|
||||||
|
expect(executions.data.workflow_executions[0]).toEqual({
|
||||||
|
workflow_id: "my-workflow-name",
|
||||||
|
transaction_id: expect.any(String),
|
||||||
|
id: expect.any(String),
|
||||||
|
state: "invoking",
|
||||||
|
created_at: expect.any(String),
|
||||||
|
updated_at: expect.any(String),
|
||||||
|
deleted_at: null,
|
||||||
|
})
|
||||||
|
|
||||||
|
const retrivedById = await api.get(
|
||||||
|
`/admin/workflows-executions/` +
|
||||||
|
executions.data.workflow_executions[0].id,
|
||||||
|
adminHeaders
|
||||||
|
)
|
||||||
|
expect(retrivedById.data.workflow_execution).toEqual(
|
||||||
|
expect.objectContaining(executions.data.workflow_executions[0])
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
it("Should list all workflows matching the filters", async () => {
|
||||||
|
for (let i = 3; i--; ) {
|
||||||
|
await api.post(
|
||||||
|
`/admin/workflows-executions/my-workflow-name/run`,
|
||||||
|
{
|
||||||
|
input: {
|
||||||
|
initial: "abc",
|
||||||
|
},
|
||||||
|
transaction_id: "transaction_" + (i + 1),
|
||||||
|
},
|
||||||
|
adminHeaders
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
const executions = await api.get(
|
||||||
|
`/admin/workflows-executions?transaction_id[]=transaction_1&transaction_id[]=transaction_2`,
|
||||||
|
adminHeaders
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(executions.data.count).toEqual(2)
|
||||||
|
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/
|
||||||
|
),
|
||||||
|
id: expect.any(String),
|
||||||
|
state: "invoking",
|
||||||
|
created_at: expect.any(String),
|
||||||
|
updated_at: expect.any(String),
|
||||||
|
deleted_at: null,
|
||||||
|
})
|
||||||
|
expect(executions.data.workflow_executions[1]).toEqual({
|
||||||
|
workflow_id: "my-workflow-name",
|
||||||
|
transaction_id: expect.stringMatching(
|
||||||
|
/transaction_1|transaction_2/
|
||||||
|
),
|
||||||
|
id: expect.any(String),
|
||||||
|
state: "invoking",
|
||||||
|
created_at: expect.any(String),
|
||||||
|
updated_at: expect.any(String),
|
||||||
|
deleted_at: null,
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it("Should execute a workflow and retrieve its execution while running and when it is completed", async () => {
|
||||||
|
const wf = await api.post(
|
||||||
|
`/admin/workflows-executions/my-workflow-name/run`,
|
||||||
|
{
|
||||||
|
input: {
|
||||||
initial: "abc",
|
initial: "abc",
|
||||||
},
|
},
|
||||||
}),
|
transaction_id: "trx_123",
|
||||||
}),
|
},
|
||||||
}),
|
adminHeaders
|
||||||
})
|
)
|
||||||
|
|
||||||
const respondAsync = await api.post(
|
expect(wf.data).toEqual({
|
||||||
`/admin/workflows-executions/my-workflow-name/steps/success`,
|
acknowledgement: {
|
||||||
{
|
transactionId: "trx_123",
|
||||||
transaction_id: "trx_123",
|
workflowId: "my-workflow-name",
|
||||||
step_id: "my-step-async",
|
},
|
||||||
response: {
|
})
|
||||||
all: "good",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
adminHeaders
|
|
||||||
)
|
|
||||||
|
|
||||||
expect(respondAsync.data.success).toEqual(true)
|
const execution = await api.get(
|
||||||
|
`/admin/workflows-executions/my-workflow-name/trx_123`,
|
||||||
|
adminHeaders
|
||||||
|
)
|
||||||
|
|
||||||
const completed = await api.get(
|
expect(execution.data).toEqual({
|
||||||
`/admin/workflows-executions/my-workflow-name/trx_123`,
|
workflow_execution: expect.objectContaining({
|
||||||
adminHeaders
|
workflow_id: "my-workflow-name",
|
||||||
)
|
transaction_id: "trx_123",
|
||||||
|
id: expect.any(String),
|
||||||
expect(completed.data).toEqual({
|
state: "invoking",
|
||||||
workflow_execution: expect.objectContaining({
|
execution: expect.objectContaining({
|
||||||
workflow_id: "my-workflow-name",
|
hasAsyncSteps: true,
|
||||||
transaction_id: "trx_123",
|
hasFailedSteps: false,
|
||||||
state: "done",
|
hasSkippedSteps: false,
|
||||||
context: expect.objectContaining({
|
hasWaitingSteps: false,
|
||||||
data: expect.objectContaining({
|
hasRevertedSteps: false,
|
||||||
invoke: expect.objectContaining({
|
}),
|
||||||
"my-step-async": {
|
context: expect.objectContaining({
|
||||||
__type: "Symbol(WorkflowStepResponse)",
|
data: expect.objectContaining({
|
||||||
output: {
|
invoke: {
|
||||||
all: "good",
|
"my-step": {
|
||||||
|
__type: "Symbol(WorkflowWorkflowData)",
|
||||||
|
output: {
|
||||||
|
__type: "Symbol(WorkflowStepResponse)",
|
||||||
|
output: {
|
||||||
|
result: "abc",
|
||||||
|
},
|
||||||
|
compensateInput: {
|
||||||
|
result: "abc",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
compensateInput: {
|
payload: {
|
||||||
all: "good",
|
initial: "abc",
|
||||||
},
|
},
|
||||||
},
|
}),
|
||||||
}),
|
}),
|
||||||
}),
|
}),
|
||||||
}),
|
})
|
||||||
}),
|
|
||||||
|
const respondAsync = await api.post(
|
||||||
|
`/admin/workflows-executions/my-workflow-name/steps/success`,
|
||||||
|
{
|
||||||
|
transaction_id: "trx_123",
|
||||||
|
step_id: "my-step-async",
|
||||||
|
response: {
|
||||||
|
all: "good",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
adminHeaders
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(respondAsync.data.success).toEqual(true)
|
||||||
|
|
||||||
|
const completed = await api.get(
|
||||||
|
`/admin/workflows-executions/my-workflow-name/trx_123`,
|
||||||
|
adminHeaders
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(completed.data).toEqual({
|
||||||
|
workflow_execution: expect.objectContaining({
|
||||||
|
workflow_id: "my-workflow-name",
|
||||||
|
transaction_id: "trx_123",
|
||||||
|
state: "done",
|
||||||
|
context: expect.objectContaining({
|
||||||
|
data: expect.objectContaining({
|
||||||
|
invoke: expect.objectContaining({
|
||||||
|
"my-step-async": {
|
||||||
|
__type: "Symbol(WorkflowStepResponse)",
|
||||||
|
output: {
|
||||||
|
all: "good",
|
||||||
|
},
|
||||||
|
compensateInput: {
|
||||||
|
all: "good",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
}),
|
||||||
|
}),
|
||||||
|
}),
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,9 +4,13 @@ import jwt from "jsonwebtoken"
|
|||||||
import { getContainer } from "../../environment-helpers/use-container"
|
import { getContainer } from "../../environment-helpers/use-container"
|
||||||
import adminSeeder from "../../helpers/admin-seeder"
|
import adminSeeder from "../../helpers/admin-seeder"
|
||||||
|
|
||||||
export const createAdminUser = async (dbConnection, adminHeaders) => {
|
export const createAdminUser = async (
|
||||||
|
dbConnection,
|
||||||
|
adminHeaders,
|
||||||
|
container?
|
||||||
|
) => {
|
||||||
await adminSeeder(dbConnection)
|
await adminSeeder(dbConnection)
|
||||||
const appContainer = getContainer()!
|
const appContainer = container ?? getContainer()!
|
||||||
|
|
||||||
const authModule: IAuthModuleService = appContainer.resolve(
|
const authModule: IAuthModuleService = appContainer.resolve(
|
||||||
ModuleRegistrationName.AUTH
|
ModuleRegistrationName.AUTH
|
||||||
|
|||||||
@@ -15,9 +15,11 @@ module.exports = {
|
|||||||
`.cache`,
|
`.cache`,
|
||||||
],
|
],
|
||||||
transformIgnorePatterns: [`/dist`],
|
transformIgnorePatterns: [`/dist`],
|
||||||
transform: { "^.+\\.[jt]s$": `../../jest-transformer.js` },
|
transform: {
|
||||||
|
"^.+\\.[jt]s$": `../../jest-transformer.js`,
|
||||||
|
},
|
||||||
setupFiles: ["../setup-env.js"],
|
setupFiles: ["../setup-env.js"],
|
||||||
setupFilesAfterEnv: ["../setup.js"],
|
/*setupFilesAfterEnv: ["../setup.js"],
|
||||||
globalSetup: "../globalSetup.js",
|
globalSetup: "../globalSetup.js",
|
||||||
globalTeardown: "../globalTeardown.js",
|
globalTeardown: "../globalTeardown.js",*/
|
||||||
}
|
}
|
||||||
@@ -5,7 +5,7 @@
|
|||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test:integration": "node --expose-gc ./../../node_modules/.bin/jest --silent=false --runInBand --bail --detectOpenHandles --logHeapUsage --clearMocks --forceExit",
|
"test:integration": "node --expose-gc ./../../node_modules/.bin/jest --ci --silent=false -i --detectOpenHandles --logHeapUsage --forceExit",
|
||||||
"build": "babel src -d dist --extensions \".ts,.js\""
|
"build": "babel src -d dist --extensions \".ts,.js\""
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
@@ -30,6 +30,7 @@
|
|||||||
"medusa-fulfillment-webshipper": "workspace:*",
|
"medusa-fulfillment-webshipper": "workspace:*",
|
||||||
"medusa-interfaces": "workspace:*",
|
"medusa-interfaces": "workspace:*",
|
||||||
"medusa-plugin-sendgrid": "workspace:*",
|
"medusa-plugin-sendgrid": "workspace:*",
|
||||||
|
"medusa-test-utils": "workspace:*",
|
||||||
"pg": "^8.11.0",
|
"pg": "^8.11.0",
|
||||||
"typeorm": "^0.3.16"
|
"typeorm": "^0.3.16"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -24,18 +24,46 @@
|
|||||||
"author": "Sebastian Rindom",
|
"author": "Sebastian Rindom",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"@medusajs/types": "^1.1.41",
|
||||||
"cross-env": "^5.2.1",
|
"cross-env": "^5.2.1",
|
||||||
"jest": "^25.5.4",
|
"jest": "^25.5.4",
|
||||||
"rimraf": "^3.0.2",
|
"rimraf": "^3.0.2",
|
||||||
"typescript": "^5.1.6"
|
"typescript": "^5.1.6"
|
||||||
},
|
},
|
||||||
|
"peerDependencies": {
|
||||||
|
"@medusajs/medusa": ">1.19",
|
||||||
|
"axios": "^0.28.0",
|
||||||
|
"express": "^4.18.3",
|
||||||
|
"get-port": "^5.1.0",
|
||||||
|
"pg-god": "^1.0.12",
|
||||||
|
"typeorm": "^0.2.43"
|
||||||
|
},
|
||||||
|
"peerDependenciesMeta": {
|
||||||
|
"@medusajs/medusa": {
|
||||||
|
"optional": true
|
||||||
|
},
|
||||||
|
"axios": {
|
||||||
|
"optional": true
|
||||||
|
},
|
||||||
|
"express": {
|
||||||
|
"optional": true
|
||||||
|
},
|
||||||
|
"get-port": {
|
||||||
|
"optional": true
|
||||||
|
},
|
||||||
|
"pg-god": {
|
||||||
|
"optional": true
|
||||||
|
},
|
||||||
|
"typeorm": {
|
||||||
|
"optional": true
|
||||||
|
}
|
||||||
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@medusajs/modules-sdk": "^1.12.6",
|
"@medusajs/modules-sdk": "^1.12.6",
|
||||||
"@medusajs/utils": "^1.1.41",
|
"@medusajs/utils": "^1.1.41",
|
||||||
"@mikro-orm/migrations": "5.9.7",
|
"@mikro-orm/migrations": "5.9.7",
|
||||||
"@mikro-orm/postgresql": "5.9.7",
|
"@mikro-orm/postgresql": "5.9.7",
|
||||||
"medusa-core-utils": "^1.2.1",
|
"medusa-core-utils": "^1.2.1",
|
||||||
"pg-god": "^1.0.12",
|
|
||||||
"randomatic": "^3.1.1"
|
"randomatic": "^3.1.1"
|
||||||
},
|
},
|
||||||
"gitHead": "81a7ff73d012fda722f6e9ef0bd9ba0232d37808"
|
"gitHead": "81a7ff73d012fda722f6e9ef0bd9ba0232d37808"
|
||||||
|
|||||||
@@ -6,3 +6,4 @@ export { default as MockRepository } from "./mock-repository"
|
|||||||
export * from "./init-modules"
|
export * from "./init-modules"
|
||||||
export { default as MockEventBusService } from "./mock-event-bus-service"
|
export { default as MockEventBusService } from "./mock-event-bus-service"
|
||||||
export * from "./module-test-runner"
|
export * from "./module-test-runner"
|
||||||
|
export * from "./medusa-test-runner"
|
||||||
@@ -0,0 +1,79 @@
|
|||||||
|
const path = require("path")
|
||||||
|
const express = require("express")
|
||||||
|
const getPort = require("get-port")
|
||||||
|
const { isObject } = require("@medusajs/utils")
|
||||||
|
|
||||||
|
async function bootstrapApp({ cwd, env = {} } = {}) {
|
||||||
|
const app = express()
|
||||||
|
|
||||||
|
if (isObject(env)) {
|
||||||
|
Object.entries(env).forEach(([k, v]) => (process.env[k] = v))
|
||||||
|
}
|
||||||
|
|
||||||
|
const loaders = require("@medusajs/medusa/dist/loaders").default
|
||||||
|
|
||||||
|
const { container, dbConnection, pgConnection, disposeResources } =
|
||||||
|
await loaders({
|
||||||
|
directory: path.resolve(cwd || process.cwd()),
|
||||||
|
expressApp: app,
|
||||||
|
isTest: false,
|
||||||
|
})
|
||||||
|
|
||||||
|
const PORT = await getPort()
|
||||||
|
|
||||||
|
return {
|
||||||
|
disposeResources,
|
||||||
|
container,
|
||||||
|
db: dbConnection,
|
||||||
|
pgConnection,
|
||||||
|
app,
|
||||||
|
port: PORT,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
startBootstrapApp: async ({
|
||||||
|
cwd,
|
||||||
|
env = {},
|
||||||
|
skipExpressListen = false,
|
||||||
|
} = {}) => {
|
||||||
|
const { app, port, container, db, pgConnection } = await bootstrapApp({
|
||||||
|
cwd,
|
||||||
|
env,
|
||||||
|
})
|
||||||
|
let expressServer
|
||||||
|
|
||||||
|
if (skipExpressListen) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const shutdown = async () => {
|
||||||
|
await Promise.all([
|
||||||
|
container.dispose(),
|
||||||
|
expressServer.close(),
|
||||||
|
db?.destroy(),
|
||||||
|
pgConnection?.context?.destroy(),
|
||||||
|
container.dispose(),
|
||||||
|
])
|
||||||
|
|
||||||
|
if (typeof global !== "undefined" && global?.gc) {
|
||||||
|
global.gc()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return await new Promise((resolve, reject) => {
|
||||||
|
expressServer = app.listen(port, async (err) => {
|
||||||
|
if (err) {
|
||||||
|
await shutdown()
|
||||||
|
return reject(err)
|
||||||
|
}
|
||||||
|
process.send(port)
|
||||||
|
resolve({
|
||||||
|
shutdown,
|
||||||
|
container,
|
||||||
|
port,
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
},
|
||||||
|
}
|
||||||
@@ -0,0 +1,113 @@
|
|||||||
|
const path = require("path")
|
||||||
|
|
||||||
|
const { getConfigFile } = require("medusa-core-utils")
|
||||||
|
const { asValue } = require("awilix")
|
||||||
|
const {
|
||||||
|
isObject,
|
||||||
|
createMedusaContainer,
|
||||||
|
MedusaV2Flag,
|
||||||
|
} = require("@medusajs/utils")
|
||||||
|
const { DataSource } = require("typeorm")
|
||||||
|
const { ContainerRegistrationKeys } = require("@medusajs/utils")
|
||||||
|
const { migrateMedusaApp } = require("@medusajs/medusa/dist/loaders/medusa-app")
|
||||||
|
const { logger } = require("@medusajs/medusa-cli/dist/reporter")
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
initDb: async function ({
|
||||||
|
cwd,
|
||||||
|
database_extra,
|
||||||
|
env,
|
||||||
|
force_modules_migration,
|
||||||
|
dbUrl = DB_URL,
|
||||||
|
dbSchema = "public",
|
||||||
|
}) {
|
||||||
|
if (isObject(env)) {
|
||||||
|
Object.entries(env).forEach(([k, v]) => (process.env[k] = v))
|
||||||
|
}
|
||||||
|
|
||||||
|
const { configModule } = getConfigFile(cwd, `medusa-config`)
|
||||||
|
|
||||||
|
const featureFlagsLoader =
|
||||||
|
require("@medusajs/medusa/dist/loaders/feature-flags").default
|
||||||
|
|
||||||
|
const featureFlagRouter = featureFlagsLoader(configModule)
|
||||||
|
const modelsLoader = require("@medusajs/medusa/dist/loaders/models").default
|
||||||
|
const entities = modelsLoader({}, { register: false })
|
||||||
|
|
||||||
|
// get migrations with enabled featureflags
|
||||||
|
const migrationDir = path.resolve(
|
||||||
|
path.join(
|
||||||
|
cwd,
|
||||||
|
`../../`,
|
||||||
|
`node_modules`,
|
||||||
|
`@medusajs`,
|
||||||
|
`medusa`,
|
||||||
|
`dist`,
|
||||||
|
`migrations`,
|
||||||
|
`*.js`
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
const {
|
||||||
|
getEnabledMigrations,
|
||||||
|
getModuleSharedResources,
|
||||||
|
} = require("@medusajs/medusa/dist/commands/utils/get-migrations")
|
||||||
|
|
||||||
|
const { migrations: moduleMigrations, models: moduleModels } =
|
||||||
|
getModuleSharedResources(configModule, featureFlagRouter)
|
||||||
|
|
||||||
|
const enabledMigrations = getEnabledMigrations([migrationDir], (flag) =>
|
||||||
|
featureFlagRouter.isFeatureEnabled(flag)
|
||||||
|
)
|
||||||
|
|
||||||
|
const enabledEntities = entities.filter(
|
||||||
|
(e) => typeof e.isFeatureEnabled === "undefined" || e.isFeatureEnabled()
|
||||||
|
)
|
||||||
|
|
||||||
|
const dbDataSource = new DataSource({
|
||||||
|
type: "postgres",
|
||||||
|
url: dbUrl,
|
||||||
|
entities: enabledEntities.concat(moduleModels),
|
||||||
|
migrations: enabledMigrations.concat(moduleMigrations),
|
||||||
|
extra: database_extra ?? {},
|
||||||
|
//name: "integration-tests",
|
||||||
|
schema: dbSchema,
|
||||||
|
})
|
||||||
|
|
||||||
|
await dbDataSource.initialize()
|
||||||
|
|
||||||
|
await dbDataSource.runMigrations()
|
||||||
|
|
||||||
|
if (
|
||||||
|
force_modules_migration ||
|
||||||
|
featureFlagRouter.isFeatureEnabled(MedusaV2Flag.key)
|
||||||
|
) {
|
||||||
|
const pgConnectionLoader =
|
||||||
|
require("@medusajs/medusa/dist/loaders/pg-connection").default
|
||||||
|
|
||||||
|
const featureFlagLoader =
|
||||||
|
require("@medusajs/medusa/dist/loaders/feature-flags").default
|
||||||
|
|
||||||
|
const container = createMedusaContainer()
|
||||||
|
|
||||||
|
const featureFlagRouter = await featureFlagLoader(configModule)
|
||||||
|
|
||||||
|
const pgConnection = await pgConnectionLoader({ configModule, container })
|
||||||
|
|
||||||
|
container.register({
|
||||||
|
[ContainerRegistrationKeys.CONFIG_MODULE]: asValue(configModule),
|
||||||
|
[ContainerRegistrationKeys.LOGGER]: asValue(logger),
|
||||||
|
[ContainerRegistrationKeys.MANAGER]: asValue(dbDataSource.manager),
|
||||||
|
[ContainerRegistrationKeys.PG_CONNECTION]: asValue(pgConnection),
|
||||||
|
featureFlagRouter: asValue(featureFlagRouter),
|
||||||
|
})
|
||||||
|
|
||||||
|
await migrateMedusaApp(
|
||||||
|
{ configModule, container },
|
||||||
|
{ registerInContainer: false }
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
return { dbDataSource, pgConnection }
|
||||||
|
},
|
||||||
|
}
|
||||||
@@ -0,0 +1,238 @@
|
|||||||
|
import { getDatabaseURL } from "./database"
|
||||||
|
import { initDb } from "./medusa-test-runner-utils/use-db"
|
||||||
|
import { startBootstrapApp } from "./medusa-test-runner-utils/bootstrap-app"
|
||||||
|
import { createDatabase, dropDatabase } from "pg-god"
|
||||||
|
import { ContainerLike } from "@medusajs/types"
|
||||||
|
|
||||||
|
const axios = require("axios").default
|
||||||
|
|
||||||
|
const keepTables = [
|
||||||
|
"store",
|
||||||
|
"staged_job",
|
||||||
|
"shipping_profile",
|
||||||
|
"fulfillment_provider",
|
||||||
|
"payment_provider",
|
||||||
|
"country",
|
||||||
|
"region_country",
|
||||||
|
"currency",
|
||||||
|
"migrations",
|
||||||
|
"mikro_orm_migrations",
|
||||||
|
]
|
||||||
|
|
||||||
|
const DB_HOST = process.env.DB_HOST
|
||||||
|
const DB_USERNAME = process.env.DB_USERNAME
|
||||||
|
const DB_PASSWORD = process.env.DB_PASSWORD
|
||||||
|
|
||||||
|
const pgGodCredentials = {
|
||||||
|
user: DB_USERNAME,
|
||||||
|
password: DB_PASSWORD,
|
||||||
|
host: DB_HOST,
|
||||||
|
}
|
||||||
|
|
||||||
|
const dbTestUtilFactory = (): any => ({
|
||||||
|
db_: null,
|
||||||
|
pgConnection_: null,
|
||||||
|
|
||||||
|
clear: async function () {
|
||||||
|
this.db_?.synchronize(true)
|
||||||
|
},
|
||||||
|
|
||||||
|
create: async function (dbName: string) {
|
||||||
|
await createDatabase({ databaseName: dbName }, pgGodCredentials)
|
||||||
|
},
|
||||||
|
|
||||||
|
teardown: async function ({
|
||||||
|
forceDelete,
|
||||||
|
schema,
|
||||||
|
}: { forceDelete?: string[]; schema?: string } = {}) {
|
||||||
|
forceDelete = forceDelete || []
|
||||||
|
const manager = this.db_.manager
|
||||||
|
|
||||||
|
await manager.query(`SET session_replication_role = 'replica';`)
|
||||||
|
const tableNames = await manager.query(`SELECT table_name
|
||||||
|
FROM information_schema.tables
|
||||||
|
WHERE table_schema = '${
|
||||||
|
schema ?? "public"
|
||||||
|
}';`)
|
||||||
|
|
||||||
|
for (const { table_name } of tableNames) {
|
||||||
|
if (
|
||||||
|
keepTables.includes(table_name) &&
|
||||||
|
!forceDelete.includes(table_name)
|
||||||
|
) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
await manager.query(`DELETE
|
||||||
|
FROM "${table_name}";`)
|
||||||
|
}
|
||||||
|
|
||||||
|
await manager.query(`SET session_replication_role = 'origin';`)
|
||||||
|
},
|
||||||
|
|
||||||
|
shutdown: async function (dbName: string) {
|
||||||
|
await this.db_?.destroy()
|
||||||
|
await this.pgConnection_?.context?.destroy()
|
||||||
|
|
||||||
|
return await dropDatabase(
|
||||||
|
{ databaseName: dbName, errorIfNonExist: false },
|
||||||
|
pgGodCredentials
|
||||||
|
)
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
export interface MedusaSuiteOptions<TService = unknown> {
|
||||||
|
dbUtils: any
|
||||||
|
dbConnection: any // Legacy typeorm connection
|
||||||
|
getContainer: () => ContainerLike
|
||||||
|
api: any
|
||||||
|
dbConfig: {
|
||||||
|
dbName: string
|
||||||
|
schema: string
|
||||||
|
clientUrl: string
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function medusaIntegrationTestRunner({
|
||||||
|
moduleName,
|
||||||
|
dbName,
|
||||||
|
schema = "public",
|
||||||
|
env = {},
|
||||||
|
force_modules_migration = false,
|
||||||
|
debug = false,
|
||||||
|
testSuite,
|
||||||
|
}: {
|
||||||
|
moduleName?: string
|
||||||
|
env?: Record<string, string>
|
||||||
|
dbName?: string
|
||||||
|
schema?: string
|
||||||
|
debug?: boolean
|
||||||
|
force_modules_migration?: boolean
|
||||||
|
testSuite: <TService = unknown>(
|
||||||
|
options: MedusaSuiteOptions<TService>
|
||||||
|
) => () => void
|
||||||
|
}) {
|
||||||
|
const tempName = parseInt(process.env.JEST_WORKER_ID || "1")
|
||||||
|
moduleName = moduleName ?? Math.random().toString(36).substring(7)
|
||||||
|
dbName ??= `medusa-${moduleName.toLowerCase()}-integration-${tempName}`
|
||||||
|
|
||||||
|
let dbConfig = {
|
||||||
|
dbName,
|
||||||
|
clientUrl: getDatabaseURL(dbName),
|
||||||
|
schema,
|
||||||
|
debug,
|
||||||
|
}
|
||||||
|
|
||||||
|
// Intercept call to this utils to apply the unique client url for the current suite
|
||||||
|
const originalCreatePgConnection =
|
||||||
|
require("@medusajs/utils/dist/modules-sdk/create-pg-connection").createPgConnection
|
||||||
|
require("@medusajs/utils/dist/modules-sdk/create-pg-connection").createPgConnection =
|
||||||
|
(options: any) => {
|
||||||
|
return originalCreatePgConnection({
|
||||||
|
...options,
|
||||||
|
clientUrl: dbConfig.clientUrl,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
const originalDatabaseLoader =
|
||||||
|
require("@medusajs/medusa/dist/loaders/database").default
|
||||||
|
require("@medusajs/medusa/dist/loaders/database").default = (
|
||||||
|
options: any
|
||||||
|
) => {
|
||||||
|
options.configModule.projectConfig.database_url
|
||||||
|
return originalDatabaseLoader({
|
||||||
|
...options,
|
||||||
|
configModule: {
|
||||||
|
...options.configModule,
|
||||||
|
projectConfig: {
|
||||||
|
database_logging: debug, // Will be used for the debug flag of the database options
|
||||||
|
...options.configModule.projectConfig,
|
||||||
|
database_url: dbConfig.clientUrl,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
const cwd = process.cwd()
|
||||||
|
|
||||||
|
let shutdown: () => Promise<void>
|
||||||
|
let dbUtils = dbTestUtilFactory()
|
||||||
|
let container: ContainerLike
|
||||||
|
let apiUtils: any
|
||||||
|
|
||||||
|
let options = {
|
||||||
|
dbUtils,
|
||||||
|
api: new Proxy(
|
||||||
|
{},
|
||||||
|
{
|
||||||
|
get: (target, prop) => {
|
||||||
|
return apiUtils[prop]
|
||||||
|
},
|
||||||
|
}
|
||||||
|
),
|
||||||
|
dbConnection: new Proxy(
|
||||||
|
{},
|
||||||
|
{
|
||||||
|
get: (target, prop) => {
|
||||||
|
return dbUtils.db_[prop]
|
||||||
|
},
|
||||||
|
}
|
||||||
|
),
|
||||||
|
getContainer: () => container,
|
||||||
|
} as MedusaSuiteOptions
|
||||||
|
|
||||||
|
const beforeAll_ = async () => {
|
||||||
|
try {
|
||||||
|
await dbUtils.create(dbName)
|
||||||
|
const { dbDataSource, pgConnection } = await initDb({
|
||||||
|
cwd,
|
||||||
|
env,
|
||||||
|
force_modules_migration,
|
||||||
|
database_extra: {},
|
||||||
|
dbUrl: dbConfig.clientUrl,
|
||||||
|
dbSchema: dbConfig.schema,
|
||||||
|
})
|
||||||
|
dbUtils.db_ = dbDataSource
|
||||||
|
dbUtils.pgConnection_ = pgConnection
|
||||||
|
|
||||||
|
const {
|
||||||
|
shutdown: shutdown_,
|
||||||
|
container: container_,
|
||||||
|
port,
|
||||||
|
} = await startBootstrapApp({
|
||||||
|
cwd,
|
||||||
|
env,
|
||||||
|
})
|
||||||
|
|
||||||
|
apiUtils = axios.create({ baseURL: `http://localhost:${port}` })
|
||||||
|
|
||||||
|
container = container_
|
||||||
|
shutdown = shutdown_
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error setting up integration environment:", error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const afterEach_ = async () => {
|
||||||
|
try {
|
||||||
|
await dbUtils.teardown({ forceDelete: [], schema })
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error tearing down database:", error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return describe("", () => {
|
||||||
|
beforeAll(beforeAll_)
|
||||||
|
afterEach(afterEach_)
|
||||||
|
afterAll(async () => {
|
||||||
|
try {
|
||||||
|
await dbUtils.shutdown(dbName)
|
||||||
|
await shutdown()
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error shutting down integration environment:", error)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
testSuite(options!)
|
||||||
|
})
|
||||||
|
}
|
||||||
@@ -39,6 +39,8 @@ export function moduleIntegrationTestRunner({
|
|||||||
debug?: boolean
|
debug?: boolean
|
||||||
testSuite: <TService = unknown>(options: SuiteOptions<TService>) => () => void
|
testSuite: <TService = unknown>(options: SuiteOptions<TService>) => () => void
|
||||||
}) {
|
}) {
|
||||||
|
process.env.LOG_LEVEL = "error"
|
||||||
|
|
||||||
moduleModels = Object.values(require(`${process.cwd()}/src/models`))
|
moduleModels = Object.values(require(`${process.cwd()}/src/models`))
|
||||||
// migrationPath ??= process.cwd() + "/src/migrations/!(*.d).{js,ts,cjs}"
|
// migrationPath ??= process.cwd() + "/src/migrations/!(*.d).{js,ts,cjs}"
|
||||||
|
|
||||||
|
|||||||
@@ -66,8 +66,12 @@ export async function migrateMedusaApp(
|
|||||||
|
|
||||||
const sharedResourcesConfig = {
|
const sharedResourcesConfig = {
|
||||||
database: {
|
database: {
|
||||||
clientUrl: configModule.projectConfig.database_url,
|
clientUrl:
|
||||||
|
injectedDependencies[ContainerRegistrationKeys.PG_CONNECTION]?.client
|
||||||
|
?.config?.connection?.connectionString ??
|
||||||
|
configModule.projectConfig.database_url,
|
||||||
driverOptions: configModule.projectConfig.database_extra,
|
driverOptions: configModule.projectConfig.database_extra,
|
||||||
|
debug: !!(configModule.projectConfig.database_logging ?? false),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -85,7 +89,7 @@ export async function migrateMedusaApp(
|
|||||||
).options ??= {
|
).options ??= {
|
||||||
database: {
|
database: {
|
||||||
type: "postgres",
|
type: "postgres",
|
||||||
url: configModule.projectConfig.database_url,
|
url: sharedResourcesConfig.database.clientUrl,
|
||||||
extra: configModule.projectConfig.database_extra,
|
extra: configModule.projectConfig.database_extra,
|
||||||
schema: configModule.projectConfig.database_schema,
|
schema: configModule.projectConfig.database_schema,
|
||||||
logging: configModule.projectConfig.database_logging,
|
logging: configModule.projectConfig.database_logging,
|
||||||
@@ -132,6 +136,7 @@ export const loadMedusaApp = async (
|
|||||||
database: {
|
database: {
|
||||||
clientUrl: configModule.projectConfig.database_url,
|
clientUrl: configModule.projectConfig.database_url,
|
||||||
driverOptions: configModule.projectConfig.database_extra,
|
driverOptions: configModule.projectConfig.database_extra,
|
||||||
|
debug: !!(configModule.projectConfig.database_logging ?? false),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -337,7 +337,7 @@ async function MedusaApp_({
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
const linkModuleOpt = { ...linkModuleOptions }
|
const linkModuleOpt = { ...(linkModuleOptions ?? {}) }
|
||||||
linkModuleOpt.database ??= {
|
linkModuleOpt.database ??= {
|
||||||
...(sharedResourcesConfig?.database ?? {}),
|
...(sharedResourcesConfig?.database ?? {}),
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -285,11 +285,14 @@ export class MedusaModule {
|
|||||||
moduleDefinition
|
moduleDefinition
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const logger_ =
|
||||||
|
container.resolve("logger", { allowUnregistered: true }) ?? logger
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await moduleLoader({
|
await moduleLoader({
|
||||||
container,
|
container,
|
||||||
moduleResolutions,
|
moduleResolutions,
|
||||||
logger,
|
logger: logger_,
|
||||||
migrationOnly,
|
migrationOnly,
|
||||||
})
|
})
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
@@ -314,7 +317,7 @@ export class MedusaModule {
|
|||||||
].__joinerConfig()
|
].__joinerConfig()
|
||||||
|
|
||||||
if (!joinerConfig.primaryKeys) {
|
if (!joinerConfig.primaryKeys) {
|
||||||
logger.warn(
|
logger_.warn(
|
||||||
`Primary keys are not defined by the module ${keyName}. Setting default primary key to 'id'${EOL}`
|
`Primary keys are not defined by the module ${keyName}. Setting default primary key to 'id'${EOL}`
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -407,11 +410,14 @@ export class MedusaModule {
|
|||||||
moduleExports
|
moduleExports
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const logger_ =
|
||||||
|
container.resolve("logger", { allowUnregistered: true }) ?? logger
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await moduleLoader({
|
await moduleLoader({
|
||||||
container,
|
container,
|
||||||
moduleResolutions,
|
moduleResolutions,
|
||||||
logger,
|
logger: logger_,
|
||||||
})
|
})
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
errorLoading(err)
|
errorLoading(err)
|
||||||
|
|||||||
@@ -8914,7 +8914,7 @@ __metadata:
|
|||||||
languageName: unknown
|
languageName: unknown
|
||||||
linkType: soft
|
linkType: soft
|
||||||
|
|
||||||
"@medusajs/types@^1.10.0, @medusajs/types@^1.11.11, @medusajs/types@^1.11.12, @medusajs/types@^1.11.13, @medusajs/types@^1.11.6, @medusajs/types@^1.11.8, @medusajs/types@^1.11.9, @medusajs/types@^1.8.10, @medusajs/types@workspace:^, @medusajs/types@workspace:packages/types":
|
"@medusajs/types@^1.1.41, @medusajs/types@^1.10.0, @medusajs/types@^1.11.11, @medusajs/types@^1.11.12, @medusajs/types@^1.11.13, @medusajs/types@^1.11.6, @medusajs/types@^1.11.8, @medusajs/types@^1.11.9, @medusajs/types@^1.8.10, @medusajs/types@workspace:^, @medusajs/types@workspace:packages/types":
|
||||||
version: 0.0.0-use.local
|
version: 0.0.0-use.local
|
||||||
resolution: "@medusajs/types@workspace:packages/types"
|
resolution: "@medusajs/types@workspace:packages/types"
|
||||||
dependencies:
|
dependencies:
|
||||||
@@ -31811,6 +31811,7 @@ __metadata:
|
|||||||
medusa-fulfillment-webshipper: "workspace:*"
|
medusa-fulfillment-webshipper: "workspace:*"
|
||||||
medusa-interfaces: "workspace:*"
|
medusa-interfaces: "workspace:*"
|
||||||
medusa-plugin-sendgrid: "workspace:*"
|
medusa-plugin-sendgrid: "workspace:*"
|
||||||
|
medusa-test-utils: "workspace:*"
|
||||||
pg: ^8.11.0
|
pg: ^8.11.0
|
||||||
typeorm: ^0.3.16
|
typeorm: ^0.3.16
|
||||||
languageName: unknown
|
languageName: unknown
|
||||||
@@ -38296,21 +38297,41 @@ __metadata:
|
|||||||
languageName: unknown
|
languageName: unknown
|
||||||
linkType: soft
|
linkType: soft
|
||||||
|
|
||||||
"medusa-test-utils@^1.1.40, medusa-test-utils@^1.1.41, medusa-test-utils@workspace:^, medusa-test-utils@workspace:packages/medusa-test-utils":
|
"medusa-test-utils@^1.1.40, medusa-test-utils@^1.1.41, medusa-test-utils@workspace:*, medusa-test-utils@workspace:^, medusa-test-utils@workspace:packages/medusa-test-utils":
|
||||||
version: 0.0.0-use.local
|
version: 0.0.0-use.local
|
||||||
resolution: "medusa-test-utils@workspace:packages/medusa-test-utils"
|
resolution: "medusa-test-utils@workspace:packages/medusa-test-utils"
|
||||||
dependencies:
|
dependencies:
|
||||||
"@medusajs/modules-sdk": ^1.12.6
|
"@medusajs/modules-sdk": ^1.12.6
|
||||||
|
"@medusajs/types": ^1.1.41
|
||||||
"@medusajs/utils": ^1.1.41
|
"@medusajs/utils": ^1.1.41
|
||||||
"@mikro-orm/migrations": 5.9.7
|
"@mikro-orm/migrations": 5.9.7
|
||||||
"@mikro-orm/postgresql": 5.9.7
|
"@mikro-orm/postgresql": 5.9.7
|
||||||
cross-env: ^5.2.1
|
cross-env: ^5.2.1
|
||||||
jest: ^25.5.4
|
jest: ^25.5.4
|
||||||
medusa-core-utils: ^1.2.1
|
medusa-core-utils: ^1.2.1
|
||||||
pg-god: ^1.0.12
|
|
||||||
randomatic: ^3.1.1
|
randomatic: ^3.1.1
|
||||||
rimraf: ^3.0.2
|
rimraf: ^3.0.2
|
||||||
typescript: ^5.1.6
|
typescript: ^5.1.6
|
||||||
|
peerDependencies:
|
||||||
|
"@medusajs/medusa": ">1.19"
|
||||||
|
axios: ^0.28.0
|
||||||
|
express: ^4.18.3
|
||||||
|
get-port: ^5.1.0
|
||||||
|
pg-god: ^1.0.12
|
||||||
|
typeorm: ^0.2.43
|
||||||
|
peerDependenciesMeta:
|
||||||
|
"@medusajs/medusa":
|
||||||
|
optional: true
|
||||||
|
axios:
|
||||||
|
optional: true
|
||||||
|
express:
|
||||||
|
optional: true
|
||||||
|
get-port:
|
||||||
|
optional: true
|
||||||
|
pg-god:
|
||||||
|
optional: true
|
||||||
|
typeorm:
|
||||||
|
optional: true
|
||||||
languageName: unknown
|
languageName: unknown
|
||||||
linkType: soft
|
linkType: soft
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user