-
Notifications
You must be signed in to change notification settings - Fork 0
[SSF-107] Manufacturer Application Backend #83
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
ac622e1
08a983a
c9741df
dd986b5
14afb2a
b2f494d
cc32e62
1283213
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,112 @@ | ||
| import { | ||
| ArrayNotEmpty, | ||
| IsBoolean, | ||
| IsEmail, | ||
| IsEnum, | ||
| IsNotEmpty, | ||
| IsOptional, | ||
| IsPhoneNumber, | ||
| IsString, | ||
| Length, | ||
| MaxLength, | ||
| } from 'class-validator'; | ||
| import { Allergen, DonateWastedFood, ManufacturerAttribute } from '../types'; | ||
|
|
||
| export class FoodManufacturerApplicationDto { | ||
| @IsString() | ||
| @IsNotEmpty() | ||
| @Length(1, 255) | ||
| foodManufacturerName: string; | ||
|
|
||
| @IsString() | ||
| @IsNotEmpty() | ||
| @Length(1, 255) | ||
| foodManufacturerWebsite: string; | ||
|
|
||
| @IsString() | ||
| @IsNotEmpty() | ||
| @Length(1, 255) | ||
| contactFirstName: string; | ||
|
|
||
| @IsString() | ||
| @IsNotEmpty() | ||
| @Length(1, 255) | ||
| contactLastName: string; | ||
|
|
||
| @IsEmail() | ||
| @IsNotEmpty() | ||
| @Length(1, 255) | ||
| contactEmail: string; | ||
|
|
||
| @IsString() | ||
| @IsNotEmpty() | ||
| @IsPhoneNumber('US', { | ||
| message: | ||
| 'contactPhone must be a valid phone number (make sure all the digits are correct)', | ||
| }) | ||
| contactPhone: string; | ||
|
|
||
| @IsOptional() | ||
| @IsString() | ||
| @IsNotEmpty() | ||
| @MaxLength(255) | ||
| secondaryContactFirstName?: string; | ||
|
|
||
| @IsOptional() | ||
| @IsString() | ||
| @IsNotEmpty() | ||
| @MaxLength(255) | ||
| secondaryContactLastName?: string; | ||
|
|
||
| @IsOptional() | ||
| @IsEmail() | ||
| @IsNotEmpty() | ||
| @MaxLength(255) | ||
| secondaryContactEmail?: string; | ||
|
|
||
| @IsOptional() | ||
| @IsString() | ||
| @IsPhoneNumber('US', { | ||
| message: | ||
| 'secondaryContactPhone must be a valid phone number (make sure all the digits are correct)', | ||
| }) | ||
| @IsNotEmpty() | ||
| secondaryContactPhone?: string; | ||
|
|
||
| @ArrayNotEmpty() | ||
| @IsEnum(Allergen, { each: true }) | ||
| unlistedProductAllergens: Allergen[]; | ||
|
|
||
| @ArrayNotEmpty() | ||
| @IsEnum(Allergen, { each: true }) | ||
| facilityFreeAllergens: Allergen[]; | ||
|
|
||
| @IsBoolean() | ||
| productsGlutenFree: boolean; | ||
|
|
||
| @IsBoolean() | ||
| productsContainSulfites: boolean; | ||
|
|
||
| @IsString() | ||
| @IsNotEmpty() | ||
| productsSustainableExplanation: string; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This and the additional comments should not be limited to a max length. Can we update this here and in the table (we can use type |
||
|
|
||
| @IsBoolean() | ||
| inKindDonations: boolean; | ||
|
|
||
| @IsEnum(DonateWastedFood) | ||
| donateWastedFood: DonateWastedFood; | ||
|
|
||
| @IsOptional() | ||
| @IsEnum(ManufacturerAttribute) | ||
| manufacturerAttribute?: ManufacturerAttribute; | ||
|
|
||
| @IsOptional() | ||
| @IsString() | ||
| @IsNotEmpty() | ||
| additionalComments?: string; | ||
|
|
||
| @IsOptional() | ||
| @IsBoolean() | ||
| newsletterSubscription?: boolean; | ||
| } | ||
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,132 @@ | ||
| import { mock } from 'jest-mock-extended'; | ||
| import { FoodManufacturersService } from './manufacturers.service'; | ||
| import { FoodManufacturersController } from './manufacturers.controller'; | ||
| import { Test, TestingModule } from '@nestjs/testing'; | ||
| import { FoodManufacturer } from './manufacturers.entity'; | ||
| import { Allergen, DonateWastedFood } from './types'; | ||
| import { ApplicationStatus } from '../shared/types'; | ||
| import { FoodManufacturerApplicationDto } from './dtos/manufacturer-application.dto'; | ||
|
|
||
| const mockManufacturersService = mock<FoodManufacturersService>(); | ||
|
|
||
| const mockManufacturer1: Partial<FoodManufacturer> = { | ||
| foodManufacturerId: 1, | ||
| foodManufacturerName: 'Good Foods Inc', | ||
| status: ApplicationStatus.PENDING, | ||
| }; | ||
|
|
||
| const mockManufacturer2: Partial<FoodManufacturer> = { | ||
| foodManufacturerId: 2, | ||
| foodManufacturerName: 'Healthy Eats LLC', | ||
| status: ApplicationStatus.PENDING, | ||
| }; | ||
|
|
||
| describe('FoodManufacturersController', () => { | ||
| let controller: FoodManufacturersController; | ||
|
|
||
| beforeEach(async () => { | ||
| jest.clearAllMocks(); | ||
|
|
||
| const module: TestingModule = await Test.createTestingModule({ | ||
| controllers: [FoodManufacturersController], | ||
| providers: [ | ||
| { | ||
| provide: FoodManufacturersService, | ||
| useValue: mockManufacturersService, | ||
| }, | ||
| ], | ||
| }).compile(); | ||
|
|
||
| controller = module.get<FoodManufacturersController>( | ||
| FoodManufacturersController, | ||
| ); | ||
| }); | ||
|
|
||
| it('should be defined', () => { | ||
| expect(controller).toBeDefined(); | ||
| }); | ||
|
|
||
| describe('GET /pending', () => { | ||
| it('should return pending food manufacturers', async () => { | ||
| const mockManufacturers: Partial<FoodManufacturer>[] = [ | ||
| mockManufacturer1, | ||
| mockManufacturer2, | ||
| ]; | ||
|
|
||
| mockManufacturersService.getPendingManufacturers.mockResolvedValue( | ||
| mockManufacturers as FoodManufacturer[], | ||
| ); | ||
|
|
||
| const result = await controller.getPendingManufacturers(); | ||
|
|
||
| expect(result).toEqual(mockManufacturers); | ||
| expect(result).toHaveLength(2); | ||
| expect(result[0].foodManufacturerId).toBe(1); | ||
| expect(result[1].foodManufacturerId).toBe(2); | ||
| expect( | ||
| mockManufacturersService.getPendingManufacturers, | ||
| ).toHaveBeenCalled(); | ||
| }); | ||
| }); | ||
|
|
||
| describe('GET /:id', () => { | ||
| it('should return a food manufacturer by id', async () => { | ||
| mockManufacturersService.findOne.mockResolvedValue( | ||
| mockManufacturer1 as FoodManufacturer, | ||
| ); | ||
|
|
||
| const result = await controller.getFoodManufacturer(1); | ||
|
|
||
| expect(result).toEqual(mockManufacturer1); | ||
| expect(mockManufacturersService.findOne).toHaveBeenCalledWith(1); | ||
| }); | ||
| }); | ||
|
|
||
| describe('POST /submit-application', () => { | ||
| it('should submit a food manufacturer application', async () => { | ||
| const mockApplicationData: FoodManufacturerApplicationDto = { | ||
| foodManufacturerName: 'Good Foods Inc', | ||
| foodManufacturerWebsite: 'https://goodfoods.example.com', | ||
| contactFirstName: 'Alice', | ||
| contactLastName: 'Johnson', | ||
| contactEmail: 'alice.johnson@goodfoods.example.com', | ||
| contactPhone: '555-123-4567', | ||
| unlistedProductAllergens: [Allergen.EGG], | ||
| facilityFreeAllergens: [Allergen.EGG], | ||
| productsGlutenFree: true, | ||
| productsContainSulfites: false, | ||
| productsSustainableExplanation: 'We use eco-friendly packaging.', | ||
| inKindDonations: true, | ||
| donateWastedFood: DonateWastedFood.SOMETIMES, | ||
| }; | ||
|
|
||
| mockManufacturersService.addFoodManufacturer.mockResolvedValue(); | ||
|
|
||
| await controller.submitFoodManufacturerApplication(mockApplicationData); | ||
|
|
||
| expect(mockManufacturersService.addFoodManufacturer).toHaveBeenCalledWith( | ||
| mockApplicationData, | ||
| ); | ||
| }); | ||
| }); | ||
|
|
||
| describe('POST /approve/:id', () => { | ||
| it('should approve a food manufacturer', async () => { | ||
| mockManufacturersService.approve.mockResolvedValue(); | ||
|
|
||
| await controller.approveManufacturer(1); | ||
|
|
||
| expect(mockManufacturersService.approve).toHaveBeenCalledWith(1); | ||
| }); | ||
| }); | ||
|
|
||
| describe('POST /deny/:id', () => { | ||
| it('should deny a food manufacturer', async () => { | ||
| mockManufacturersService.deny.mockResolvedValue(); | ||
|
|
||
| await controller.denyManufacturer(1); | ||
|
|
||
| expect(mockManufacturersService.deny).toHaveBeenCalledWith(1); | ||
| }); | ||
| }); | ||
| }); |
Uh oh!
There was an error while loading. Please reload this page.