Merge remote-tracking branch 'origin/develop' into release/next
This commit is contained in:
@@ -44,7 +44,7 @@ describe("GET /admin/discounts", () => {
|
|||||||
jest.clearAllMocks()
|
jest.clearAllMocks()
|
||||||
subject = await request(
|
subject = await request(
|
||||||
"GET",
|
"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: {
|
adminSession: {
|
||||||
jwt: {
|
jwt: {
|
||||||
@@ -62,7 +62,7 @@ describe("GET /admin/discounts", () => {
|
|||||||
it("calls service retrieve with config", () => {
|
it("calls service retrieve with config", () => {
|
||||||
expect(DiscountServiceMock.listAndCount).toHaveBeenCalledTimes(1)
|
expect(DiscountServiceMock.listAndCount).toHaveBeenCalledTimes(1)
|
||||||
expect(DiscountServiceMock.listAndCount).toHaveBeenCalledWith(
|
expect(DiscountServiceMock.listAndCount).toHaveBeenCalledWith(
|
||||||
{ q: "OLI", is_dynamic: false },
|
{ q: "OLI", is_dynamic: false, is_disabled: false },
|
||||||
{
|
{
|
||||||
select: defaultFields,
|
select: defaultFields,
|
||||||
relations: defaultRelations,
|
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"
|
selector.is_dynamic = req.query.is_dynamic === "true"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ("is_disabled" in req.query) {
|
||||||
|
selector.is_disabled = req.query.is_disabled === "true"
|
||||||
|
}
|
||||||
|
|
||||||
const listConfig = {
|
const listConfig = {
|
||||||
select: defaultFields,
|
select: defaultFields,
|
||||||
relations: defaultRelations,
|
relations: defaultRelations,
|
||||||
|
|||||||
@@ -222,10 +222,18 @@ export default async (req, res) => {
|
|||||||
inventory_quantity: Validator.number().default(0),
|
inventory_quantity: Validator.number().default(0),
|
||||||
allow_backorder: Validator.boolean().optional(),
|
allow_backorder: Validator.boolean().optional(),
|
||||||
manage_inventory: Validator.boolean().optional(),
|
manage_inventory: Validator.boolean().optional(),
|
||||||
weight: Validator.number().optional(),
|
weight: Validator.number()
|
||||||
length: Validator.number().optional(),
|
.allow(null)
|
||||||
height: Validator.number().optional(),
|
.optional(),
|
||||||
width: Validator.number().optional(),
|
length: Validator.number()
|
||||||
|
.allow(null)
|
||||||
|
.optional(),
|
||||||
|
height: Validator.number()
|
||||||
|
.allow(null)
|
||||||
|
.optional(),
|
||||||
|
width: Validator.number()
|
||||||
|
.allow(null)
|
||||||
|
.optional(),
|
||||||
origin_country: Validator.string()
|
origin_country: Validator.string()
|
||||||
.optional()
|
.optional()
|
||||||
.allow("")
|
.allow("")
|
||||||
@@ -259,10 +267,18 @@ export default async (req, res) => {
|
|||||||
})
|
})
|
||||||
.default([]),
|
.default([]),
|
||||||
}),
|
}),
|
||||||
weight: Validator.number().optional(),
|
weight: Validator.number()
|
||||||
length: Validator.number().optional(),
|
.allow(null)
|
||||||
height: Validator.number().optional(),
|
.optional(),
|
||||||
width: Validator.number().optional(),
|
length: Validator.number()
|
||||||
|
.allow(null)
|
||||||
|
.optional(),
|
||||||
|
height: Validator.number()
|
||||||
|
.allow(null)
|
||||||
|
.optional(),
|
||||||
|
width: Validator.number()
|
||||||
|
.allow(null)
|
||||||
|
.optional(),
|
||||||
hs_code: Validator.string()
|
hs_code: Validator.string()
|
||||||
.optional()
|
.optional()
|
||||||
.allow(""),
|
.allow(""),
|
||||||
|
|||||||
@@ -115,10 +115,18 @@ export default async (req, res) => {
|
|||||||
inventory_quantity: Validator.number().default(0),
|
inventory_quantity: Validator.number().default(0),
|
||||||
allow_backorder: Validator.boolean().optional(),
|
allow_backorder: Validator.boolean().optional(),
|
||||||
manage_inventory: Validator.boolean().optional(),
|
manage_inventory: Validator.boolean().optional(),
|
||||||
weight: Validator.number().optional(),
|
weight: Validator.number()
|
||||||
length: Validator.number().optional(),
|
.allow(null)
|
||||||
height: Validator.number().optional(),
|
.optional(),
|
||||||
width: Validator.number().optional(),
|
length: Validator.number()
|
||||||
|
.allow(null)
|
||||||
|
.optional(),
|
||||||
|
height: Validator.number()
|
||||||
|
.allow(null)
|
||||||
|
.optional(),
|
||||||
|
width: Validator.number()
|
||||||
|
.allow(null)
|
||||||
|
.optional(),
|
||||||
origin_country: Validator.string().allow(""),
|
origin_country: Validator.string().allow(""),
|
||||||
mid_code: Validator.string().allow(""),
|
mid_code: Validator.string().allow(""),
|
||||||
material: Validator.string().allow(""),
|
material: Validator.string().allow(""),
|
||||||
@@ -127,7 +135,7 @@ export default async (req, res) => {
|
|||||||
.items(
|
.items(
|
||||||
Validator.object()
|
Validator.object()
|
||||||
.keys({
|
.keys({
|
||||||
region_id: Validator.string(),
|
region_id: Validator.string().empty(null),
|
||||||
currency_code: Validator.string().required(),
|
currency_code: Validator.string().required(),
|
||||||
amount: Validator.number()
|
amount: Validator.number()
|
||||||
.integer()
|
.integer()
|
||||||
|
|||||||
@@ -210,11 +210,20 @@ export default async (req, res) => {
|
|||||||
})
|
})
|
||||||
.optional(),
|
.optional(),
|
||||||
handle: Validator.string().optional(),
|
handle: Validator.string().optional(),
|
||||||
weight: Validator.number().optional(),
|
weight: Validator.number()
|
||||||
length: Validator.number().optional(),
|
.allow(null)
|
||||||
height: Validator.number().optional(),
|
.optional(),
|
||||||
width: Validator.number().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, ""),
|
origin_country: Validator.string().allow(null, ""),
|
||||||
|
hs_code: Validator.string().allow(null, ""),
|
||||||
mid_code: Validator.string().allow(null, ""),
|
mid_code: Validator.string().allow(null, ""),
|
||||||
material: Validator.string().allow(null, ""),
|
material: Validator.string().allow(null, ""),
|
||||||
images: Validator.array()
|
images: Validator.array()
|
||||||
@@ -250,10 +259,18 @@ export default async (req, res) => {
|
|||||||
inventory_quantity: Validator.number().allow(null),
|
inventory_quantity: Validator.number().allow(null),
|
||||||
allow_backorder: Validator.boolean().allow(null),
|
allow_backorder: Validator.boolean().allow(null),
|
||||||
manage_inventory: Validator.boolean().allow(null),
|
manage_inventory: Validator.boolean().allow(null),
|
||||||
weight: Validator.number().optional(),
|
weight: Validator.number()
|
||||||
length: Validator.number().optional(),
|
.allow(null)
|
||||||
height: Validator.number().optional(),
|
.optional(),
|
||||||
width: Validator.number().optional(),
|
length: Validator.number()
|
||||||
|
.allow(null)
|
||||||
|
.optional(),
|
||||||
|
height: Validator.number()
|
||||||
|
.allow(null)
|
||||||
|
.optional(),
|
||||||
|
width: Validator.number()
|
||||||
|
.allow(null)
|
||||||
|
.optional(),
|
||||||
hs_code: Validator.string()
|
hs_code: Validator.string()
|
||||||
.optional()
|
.optional()
|
||||||
.allow(null, ""),
|
.allow(null, ""),
|
||||||
|
|||||||
@@ -114,7 +114,7 @@ export default async (req, res) => {
|
|||||||
prices: Validator.array().items(
|
prices: Validator.array().items(
|
||||||
Validator.object()
|
Validator.object()
|
||||||
.keys({
|
.keys({
|
||||||
region_id: Validator.string(),
|
region_id: Validator.string().empty(null),
|
||||||
currency_code: Validator.string(),
|
currency_code: Validator.string(),
|
||||||
amount: Validator.number()
|
amount: Validator.number()
|
||||||
.integer()
|
.integer()
|
||||||
@@ -133,10 +133,18 @@ export default async (req, res) => {
|
|||||||
inventory_quantity: Validator.number().optional(),
|
inventory_quantity: Validator.number().optional(),
|
||||||
allow_backorder: Validator.boolean().optional(),
|
allow_backorder: Validator.boolean().optional(),
|
||||||
manage_inventory: Validator.boolean().optional(),
|
manage_inventory: Validator.boolean().optional(),
|
||||||
weight: Validator.number().optional(),
|
weight: Validator.number()
|
||||||
length: Validator.number().optional(),
|
.allow(null)
|
||||||
height: Validator.number().optional(),
|
.optional(),
|
||||||
width: Validator.number().optional(),
|
length: Validator.number()
|
||||||
|
.allow(null)
|
||||||
|
.optional(),
|
||||||
|
height: Validator.number()
|
||||||
|
.allow(null)
|
||||||
|
.optional(),
|
||||||
|
width: Validator.number()
|
||||||
|
.allow(null)
|
||||||
|
.optional(),
|
||||||
hs_code: Validator.string()
|
hs_code: Validator.string()
|
||||||
.optional()
|
.optional()
|
||||||
.allow(null, ""),
|
.allow(null, ""),
|
||||||
|
|||||||
Reference in New Issue
Block a user