Skip to content

Commit

Permalink
add owner notification to expire reservation job
Browse files Browse the repository at this point in the history
  • Loading branch information
Petter Andersson committed Jun 18, 2024
1 parent 2913377 commit 5e1fb2b
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { createExpiredClaimsNotifier } from '.'
import { end2endTest } from '../../../test-utils'
import {
createTestNotificationServices,
end2endTest,
} from '../../../test-utils'
import { createEmptyAdvert } from '../../mappers'
import { AdvertClaimType } from '../../types'

Expand Down Expand Up @@ -88,4 +91,65 @@ describe('notifyExpiredClaims', () => {
)
expect(result.advert).toBeNull()
}))
it('should call notification actions when a claim expired)', () => {
const advertReservationWasCancelled = jest.fn(async () => undefined)
const advertReservationWasCancelledOwner = jest.fn(async () => undefined)
const notifications = createTestNotificationServices({
advertReservationWasCancelled,
advertReservationWasCancelledOwner,
})

return end2endTest(
{
services: { notifications },
},
async ({ user, adverts, services }) => {
const createTestAdvert = () => ({
...createEmptyAdvert(),
id: 'advert-123',
createdBy: user.id,
quantity: 50,
claims: [
{
by: '[email protected]',
at: '2023-05-01T00:00:00.000Z',
quantity: 2,
type: AdvertClaimType.reserved,
events: [],
},
{
by: '[email protected]',
at: '2024-05-01T00:00:00.000Z',
quantity: 4,
type: AdvertClaimType.reserved,
events: [],
},
],
})
// eslint-disable-next-line no-param-reassign
adverts['advert-123'] = createTestAdvert()

const notifyExpiredClaims = createExpiredClaimsNotifier(services)

await notifyExpiredClaims(
user,
'advert-123',
1,
new Date('2024-05-01T00:00:00.000Z')
)
expect(advertReservationWasCancelled).toHaveBeenCalledWith(
'[email protected]',
expect.objectContaining(user),
2,
createTestAdvert()
)
expect(advertReservationWasCancelledOwner).toHaveBeenCalledWith(
adverts['advert-123'].createdBy,
expect.objectContaining(user),
2,
createTestAdvert()
)
}
)
})
})
8 changes: 8 additions & 0 deletions src/adverts/advert-mutations/claims/notify-expired-claims.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ export const createExpiredClaimsNotifier =
advert
)
)
actions(() =>
notifications.advertReservationWasCancelledOwner(
advert.createdBy,
user,
c.quantity,
advert
)
)
actions(() =>
syslog.write({
by: user.id,
Expand Down

0 comments on commit 5e1fb2b

Please sign in to comment.