forked from Code-4-Community/scaffolding
-
Notifications
You must be signed in to change notification settings - Fork 0
[SSF-79] Improve Peformance for Log New Donation Form Modal #58
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
Merged
dburkhart07
merged 29 commits into
main
from
ddb/SSF-79-improve-performance-log-new-donation-form
Jan 26, 2026
Merged
Changes from all commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
c1c0485
Created initial Api and frontend integration, awaiting some validatio…
dburkhart07 09d9357
Changes for setting upstream
dburkhart07 3d95bbd
Added tests for donation items controller only
dburkhart07 706b59f
Final commit
dburkhart07 9c47821
Final commit
dburkhart07 ea1d063
Resolved merge conflicts
dburkhart07 ec957b7
Final commit
dburkhart07 20b9bbe
Prettier
dburkhart07 8e773fe
Resolved merge conflicts
dburkhart07 98b5e25
prettier
dburkhart07 0c249bc
Made changes
dburkhart07 c971104
Changes with one multiple donation item saving
dburkhart07 8548fc4
Fixed DTO formatting
dburkhart07 9c36a1c
prettier
dburkhart07 cc585cf
Fixed changes and rewrote test
dburkhart07 9451c7b
prettier
dburkhart07 ee7ad64
Final commits
dburkhart07 1106308
prettier
dburkhart07 c0f4c1e
Resolved merge conficts
dburkhart07 79df911
Resolved merge conflicts
dburkhart07 bc0e307
Final commit
dburkhart07 2f7c61a
Final commit
dburkhart07 ccc073d
Merged main
dburkhart07 aa6a0ab
Merged main
dburkhart07 72e34dc
Resolved comments
dburkhart07 9ccc8df
prettier
dburkhart07 8656f5c
Final commit
dburkhart07 eba7e50
Merged main
dburkhart07 00a57f6
fixed comments
dburkhart07 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
93 changes: 93 additions & 0 deletions
93
apps/backend/src/donationItems/donationItems.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,93 @@ | ||
| import { Test, TestingModule } from '@nestjs/testing'; | ||
| import { DonationItemsController } from './donationItems.controller'; | ||
| import { DonationItemsService } from './donationItems.service'; | ||
| import { DonationItem } from './donationItems.entity'; | ||
| import { mock } from 'jest-mock-extended'; | ||
| import { FoodType } from './types'; | ||
| import { CreateMultipleDonationItemsDto } from './dtos/create-donation-items.dto'; | ||
|
|
||
| const mockDonationItemsService = mock<DonationItemsService>(); | ||
|
|
||
| describe('DonationItemsController', () => { | ||
| let controller: DonationItemsController; | ||
|
|
||
| const mockDonationItemsCreateData: Partial<DonationItem>[] = [ | ||
| { | ||
| itemId: 1, | ||
| donationId: 1, | ||
| itemName: 'Canned Beans', | ||
| quantity: 100, | ||
| reservedQuantity: 0, | ||
| ozPerItem: 15, | ||
| estimatedValue: 200, | ||
| foodType: FoodType.DAIRY_FREE_ALTERNATIVES, | ||
| }, | ||
| { | ||
| itemId: 2, | ||
| donationId: 1, | ||
| itemName: 'Rice', | ||
| quantity: 50, | ||
| reservedQuantity: 0, | ||
| ozPerItem: 20, | ||
| estimatedValue: 150, | ||
| foodType: FoodType.GLUTEN_FREE_BAKING_PANCAKE_MIXES, | ||
| }, | ||
| ]; | ||
|
|
||
| beforeEach(async () => { | ||
| const module: TestingModule = await Test.createTestingModule({ | ||
| controllers: [DonationItemsController], | ||
| providers: [ | ||
| { provide: DonationItemsService, useValue: mockDonationItemsService }, | ||
| ], | ||
| }).compile(); | ||
|
|
||
| controller = module.get<DonationItemsController>(DonationItemsController); | ||
| }); | ||
|
|
||
| it('should be defined', () => { | ||
| expect(controller).toBeDefined(); | ||
| }); | ||
|
|
||
| describe('createMultipleDonationItems', () => { | ||
| it('should call donationItemsService.createMultipleDonationItems with donationId and items, and return the created donation items', async () => { | ||
| const mockBody: CreateMultipleDonationItemsDto = { | ||
| donationId: 1, | ||
| items: [ | ||
| { | ||
| itemName: 'Rice Noodles', | ||
| quantity: 100, | ||
| reservedQuantity: 0, | ||
| ozPerItem: 5, | ||
| estimatedValue: 100, | ||
| foodType: FoodType.DAIRY_FREE_ALTERNATIVES, | ||
| }, | ||
| { | ||
| itemName: 'Beans', | ||
| quantity: 50, | ||
| reservedQuantity: 0, | ||
| ozPerItem: 10, | ||
| estimatedValue: 80, | ||
| foodType: FoodType.GLUTEN_FREE_BAKING_PANCAKE_MIXES, | ||
| }, | ||
| ], | ||
| }; | ||
|
|
||
| const mockCreatedItems: Partial<DonationItem>[] = [ | ||
| { itemId: 1, donationId: 1, ...mockBody.items[0] }, | ||
| { itemId: 2, donationId: 1, ...mockBody.items[1] }, | ||
| ]; | ||
|
|
||
| mockDonationItemsService.createMultipleDonationItems.mockResolvedValue( | ||
| mockCreatedItems as DonationItem[], | ||
| ); | ||
|
|
||
| const result = await controller.createMultipleDonationItems(mockBody); | ||
|
|
||
| expect( | ||
| mockDonationItemsService.createMultipleDonationItems, | ||
| ).toHaveBeenCalledWith(mockBody.donationId, mockBody.items); | ||
| expect(result).toEqual(mockCreatedItems); | ||
| }); | ||
| }); | ||
| }); | ||
Yurika-Kan marked this conversation as resolved.
Show resolved
Hide resolved
|
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
48 changes: 48 additions & 0 deletions
48
apps/backend/src/donationItems/dtos/create-donation-items.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,48 @@ | ||
| import { | ||
dburkhart07 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| IsNumber, | ||
| IsString, | ||
| IsArray, | ||
| ValidateNested, | ||
| Min, | ||
| IsEnum, | ||
| IsNotEmpty, | ||
| Length, | ||
| } from 'class-validator'; | ||
| import { Type } from 'class-transformer'; | ||
| import { FoodType } from '../types'; | ||
|
|
||
| export class CreateDonationItemDto { | ||
| @IsString() | ||
| @IsNotEmpty() | ||
| @Length(1, 255) | ||
| itemName: string; | ||
|
|
||
| @IsNumber() | ||
| @Min(1) | ||
| quantity: number; | ||
|
|
||
| @IsNumber() | ||
| @Min(0) | ||
| reservedQuantity: number; | ||
|
|
||
| @IsNumber() | ||
| @Min(1) | ||
| ozPerItem: number; | ||
|
|
||
| @IsNumber() | ||
| @Min(1) | ||
| estimatedValue: number; | ||
|
|
||
| @IsEnum(FoodType) | ||
| foodType: FoodType; | ||
| } | ||
|
|
||
| export class CreateMultipleDonationItemsDto { | ||
| @IsNumber() | ||
| donationId: number; | ||
|
|
||
| @IsArray() | ||
| @ValidateNested({ each: true }) | ||
| @Type(() => CreateDonationItemDto) | ||
| items: CreateDonationItemDto[]; | ||
| } | ||
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
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.