added tests to remaining components
This commit is contained in:
1 parent
5b65345af1
commit
bd6d0c6130
8 files changed
+39
-24
No files matched your search
@@ -27,6 +27,7 @@ export default async (req, res) => {
|
|||||||
items: Validator.array().optional(),
|
items: Validator.array().optional(),
|
||||||
})
|
})
|
||||||
.required(),
|
.required(),
|
||||||
|
no_notification: Validator.boolean().optional(),
|
||||||
metadata: Validator.object().optional(),
|
metadata: Validator.object().optional(),
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -25,6 +25,9 @@ import { defaultRelations, defaultFields } from "./"
|
|||||||
* note:
|
* note:
|
||||||
* description: A not with additional details about the Refund.
|
* description: A not with additional details about the Refund.
|
||||||
* type: string
|
* type: string
|
||||||
|
* no_notification:
|
||||||
|
* description: If set to true no notification will be send related to this Swap.
|
||||||
|
* type: boolean
|
||||||
* tags:
|
* tags:
|
||||||
* - Order
|
* - Order
|
||||||
* responses:
|
* responses:
|
||||||
@@ -47,6 +50,7 @@ export default async (req, res) => {
|
|||||||
note: Validator.string()
|
note: Validator.string()
|
||||||
.allow("")
|
.allow("")
|
||||||
.optional(),
|
.optional(),
|
||||||
|
no_notification: Validator.boolean().optional(),
|
||||||
})
|
})
|
||||||
|
|
||||||
const { value, error } = schema.validate(req.body)
|
const { value, error } = schema.validate(req.body)
|
||||||
@@ -57,7 +61,7 @@ export default async (req, res) => {
|
|||||||
try {
|
try {
|
||||||
const orderService = req.scope.resolve("orderService")
|
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, {
|
const order = await orderService.retrieve(id, {
|
||||||
select: defaultFields,
|
select: defaultFields,
|
||||||
|
|||||||
@@ -22,7 +22,8 @@ export default async (req, res) => {
|
|||||||
price: Validator.number(),
|
price: Validator.number(),
|
||||||
data: Validator.object(),
|
data: Validator.object(),
|
||||||
items: Validator.array(),
|
items: Validator.array(),
|
||||||
})
|
}),
|
||||||
|
no_notification: Validator.boolean(),
|
||||||
})
|
})
|
||||||
|
|
||||||
const { value, error } = schema.validate(req.body)
|
const { value, error } = schema.validate(req.body)
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ describe("ClaimService", () => {
|
|||||||
order: {
|
order: {
|
||||||
id: "1234",
|
id: "1234",
|
||||||
region_id: "order_region",
|
region_id: "order_region",
|
||||||
|
no_notification: true,
|
||||||
items: [
|
items: [
|
||||||
{
|
{
|
||||||
id: "itm_1",
|
id: "itm_1",
|
||||||
@@ -138,6 +139,7 @@ describe("ClaimService", () => {
|
|||||||
expect(claimRepo.create).toHaveBeenCalledTimes(1)
|
expect(claimRepo.create).toHaveBeenCalledTimes(1)
|
||||||
expect(claimRepo.create).toHaveBeenCalledWith({
|
expect(claimRepo.create).toHaveBeenCalledWith({
|
||||||
payment_status: "not_refunded",
|
payment_status: "not_refunded",
|
||||||
|
no_notification: true,
|
||||||
refund_amount: 1000,
|
refund_amount: 1000,
|
||||||
type: "refund",
|
type: "refund",
|
||||||
order_id: "1234",
|
order_id: "1234",
|
||||||
@@ -156,6 +158,7 @@ describe("ClaimService", () => {
|
|||||||
expect(eventBusService.emit).toHaveBeenCalledTimes(1)
|
expect(eventBusService.emit).toHaveBeenCalledTimes(1)
|
||||||
expect(eventBusService.emit).toHaveBeenCalledWith("claim.created", {
|
expect(eventBusService.emit).toHaveBeenCalledWith("claim.created", {
|
||||||
id: "claim_134",
|
id: "claim_134",
|
||||||
|
no_notification: true,
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -208,6 +211,24 @@ describe("ClaimService", () => {
|
|||||||
})
|
})
|
||||||
).rejects.toThrow(`Claims must have at least one claim item.`)
|
).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", () => {
|
describe("retrieve", () => {
|
||||||
|
|||||||
@@ -1081,6 +1081,7 @@ describe("OrderService", () => {
|
|||||||
paid_total: 100,
|
paid_total: 100,
|
||||||
refundable_amount: 100,
|
refundable_amount: 100,
|
||||||
refunded_total: 0,
|
refunded_total: 0,
|
||||||
|
no_notification: true,
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
@@ -1130,18 +1131,21 @@ describe("OrderService", () => {
|
|||||||
).rejects.toThrow("Cannot refund more than the original order amount")
|
).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(
|
await orderService.createRefund(
|
||||||
IdMap.getId("order_123"),
|
IdMap.getId("order_123"),
|
||||||
100,
|
100,
|
||||||
"discount",
|
"discount",
|
||||||
"note",
|
"note",
|
||||||
false
|
input
|
||||||
)
|
)
|
||||||
|
|
||||||
expect(eventBusService.emit).toHaveBeenCalledWith(expect.any(String),{
|
expect(eventBusService.emit).toHaveBeenCalledWith(expect.any(String),{
|
||||||
id: expect.any(String),
|
id: expect.any(String),
|
||||||
no_notification: false,
|
no_notification: expected,
|
||||||
refund_id: expect.any(String)
|
refund_id: expect.any(String)
|
||||||
} )
|
} )
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -344,6 +344,7 @@ describe("SwapService", () => {
|
|||||||
it.each([
|
it.each([
|
||||||
[true, true],
|
[true, true],
|
||||||
[false, false],
|
[false, false],
|
||||||
|
[undefined, true],
|
||||||
])( "passes correct no_notification to eventBus with %s", async (input, expected) => {
|
])( "passes correct no_notification to eventBus with %s", async (input, expected) => {
|
||||||
|
|
||||||
await swapService.create(
|
await swapService.create(
|
||||||
@@ -361,23 +362,6 @@ describe("SwapService", () => {
|
|||||||
expect.any(String),
|
expect.any(String),
|
||||||
{"id": undefined, "no_notification": expected})
|
{"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})
|
|
||||||
})
|
|
||||||
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -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({
|
const created = claimRepo.create({
|
||||||
shipping_address_id: addressId,
|
shipping_address_id: addressId,
|
||||||
|
|||||||
@@ -1132,7 +1132,7 @@ class OrderService extends BaseService {
|
|||||||
|
|
||||||
const result = await this.retrieve(orderId)
|
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, {
|
this.eventBus_.emit(OrderService.Events.REFUND_CREATED, {
|
||||||
id: result.id,
|
id: result.id,
|
||||||
|
|||||||
Reference in new issue
Block a user