forked from Code-4-Community/scaffolding
-
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
Open
amywng
wants to merge
2
commits into
main
Choose a base branch
from
acw/SSF-107-manufacturer-app-backend
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
113 changes: 113 additions & 0 deletions
113
apps/backend/src/foodManufacturers/dtos/manufacturer-application.dto.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,113 @@ | ||
| 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() | ||
| @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() | ||
| @Length(1, 255) | ||
| productsSustainableExplanation: string; | ||
|
|
||
| @IsBoolean() | ||
| inKindDonations: boolean; | ||
|
|
||
| @IsEnum(DonateWastedFood) | ||
| donateWastedFood: DonateWastedFood; | ||
|
|
||
| @IsOptional() | ||
| @IsEnum(ManufacturerAttribute) | ||
| manufacturerAttribute?: ManufacturerAttribute; | ||
|
|
||
| @IsOptional() | ||
| @IsString() | ||
| @IsNotEmpty() | ||
| @MaxLength(255) | ||
| additionalComments?: string; | ||
|
|
||
| @IsOptional() | ||
| @IsBoolean() | ||
| newsletterSubscription?: boolean; | ||
| } | ||
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
131 changes: 131 additions & 0 deletions
131
apps/backend/src/foodManufacturers/manufacturers.controller.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,131 @@ | ||
| 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, ManufacturerStatus } from './types'; | ||
| import { FoodManufacturerApplicationDto } from './dtos/manufacturer-application.dto'; | ||
|
|
||
| const mockManufacturersService = mock<FoodManufacturersService>(); | ||
|
|
||
| const mockManufacturer1: Partial<FoodManufacturer> = { | ||
| foodManufacturerId: 1, | ||
| foodManufacturerName: 'Good Foods Inc', | ||
| status: ManufacturerStatus.PENDING, | ||
| }; | ||
|
|
||
| const mockManufacturer2: Partial<FoodManufacturer> = { | ||
| foodManufacturerId: 2, | ||
| foodManufacturerName: 'Healthy Eats LLC', | ||
| status: ManufacturerStatus.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 /api/manufacturers', () => { | ||
| 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); | ||
| }); | ||
| }); | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.