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 parent
cabdb2fcd8
commit
100154d905
11 files changed
+407
-1006
No files matched your search
@@ -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()
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
|
||||||
@@ -0,0 +1,76 @@
|
|||||||
|
import {
|
||||||
|
adminHeaders,
|
||||||
|
createAdminUser,
|
||||||
|
} from "../../../../helpers/create-admin-user"
|
||||||
|
import { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||||
|
|
||||||
|
jest.setTimeout(30000)
|
||||||
|
|
||||||
|
medusaIntegrationTestRunner({
|
||||||
|
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||||
|
beforeEach(async () => {
|
||||||
|
await createAdminUser(dbConnection, adminHeaders, getContainer())
|
||||||
|
})
|
||||||
|
|
||||||
|
it.only("test the entire authentication flow", async () => {
|
||||||
|
// BREAKING: `/admin/auth` changes to `/auth/user/emailpass`
|
||||||
|
const signup = await api.post("/auth/user/emailpass", {
|
||||||
|
email: "newadmin@medusa.js",
|
||||||
|
password: "secret_password",
|
||||||
|
})
|
||||||
|
|
||||||
|
//BREAKING: In V2, we respond with a JWT token instead of the user object, and a session is not created. you need to call `/auth/session` to create a session
|
||||||
|
expect(signup.status).toEqual(200)
|
||||||
|
expect(signup.data).toEqual({ token: expect.any(String) })
|
||||||
|
|
||||||
|
// BREAKING: IN V2 creating a user is separated from creating an auth identity
|
||||||
|
const createdUser = await api.post(
|
||||||
|
"/admin/users",
|
||||||
|
{ email: "newadmin@medusa.js" },
|
||||||
|
{ headers: { authorization: `Bearer ${signup.data.token}` } }
|
||||||
|
)
|
||||||
|
expect(createdUser.status).toEqual(200)
|
||||||
|
expect(createdUser.data.user.email).toEqual("newadmin@medusa.js")
|
||||||
|
|
||||||
|
const login = await api.post("/auth/user/emailpass", {
|
||||||
|
email: "newadmin@medusa.js",
|
||||||
|
password: "secret_password",
|
||||||
|
})
|
||||||
|
expect(login.status).toEqual(200)
|
||||||
|
expect(login.data).toEqual({ token: expect.any(String) })
|
||||||
|
|
||||||
|
const createSession = await api.post(
|
||||||
|
"/auth/session",
|
||||||
|
{},
|
||||||
|
{ headers: { authorization: `Bearer ${login.data.token}` } }
|
||||||
|
)
|
||||||
|
expect(createSession.status).toEqual(200)
|
||||||
|
|
||||||
|
// extract cookie
|
||||||
|
const [cookie] = createSession.headers["set-cookie"][0].split(";")
|
||||||
|
expect(cookie).toEqual(expect.stringContaining("connect.sid"))
|
||||||
|
|
||||||
|
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)
|
||||||
|
})
|
||||||
|
},
|
||||||
|
})
|
||||||
@@ -0,0 +1,262 @@
|
|||||||
|
import { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||||
|
import {
|
||||||
|
createAdminUser,
|
||||||
|
adminHeaders,
|
||||||
|
} from "../../../../helpers/create-admin-user"
|
||||||
|
|
||||||
|
jest.setTimeout(30000)
|
||||||
|
|
||||||
|
medusaIntegrationTestRunner({
|
||||||
|
env: {},
|
||||||
|
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||||
|
let baseCollection
|
||||||
|
let baseCollection1
|
||||||
|
let baseCollection2
|
||||||
|
|
||||||
|
let baseProduct
|
||||||
|
let baseProduct1
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
const container = getContainer()
|
||||||
|
await createAdminUser(dbConnection, adminHeaders, container)
|
||||||
|
|
||||||
|
baseCollection = (
|
||||||
|
await api.post(
|
||||||
|
"/admin/collections",
|
||||||
|
{ title: "test-collection" },
|
||||||
|
adminHeaders
|
||||||
|
)
|
||||||
|
).data.collection
|
||||||
|
|
||||||
|
baseCollection1 = (
|
||||||
|
await api.post(
|
||||||
|
"/admin/collections",
|
||||||
|
{ title: "test-collection1" },
|
||||||
|
adminHeaders
|
||||||
|
)
|
||||||
|
).data.collection
|
||||||
|
|
||||||
|
baseCollection2 = (
|
||||||
|
await api.post(
|
||||||
|
"/admin/collections",
|
||||||
|
{ title: "test-collection2" },
|
||||||
|
adminHeaders
|
||||||
|
)
|
||||||
|
).data.collection
|
||||||
|
|
||||||
|
baseProduct = (
|
||||||
|
await api.post(
|
||||||
|
"/admin/products",
|
||||||
|
{
|
||||||
|
title: "test-product",
|
||||||
|
},
|
||||||
|
adminHeaders
|
||||||
|
)
|
||||||
|
).data.product
|
||||||
|
|
||||||
|
baseProduct1 = (
|
||||||
|
await api.post(
|
||||||
|
"/admin/products",
|
||||||
|
{
|
||||||
|
title: "test-product1",
|
||||||
|
},
|
||||||
|
adminHeaders
|
||||||
|
)
|
||||||
|
).data.product
|
||||||
|
})
|
||||||
|
|
||||||
|
describe("/admin/collections", () => {
|
||||||
|
it("creates a collection", async () => {
|
||||||
|
const response = await api.post(
|
||||||
|
"/admin/collections",
|
||||||
|
{
|
||||||
|
title: "New collection",
|
||||||
|
handle: "test-new-collection",
|
||||||
|
},
|
||||||
|
adminHeaders
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(response.status).toEqual(200)
|
||||||
|
expect(response.data).toEqual(
|
||||||
|
expect.objectContaining({
|
||||||
|
collection: expect.objectContaining({
|
||||||
|
id: expect.stringMatching(/^pcol_*/),
|
||||||
|
title: "New collection",
|
||||||
|
handle: "test-new-collection",
|
||||||
|
created_at: expect.any(String),
|
||||||
|
updated_at: expect.any(String),
|
||||||
|
}),
|
||||||
|
})
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
it("lists collections", async () => {
|
||||||
|
const response = await api.get("/admin/collections", adminHeaders)
|
||||||
|
|
||||||
|
expect(response.data).toEqual(
|
||||||
|
expect.objectContaining({
|
||||||
|
count: 3,
|
||||||
|
collections: expect.arrayContaining([
|
||||||
|
expect.objectContaining({
|
||||||
|
id: baseCollection2.id,
|
||||||
|
created_at: expect.any(String),
|
||||||
|
updated_at: expect.any(String),
|
||||||
|
}),
|
||||||
|
expect.objectContaining({
|
||||||
|
id: baseCollection1.id,
|
||||||
|
created_at: expect.any(String),
|
||||||
|
updated_at: expect.any(String),
|
||||||
|
}),
|
||||||
|
expect.objectContaining({
|
||||||
|
id: baseCollection.id,
|
||||||
|
created_at: expect.any(String),
|
||||||
|
updated_at: expect.any(String),
|
||||||
|
}),
|
||||||
|
]),
|
||||||
|
})
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
it("filters collections by title", async () => {
|
||||||
|
const response = await api.get(
|
||||||
|
"/admin/collections?title=test-collection",
|
||||||
|
adminHeaders
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(response.data).toEqual(
|
||||||
|
expect.objectContaining({
|
||||||
|
count: 1,
|
||||||
|
collections: expect.arrayContaining([
|
||||||
|
expect.objectContaining({
|
||||||
|
id: baseCollection.id,
|
||||||
|
created_at: expect.any(String),
|
||||||
|
updated_at: expect.any(String),
|
||||||
|
}),
|
||||||
|
]),
|
||||||
|
})
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
// BREAKING: There is no longer discount condition ID filtering for collections (test case: "returns a list of collections filtered by discount condition id")
|
||||||
|
})
|
||||||
|
|
||||||
|
describe("/admin/collections/:id", () => {
|
||||||
|
it("updates a collection", async () => {
|
||||||
|
const response = await api.post(
|
||||||
|
`/admin/collections/${baseCollection.id}`,
|
||||||
|
{
|
||||||
|
title: "test collection creation",
|
||||||
|
handle: "test-handle-creation",
|
||||||
|
},
|
||||||
|
adminHeaders
|
||||||
|
)
|
||||||
|
|
||||||
|
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 response = await api.delete(
|
||||||
|
`/admin/collections/${baseCollection.id}`,
|
||||||
|
adminHeaders
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(response.status).toEqual(200)
|
||||||
|
expect(response.data).toEqual({
|
||||||
|
id: baseCollection.id,
|
||||||
|
object: "collection",
|
||||||
|
deleted: true,
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it("gets collection", async () => {
|
||||||
|
const response = await api.get(
|
||||||
|
`/admin/collections/${baseCollection.id}`,
|
||||||
|
adminHeaders
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(response.data).toEqual(
|
||||||
|
expect.objectContaining({
|
||||||
|
collection: expect.objectContaining({
|
||||||
|
id: baseCollection.id,
|
||||||
|
created_at: expect.any(String),
|
||||||
|
updated_at: expect.any(String),
|
||||||
|
}),
|
||||||
|
})
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
// BREAKING: URL and payload changes for adding products to a collection (there is no more "batch" suffix)
|
||||||
|
it("adds products to collection", async () => {
|
||||||
|
const response = await api.post(
|
||||||
|
`/admin/collections/${baseCollection.id}/products?fields=*products`,
|
||||||
|
{
|
||||||
|
add: [baseProduct.id, baseProduct1.id],
|
||||||
|
},
|
||||||
|
adminHeaders
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(response.status).toEqual(200)
|
||||||
|
expect(response.data.collection).toEqual(
|
||||||
|
expect.objectContaining({
|
||||||
|
id: baseCollection.id,
|
||||||
|
created_at: expect.any(String),
|
||||||
|
updated_at: expect.any(String),
|
||||||
|
products: expect.arrayContaining([
|
||||||
|
expect.objectContaining({
|
||||||
|
collection_id: baseCollection.id,
|
||||||
|
title: "test-product",
|
||||||
|
}),
|
||||||
|
expect.objectContaining({
|
||||||
|
collection_id: baseCollection.id,
|
||||||
|
title: "test-product1",
|
||||||
|
}),
|
||||||
|
]),
|
||||||
|
})
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
it("removes products from collection", async () => {
|
||||||
|
await api.post(
|
||||||
|
`/admin/collections/${baseCollection.id}/products`,
|
||||||
|
{
|
||||||
|
add: [baseProduct.id, baseProduct1.id],
|
||||||
|
},
|
||||||
|
adminHeaders
|
||||||
|
)
|
||||||
|
|
||||||
|
const response = await api.post(
|
||||||
|
`/admin/collections/${baseCollection.id}/products?fields=*products`,
|
||||||
|
{
|
||||||
|
remove: [baseProduct1.id],
|
||||||
|
},
|
||||||
|
adminHeaders
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(response.data.collection).toEqual(
|
||||||
|
expect.objectContaining({
|
||||||
|
id: baseCollection.id,
|
||||||
|
products: [
|
||||||
|
expect.objectContaining({
|
||||||
|
collection_id: baseCollection.id,
|
||||||
|
title: "test-product",
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
})
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(response.status).toEqual(200)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
},
|
||||||
|
})
|
||||||
File renamed without changes.
@@ -0,0 +1,66 @@
|
|||||||
|
import { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||||
|
import {
|
||||||
|
createAdminUser,
|
||||||
|
adminHeaders,
|
||||||
|
} from "../../../../helpers/create-admin-user"
|
||||||
|
|
||||||
|
jest.setTimeout(30000)
|
||||||
|
|
||||||
|
medusaIntegrationTestRunner({
|
||||||
|
env: {},
|
||||||
|
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||||
|
beforeEach(async () => {
|
||||||
|
const container = getContainer()
|
||||||
|
await createAdminUser(dbConnection, adminHeaders, container)
|
||||||
|
})
|
||||||
|
|
||||||
|
describe("GET /admin/currencies", () => {
|
||||||
|
it("should retrieve the currencies", async () => {
|
||||||
|
const response = await api.get(
|
||||||
|
"/admin/currencies?order=code",
|
||||||
|
adminHeaders
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(response.status).toEqual(200)
|
||||||
|
expect(response.data.currencies).toHaveLength(120)
|
||||||
|
expect(response.data.currencies).toEqual(
|
||||||
|
expect.arrayContaining([
|
||||||
|
expect.objectContaining({
|
||||||
|
code: "usd",
|
||||||
|
name: "US Dollar",
|
||||||
|
}),
|
||||||
|
])
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should retrieve the currencies filtered with q param", async () => {
|
||||||
|
const response = await api.get(
|
||||||
|
`/admin/currencies?q=us&order=code`,
|
||||||
|
adminHeaders
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(response.status).toEqual(200)
|
||||||
|
expect(response.data.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",
|
||||||
|
}),
|
||||||
|
])
|
||||||
|
})
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
|
// BREAKING: There was an "should update currency includes_tax" test that no longer applies in v2 (realted to MEDUSA_FF_TAX_INCLUSIVE_PRICING)
|
||||||
|
})
|
||||||
@@ -14,6 +14,6 @@ export const retrieveTransformQueryConfig = {
|
|||||||
|
|
||||||
export const listTransformQueryConfig = {
|
export const listTransformQueryConfig = {
|
||||||
...retrieveTransformQueryConfig,
|
...retrieveTransformQueryConfig,
|
||||||
defaultLimit: 50,
|
defaultLimit: 200,
|
||||||
isList: true,
|
isList: true,
|
||||||
}
|
}
|
||||||
@@ -8,7 +8,7 @@ export type AdminGetCurrenciesParamsType = z.infer<
|
|||||||
>
|
>
|
||||||
export const AdminGetCurrenciesParams = createFindParams({
|
export const AdminGetCurrenciesParams = createFindParams({
|
||||||
offset: 0,
|
offset: 0,
|
||||||
limit: 50,
|
limit: 200,
|
||||||
}).merge(
|
}).merge(
|
||||||
z.object({
|
z.object({
|
||||||
q: z.string().optional(),
|
q: z.string().optional(),
|
||||||
|
|||||||
@@ -59,6 +59,7 @@ export const GET = async (req: MedusaRequest, res: MedusaResponse) => {
|
|||||||
const entityIdKey = `${actor_type}_id`
|
const entityIdKey = `${actor_type}_id`
|
||||||
const entityId = authIdentity.app_metadata?.[entityIdKey]
|
const entityId = authIdentity.app_metadata?.[entityIdKey]
|
||||||
const { jwtSecret, jwtExpiresIn } = http
|
const { jwtSecret, jwtExpiresIn } = http
|
||||||
|
|
||||||
const token = generateJwtToken(
|
const token = generateJwtToken(
|
||||||
{
|
{
|
||||||
actor_id: entityId,
|
actor_id: entityId,
|
||||||
|
|||||||
Reference in new issue
Block a user