@@ -10,6 +10,7 @@ import { Donation } from '../donations/donations.entity';
1010import { UpdateFoodManufacturerApplicationDto } from './dtos/update-manufacturer-application.dto' ;
1111import { NotFoundException } from '@nestjs/common' ;
1212import { AuthenticatedRequest } from '../auth/authenticated-request' ;
13+ import { Role } from '../users/types' ;
1314import {
1415 DonationDetailsDto ,
1516 DonationReminderDto ,
@@ -78,6 +79,37 @@ describe('FoodManufacturersController', () => {
7879 } ) ;
7980 } ) ;
8081
82+ describe ( 'GET /approved' , ( ) => {
83+ it ( 'should return approved food manufacturers' , async ( ) => {
84+ const mockManufacturers : Partial < FoodManufacturer > [ ] = [
85+ {
86+ foodManufacturerId : 1 ,
87+ foodManufacturerName : 'Good Foods Inc' ,
88+ status : ApplicationStatus . APPROVED ,
89+ } ,
90+ {
91+ foodManufacturerId : 2 ,
92+ foodManufacturerName : 'Healthy Eats LLC' ,
93+ status : ApplicationStatus . APPROVED ,
94+ } ,
95+ ] ;
96+
97+ mockManufacturersService . getApprovedManufacturers . mockResolvedValue (
98+ mockManufacturers as FoodManufacturer [ ] ,
99+ ) ;
100+
101+ const result = await controller . getApprovedManufacturers ( ) ;
102+
103+ expect ( result ) . toEqual ( mockManufacturers ) ;
104+ expect ( result ) . toHaveLength ( 2 ) ;
105+ expect ( result [ 0 ] . foodManufacturerId ) . toBe ( 1 ) ;
106+ expect ( result [ 1 ] . foodManufacturerId ) . toBe ( 2 ) ;
107+ expect (
108+ mockManufacturersService . getApprovedManufacturers ,
109+ ) . toHaveBeenCalled ( ) ;
110+ } ) ;
111+ } ) ;
112+
81113 describe ( 'GET /:id' , ( ) => {
82114 it ( 'should return a food manufacturer by id' , async ( ) => {
83115 mockManufacturersService . findOne . mockResolvedValue (
@@ -224,7 +256,7 @@ describe('FoodManufacturersController', () => {
224256 } ) ;
225257
226258 describe ( 'PATCH /:manufacturerId/application' , ( ) => {
227- const req = { user : { id : 1 } } ;
259+ const req = { user : { id : 1 , role : Role . FOODMANUFACTURER } } ;
228260
229261 it ( 'should update a food manufacturer application' , async ( ) => {
230262 const manufacturerId = 1 ;
@@ -251,7 +283,12 @@ describe('FoodManufacturersController', () => {
251283 expect ( result ) . toEqual ( mockManufacturer1 ) ;
252284 expect (
253285 mockManufacturersService . updateFoodManufacturerApplication ,
254- ) . toHaveBeenCalledWith ( manufacturerId , mockUpdateData , 1 ) ;
286+ ) . toHaveBeenCalledWith (
287+ manufacturerId ,
288+ mockUpdateData ,
289+ 1 ,
290+ Role . FOODMANUFACTURER ,
291+ ) ;
255292 } ) ;
256293
257294 it ( 'should throw error if manufacturer does not exist' , async ( ) => {
@@ -272,7 +309,31 @@ describe('FoodManufacturersController', () => {
272309 ) . rejects . toThrow ( ) ;
273310 expect (
274311 mockManufacturersService . updateFoodManufacturerApplication ,
275- ) . toHaveBeenCalledWith ( 999 , mockUpdateData , 1 ) ;
312+ ) . toHaveBeenCalledWith ( 999 , mockUpdateData , 1 , Role . FOODMANUFACTURER ) ;
313+ } ) ;
314+
315+ it ( 'should allow admin to update any food manufacturer application' , async ( ) => {
316+ const adminReq = { user : { id : 2 , role : Role . ADMIN } } ;
317+ const manufacturerId = 1 ;
318+
319+ const mockUpdateData : UpdateFoodManufacturerApplicationDto = {
320+ secondaryContactFirstName : 'Admin Updated' ,
321+ } ;
322+
323+ mockManufacturersService . updateFoodManufacturerApplication . mockResolvedValue (
324+ mockManufacturer1 as FoodManufacturer ,
325+ ) ;
326+
327+ const result = await controller . updateFoodManufacturerApplication (
328+ adminReq as AuthenticatedRequest ,
329+ manufacturerId ,
330+ mockUpdateData ,
331+ ) ;
332+
333+ expect ( result ) . toEqual ( mockManufacturer1 ) ;
334+ expect (
335+ mockManufacturersService . updateFoodManufacturerApplication ,
336+ ) . toHaveBeenCalledWith ( manufacturerId , mockUpdateData , 2 , Role . ADMIN ) ;
276337 } ) ;
277338 } ) ;
278339
0 commit comments