@@ -263,4 +263,89 @@ describe("SupplierConfigRepository", () => {
263263 `Supplier with id ${ supplierId } not found` ,
264264 ) ;
265265 } ) ;
266+
267+ test ( "getSupplierPacksForPackSpecification returns correct supplier packs" , async ( ) => {
268+ const packSpecId = "pack-spec-123" ;
269+ const supplierId = "supplier-123" ;
270+ const supplierPackId = "supplier-pack-123" ;
271+
272+ await dbContext . docClient . send (
273+ new PutCommand ( {
274+ TableName : dbContext . config . supplierConfigTableName ,
275+ Item : {
276+ PK : "SUPPLIER_PACK" ,
277+ SK : supplierPackId ,
278+ id : supplierPackId ,
279+ packSpecificationId : packSpecId ,
280+ supplierId,
281+ status : "PROD" ,
282+ approval : "APPROVED" ,
283+ } ,
284+ } ) ,
285+ ) ;
286+
287+ const result =
288+ await repository . getSupplierPacksForPackSpecification ( packSpecId ) ;
289+ expect ( result ) . toEqual ( [
290+ {
291+ approval : "APPROVED" ,
292+ id : supplierPackId ,
293+ packSpecificationId : packSpecId ,
294+ supplierId,
295+ status : "PROD" ,
296+ } ,
297+ ] ) ;
298+ } ) ;
299+
300+ test ( "getSupplierPacksForPackSpecification throws error for non-existent pack specification" , async ( ) => {
301+ const packSpecId = "non-existent-pack-spec" ;
302+
303+ await expect (
304+ repository . getSupplierPacksForPackSpecification ( packSpecId ) ,
305+ ) . rejects . toThrow (
306+ `No supplier packs found for pack specification id ${ packSpecId } ` ,
307+ ) ;
308+ } ) ;
309+
310+ test ( "getPackSpecification returns correct pack specification details" , async ( ) => {
311+ const packSpecId = "pack-spec-123" ;
312+
313+ await dbContext . docClient . send (
314+ new PutCommand ( {
315+ TableName : dbContext . config . supplierConfigTableName ,
316+ Item : {
317+ PK : "PACK_SPECIFICATION" ,
318+ SK : packSpecId ,
319+ id : packSpecId ,
320+ name : `Pack Specification ${ packSpecId } ` ,
321+ createdAt : new Date ( ) . toISOString ( ) ,
322+ updatedAt : new Date ( ) . toISOString ( ) ,
323+ version : 1 ,
324+ billingId : `billing-${ packSpecId } ` ,
325+ postage : { id : "postageId" , size : "STANDARD" } ,
326+ status : "PROD" ,
327+ } ,
328+ } ) ,
329+ ) ;
330+
331+ const result = await repository . getPackSpecification ( packSpecId ) ;
332+ expect ( result ) . toEqual ( {
333+ billingId : `billing-${ packSpecId } ` ,
334+ createdAt : expect . any ( String ) ,
335+ id : packSpecId ,
336+ name : `Pack Specification ${ packSpecId } ` ,
337+ postage : { id : "postageId" , size : "STANDARD" } ,
338+ updatedAt : expect . any ( String ) ,
339+ version : 1 ,
340+ status : "PROD" ,
341+ } ) ;
342+ } ) ;
343+
344+ test ( "getPackSpecification throws error for non-existent pack specification" , async ( ) => {
345+ const packSpecId = "non-existent-pack-spec" ;
346+
347+ await expect ( repository . getPackSpecification ( packSpecId ) ) . rejects . toThrow (
348+ `No pack specification found for id ${ packSpecId } ` ,
349+ ) ;
350+ } ) ;
266351} ) ;
0 commit comments