added tests to remaining components

This commit is contained in:
--list
2021-06-10 11:33:31 +02:00
parent 5507f35acf
commit 04fe5292f7
8 changed files with 39 additions and 24 deletions

View File

@@ -27,6 +27,7 @@ export default async (req, res) => {
items: Validator.array().optional(),
})
.required(),
no_notification: Validator.boolean().optional(),
metadata: Validator.object().optional(),
})

View File

@@ -25,6 +25,9 @@ import { defaultRelations, defaultFields } from "./"
* note:
* description: A not with additional details about the Refund.
* type: string
* no_notification:
* description: If set to true no notification will be send related to this Swap.
* type: boolean
* tags:
* - Order
* responses:
@@ -47,6 +50,7 @@ export default async (req, res) => {
note: Validator.string()
.allow("")
.optional(),
no_notification: Validator.boolean().optional(),
})
const { value, error } = schema.validate(req.body)
@@ -57,7 +61,7 @@ export default async (req, res) => {
try {
const orderService = req.scope.resolve("orderService")
await orderService.createRefund(id, value.amount, value.reason, value.note)
await orderService.createRefund(id, value.amount, value.reason, value.note, value.no_notification)
const order = await orderService.retrieve(id, {
select: defaultFields,

View File

@@ -22,7 +22,8 @@ export default async (req, res) => {
price: Validator.number(),
data: Validator.object(),
items: Validator.array(),
})
}),
no_notification: Validator.boolean(),
})
const { value, error } = schema.validate(req.body)

View File

@@ -22,6 +22,7 @@ describe("ClaimService", () => {
order: {
id: "1234",
region_id: "order_region",
no_notification: true,
items: [
{
id: "itm_1",
@@ -138,6 +139,7 @@ describe("ClaimService", () => {
expect(claimRepo.create).toHaveBeenCalledTimes(1)
expect(claimRepo.create).toHaveBeenCalledWith({
payment_status: "not_refunded",
no_notification: true,
refund_amount: 1000,
type: "refund",
order_id: "1234",
@@ -156,6 +158,7 @@ describe("ClaimService", () => {
expect(eventBusService.emit).toHaveBeenCalledTimes(1)
expect(eventBusService.emit).toHaveBeenCalledWith("claim.created", {
id: "claim_134",
no_notification: true,
})
})
@@ -208,6 +211,24 @@ describe("ClaimService", () => {
})
).rejects.toThrow(`Claims must have at least one claim item.`)
})
it.each(
[
[false, false],
[undefined, true]
],
"passes correct no_notification status to event bus", async (input, expected) => {
await claimService.create({
...testClaim,
no_notification: input,
})
expect(eventBusService.emit).toHaveBeenCalledWith(expect.any(String),{
id: expect.any(String),
no_notification: expected
})
})
})
describe("retrieve", () => {

View File

@@ -1081,6 +1081,7 @@ describe("OrderService", () => {
paid_total: 100,
refundable_amount: 100,
refunded_total: 0,
no_notification: true,
})
},
})
@@ -1130,18 +1131,21 @@ describe("OrderService", () => {
).rejects.toThrow("Cannot refund more than the original order amount")
})
it("emits correct no_notification option", async () => {
it.each([
[false, false],
[undefined, true],
],"emits correct no_notification option", async (input, expected) => {
await orderService.createRefund(
IdMap.getId("order_123"),
100,
"discount",
"note",
false
input
)
expect(eventBusService.emit).toHaveBeenCalledWith(expect.any(String),{
id: expect.any(String),
no_notification: false,
no_notification: expected,
refund_id: expect.any(String)
} )
})

View File

@@ -344,6 +344,7 @@ describe("SwapService", () => {
it.each([
[true, true],
[false, false],
[undefined, true],
])( "passes correct no_notification to eventBus with %s", async (input, expected) => {
await swapService.create(
@@ -361,23 +362,6 @@ describe("SwapService", () => {
expect.any(String),
{"id": undefined, "no_notification": expected})
})
it("passes inherited value of order when no no_notification value is given ", async () => {
await swapService.create(
testOrder,
[{ item_id: IdMap.getId("line"), quantity: 1 }],
[{ variant_id: IdMap.getId("new-variant"), quantity: 1 }],
{
id: IdMap.getId("return-shipping"),
price: 20,
}
)
expect(eventBusService.emit).toHaveBeenCalledWith(
expect.anything(),
{"id": undefined, "no_notification": true})
})
})
})

View File

@@ -235,7 +235,7 @@ class ClaimService extends BaseService {
)
)
const evaluatedNoNotification = no_notification ? no_notification : order.no_notification
const evaluatedNoNotification = no_notification !== undefined ? no_notification : order.no_notification
const created = claimRepo.create({
shipping_address_id: addressId,

View File

@@ -1133,7 +1133,7 @@ class OrderService extends BaseService {
const result = await this.retrieve(orderId)
const evaluatedNoNotification = noNotification != undefined ? noNotification : order.no_notification
const evaluatedNoNotification = noNotification !== undefined ? noNotification : order.no_notification
this.eventBus_.emit(OrderService.Events.REFUND_CREATED, {
id: result.id,