fix(medusa): add q param to listAndCount product types and product tags (#1531)
This commit is contained in:
committed by
GitHub
parent
847508af02
commit
46d9e6c44c
@@ -22,3 +22,26 @@ Array [
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`/admin/product-tags GET /admin/product-tags returns a list of product tags matching free text search param 1`] = `
|
||||
Array [
|
||||
Object {
|
||||
"created_at": Any<String>,
|
||||
"id": "tag1",
|
||||
"updated_at": Any<String>,
|
||||
"value": "123",
|
||||
},
|
||||
Object {
|
||||
"created_at": Any<String>,
|
||||
"id": "tag3",
|
||||
"updated_at": Any<String>,
|
||||
"value": "123",
|
||||
},
|
||||
Object {
|
||||
"created_at": Any<String>,
|
||||
"id": "tag4",
|
||||
"updated_at": Any<String>,
|
||||
"value": "123",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`/admin/product-types GET /admin/product-types returns a list of product types 1`] = `
|
||||
Array [
|
||||
Object {
|
||||
"created_at": Any<String>,
|
||||
"id": "test-type",
|
||||
"updated_at": Any<String>,
|
||||
"value": "test-type",
|
||||
},
|
||||
Object {
|
||||
"created_at": Any<String>,
|
||||
"id": "test-type-new",
|
||||
"updated_at": Any<String>,
|
||||
"value": "test-type-new",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`/admin/product-types GET /admin/product-types returns a list of product types matching free text search param 1`] = `
|
||||
Array [
|
||||
Object {
|
||||
"created_at": Any<String>,
|
||||
"id": "test-type-new",
|
||||
"updated_at": Any<String>,
|
||||
"value": "test-type-new",
|
||||
},
|
||||
]
|
||||
`;
|
||||
@@ -68,5 +68,38 @@ describe("/admin/product-tags", () => {
|
||||
tagMatch,
|
||||
])
|
||||
})
|
||||
|
||||
it("returns a list of product tags matching free text search param", async () => {
|
||||
const api = useApi()
|
||||
|
||||
const res = await api
|
||||
.get("/admin/product-tags?q=123", {
|
||||
headers: {
|
||||
Authorization: "Bearer test_token",
|
||||
},
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log(err)
|
||||
})
|
||||
|
||||
expect(res.status).toEqual(200)
|
||||
|
||||
const tagMatch = {
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
}
|
||||
|
||||
expect(res.data.product_tags.map((pt) => pt.value)).toEqual([
|
||||
"123",
|
||||
"123",
|
||||
"123",
|
||||
])
|
||||
|
||||
expect(res.data.product_tags).toMatchSnapshot([
|
||||
tagMatch,
|
||||
tagMatch,
|
||||
tagMatch,
|
||||
])
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -0,0 +1,102 @@
|
||||
const path = require("path")
|
||||
|
||||
const setupServer = require("../../../helpers/setup-server")
|
||||
const { useApi } = require("../../../helpers/use-api")
|
||||
const { initDb, useDb } = require("../../../helpers/use-db")
|
||||
|
||||
const adminSeeder = require("../../helpers/admin-seeder")
|
||||
const productSeeder = require("../../helpers/product-seeder")
|
||||
|
||||
jest.setTimeout(50000)
|
||||
|
||||
describe("/admin/product-types", () => {
|
||||
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/product-types", () => {
|
||||
beforeEach(async () => {
|
||||
try {
|
||||
await productSeeder(dbConnection)
|
||||
await adminSeeder(dbConnection)
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
throw err
|
||||
}
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
const db = useDb()
|
||||
await db.teardown()
|
||||
})
|
||||
|
||||
it("returns a list of product types", async () => {
|
||||
const api = useApi()
|
||||
|
||||
const res = await api
|
||||
.get("/admin/product-types", {
|
||||
headers: {
|
||||
Authorization: "Bearer test_token",
|
||||
},
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log(err)
|
||||
})
|
||||
|
||||
expect(res.status).toEqual(200)
|
||||
|
||||
const typeMatch = {
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
}
|
||||
|
||||
expect(res.data.product_types).toMatchSnapshot([
|
||||
typeMatch,
|
||||
typeMatch,
|
||||
])
|
||||
})
|
||||
|
||||
it("returns a list of product types matching free text search param", async () => {
|
||||
const api = useApi()
|
||||
|
||||
const res = await api
|
||||
.get("/admin/product-types?q=test-type-new", {
|
||||
headers: {
|
||||
Authorization: "Bearer test_token",
|
||||
},
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log(err)
|
||||
})
|
||||
|
||||
expect(res.status).toEqual(200)
|
||||
|
||||
const typeMatch = {
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
}
|
||||
|
||||
// The value of the type should match the search param
|
||||
expect(res.data.product_types.map((pt) => pt.value)).toEqual([
|
||||
"test-type-new"
|
||||
])
|
||||
|
||||
// Should only return one type as there is only one match to the search param
|
||||
expect(res.data.product_types).toMatchSnapshot([
|
||||
typeMatch
|
||||
])
|
||||
})
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user