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
Open
dburkhart07
wants to merge
22
commits into
main
Choose a base branch
from
ddb/SSF-79-improve-performance-log-new-donation-form
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
22 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 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
115 changes: 115 additions & 0 deletions
115
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,115 @@ | ||
| 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('create', () => { | ||
| it('should call donationItemsService.create and return a donationItem', async () => { | ||
| const donationItemData = mockDonationItemsCreateData[0]; | ||
| mockDonationItemsService.create.mockResolvedValue( | ||
| donationItemData as DonationItem, | ||
| ); | ||
| const result = await controller.createDonationItem( | ||
| donationItemData as DonationItem, | ||
| ); | ||
| expect(result).toEqual(donationItemData as DonationItem); | ||
| expect(mockDonationItemsService.create).toHaveBeenCalledWith( | ||
| donationItemData.donationId, | ||
| donationItemData.itemName, | ||
| donationItemData.quantity, | ||
| donationItemData.reservedQuantity, | ||
| donationItemData.ozPerItem, | ||
| donationItemData.estimatedValue, | ||
| donationItemData.foodType, | ||
| ); | ||
| }); | ||
| }); | ||
|
|
||
| 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); | ||
| }); | ||
| }); | ||
| }); |
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 { | ||
| 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[]; | ||
| } | ||
27 changes: 13 additions & 14 deletions
27
apps/backend/src/migrations/1764816885341-RemoveUnusedStatuses.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 |
|---|---|---|
| @@ -1,25 +1,24 @@ | ||
| import { MigrationInterface, QueryRunner } from "typeorm"; | ||
| import { MigrationInterface, QueryRunner } from 'typeorm'; | ||
|
|
||
| export class RemoveUnusedStatuses1764816885341 implements MigrationInterface { | ||
| public async up(queryRunner: QueryRunner): Promise<void> { | ||
| await queryRunner.query( | ||
| `ALTER TABLE allocations DROP COLUMN IF EXISTS status;`, | ||
| ); | ||
| await queryRunner.query( | ||
| `ALTER TABLE donation_items DROP COLUMN IF EXISTS status;`, | ||
| ); | ||
| } | ||
|
|
||
| public async up(queryRunner: QueryRunner): Promise<void> { | ||
| await queryRunner.query( | ||
| `ALTER TABLE allocations DROP COLUMN IF EXISTS status;` | ||
| ); | ||
| await queryRunner.query( | ||
| `ALTER TABLE donation_items DROP COLUMN IF EXISTS status;` | ||
| ); | ||
| } | ||
|
|
||
| public async down(queryRunner: QueryRunner): Promise<void> { | ||
| await queryRunner.query(` | ||
| public async down(queryRunner: QueryRunner): Promise<void> { | ||
| await queryRunner.query(` | ||
| ALTER TABLE allocations | ||
| ADD COLUMN status VARCHAR(25) NOT NULL DEFAULT 'pending'; | ||
| `); | ||
|
|
||
| await queryRunner.query(` | ||
| await queryRunner.query(` | ||
| ALTER TABLE donation_items | ||
| ADD COLUMN status VARCHAR(25) NOT NULL DEFAULT 'available'; | ||
| `); | ||
| } | ||
| } | ||
| } |
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
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.