add: is_discount filtering + unit tests (#330)
This commit is contained in:
@@ -44,7 +44,7 @@ describe("GET /admin/discounts", () => {
|
||||
jest.clearAllMocks()
|
||||
subject = await request(
|
||||
"GET",
|
||||
`/admin/discounts?q=OLI&limit=40&offset=20&is_dynamic=false`,
|
||||
`/admin/discounts?q=OLI&limit=40&offset=20&is_dynamic=false&is_disabled=false`,
|
||||
{
|
||||
adminSession: {
|
||||
jwt: {
|
||||
@@ -62,7 +62,7 @@ describe("GET /admin/discounts", () => {
|
||||
it("calls service retrieve with config", () => {
|
||||
expect(DiscountServiceMock.listAndCount).toHaveBeenCalledTimes(1)
|
||||
expect(DiscountServiceMock.listAndCount).toHaveBeenCalledWith(
|
||||
{ q: "OLI", is_dynamic: false },
|
||||
{ q: "OLI", is_dynamic: false, is_disabled: false },
|
||||
{
|
||||
select: defaultFields,
|
||||
relations: defaultRelations,
|
||||
@@ -73,4 +73,70 @@ describe("GET /admin/discounts", () => {
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe("successful retrieval of dynamic discounts", () => {
|
||||
let subject
|
||||
|
||||
beforeAll(async () => {
|
||||
jest.clearAllMocks()
|
||||
subject = await request("GET", `/admin/discounts?is_dynamic=true`, {
|
||||
adminSession: {
|
||||
jwt: {
|
||||
userId: IdMap.getId("admin_user"),
|
||||
},
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
it("returns 200", () => {
|
||||
expect(subject.status).toEqual(200)
|
||||
})
|
||||
|
||||
it("calls service retrieve with corresponding config", () => {
|
||||
expect(DiscountServiceMock.listAndCount).toHaveBeenCalledTimes(1)
|
||||
expect(DiscountServiceMock.listAndCount).toHaveBeenCalledWith(
|
||||
{ is_dynamic: true },
|
||||
{
|
||||
select: defaultFields,
|
||||
relations: defaultRelations,
|
||||
skip: 0,
|
||||
take: 20,
|
||||
order: { created_at: "DESC" },
|
||||
}
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe("successful retrieval of disabled discounts", () => {
|
||||
let subject
|
||||
|
||||
beforeAll(async () => {
|
||||
jest.clearAllMocks()
|
||||
subject = await request("GET", `/admin/discounts?is_disabled=true`, {
|
||||
adminSession: {
|
||||
jwt: {
|
||||
userId: IdMap.getId("admin_user"),
|
||||
},
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
it("returns 200", () => {
|
||||
expect(subject.status).toEqual(200)
|
||||
})
|
||||
|
||||
it("calls service retrieve with corresponding config", () => {
|
||||
expect(DiscountServiceMock.listAndCount).toHaveBeenCalledTimes(1)
|
||||
expect(DiscountServiceMock.listAndCount).toHaveBeenCalledWith(
|
||||
{ is_disabled: true },
|
||||
{
|
||||
select: defaultFields,
|
||||
relations: defaultRelations,
|
||||
skip: 0,
|
||||
take: 20,
|
||||
order: { created_at: "DESC" },
|
||||
}
|
||||
)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -34,6 +34,10 @@ export default async (req, res) => {
|
||||
selector.is_dynamic = req.query.is_dynamic === "true"
|
||||
}
|
||||
|
||||
if ("is_disabled" in req.query) {
|
||||
selector.is_disabled = req.query.is_disabled === "true"
|
||||
}
|
||||
|
||||
const listConfig = {
|
||||
select: defaultFields,
|
||||
relations: defaultRelations,
|
||||
|
||||
Reference in New Issue
Block a user