@@ -263,4 +263,86 @@ 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 returns empty array for non-existent pack specification" , async ( ) => {
301+ const packSpecId = "non-existent-pack-spec" ;
302+ const result =
303+ await repository . getSupplierPacksForPackSpecification ( packSpecId ) ;
304+ expect ( result ) . toEqual ( [ ] ) ;
305+ } ) ;
306+
307+ test ( "getPackSpecification returns correct pack specification details" , async ( ) => {
308+ const packSpecId = "pack-spec-123" ;
309+
310+ await dbContext . docClient . send (
311+ new PutCommand ( {
312+ TableName : dbContext . config . supplierConfigTableName ,
313+ Item : {
314+ PK : "PACK_SPECIFICATION" ,
315+ SK : packSpecId ,
316+ id : packSpecId ,
317+ name : `Pack Specification ${ packSpecId } ` ,
318+ createdAt : new Date ( ) . toISOString ( ) ,
319+ updatedAt : new Date ( ) . toISOString ( ) ,
320+ version : 1 ,
321+ billingId : `billing-${ packSpecId } ` ,
322+ postage : { id : "postageId" , size : "STANDARD" } ,
323+ status : "PROD" ,
324+ } ,
325+ } ) ,
326+ ) ;
327+
328+ const result = await repository . getPackSpecification ( packSpecId ) ;
329+ expect ( result ) . toEqual ( {
330+ billingId : `billing-${ packSpecId } ` ,
331+ createdAt : expect . any ( String ) ,
332+ id : packSpecId ,
333+ name : `Pack Specification ${ packSpecId } ` ,
334+ postage : { id : "postageId" , size : "STANDARD" } ,
335+ updatedAt : expect . any ( String ) ,
336+ version : 1 ,
337+ status : "PROD" ,
338+ } ) ;
339+ } ) ;
340+
341+ test ( "getPackSpecification throws error for non-existent pack specification" , async ( ) => {
342+ const packSpecId = "non-existent-pack-spec" ;
343+
344+ await expect ( repository . getPackSpecification ( packSpecId ) ) . rejects . toThrow (
345+ `No pack specification found for id ${ packSpecId } ` ,
346+ ) ;
347+ } ) ;
266348} ) ;
0 commit comments