@@ -7,13 +7,9 @@ import {
77 $LetterStatusChangeEvent ,
88 LetterStatusChangeEvent ,
99} from "@nhsdigital/nhs-notify-event-schemas-supplier-api/src/events/letter-events" ;
10- import {
11- SupplierConfigRepository ,
12- SupplierQuotasRepository ,
13- } from "@internal/datastore" ;
10+ import { SupplierConfigRepository } from "@internal/datastore" ;
1411import createSupplierAllocatorHandler from "../allocate-handler" ;
1512import * as supplierConfig from "../../services/supplier-config" ;
16- import * as supplierQuotas from "../../services/supplier-quotas" ;
1713
1814import { Deps } from "../../config/deps" ;
1915import { EnvVars } from "../../config/env" ;
@@ -25,7 +21,6 @@ const renderingSchemaVersion: string =
2521 ] ;
2622
2723jest . mock ( "../../services/supplier-config" ) ;
28- jest . mock ( "../../services/supplier-quotas" ) ;
2924
3025function createSQSEvent ( records : SQSRecord [ ] ) : SQSEvent {
3126 return {
@@ -174,19 +169,12 @@ function setupDefaultMocks() {
174169 colour : false ,
175170 duplex : false ,
176171 } ) ;
177- (
178- supplierQuotas . calculateSupplierAllocatedFactor as jest . Mock
179- ) . mockResolvedValue ( {
180- supplierId : "supplier-1" ,
181- factor : 0.5 ,
182- } ) ;
183172}
184173
185174describe ( "createSupplierAllocatorHandler" , ( ) => {
186175 let mockSqsClient : jest . Mocked < SQSClient > ;
187176 let mockedDeps : jest . Mocked < Deps > ;
188177 let mockedSupplierConfigRepo : jest . Mocked < SupplierConfigRepository > ;
189- let mockedSupplierQuotasRepo : jest . Mocked < SupplierQuotasRepository > ;
190178 beforeEach ( ( ) => {
191179 mockSqsClient = {
192180 send : jest . fn ( ) ,
@@ -203,22 +191,10 @@ describe("createSupplierAllocatorHandler", () => {
203191 getPackSpecification : jest . fn ( ) ,
204192 } as jest . Mocked < SupplierConfigRepository > ;
205193
206- mockedSupplierQuotasRepo = {
207- ddbClient : { } as any ,
208- config : { } as any ,
209- getOverallAllocation : jest . fn ( ) ,
210- putOverallAllocation : jest . fn ( ) ,
211- updateOverallAllocation : jest . fn ( ) ,
212- getDailyAllocation : jest . fn ( ) ,
213- putDailyAllocation : jest . fn ( ) ,
214- updateDailyAllocation : jest . fn ( ) ,
215- } as jest . Mocked < SupplierQuotasRepository > ;
216-
217194 mockedDeps = {
218195 logger : { error : jest . fn ( ) , info : jest . fn ( ) } as unknown as pino . Logger ,
219196 env : {
220197 SUPPLIER_CONFIG_TABLE_NAME : "SupplierConfigTable" ,
221- SUPPLIER_QUOTAS_TABLE_NAME : "SupplierQuotasTable" ,
222198 VARIANT_MAP : {
223199 lv1 : {
224200 supplierId : "supplier1" ,
@@ -230,7 +206,6 @@ describe("createSupplierAllocatorHandler", () => {
230206 } as EnvVars ,
231207 sqsClient : mockSqsClient ,
232208 supplierConfigRepo : mockedSupplierConfigRepo ,
233- supplierQuotasRepo : mockedSupplierQuotasRepo ,
234209 } as jest . Mocked < Deps > ;
235210 jest . clearAllMocks ( ) ;
236211 } ) ;
@@ -459,39 +434,6 @@ describe("createSupplierAllocatorHandler", () => {
459434 ) ;
460435 } ) ;
461436
462- test ( "returns batch failure when variant mapping is missing for multiple events" , async ( ) => {
463- const preparedEvent1 = createPreparedV2Event ( ) ;
464- preparedEvent1 . data . letterVariantId = "missing-variant1" ;
465- const preparedEvent2 = createPreparedV2Event ( ) ;
466- preparedEvent2 . data . letterVariantId = "missing-variant2" ;
467-
468- const evt : SQSEvent = createSQSEvent ( [
469- createSqsRecord ( "msg1" , JSON . stringify ( preparedEvent1 ) ) ,
470- createSqsRecord ( "msg2" , JSON . stringify ( preparedEvent2 ) ) ,
471- ] ) ;
472-
473- process . env . UPSERT_LETTERS_QUEUE_URL = "https://sqs.test.queue" ;
474-
475- // Override variant map to be empty for this test
476- mockedDeps . env . VARIANT_MAP = { } as any ;
477-
478- const handler = createSupplierAllocatorHandler ( mockedDeps ) ;
479- const result = await handler ( evt , { } as any , { } as any ) ;
480- if ( ! result ) throw new Error ( "expected BatchResponse, got void" ) ;
481-
482- expect ( result . batchItemFailures ) . toHaveLength ( 2 ) ;
483- expect ( result . batchItemFailures [ 0 ] . itemIdentifier ) . toBe ( "msg1" ) ;
484- expect ( result . batchItemFailures [ 1 ] . itemIdentifier ) . toBe ( "msg2" ) ;
485- expect (
486- ( mockedDeps . logger . error as jest . Mock ) . mock . calls . length ,
487- ) . toBeGreaterThan ( 0 ) ;
488- expect ( ( mockedDeps . logger . error as jest . Mock ) . mock . calls [ 0 ] [ 0 ] ) . toEqual (
489- expect . objectContaining ( {
490- description : "No supplier mapping found for variant" ,
491- } ) ,
492- ) ;
493- } ) ;
494-
495437 test ( "handles SQS send errors and returns batch failure" , async ( ) => {
496438 const preparedEvent = createPreparedV2Event ( ) ;
497439
0 commit comments