|
1 | 1 | import LetterAcceptedEvent from '@nhsdigital/nhs-notify-event-schemas-supplier-api/schemas/examples/letter.ACCEPTED.json'; |
2 | | -import LetterReturnedEvent from '@nhsdigital/nhs-notify-event-schemas-supplier-api/schemas/examples/letter.RETURNED.json'; |
3 | | -import LetterFailedEvent from '@nhsdigital/nhs-notify-event-schemas-supplier-api/schemas/examples/letter.FAILED.json'; |
| 2 | +import LetterCancelledEvent from '@nhsdigital/nhs-notify-event-schemas-supplier-api/schemas/examples/letter.CANCELLED.json'; |
| 3 | +import LetterDeliveredEvent from '@nhsdigital/nhs-notify-event-schemas-supplier-api/schemas/examples/letter.DELIVERED.json'; |
4 | 4 | import LetterDispatchedEvent from '@nhsdigital/nhs-notify-event-schemas-supplier-api/schemas/examples/letter.DISPATCHED.json'; |
| 5 | +import LetterEnclosedEvent from '@nhsdigital/nhs-notify-event-schemas-supplier-api/schemas/examples/letter.ENCLOSED.json'; |
| 6 | +import LetterFailedEvent from '@nhsdigital/nhs-notify-event-schemas-supplier-api/schemas/examples/letter.FAILED.json'; |
| 7 | +import LetterForwardedEvent from '@nhsdigital/nhs-notify-event-schemas-supplier-api/schemas/examples/letter.FORWARDED.json'; |
| 8 | +import LetterPendingEvent from '@nhsdigital/nhs-notify-event-schemas-supplier-api/schemas/examples/letter.PENDING.json'; |
5 | 9 | import LetterPrintedEvent from '@nhsdigital/nhs-notify-event-schemas-supplier-api/schemas/examples/letter.PRINTED.json'; |
6 | 10 | import LetterRejectedEvent from '@nhsdigital/nhs-notify-event-schemas-supplier-api/schemas/examples/letter.REJECTED.json'; |
| 11 | +import LetterReturnedEvent from '@nhsdigital/nhs-notify-event-schemas-supplier-api/schemas/examples/letter.RETURNED.json'; |
7 | 12 | import { |
8 | 13 | MatchersV3, |
9 | 14 | MessageConsumerPact, |
@@ -197,4 +202,143 @@ describe('Pact message consumer - Supplier API events', () => { |
197 | 202 | .verify(asynchronousBodyHandler(handle)), |
198 | 203 | ).resolves.not.toThrow(); |
199 | 204 | }); |
| 205 | + |
| 206 | + it('validates a letter cancelled event', async () => { |
| 207 | + await expect( |
| 208 | + messagePact |
| 209 | + .expectsToReceive('SupplierApiEvent-letter_cancelled') |
| 210 | + .withContent({ |
| 211 | + data: { |
| 212 | + origin: { |
| 213 | + subject: MatchersV3.regex( |
| 214 | + /^client\/[^/]+\/letter-request\/[^/]+$/, |
| 215 | + LetterCancelledEvent.data.origin.subject, |
| 216 | + ), |
| 217 | + }, |
| 218 | + reasonCode: MatchersV3.string(LetterCancelledEvent.data.reasonCode), |
| 219 | + reasonText: MatchersV3.string(LetterCancelledEvent.data.reasonText), |
| 220 | + specificationId: MatchersV3.string( |
| 221 | + LetterCancelledEvent.data.specificationId, |
| 222 | + ), |
| 223 | + status: LetterCancelledEvent.data.status, |
| 224 | + supplierId: MatchersV3.string(LetterCancelledEvent.data.supplierId), |
| 225 | + }, |
| 226 | + time: MatchersV3.timestamp( |
| 227 | + "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", |
| 228 | + LetterCancelledEvent.time, |
| 229 | + ), |
| 230 | + }) |
| 231 | + .verify(asynchronousBodyHandler(handle)), |
| 232 | + ).resolves.not.toThrow(); |
| 233 | + }); |
| 234 | + |
| 235 | + it('validates a letter delivered event', async () => { |
| 236 | + await expect( |
| 237 | + messagePact |
| 238 | + .expectsToReceive('SupplierApiEvent-letter_delivered') |
| 239 | + .withContent({ |
| 240 | + data: { |
| 241 | + origin: { |
| 242 | + subject: MatchersV3.regex( |
| 243 | + /^client\/[^/]+\/letter-request\/[^/]+$/, |
| 244 | + LetterDeliveredEvent.data.origin.subject, |
| 245 | + ), |
| 246 | + }, |
| 247 | + specificationId: MatchersV3.string( |
| 248 | + LetterDeliveredEvent.data.specificationId, |
| 249 | + ), |
| 250 | + status: LetterDeliveredEvent.data.status, |
| 251 | + supplierId: MatchersV3.string(LetterDeliveredEvent.data.supplierId), |
| 252 | + }, |
| 253 | + time: MatchersV3.timestamp( |
| 254 | + "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", |
| 255 | + LetterDeliveredEvent.time, |
| 256 | + ), |
| 257 | + }) |
| 258 | + .verify(asynchronousBodyHandler(handle)), |
| 259 | + ).resolves.not.toThrow(); |
| 260 | + }); |
| 261 | + |
| 262 | + it('validates a letter enclosed event', async () => { |
| 263 | + await expect( |
| 264 | + messagePact |
| 265 | + .expectsToReceive('SupplierApiEvent-letter_enclosed') |
| 266 | + .withContent({ |
| 267 | + data: { |
| 268 | + origin: { |
| 269 | + subject: MatchersV3.regex( |
| 270 | + /^client\/[^/]+\/letter-request\/[^/]+$/, |
| 271 | + LetterEnclosedEvent.data.origin.subject, |
| 272 | + ), |
| 273 | + }, |
| 274 | + specificationId: MatchersV3.string( |
| 275 | + LetterEnclosedEvent.data.specificationId, |
| 276 | + ), |
| 277 | + status: LetterEnclosedEvent.data.status, |
| 278 | + supplierId: MatchersV3.string(LetterEnclosedEvent.data.supplierId), |
| 279 | + }, |
| 280 | + time: MatchersV3.timestamp( |
| 281 | + "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", |
| 282 | + LetterEnclosedEvent.time, |
| 283 | + ), |
| 284 | + }) |
| 285 | + .verify(asynchronousBodyHandler(handle)), |
| 286 | + ).resolves.not.toThrow(); |
| 287 | + }); |
| 288 | + |
| 289 | + it('validates a letter forwarded event', async () => { |
| 290 | + await expect( |
| 291 | + messagePact |
| 292 | + .expectsToReceive('SupplierApiEvent-letter_forwarded') |
| 293 | + .withContent({ |
| 294 | + data: { |
| 295 | + origin: { |
| 296 | + subject: MatchersV3.regex( |
| 297 | + /^client\/[^/]+\/letter-request\/[^/]+$/, |
| 298 | + LetterForwardedEvent.data.origin.subject, |
| 299 | + ), |
| 300 | + }, |
| 301 | + reasonCode: MatchersV3.string(LetterForwardedEvent.data.reasonCode), |
| 302 | + reasonText: MatchersV3.string(LetterForwardedEvent.data.reasonText), |
| 303 | + specificationId: MatchersV3.string( |
| 304 | + LetterForwardedEvent.data.specificationId, |
| 305 | + ), |
| 306 | + status: LetterForwardedEvent.data.status, |
| 307 | + supplierId: MatchersV3.string(LetterForwardedEvent.data.supplierId), |
| 308 | + }, |
| 309 | + time: MatchersV3.timestamp( |
| 310 | + "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", |
| 311 | + LetterForwardedEvent.time, |
| 312 | + ), |
| 313 | + }) |
| 314 | + .verify(asynchronousBodyHandler(handle)), |
| 315 | + ).resolves.not.toThrow(); |
| 316 | + }); |
| 317 | + |
| 318 | + it('validates a letter pending event', async () => { |
| 319 | + await expect( |
| 320 | + messagePact |
| 321 | + .expectsToReceive('SupplierApiEvent-letter_pending') |
| 322 | + .withContent({ |
| 323 | + data: { |
| 324 | + origin: { |
| 325 | + subject: MatchersV3.regex( |
| 326 | + /^client\/[^/]+\/letter-request\/[^/]+$/, |
| 327 | + LetterPendingEvent.data.origin.subject, |
| 328 | + ), |
| 329 | + }, |
| 330 | + specificationId: MatchersV3.string( |
| 331 | + LetterPendingEvent.data.specificationId, |
| 332 | + ), |
| 333 | + status: LetterPendingEvent.data.status, |
| 334 | + supplierId: MatchersV3.string(LetterPendingEvent.data.supplierId), |
| 335 | + }, |
| 336 | + time: MatchersV3.timestamp( |
| 337 | + "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", |
| 338 | + LetterPendingEvent.time, |
| 339 | + ), |
| 340 | + }) |
| 341 | + .verify(asynchronousBodyHandler(handle)), |
| 342 | + ).resolves.not.toThrow(); |
| 343 | + }); |
200 | 344 | }); |
0 commit comments