Merge remote-tracking branch 'origin/develop' into release/next
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,
|
||||
|
||||
@@ -222,10 +222,18 @@ export default async (req, res) => {
|
||||
inventory_quantity: Validator.number().default(0),
|
||||
allow_backorder: Validator.boolean().optional(),
|
||||
manage_inventory: Validator.boolean().optional(),
|
||||
weight: Validator.number().optional(),
|
||||
length: Validator.number().optional(),
|
||||
height: Validator.number().optional(),
|
||||
width: Validator.number().optional(),
|
||||
weight: Validator.number()
|
||||
.allow(null)
|
||||
.optional(),
|
||||
length: Validator.number()
|
||||
.allow(null)
|
||||
.optional(),
|
||||
height: Validator.number()
|
||||
.allow(null)
|
||||
.optional(),
|
||||
width: Validator.number()
|
||||
.allow(null)
|
||||
.optional(),
|
||||
origin_country: Validator.string()
|
||||
.optional()
|
||||
.allow("")
|
||||
@@ -259,10 +267,18 @@ export default async (req, res) => {
|
||||
})
|
||||
.default([]),
|
||||
}),
|
||||
weight: Validator.number().optional(),
|
||||
length: Validator.number().optional(),
|
||||
height: Validator.number().optional(),
|
||||
width: Validator.number().optional(),
|
||||
weight: Validator.number()
|
||||
.allow(null)
|
||||
.optional(),
|
||||
length: Validator.number()
|
||||
.allow(null)
|
||||
.optional(),
|
||||
height: Validator.number()
|
||||
.allow(null)
|
||||
.optional(),
|
||||
width: Validator.number()
|
||||
.allow(null)
|
||||
.optional(),
|
||||
hs_code: Validator.string()
|
||||
.optional()
|
||||
.allow(""),
|
||||
|
||||
@@ -115,10 +115,18 @@ export default async (req, res) => {
|
||||
inventory_quantity: Validator.number().default(0),
|
||||
allow_backorder: Validator.boolean().optional(),
|
||||
manage_inventory: Validator.boolean().optional(),
|
||||
weight: Validator.number().optional(),
|
||||
length: Validator.number().optional(),
|
||||
height: Validator.number().optional(),
|
||||
width: Validator.number().optional(),
|
||||
weight: Validator.number()
|
||||
.allow(null)
|
||||
.optional(),
|
||||
length: Validator.number()
|
||||
.allow(null)
|
||||
.optional(),
|
||||
height: Validator.number()
|
||||
.allow(null)
|
||||
.optional(),
|
||||
width: Validator.number()
|
||||
.allow(null)
|
||||
.optional(),
|
||||
origin_country: Validator.string().allow(""),
|
||||
mid_code: Validator.string().allow(""),
|
||||
material: Validator.string().allow(""),
|
||||
@@ -127,7 +135,7 @@ export default async (req, res) => {
|
||||
.items(
|
||||
Validator.object()
|
||||
.keys({
|
||||
region_id: Validator.string(),
|
||||
region_id: Validator.string().empty(null),
|
||||
currency_code: Validator.string().required(),
|
||||
amount: Validator.number()
|
||||
.integer()
|
||||
|
||||
@@ -210,11 +210,20 @@ export default async (req, res) => {
|
||||
})
|
||||
.optional(),
|
||||
handle: Validator.string().optional(),
|
||||
weight: Validator.number().optional(),
|
||||
length: Validator.number().optional(),
|
||||
height: Validator.number().optional(),
|
||||
width: Validator.number().optional(),
|
||||
weight: Validator.number()
|
||||
.allow(null)
|
||||
.optional(),
|
||||
length: Validator.number()
|
||||
.allow(null)
|
||||
.optional(),
|
||||
height: Validator.number()
|
||||
.allow(null)
|
||||
.optional(),
|
||||
width: Validator.number()
|
||||
.allow(null)
|
||||
.optional(),
|
||||
origin_country: Validator.string().allow(null, ""),
|
||||
hs_code: Validator.string().allow(null, ""),
|
||||
mid_code: Validator.string().allow(null, ""),
|
||||
material: Validator.string().allow(null, ""),
|
||||
images: Validator.array()
|
||||
@@ -250,10 +259,18 @@ export default async (req, res) => {
|
||||
inventory_quantity: Validator.number().allow(null),
|
||||
allow_backorder: Validator.boolean().allow(null),
|
||||
manage_inventory: Validator.boolean().allow(null),
|
||||
weight: Validator.number().optional(),
|
||||
length: Validator.number().optional(),
|
||||
height: Validator.number().optional(),
|
||||
width: Validator.number().optional(),
|
||||
weight: Validator.number()
|
||||
.allow(null)
|
||||
.optional(),
|
||||
length: Validator.number()
|
||||
.allow(null)
|
||||
.optional(),
|
||||
height: Validator.number()
|
||||
.allow(null)
|
||||
.optional(),
|
||||
width: Validator.number()
|
||||
.allow(null)
|
||||
.optional(),
|
||||
hs_code: Validator.string()
|
||||
.optional()
|
||||
.allow(null, ""),
|
||||
|
||||
@@ -114,7 +114,7 @@ export default async (req, res) => {
|
||||
prices: Validator.array().items(
|
||||
Validator.object()
|
||||
.keys({
|
||||
region_id: Validator.string(),
|
||||
region_id: Validator.string().empty(null),
|
||||
currency_code: Validator.string(),
|
||||
amount: Validator.number()
|
||||
.integer()
|
||||
@@ -133,10 +133,18 @@ export default async (req, res) => {
|
||||
inventory_quantity: Validator.number().optional(),
|
||||
allow_backorder: Validator.boolean().optional(),
|
||||
manage_inventory: Validator.boolean().optional(),
|
||||
weight: Validator.number().optional(),
|
||||
length: Validator.number().optional(),
|
||||
height: Validator.number().optional(),
|
||||
width: Validator.number().optional(),
|
||||
weight: Validator.number()
|
||||
.allow(null)
|
||||
.optional(),
|
||||
length: Validator.number()
|
||||
.allow(null)
|
||||
.optional(),
|
||||
height: Validator.number()
|
||||
.allow(null)
|
||||
.optional(),
|
||||
width: Validator.number()
|
||||
.allow(null)
|
||||
.optional(),
|
||||
hs_code: Validator.string()
|
||||
.optional()
|
||||
.allow(null, ""),
|
||||
|
||||
Reference in New Issue
Block a user