feat(medusa): adds support for gift cards (#132)
* fix(medusa-plugin-brightpearl): adds gift cards to gift card nominal code * fix: allow orders with 0 total to be created * fix: gift card ready * tests passing * docs: brightpearl comment * docs: clearer REMEMBER note
This commit is contained in:
@@ -7,6 +7,7 @@ describe("GET /admin/discounts", () => {
|
||||
let subject
|
||||
|
||||
beforeAll(async () => {
|
||||
jest.clearAllMocks()
|
||||
subject = await request("GET", `/admin/discounts`, {
|
||||
adminSession: {
|
||||
jwt: {
|
||||
@@ -22,7 +23,61 @@ describe("GET /admin/discounts", () => {
|
||||
|
||||
it("calls service retrieve", () => {
|
||||
expect(DiscountServiceMock.list).toHaveBeenCalledTimes(1)
|
||||
expect(DiscountServiceMock.list).toHaveBeenCalledWith()
|
||||
expect(DiscountServiceMock.list).toHaveBeenCalledWith({})
|
||||
})
|
||||
})
|
||||
|
||||
describe("is_giftcard filter", () => {
|
||||
let subject
|
||||
|
||||
beforeAll(async () => {
|
||||
jest.clearAllMocks()
|
||||
subject = await request("GET", `/admin/discounts?is_giftcard=true`, {
|
||||
adminSession: {
|
||||
jwt: {
|
||||
userId: IdMap.getId("admin_user"),
|
||||
},
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
it("returns 200", () => {
|
||||
expect(subject.status).toEqual(200)
|
||||
})
|
||||
|
||||
it("calls service retrieve", () => {
|
||||
expect(DiscountServiceMock.list).toHaveBeenCalledTimes(1)
|
||||
expect(DiscountServiceMock.list).toHaveBeenCalledWith({
|
||||
is_giftcard: true,
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe("expand region filter", () => {
|
||||
let subject
|
||||
|
||||
beforeAll(async () => {
|
||||
jest.clearAllMocks()
|
||||
subject = await request("GET", `/admin/discounts?expand_fields=regions`, {
|
||||
adminSession: {
|
||||
jwt: {
|
||||
userId: IdMap.getId("admin_user"),
|
||||
},
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
it("returns 200", () => {
|
||||
expect(subject.status).toEqual(200)
|
||||
})
|
||||
|
||||
it("calls service retrieve", () => {
|
||||
expect(DiscountServiceMock.decorate).toHaveBeenCalledTimes(1)
|
||||
expect(
|
||||
DiscountServiceMock.decorate
|
||||
).toHaveBeenCalledWith(expect.anything(), expect.anything(), ["regions"])
|
||||
expect(DiscountServiceMock.list).toHaveBeenCalledTimes(1)
|
||||
expect(DiscountServiceMock.list).toHaveBeenCalledWith({})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,7 +1,34 @@
|
||||
export default async (req, res) => {
|
||||
try {
|
||||
const selector = {}
|
||||
|
||||
const discountService = req.scope.resolve("discountService")
|
||||
const data = await discountService.list()
|
||||
|
||||
if ("is_giftcard" in req.query) {
|
||||
selector.is_giftcard = req.query.is_giftcard === "true"
|
||||
}
|
||||
|
||||
let expandFields = []
|
||||
if ("expand_fields" in req.query) {
|
||||
expandFields = req.query.expand_fields.split(",")
|
||||
}
|
||||
|
||||
let includeFields = [
|
||||
"usage_count",
|
||||
"starts_at",
|
||||
"ends_at",
|
||||
"original_amount",
|
||||
"created",
|
||||
]
|
||||
if ("fields" in req.query) {
|
||||
includeFields = req.query.fields.split(",")
|
||||
}
|
||||
|
||||
const raw = await discountService.list(selector)
|
||||
|
||||
const data = await Promise.all(
|
||||
raw.map(d => discountService.decorate(d, includeFields, expandFields))
|
||||
)
|
||||
|
||||
res.status(200).json({ discounts: data })
|
||||
} catch (err) {
|
||||
|
||||
@@ -10,6 +10,10 @@ export default async (req, res) => {
|
||||
"description",
|
||||
])
|
||||
|
||||
if ("is_giftcard" in req.query) {
|
||||
query.is_giftcard = req.query.is_giftcard === "true"
|
||||
}
|
||||
|
||||
const limit = parseInt(req.query.limit) || 0
|
||||
const offset = parseInt(req.query.offset) || 0
|
||||
|
||||
@@ -40,7 +44,6 @@ export default async (req, res) => {
|
||||
|
||||
res.json({ products, total_count: numProducts })
|
||||
} catch (error) {
|
||||
console.log(error)
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user