feat: Typescript for API layer (#817)
Co-authored-by: Philip Korsholm <88927411+pKorsholm@users.noreply.github.com> Co-authored-by: Zakaria El Asri <33696020+zakariaelas@users.noreply.github.com> Co-authored-by: Kasper Fabricius Kristensen <45367945+kasperkristensen@users.noreply.github.com> Co-authored-by: Philip Korsholm <philip.korsholm@hotmail.com> Co-authored-by: Sebastian Rindom <seb@medusa-commerce.com>
This commit is contained in:
committed by
GitHub
parent
55e200bf68
commit
373532ecbc
220
integration-tests/api/__tests__/admin/colllections.js
Normal file
220
integration-tests/api/__tests__/admin/colllections.js
Normal file
@@ -0,0 +1,220 @@
|
||||
const path = require("path")
|
||||
const setupServer = require("../../../helpers/setup-server")
|
||||
const { useApi } = require("../../../helpers/use-api")
|
||||
const { initDb, useDb } = require("../../../helpers/use-db")
|
||||
|
||||
const productSeeder = require("../../helpers/product-seeder")
|
||||
const adminSeeder = require("../../helpers/admin-seeder")
|
||||
|
||||
jest.setTimeout(30000)
|
||||
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 () => {
|
||||
try {
|
||||
await adminSeeder(dbConnection)
|
||||
await productSeeder(dbConnection)
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
throw err
|
||||
}
|
||||
})
|
||||
|
||||
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: { Authorization: "Bearer test_token" } }
|
||||
)
|
||||
|
||||
const response = await api.post(
|
||||
`/admin/collections/${creationResponse.data.collection.id}`,
|
||||
{
|
||||
title: "test collection creation",
|
||||
handle: "test-handle-creation",
|
||||
},
|
||||
{ headers: { Authorization: "Bearer test_token" } }
|
||||
)
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data).toMatchSnapshot({
|
||||
collection: {
|
||||
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: { Authorization: "Bearer test_token" } }
|
||||
)
|
||||
|
||||
const response = await api.delete(
|
||||
`/admin/collections/${creationResponse.data.collection.id}`,
|
||||
{ headers: { Authorization: "Bearer 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: { Authorization: "Bearer test_token" },
|
||||
})
|
||||
|
||||
expect(response.data).toMatchSnapshot({
|
||||
collection: {
|
||||
id: "test-collection",
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
},
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe("/admin/collections", () => {
|
||||
beforeEach(async () => {
|
||||
try {
|
||||
await adminSeeder(dbConnection)
|
||||
await productSeeder(dbConnection)
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
throw err
|
||||
}
|
||||
})
|
||||
|
||||
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: { Authorization: "Bearer test_token" } }
|
||||
)
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data).toMatchSnapshot({
|
||||
collection: {
|
||||
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: { Authorization: "Bearer test_token" },
|
||||
})
|
||||
|
||||
expect(response.data).toMatchSnapshot({
|
||||
collections: [
|
||||
{
|
||||
id: "test-collection",
|
||||
handle: "test-collection",
|
||||
title: "Test collection",
|
||||
products: [
|
||||
{
|
||||
collection_id: "test-collection",
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
profile_id: expect.stringMatching(/^sp_*/),
|
||||
},
|
||||
{
|
||||
collection_id: "test-collection",
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
profile_id: expect.stringMatching(/^sp_*/),
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
id: "test-collection1",
|
||||
handle: "test-collection1",
|
||||
title: "Test collection 1",
|
||||
products: [
|
||||
{
|
||||
collection_id: "test-collection1",
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
profile_id: expect.stringMatching(/^sp_*/),
|
||||
},
|
||||
{
|
||||
collection_id: "test-collection1",
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
profile_id: expect.stringMatching(/^sp_*/),
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
id: "test-collection2",
|
||||
handle: "test-collection2",
|
||||
title: "Test collection 2",
|
||||
products: [
|
||||
{
|
||||
collection_id: "test-collection2",
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
profile_id: expect.stringMatching(/^sp_*/),
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
count: 3,
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user