chore: Move currency, collection, and auth tests to http folder (#7581)
* chore: Move auth tests to http folder * chore: Migrate collection tests to http folder * chore: Move currency tests to http folder
This commit is contained in:
@@ -1,293 +0,0 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`/admin/currencies GET /admin/currencies should retrieve the currencies 1`] = `
|
||||
Object {
|
||||
"count": 120,
|
||||
"currencies": Array [
|
||||
Object {
|
||||
"code": "aed",
|
||||
"name": "United Arab Emirates Dirham",
|
||||
"symbol": "AED",
|
||||
"symbol_native": "د.إ.",
|
||||
},
|
||||
Object {
|
||||
"code": "afn",
|
||||
"name": "Afghan Afghani",
|
||||
"symbol": "Af",
|
||||
"symbol_native": "؋",
|
||||
},
|
||||
Object {
|
||||
"code": "all",
|
||||
"name": "Albanian Lek",
|
||||
"symbol": "ALL",
|
||||
"symbol_native": "Lek",
|
||||
},
|
||||
Object {
|
||||
"code": "amd",
|
||||
"name": "Armenian Dram",
|
||||
"symbol": "AMD",
|
||||
"symbol_native": "դր.",
|
||||
},
|
||||
Object {
|
||||
"code": "ars",
|
||||
"name": "Argentine Peso",
|
||||
"symbol": "AR$",
|
||||
"symbol_native": "$",
|
||||
},
|
||||
Object {
|
||||
"code": "aud",
|
||||
"name": "Australian Dollar",
|
||||
"symbol": "AU$",
|
||||
"symbol_native": "$",
|
||||
},
|
||||
Object {
|
||||
"code": "azn",
|
||||
"name": "Azerbaijani Manat",
|
||||
"symbol": "man.",
|
||||
"symbol_native": "ман.",
|
||||
},
|
||||
Object {
|
||||
"code": "bam",
|
||||
"name": "Bosnia-Herzegovina Convertible Mark",
|
||||
"symbol": "KM",
|
||||
"symbol_native": "KM",
|
||||
},
|
||||
Object {
|
||||
"code": "bdt",
|
||||
"name": "Bangladeshi Taka",
|
||||
"symbol": "Tk",
|
||||
"symbol_native": "৳",
|
||||
},
|
||||
Object {
|
||||
"code": "bgn",
|
||||
"name": "Bulgarian Lev",
|
||||
"symbol": "BGN",
|
||||
"symbol_native": "лв.",
|
||||
},
|
||||
Object {
|
||||
"code": "bhd",
|
||||
"name": "Bahraini Dinar",
|
||||
"symbol": "BD",
|
||||
"symbol_native": "د.ب.",
|
||||
},
|
||||
Object {
|
||||
"code": "bif",
|
||||
"name": "Burundian Franc",
|
||||
"symbol": "FBu",
|
||||
"symbol_native": "FBu",
|
||||
},
|
||||
Object {
|
||||
"code": "bnd",
|
||||
"name": "Brunei Dollar",
|
||||
"symbol": "BN$",
|
||||
"symbol_native": "$",
|
||||
},
|
||||
Object {
|
||||
"code": "bob",
|
||||
"name": "Bolivian Boliviano",
|
||||
"symbol": "Bs",
|
||||
"symbol_native": "Bs",
|
||||
},
|
||||
Object {
|
||||
"code": "brl",
|
||||
"name": "Brazilian Real",
|
||||
"symbol": "R$",
|
||||
"symbol_native": "R$",
|
||||
},
|
||||
Object {
|
||||
"code": "bwp",
|
||||
"name": "Botswanan Pula",
|
||||
"symbol": "BWP",
|
||||
"symbol_native": "P",
|
||||
},
|
||||
Object {
|
||||
"code": "byn",
|
||||
"name": "Belarusian Ruble",
|
||||
"symbol": "Br",
|
||||
"symbol_native": "руб.",
|
||||
},
|
||||
Object {
|
||||
"code": "bzd",
|
||||
"name": "Belize Dollar",
|
||||
"symbol": "BZ$",
|
||||
"symbol_native": "$",
|
||||
},
|
||||
Object {
|
||||
"code": "cad",
|
||||
"name": "Canadian Dollar",
|
||||
"symbol": "CA$",
|
||||
"symbol_native": "$",
|
||||
},
|
||||
Object {
|
||||
"code": "cdf",
|
||||
"name": "Congolese Franc",
|
||||
"symbol": "CDF",
|
||||
"symbol_native": "FrCD",
|
||||
},
|
||||
],
|
||||
"limit": 20,
|
||||
"offset": 0,
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`[MEDUSA_FF_TAX_INCLUSIVE_PRICING] /admin/currencies GET /admin/currencies should retrieve the currencies 1`] = `
|
||||
Object {
|
||||
"count": 120,
|
||||
"currencies": Array [
|
||||
Object {
|
||||
"code": "aed",
|
||||
"includes_tax": false,
|
||||
"name": "United Arab Emirates Dirham",
|
||||
"symbol": "AED",
|
||||
"symbol_native": "د.إ.",
|
||||
},
|
||||
Object {
|
||||
"code": "afn",
|
||||
"includes_tax": false,
|
||||
"name": "Afghan Afghani",
|
||||
"symbol": "Af",
|
||||
"symbol_native": "؋",
|
||||
},
|
||||
Object {
|
||||
"code": "all",
|
||||
"includes_tax": false,
|
||||
"name": "Albanian Lek",
|
||||
"symbol": "ALL",
|
||||
"symbol_native": "Lek",
|
||||
},
|
||||
Object {
|
||||
"code": "amd",
|
||||
"includes_tax": false,
|
||||
"name": "Armenian Dram",
|
||||
"symbol": "AMD",
|
||||
"symbol_native": "դր.",
|
||||
},
|
||||
Object {
|
||||
"code": "ars",
|
||||
"includes_tax": false,
|
||||
"name": "Argentine Peso",
|
||||
"symbol": "AR$",
|
||||
"symbol_native": "$",
|
||||
},
|
||||
Object {
|
||||
"code": "aud",
|
||||
"includes_tax": false,
|
||||
"name": "Australian Dollar",
|
||||
"symbol": "AU$",
|
||||
"symbol_native": "$",
|
||||
},
|
||||
Object {
|
||||
"code": "azn",
|
||||
"includes_tax": false,
|
||||
"name": "Azerbaijani Manat",
|
||||
"symbol": "man.",
|
||||
"symbol_native": "ман.",
|
||||
},
|
||||
Object {
|
||||
"code": "bam",
|
||||
"includes_tax": false,
|
||||
"name": "Bosnia-Herzegovina Convertible Mark",
|
||||
"symbol": "KM",
|
||||
"symbol_native": "KM",
|
||||
},
|
||||
Object {
|
||||
"code": "bdt",
|
||||
"includes_tax": false,
|
||||
"name": "Bangladeshi Taka",
|
||||
"symbol": "Tk",
|
||||
"symbol_native": "৳",
|
||||
},
|
||||
Object {
|
||||
"code": "bgn",
|
||||
"includes_tax": false,
|
||||
"name": "Bulgarian Lev",
|
||||
"symbol": "BGN",
|
||||
"symbol_native": "лв.",
|
||||
},
|
||||
Object {
|
||||
"code": "bhd",
|
||||
"includes_tax": false,
|
||||
"name": "Bahraini Dinar",
|
||||
"symbol": "BD",
|
||||
"symbol_native": "د.ب.",
|
||||
},
|
||||
Object {
|
||||
"code": "bif",
|
||||
"includes_tax": false,
|
||||
"name": "Burundian Franc",
|
||||
"symbol": "FBu",
|
||||
"symbol_native": "FBu",
|
||||
},
|
||||
Object {
|
||||
"code": "bnd",
|
||||
"includes_tax": false,
|
||||
"name": "Brunei Dollar",
|
||||
"symbol": "BN$",
|
||||
"symbol_native": "$",
|
||||
},
|
||||
Object {
|
||||
"code": "bob",
|
||||
"includes_tax": false,
|
||||
"name": "Bolivian Boliviano",
|
||||
"symbol": "Bs",
|
||||
"symbol_native": "Bs",
|
||||
},
|
||||
Object {
|
||||
"code": "brl",
|
||||
"includes_tax": false,
|
||||
"name": "Brazilian Real",
|
||||
"symbol": "R$",
|
||||
"symbol_native": "R$",
|
||||
},
|
||||
Object {
|
||||
"code": "bwp",
|
||||
"includes_tax": false,
|
||||
"name": "Botswanan Pula",
|
||||
"symbol": "BWP",
|
||||
"symbol_native": "P",
|
||||
},
|
||||
Object {
|
||||
"code": "byn",
|
||||
"includes_tax": false,
|
||||
"name": "Belarusian Ruble",
|
||||
"symbol": "Br",
|
||||
"symbol_native": "руб.",
|
||||
},
|
||||
Object {
|
||||
"code": "bzd",
|
||||
"includes_tax": false,
|
||||
"name": "Belize Dollar",
|
||||
"symbol": "BZ$",
|
||||
"symbol_native": "$",
|
||||
},
|
||||
Object {
|
||||
"code": "cad",
|
||||
"includes_tax": false,
|
||||
"name": "Canadian Dollar",
|
||||
"symbol": "CA$",
|
||||
"symbol_native": "$",
|
||||
},
|
||||
Object {
|
||||
"code": "cdf",
|
||||
"includes_tax": false,
|
||||
"name": "Congolese Franc",
|
||||
"symbol": "CDF",
|
||||
"symbol_native": "FrCD",
|
||||
},
|
||||
],
|
||||
"limit": 20,
|
||||
"offset": 0,
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`[MEDUSA_FF_TAX_INCLUSIVE_PRICING] /admin/currencies POST /admin/currencies/:code should update currency includes_tax 1`] = `
|
||||
Object {
|
||||
"currency": Object {
|
||||
"code": "aed",
|
||||
"includes_tax": true,
|
||||
"name": "United Arab Emirates Dirham",
|
||||
"symbol": "AED",
|
||||
"symbol_native": "د.إ.",
|
||||
},
|
||||
}
|
||||
`;
|
||||
@@ -1,107 +0,0 @@
|
||||
const { useApi } = require("../../../environment-helpers/use-api")
|
||||
const { medusaIntegrationTestRunner } = require("medusa-test-utils")
|
||||
const { createAdminUser } = require("../../../helpers/create-admin-user")
|
||||
const { breaking } = require("../../../helpers/breaking")
|
||||
|
||||
const adminHeaders = {
|
||||
headers: {
|
||||
"x-medusa-access-token": "test_token",
|
||||
},
|
||||
}
|
||||
|
||||
jest.setTimeout(30000)
|
||||
|
||||
medusaIntegrationTestRunner({
|
||||
env: {
|
||||
MEDUSA_FF_MEDUSA_V2: true,
|
||||
},
|
||||
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||
let container
|
||||
|
||||
beforeEach(async () => {
|
||||
container = getContainer()
|
||||
await createAdminUser(dbConnection, adminHeaders, container)
|
||||
})
|
||||
|
||||
it("creates admin session correctly", async () => {
|
||||
const response = await breaking(
|
||||
async () => {
|
||||
return await api.post("/admin/auth", {
|
||||
email: "admin@medusa.js",
|
||||
password: "secret_password",
|
||||
})
|
||||
},
|
||||
async () => {
|
||||
return await api.post("/auth/user/emailpass", {
|
||||
email: "admin@medusa.js",
|
||||
password: "secret_password",
|
||||
})
|
||||
}
|
||||
)
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
|
||||
const v1Result = {
|
||||
user: expect.objectContaining({
|
||||
email: "admin@medusa.js",
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
}),
|
||||
}
|
||||
|
||||
// In V2, we respond with a token instead of the user object on session creation
|
||||
const v2Result = { token: expect.any(String) }
|
||||
|
||||
expect(response.data).toEqual(
|
||||
breaking(
|
||||
() => v1Result,
|
||||
() => v2Result
|
||||
)
|
||||
)
|
||||
})
|
||||
|
||||
it("should test the entire authentication lifecycle", async () => {
|
||||
// sign in
|
||||
const response = await api.post("/auth/user/emailpass", {
|
||||
email: "admin@medusa.js",
|
||||
password: "secret_password",
|
||||
})
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data).toEqual({ token: expect.any(String) })
|
||||
|
||||
const headers = {
|
||||
headers: { ["authorization"]: `Bearer ${response.data.token}` },
|
||||
}
|
||||
|
||||
// convert token to session
|
||||
const cookieRequest = await api.post("/auth/session", {}, headers)
|
||||
expect(cookieRequest.status).toEqual(200)
|
||||
|
||||
// extract cookie
|
||||
const [cookie] = cookieRequest.headers["set-cookie"][0].split(";")
|
||||
|
||||
const cookieHeader = {
|
||||
headers: { Cookie: cookie },
|
||||
}
|
||||
|
||||
// perform cookie authenticated request
|
||||
const authedRequest = await api.get(
|
||||
"/admin/products?limit=1",
|
||||
cookieHeader
|
||||
)
|
||||
expect(authedRequest.status).toEqual(200)
|
||||
|
||||
// sign out
|
||||
const signOutRequest = await api.delete("/auth/session", cookieHeader)
|
||||
expect(signOutRequest.status).toEqual(200)
|
||||
|
||||
// attempt to perform authenticated request
|
||||
const unAuthedRequest = await api
|
||||
.get("/admin/products?limit=1", cookieHeader)
|
||||
.catch((e) => e)
|
||||
|
||||
expect(unAuthedRequest.response.status).toEqual(401)
|
||||
})
|
||||
},
|
||||
})
|
||||
@@ -1,444 +0,0 @@
|
||||
const path = require("path")
|
||||
const setupServer = require("../../../environment-helpers/setup-server")
|
||||
const { useApi } = require("../../../environment-helpers/use-api")
|
||||
const { initDb, useDb } = require("../../../environment-helpers/use-db")
|
||||
|
||||
const productSeeder = require("../../../helpers/product-seeder")
|
||||
const adminSeeder = require("../../../helpers/admin-seeder")
|
||||
const {
|
||||
DiscountRuleType,
|
||||
AllocationType,
|
||||
DiscountConditionType,
|
||||
DiscountConditionOperator,
|
||||
} = require("@medusajs/medusa")
|
||||
const { IdMap } = require("medusa-test-utils")
|
||||
const { simpleDiscountFactory } = require("../../../factories")
|
||||
|
||||
jest.setTimeout(30000)
|
||||
|
||||
const adminReqConfig = {
|
||||
headers: {
|
||||
"x-medusa-access-token": "test_token",
|
||||
},
|
||||
}
|
||||
|
||||
describe("/admin/collections", () => {
|
||||
let medusaProcess
|
||||
let dbConnection
|
||||
|
||||
beforeAll(async () => {
|
||||
const cwd = path.resolve(path.join(__dirname, "..", ".."))
|
||||
dbConnection = await initDb({ cwd })
|
||||
medusaProcess = await setupServer({ cwd })
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
const db = useDb()
|
||||
await db.shutdown()
|
||||
medusaProcess.kill()
|
||||
})
|
||||
|
||||
describe("/admin/collections/:id", () => {
|
||||
beforeEach(async () => {
|
||||
await adminSeeder(dbConnection)
|
||||
await productSeeder(dbConnection)
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
const db = useDb()
|
||||
await db.teardown()
|
||||
})
|
||||
|
||||
it("updates a collection", async () => {
|
||||
const api = useApi()
|
||||
|
||||
const creationResponse = await api.post(
|
||||
"/admin/collections",
|
||||
{
|
||||
title: "test",
|
||||
},
|
||||
{ headers: { "x-medusa-access-token": "test_token" } }
|
||||
)
|
||||
|
||||
const response = await api.post(
|
||||
`/admin/collections/${creationResponse.data.collection.id}`,
|
||||
{
|
||||
title: "test collection creation",
|
||||
handle: "test-handle-creation",
|
||||
},
|
||||
{ headers: { "x-medusa-access-token": "test_token" } }
|
||||
)
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data).toEqual(
|
||||
expect.objectContaining({
|
||||
collection: expect.objectContaining({
|
||||
id: expect.stringMatching(/^pcol_*/),
|
||||
title: "test collection creation",
|
||||
handle: "test-handle-creation",
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
}),
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
it("deletes a collection", async () => {
|
||||
const api = useApi()
|
||||
|
||||
const creationResponse = await api.post(
|
||||
"/admin/collections",
|
||||
{
|
||||
title: "test",
|
||||
},
|
||||
{ headers: { "x-medusa-access-token": "test_token" } }
|
||||
)
|
||||
|
||||
const response = await api.delete(
|
||||
`/admin/collections/${creationResponse.data.collection.id}`,
|
||||
{ headers: { "x-medusa-access-token": "test_token" } }
|
||||
)
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data).toEqual({
|
||||
id: creationResponse.data.collection.id,
|
||||
object: "product-collection",
|
||||
deleted: true,
|
||||
})
|
||||
})
|
||||
|
||||
it("gets collection", async () => {
|
||||
const api = useApi()
|
||||
|
||||
const response = await api.get("/admin/collections/test-collection", {
|
||||
headers: { "x-medusa-access-token": "test_token" },
|
||||
})
|
||||
|
||||
expect(response.data).toEqual(
|
||||
expect.objectContaining({
|
||||
collection: expect.objectContaining({
|
||||
id: "test-collection",
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
products: expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
collection_id: "test-collection",
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
profile_id: expect.stringMatching(/^sp_*/),
|
||||
}),
|
||||
expect.objectContaining({
|
||||
collection_id: "test-collection",
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
profile_id: expect.stringMatching(/^sp_*/),
|
||||
}),
|
||||
]),
|
||||
}),
|
||||
})
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe("/admin/collections", () => {
|
||||
beforeEach(async () => {
|
||||
await adminSeeder(dbConnection)
|
||||
await productSeeder(dbConnection)
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
const db = useDb()
|
||||
await db.teardown()
|
||||
})
|
||||
|
||||
it("creates a collection", async () => {
|
||||
const api = useApi()
|
||||
|
||||
const response = await api.post(
|
||||
"/admin/collections",
|
||||
{
|
||||
title: "test collection creation",
|
||||
handle: "test-handle-creation",
|
||||
},
|
||||
{ headers: { "x-medusa-access-token": "test_token" } }
|
||||
)
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data).toEqual(
|
||||
expect.objectContaining({
|
||||
collection: expect.objectContaining({
|
||||
id: expect.stringMatching(/^pcol_*/),
|
||||
title: "test collection creation",
|
||||
handle: "test-handle-creation",
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
}),
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
it("lists collections", async () => {
|
||||
const api = useApi()
|
||||
|
||||
const response = await api.get("/admin/collections", {
|
||||
headers: { "x-medusa-access-token": "test_token" },
|
||||
})
|
||||
|
||||
expect(response.data).toEqual(
|
||||
expect.objectContaining({
|
||||
count: 3,
|
||||
collections: expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
id: "test-collection2",
|
||||
handle: "test-collection2",
|
||||
title: "Test collection 2",
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
products: expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
collection_id: "test-collection2",
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
profile_id: expect.stringMatching(/^sp_*/),
|
||||
}),
|
||||
]),
|
||||
}),
|
||||
expect.objectContaining({
|
||||
id: "test-collection1",
|
||||
handle: "test-collection1",
|
||||
title: "Test collection 1",
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
products: expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
collection_id: "test-collection1",
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
profile_id: expect.stringMatching(/^sp_*/),
|
||||
}),
|
||||
expect.objectContaining({
|
||||
collection_id: "test-collection1",
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
profile_id: expect.stringMatching(/^sp_*/),
|
||||
}),
|
||||
]),
|
||||
}),
|
||||
expect.objectContaining({
|
||||
id: "test-collection",
|
||||
handle: "test-collection",
|
||||
title: "Test collection",
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
products: expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
collection_id: "test-collection",
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
profile_id: expect.stringMatching(/^sp_*/),
|
||||
}),
|
||||
expect.objectContaining({
|
||||
collection_id: "test-collection",
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
profile_id: expect.stringMatching(/^sp_*/),
|
||||
}),
|
||||
]),
|
||||
}),
|
||||
]),
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
it("adds products to collection", async () => {
|
||||
const api = useApi()
|
||||
|
||||
// adds product test-product-filterid-1
|
||||
const response = await api
|
||||
.post(
|
||||
"/admin/collections/test-collection/products/batch",
|
||||
{
|
||||
product_ids: ["test-product_filtering_1"],
|
||||
},
|
||||
{
|
||||
headers: { "x-medusa-access-token": "test_token" },
|
||||
}
|
||||
)
|
||||
.catch((err) => console.warn(err))
|
||||
|
||||
expect(response.data).toEqual(
|
||||
expect.objectContaining({
|
||||
collection: expect.objectContaining({
|
||||
id: "test-collection",
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
products: expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
collection_id: "test-collection",
|
||||
id: "test-product",
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
profile_id: expect.stringMatching(/^sp_*/),
|
||||
}),
|
||||
expect.objectContaining({
|
||||
collection_id: "test-collection",
|
||||
id: "test-product_filtering_1",
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
profile_id: expect.stringMatching(/^sp_*/),
|
||||
}),
|
||||
expect.objectContaining({
|
||||
collection_id: "test-collection",
|
||||
id: "test-product1",
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
profile_id: expect.stringMatching(/^sp_*/),
|
||||
}),
|
||||
]),
|
||||
}),
|
||||
})
|
||||
)
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
})
|
||||
|
||||
it("removes products from collection", async () => {
|
||||
const api = useApi()
|
||||
|
||||
const response = await api
|
||||
.delete("/admin/collections/test-collection/products/batch", {
|
||||
headers: { "x-medusa-access-token": "test_token" },
|
||||
data: { product_ids: ["test-product"] },
|
||||
})
|
||||
.catch((err) => console.warn(err))
|
||||
|
||||
expect(response.data).toEqual(
|
||||
expect.objectContaining({
|
||||
id: "test-collection",
|
||||
object: "product-collection",
|
||||
removed_products: ["test-product"],
|
||||
})
|
||||
)
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
})
|
||||
|
||||
it("filters collections by title", async () => {
|
||||
const api = useApi()
|
||||
|
||||
const response = await api
|
||||
.get("/admin/collections?title=Test%20collection", {
|
||||
headers: { "x-medusa-access-token": "test_token" },
|
||||
})
|
||||
.catch((err) => console.log(err))
|
||||
|
||||
expect(response.data).toEqual(
|
||||
expect.objectContaining({
|
||||
count: 1,
|
||||
limit: 10,
|
||||
offset: 0,
|
||||
collections: expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
id: "test-collection",
|
||||
handle: "test-collection",
|
||||
title: "Test collection",
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
products: expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
collection_id: "test-collection",
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
profile_id: expect.stringMatching(/^sp_*/),
|
||||
}),
|
||||
expect.objectContaining({
|
||||
collection_id: "test-collection",
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
profile_id: expect.stringMatching(/^sp_*/),
|
||||
}),
|
||||
]),
|
||||
}),
|
||||
]),
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
it("returns a list of collections filtered by discount condition id", async () => {
|
||||
const api = useApi()
|
||||
|
||||
const resCollections = await api.get("/admin/collections", adminReqConfig)
|
||||
|
||||
const collection1 = resCollections.data.collections[0]
|
||||
const collection2 = resCollections.data.collections[1]
|
||||
|
||||
const buildDiscountData = (code, conditionId, collections) => {
|
||||
return {
|
||||
code,
|
||||
rule: {
|
||||
type: DiscountRuleType.PERCENTAGE,
|
||||
value: 10,
|
||||
allocation: AllocationType.TOTAL,
|
||||
conditions: [
|
||||
{
|
||||
id: conditionId,
|
||||
type: DiscountConditionType.PRODUCT_COLLECTIONS,
|
||||
operator: DiscountConditionOperator.IN,
|
||||
product_collections: collections,
|
||||
},
|
||||
],
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
const discountConditionId = IdMap.getId("discount-condition-type-1")
|
||||
await simpleDiscountFactory(
|
||||
dbConnection,
|
||||
buildDiscountData("code-1", discountConditionId, [collection1.id])
|
||||
)
|
||||
|
||||
const discountConditionId2 = IdMap.getId("discount-condition-type-2")
|
||||
await simpleDiscountFactory(
|
||||
dbConnection,
|
||||
buildDiscountData("code-2", discountConditionId2, [collection2.id])
|
||||
)
|
||||
|
||||
let res = await api.get(
|
||||
`/admin/collections?discount_condition_id=${discountConditionId}`,
|
||||
adminReqConfig
|
||||
)
|
||||
|
||||
expect(res.status).toEqual(200)
|
||||
expect(res.data.collections).toHaveLength(1)
|
||||
expect(res.data.collections).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({ id: collection1.id }),
|
||||
])
|
||||
)
|
||||
|
||||
res = await api.get(
|
||||
`/admin/collections?discount_condition_id=${discountConditionId2}`,
|
||||
adminReqConfig
|
||||
)
|
||||
|
||||
expect(res.status).toEqual(200)
|
||||
expect(res.data.collections).toHaveLength(1)
|
||||
expect(res.data.collections).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({ id: collection2.id }),
|
||||
])
|
||||
)
|
||||
|
||||
res = await api.get(`/admin/collections`, adminReqConfig)
|
||||
|
||||
expect(res.status).toEqual(200)
|
||||
expect(res.data.collections).toHaveLength(3)
|
||||
expect(res.data.collections).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({ id: collection1.id }),
|
||||
expect.objectContaining({ id: collection2.id }),
|
||||
])
|
||||
)
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -1,160 +0,0 @@
|
||||
const path = require("path")
|
||||
const setupServer = require("../../../environment-helpers/setup-server")
|
||||
const startServerWithEnvironment =
|
||||
require("../../../environment-helpers/start-server-with-environment").default
|
||||
const { useApi } = require("../../../environment-helpers/use-api")
|
||||
const { useDb, initDb } = require("../../../environment-helpers/use-db")
|
||||
const adminSeeder = require("../../../helpers/admin-seeder")
|
||||
|
||||
const adminReqConfig = {
|
||||
headers: {
|
||||
"x-medusa-access-token": "test_token",
|
||||
},
|
||||
}
|
||||
|
||||
jest.setTimeout(30000)
|
||||
describe("/admin/currencies", () => {
|
||||
let medusaProcess
|
||||
let dbConnection
|
||||
|
||||
beforeAll(async () => {
|
||||
const cwd = path.resolve(path.join(__dirname, "..", ".."))
|
||||
dbConnection = await initDb({ cwd })
|
||||
medusaProcess = await setupServer({ cwd })
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
const db = useDb()
|
||||
await db.shutdown()
|
||||
|
||||
medusaProcess.kill()
|
||||
})
|
||||
|
||||
describe("GET /admin/currencies", function () {
|
||||
beforeEach(async () => {
|
||||
try {
|
||||
await adminSeeder(dbConnection)
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
}
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
const db = useDb()
|
||||
await db.teardown()
|
||||
})
|
||||
|
||||
it("should retrieve the currencies", async () => {
|
||||
const api = useApi()
|
||||
const response = await api.get(
|
||||
`/admin/currencies?order=code`,
|
||||
adminReqConfig
|
||||
)
|
||||
|
||||
expect(response.data).toMatchSnapshot()
|
||||
})
|
||||
|
||||
it("should retrieve the currencies filtered with q param", async () => {
|
||||
const api = useApi()
|
||||
const response = await api.get(
|
||||
`/admin/currencies?q=us&order=code`,
|
||||
adminReqConfig
|
||||
)
|
||||
|
||||
const { currencies } = response.data
|
||||
|
||||
expect(currencies).toEqual([
|
||||
expect.objectContaining({
|
||||
code: "aud",
|
||||
name: "Australian Dollar",
|
||||
}),
|
||||
expect.objectContaining({
|
||||
code: "byn",
|
||||
name: "Belarusian Ruble",
|
||||
}),
|
||||
expect.objectContaining({
|
||||
code: "rub",
|
||||
name: "Russian Ruble",
|
||||
}),
|
||||
expect.objectContaining({
|
||||
code: "usd",
|
||||
name: "US Dollar",
|
||||
}),
|
||||
])
|
||||
})
|
||||
})
|
||||
})
|
||||
describe("[MEDUSA_FF_TAX_INCLUSIVE_PRICING] /admin/currencies", () => {
|
||||
let medusaProcess
|
||||
let dbConnection
|
||||
|
||||
beforeAll(async () => {
|
||||
const cwd = path.resolve(path.join(__dirname, "..", ".."))
|
||||
const [process, connection] = await startServerWithEnvironment({
|
||||
cwd,
|
||||
env: { MEDUSA_FF_TAX_INCLUSIVE_PRICING: true },
|
||||
})
|
||||
dbConnection = connection
|
||||
medusaProcess = process
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
const db = useDb()
|
||||
await db.shutdown()
|
||||
|
||||
medusaProcess.kill()
|
||||
})
|
||||
|
||||
describe("GET /admin/currencies", function () {
|
||||
beforeEach(async () => {
|
||||
try {
|
||||
await adminSeeder(dbConnection)
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
}
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
const db = useDb()
|
||||
await db.teardown()
|
||||
})
|
||||
|
||||
it("should retrieve the currencies", async () => {
|
||||
const api = useApi()
|
||||
const response = await api.get(
|
||||
`/admin/currencies?order=code`,
|
||||
adminReqConfig
|
||||
)
|
||||
|
||||
expect(response.data).toMatchSnapshot()
|
||||
})
|
||||
})
|
||||
|
||||
describe("POST /admin/currencies/:code", function () {
|
||||
beforeEach(async () => {
|
||||
try {
|
||||
await adminSeeder(dbConnection)
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
}
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
const db = useDb()
|
||||
await db.teardown()
|
||||
})
|
||||
|
||||
it("should update currency includes_tax", async () => {
|
||||
const api = useApi()
|
||||
const response = await api.post(
|
||||
`/admin/currencies/aed`,
|
||||
{
|
||||
includes_tax: true,
|
||||
},
|
||||
adminReqConfig
|
||||
)
|
||||
|
||||
expect(response.data).toMatchSnapshot()
|
||||
})
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user