|
1 | 1 | import { |
| 2 | + getPackSpecification, |
| 3 | + getPreferredSupplierPacks, |
2 | 4 | getSupplierAllocationsForVolumeGroup, |
3 | 5 | getSupplierDetails, |
4 | 6 | getVariantDetails, |
@@ -31,7 +33,7 @@ describe("supplier-config service", () => { |
31 | 33 | afterEach(() => jest.resetAllMocks()); |
32 | 34 |
|
33 | 35 | describe("getVariantDetails", () => { |
34 | | - it("returns variant details", async () => { |
| 36 | + it("returns variant details for valid id", async () => { |
35 | 37 | const variant = { id: "v1", volumeGroupId: "g1" } as any; |
36 | 38 | const deps = makeDeps(); |
37 | 39 | deps.supplierConfigRepo.getLetterVariant = jest |
@@ -336,4 +338,67 @@ describe("supplier-config service", () => { |
336 | 338 | expect(result).toEqual([suppliers[0], suppliers[2]]); |
337 | 339 | expect(result.every((s) => s.status === "PROD")).toBe(true); |
338 | 340 | }); |
| 341 | + describe("getPreferredSupplierPacks", () => { |
| 342 | + it("returns preferred supplier packs when found", async () => { |
| 343 | + const suppliers = [ |
| 344 | + { id: "s1", name: "Supplier 1", status: "PROD" }, |
| 345 | + { id: "s2", name: "Supplier 2", status: "PROD" }, |
| 346 | + ] as any[]; |
| 347 | + const supplierPacks = [ |
| 348 | + { id: "p1", supplierId: "s1", packSpecificationId: "spec1" }, |
| 349 | + { id: "p2", supplierId: "s2", packSpecificationId: "spec1" }, |
| 350 | + { id: "p3", supplierId: "s3", packSpecificationId: "spec1" }, |
| 351 | + ] as any[]; |
| 352 | + const deps = makeDeps(); |
| 353 | + deps.supplierConfigRepo.getSupplierPacksForPackSpecification = jest |
| 354 | + .fn() |
| 355 | + .mockResolvedValue(supplierPacks); |
| 356 | + |
| 357 | + const result = await getPreferredSupplierPacks( |
| 358 | + ["spec1"], |
| 359 | + suppliers, |
| 360 | + deps, |
| 361 | + ); |
| 362 | + |
| 363 | + expect(result).toEqual([ |
| 364 | + { id: "p1", supplierId: "s1", packSpecificationId: "spec1" }, |
| 365 | + { id: "p2", supplierId: "s2", packSpecificationId: "spec1" }, |
| 366 | + ]); |
| 367 | + }); |
| 368 | + |
| 369 | + it("throws when no preferred supplier packs found", async () => { |
| 370 | + const suppliers = [ |
| 371 | + { id: "s1", name: "Supplier 1", status: "PROD" }, |
| 372 | + { id: "s2", name: "Supplier 2", status: "PROD" }, |
| 373 | + ] as any[]; |
| 374 | + const deps = makeDeps(); |
| 375 | + deps.supplierConfigRepo.getSupplierPacksForPackSpecification = jest |
| 376 | + .fn() |
| 377 | + .mockResolvedValue([]); |
| 378 | + |
| 379 | + await expect( |
| 380 | + getPreferredSupplierPacks(["spec1"], suppliers, deps), |
| 381 | + ).rejects.toThrow(/No preferred supplier packs found/); |
| 382 | + expect(deps.logger.error).toHaveBeenCalledWith( |
| 383 | + expect.objectContaining({ |
| 384 | + description: |
| 385 | + "No preferred supplier packs found for pack specification ids and suppliers", |
| 386 | + }), |
| 387 | + ); |
| 388 | + }); |
| 389 | + }); |
| 390 | + |
| 391 | + describe("getPackSpecification", () => { |
| 392 | + it("returns pack specification when found", async () => { |
| 393 | + const packSpec = { id: "spec1", name: "Pack Spec 1" } as any; |
| 394 | + const deps = makeDeps(); |
| 395 | + deps.supplierConfigRepo.getPackSpecification = jest |
| 396 | + .fn() |
| 397 | + .mockResolvedValue(packSpec); |
| 398 | + |
| 399 | + const result = await getPackSpecification("spec1", deps); |
| 400 | + |
| 401 | + expect(result).toBe(packSpec); |
| 402 | + }); |
| 403 | + }); |
339 | 404 | }); |
0 commit comments