corrected tests and added null checks

This commit is contained in:
--list committed 2021-06-15 10:33:53 +02:00
1 parent bd6d0c6130
commit 6a0da1a423
8 files changed
+27 -13

No files matched your search

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