generated from helsingborg-stad/gdi-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add owner notification to expire reservation job
- Loading branch information
Petter Andersson
committed
Jun 18, 2024
1 parent
2913377
commit 5e1fb2b
Showing
2 changed files
with
73 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' | ||
|
||
|
@@ -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() | ||
) | ||
} | ||
) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters