@@ -72,17 +72,6 @@ describe("supplier-config service", () => {
7272
7373 expect ( result ) . toBe ( group ) ;
7474 } ) ;
75- it ( "logs an error and returns group details when not found" , async ( ) => {
76- const group = undefined ;
77- const deps = makeDeps ( ) ;
78- deps . supplierConfigRepo . getVolumeGroup = jest
79- . fn ( )
80- . mockResolvedValue ( group ) ;
81-
82- const result = await getVolumeGroupDetails ( "missing" , deps ) ;
83-
84- expect ( result ) . toBeUndefined ( ) ;
85- } ) ;
8675
8776 it ( "throws when group is not active based on status" , async ( ) => {
8877 const group = {
@@ -187,8 +176,8 @@ describe("supplier-config service", () => {
187176 { supplier : "s2" , variantId : "v2" } ,
188177 ] as any [ ] ;
189178 const suppliers = [
190- { id : "s1" , name : "Supplier 1" } ,
191- { id : "s2" , name : "Supplier 2" } ,
179+ { id : "s1" , name : "Supplier 1" , status : "PROD" } ,
180+ { id : "s2" , name : "Supplier 2" , status : "PROD" } ,
192181 ] as any [ ] ;
193182 const deps = makeDeps ( ) ;
194183 deps . supplierConfigRepo . getSuppliersDetails = jest
@@ -223,9 +212,9 @@ describe("supplier-config service", () => {
223212 { supplier : "s5" , variantId : "v3" } ,
224213 ] as any [ ] ;
225214 const suppliers = [
226- { id : "s1" , name : "Supplier 1" } ,
227- { id : "s3" , name : "Supplier 3" } ,
228- { id : "s5" , name : "Supplier 5" } ,
215+ { id : "s1" , name : "Supplier 1" , status : "PROD" } ,
216+ { id : "s3" , name : "Supplier 3" , status : "PROD" } ,
217+ { id : "s5" , name : "Supplier 5" , status : "PROD" } ,
229218 ] as any [ ] ;
230219 const deps = makeDeps ( ) ;
231220 deps . supplierConfigRepo . getSuppliersDetails = jest
@@ -248,8 +237,8 @@ describe("supplier-config service", () => {
248237 { supplier : "s3" , variantId : "v3" } ,
249238 ] as any [ ] ;
250239 const suppliers = [
251- { id : "s1" , name : "Supplier 1" } ,
252- { id : "s2" , name : "Supplier 2" } ,
240+ { id : "s1" , name : "Supplier 1" , status : "PROD" } ,
241+ { id : "s2" , name : "Supplier 2" , status : "PROD" } ,
253242 ] as any [ ] ;
254243 const deps = makeDeps ( ) ;
255244 deps . supplierConfigRepo . getSuppliersDetails = jest
@@ -272,8 +261,8 @@ describe("supplier-config service", () => {
272261 { supplier : "s2" , variantId : "v2" } ,
273262 ] as any [ ] ;
274263 const suppliers = [
275- { id : "s1" , name : "Supplier 1" } ,
276- { id : "s2" , name : "Supplier 2" } ,
264+ { id : "s1" , name : "Supplier 1" , status : "PROD" } ,
265+ { id : "s2" , name : "Supplier 2" , status : "PROD" } ,
277266 ] as any [ ] ;
278267 const deps = makeDeps ( ) ;
279268 deps . supplierConfigRepo . getSuppliersDetails = jest
@@ -284,4 +273,50 @@ describe("supplier-config service", () => {
284273
285274 expect ( deps . logger . warn ) . not . toHaveBeenCalled ( ) ;
286275 } ) ;
276+
277+ it ( "throws when no active suppliers found" , async ( ) => {
278+ const allocations = [
279+ { supplier : "s1" , variantId : "v1" } ,
280+ { supplier : "s2" , variantId : "v2" } ,
281+ ] as any [ ] ;
282+ const suppliers = [
283+ { id : "s1" , name : "Supplier 1" , status : "DRAFT" } ,
284+ { id : "s2" , name : "Supplier 2" , status : "DRAFT" } ,
285+ ] as any [ ] ;
286+ const deps = makeDeps ( ) ;
287+ deps . supplierConfigRepo . getSuppliersDetails = jest
288+ . fn ( )
289+ . mockResolvedValue ( suppliers ) ;
290+
291+ await expect ( getSupplierDetails ( allocations , deps ) ) . rejects . toThrow (
292+ / N o a c t i v e s u p p l i e r s f o u n d / ,
293+ ) ;
294+ expect ( deps . logger . error ) . toHaveBeenCalledWith (
295+ expect . objectContaining ( {
296+ description : "No active suppliers found for supplier allocations" ,
297+ } ) ,
298+ ) ;
299+ } ) ;
300+
301+ it ( "filters to return only active suppliers with PROD status" , async ( ) => {
302+ const allocations = [
303+ { supplier : "s1" , variantId : "v1" } ,
304+ { supplier : "s2" , variantId : "v2" } ,
305+ { supplier : "s3" , variantId : "v3" } ,
306+ ] as any [ ] ;
307+ const suppliers = [
308+ { id : "s1" , name : "Supplier 1" , status : "PROD" } ,
309+ { id : "s2" , name : "Supplier 2" , status : "DRAFT" } ,
310+ { id : "s3" , name : "Supplier 3" , status : "PROD" } ,
311+ ] as any [ ] ;
312+ const deps = makeDeps ( ) ;
313+ deps . supplierConfigRepo . getSuppliersDetails = jest
314+ . fn ( )
315+ . mockResolvedValue ( suppliers ) ;
316+
317+ const result = await getSupplierDetails ( allocations , deps ) ;
318+
319+ expect ( result ) . toEqual ( [ suppliers [ 0 ] , suppliers [ 2 ] ] ) ;
320+ expect ( result . every ( ( s ) => s . status === "PROD" ) ) . toBe ( true ) ;
321+ } ) ;
287322} ) ;
0 commit comments