corrected tests and added null checks
This commit is contained in:
@@ -149,7 +149,7 @@ export default async (req, res) => {
|
||||
.withTransaction(manager)
|
||||
.retrieve(id)
|
||||
|
||||
const evaluatedNoNotification = value.no_notification !== undefined ? value.no_notification : order.no_notification
|
||||
const evaluatedNoNotification = value.no_notification !== undefined && value.no_notification !== null ? value.no_notification : order.no_notification
|
||||
returnObj.no_notification = evaluatedNoNotification
|
||||
|
||||
const createdReturn = await returnService
|
||||
|
||||
@@ -215,9 +215,10 @@ describe("ClaimService", () => {
|
||||
it.each(
|
||||
[
|
||||
[false, false],
|
||||
[undefined, true]
|
||||
],
|
||||
"passes correct no_notification status to event bus", async (input, expected) => {
|
||||
[undefined, true],
|
||||
[null, true],
|
||||
])
|
||||
("passes correct no_notification status to event bus, with '%s'", async (input, expected) => {
|
||||
await claimService.create({
|
||||
...testClaim,
|
||||
no_notification: input,
|
||||
@@ -227,7 +228,6 @@ describe("ClaimService", () => {
|
||||
id: expect.any(String),
|
||||
no_notification: expected
|
||||
})
|
||||
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
@@ -1134,7 +1134,8 @@ describe("OrderService", () => {
|
||||
it.each([
|
||||
[false, false],
|
||||
[undefined, true],
|
||||
],"emits correct no_notification option", async (input, expected) => {
|
||||
[null, true],
|
||||
])("emits correct no_notification option with '%s'", async (input, expected) => {
|
||||
await orderService.createRefund(
|
||||
IdMap.getId("order_123"),
|
||||
100,
|
||||
|
||||
@@ -345,7 +345,8 @@ describe("SwapService", () => {
|
||||
[true, true],
|
||||
[false, false],
|
||||
[undefined, true],
|
||||
])( "passes correct no_notification to eventBus with %s", async (input, expected) => {
|
||||
[null, true],
|
||||
])( "passes correct no_notification to eventBus with '%s'", async (input, expected) => {
|
||||
|
||||
await swapService.create(
|
||||
testOrder,
|
||||
|
||||
@@ -101,7 +101,7 @@ class ClaimService extends BaseService {
|
||||
const claimRepo = manager.getCustomRepository(this.claimRepository_)
|
||||
const claim = await this.retrieve(id, { relations: ["shipping_methods"] })
|
||||
|
||||
const { claim_items, shipping_methods, metadata } = data
|
||||
const { claim_items, shipping_methods, metadata, no_notification } = data
|
||||
|
||||
if (metadata) {
|
||||
claim.metadata = this.setMetadata_(claim, metadata)
|
||||
@@ -135,6 +135,11 @@ class ClaimService extends BaseService {
|
||||
}
|
||||
}
|
||||
|
||||
if(no_notification !== undefined || no_notification !== null){
|
||||
claim.no_notification = no_notification
|
||||
await claimRepo.save(claim)
|
||||
}
|
||||
|
||||
if (claim_items) {
|
||||
for (const i of claim_items) {
|
||||
if (i.id) {
|
||||
@@ -145,6 +150,7 @@ class ClaimService extends BaseService {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
await this.eventBus_
|
||||
.withTransaction(manager)
|
||||
.emit(ClaimService.Events.UPDATED, {
|
||||
@@ -235,7 +241,7 @@ class ClaimService extends BaseService {
|
||||
)
|
||||
)
|
||||
|
||||
const evaluatedNoNotification = no_notification !== undefined ? no_notification : order.no_notification
|
||||
const evaluatedNoNotification = no_notification !== undefined && no_notification !== null ? no_notification : order.no_notification
|
||||
|
||||
const created = claimRepo.create({
|
||||
shipping_address_id: addressId,
|
||||
|
||||
@@ -164,6 +164,7 @@ class NotificationService extends BaseService {
|
||||
if (!subs) {
|
||||
return
|
||||
}
|
||||
|
||||
if(data['no_notification'] === true) {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -308,9 +308,12 @@ class OrderService extends BaseService {
|
||||
* @return {Promise<Order>} the order document
|
||||
*/
|
||||
async retrieve(orderId, config = {}) {
|
||||
|
||||
|
||||
const orderRepo = this.manager_.getCustomRepository(this.orderRepository_)
|
||||
const validatedId = this.validateId_(orderId)
|
||||
|
||||
|
||||
const { select, relations, totalsToSelect } = this.transformQueryForTotals_(
|
||||
config
|
||||
)
|
||||
@@ -330,7 +333,6 @@ class OrderService extends BaseService {
|
||||
const rels = query.relations
|
||||
delete query.relations
|
||||
const raw = await orderRepo.findOneWithRelations(rels, query)
|
||||
|
||||
if (!raw) {
|
||||
throw new MedusaError(
|
||||
MedusaError.Types.NOT_FOUND,
|
||||
@@ -983,7 +985,6 @@ class OrderService extends BaseService {
|
||||
"tax_total",
|
||||
"gift_card_total",
|
||||
"total",
|
||||
"no_notification"
|
||||
],
|
||||
relations: [
|
||||
"discounts",
|
||||
@@ -1132,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 !== null ? noNotification : order.no_notification
|
||||
|
||||
this.eventBus_.emit(OrderService.Events.REFUND_CREATED, {
|
||||
id: result.id,
|
||||
|
||||
@@ -238,7 +238,7 @@ class SwapService extends BaseService {
|
||||
})
|
||||
)
|
||||
|
||||
const evaluatedNoNotification = noNotification !== undefined ? noNotification : order.no_notification
|
||||
const evaluatedNoNotification = noNotification !== undefined && noNotification !== null ? noNotification : order.no_notification
|
||||
|
||||
const swapRepo = manager.getCustomRepository(this.swapRepository_)
|
||||
const created = swapRepo.create({
|
||||
@@ -363,6 +363,10 @@ class SwapService extends BaseService {
|
||||
swap.metadata = this.setMetadata_(swap, update.metadata)
|
||||
}
|
||||
|
||||
if("no_notification" in update){
|
||||
swap.no_notification = update.no_notification
|
||||
}
|
||||
|
||||
if ("shipping_address" in update) {
|
||||
await this.updateShippingAddress_(swap, update.shipping_address)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user