Repository navigation
MSPCA-24: Add animal-updates opt-in endpoint and make fosterType a list #11
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
psmolyan
wants to merge
3
commits into
jw/mspca-20-create-volunteer-endpoint
Choose a base branch
from
ps/mspca-24-animal-updates-endpoint
base: jw/mspca-20-create-volunteer-endpoint
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
3 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
27 changes: 27 additions & 0 deletions
27
apps/backend/src/migrations/1791429623582-AddAnimalUpdatesAndFosterTypeArray.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,27 @@ | ||
| import { MigrationInterface, QueryRunner } from 'typeorm'; | ||
|
|
||
| export class AddAnimalUpdatesAndFosterTypeArray1791429623582 | ||
| implements MigrationInterface | ||
| { | ||
| public async up(queryRunner: QueryRunner): Promise<void> { | ||
| await queryRunner.query( | ||
| `ALTER TABLE "foster_volunteers" ADD "animal_updates" boolean NOT NULL DEFAULT true`, | ||
| ); | ||
| await queryRunner.query( | ||
| `ALTER TABLE "foster_volunteers" | ||
| ALTER COLUMN "foster_type" TYPE "foster_type_enum"[] | ||
| USING ARRAY["foster_type"]`, | ||
| ); | ||
| } | ||
|
|
||
| public async down(queryRunner: QueryRunner): Promise<void> { | ||
| await queryRunner.query( | ||
| `ALTER TABLE "foster_volunteers" | ||
| ALTER COLUMN "foster_type" TYPE "foster_type_enum" | ||
| USING "foster_type"[1]`, | ||
| ); | ||
| await queryRunner.query( | ||
| `ALTER TABLE "foster_volunteers" DROP COLUMN "animal_updates"`, | ||
| ); | ||
| } | ||
| } |
53 changes: 53 additions & 0 deletions
53
apps/backend/src/volunteers/dtos/create-volunteer.dto.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,53 @@ | ||
| import { plainToInstance } from 'class-transformer'; | ||
| import { validate } from 'class-validator'; | ||
| import { CreateVolunteerDto } from './create-volunteer.dto'; | ||
| import { FosterType } from '../volunteers.types'; | ||
| import { Homebase } from '../../types'; | ||
|
|
||
| const validBody = { | ||
| firstName: 'Jane', | ||
| lastName: 'Doe', | ||
| phone: '617-555-0100', | ||
| email: 'jane@example.com', | ||
| address: '350 S Huntington Ave', | ||
| city: 'Boston', | ||
| zipcode: '02130', | ||
| homebase: Homebase.BOSTON, | ||
| residentAnimals: 'One cat', | ||
| fosterType: [FosterType.CAT], | ||
| }; | ||
|
|
||
| async function fosterTypeErrors(fosterType: unknown) { | ||
| const errors = await validate( | ||
| plainToInstance(CreateVolunteerDto, { ...validBody, fosterType }), | ||
| ); | ||
| return errors.filter((e) => e.property === 'fosterType'); | ||
| } | ||
|
|
||
| describe('CreateVolunteerDto fosterType', () => { | ||
| it('accepts a list with one type', async () => { | ||
| expect(await fosterTypeErrors([FosterType.DOG])).toHaveLength(0); | ||
| }); | ||
|
|
||
| it('accepts a list with several types', async () => { | ||
| expect( | ||
| await fosterTypeErrors([FosterType.DOG, FosterType.CAT]), | ||
| ).toHaveLength(0); | ||
| }); | ||
|
|
||
| it('rejects an empty list', async () => { | ||
| expect(await fosterTypeErrors([])).not.toHaveLength(0); | ||
| }); | ||
|
|
||
| it('rejects a single value that is not in a list', async () => { | ||
| expect(await fosterTypeErrors(FosterType.DOG)).not.toHaveLength(0); | ||
| }); | ||
|
|
||
| it('rejects a list containing an invalid type', async () => { | ||
| expect(await fosterTypeErrors(['Dragon'])).not.toHaveLength(0); | ||
| }); | ||
|
|
||
| it('rejects a missing fosterType', async () => { | ||
| expect(await fosterTypeErrors(undefined)).not.toHaveLength(0); | ||
| }); | ||
| }); | ||
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
33 changes: 33 additions & 0 deletions
33
apps/backend/src/volunteers/dtos/update-animal-updates.dto.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,33 @@ | ||
| import { plainToInstance } from 'class-transformer'; | ||
| import { validate } from 'class-validator'; | ||
| import { UpdateAnimalUpdatesDto } from './update-animal-updates.dto'; | ||
|
|
||
| async function errorsFor(body: unknown) { | ||
| return validate(plainToInstance(UpdateAnimalUpdatesDto, body)); | ||
| } | ||
|
|
||
| describe('UpdateAnimalUpdatesDto', () => { | ||
| it('accepts true', async () => { | ||
| expect(await errorsFor({ animalUpdates: true })).toHaveLength(0); | ||
| }); | ||
|
|
||
| it('accepts false', async () => { | ||
| expect(await errorsFor({ animalUpdates: false })).toHaveLength(0); | ||
| }); | ||
|
|
||
| it('rejects an empty body', async () => { | ||
| expect(await errorsFor({})).not.toHaveLength(0); | ||
| }); | ||
|
|
||
| it('rejects a string', async () => { | ||
| expect(await errorsFor({ animalUpdates: 'true' })).not.toHaveLength(0); | ||
| }); | ||
|
|
||
| it('rejects a number', async () => { | ||
| expect(await errorsFor({ animalUpdates: 1 })).not.toHaveLength(0); | ||
| }); | ||
|
|
||
| it('rejects null', async () => { | ||
| expect(await errorsFor({ animalUpdates: null })).not.toHaveLength(0); | ||
| }); | ||
| }); |
6 changes: 6 additions & 0 deletions
6
apps/backend/src/volunteers/dtos/update-animal-updates.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,6 @@ | ||
| import { IsBoolean } from 'class-validator'; | ||
|
|
||
| export class UpdateAnimalUpdatesDto { | ||
| @IsBoolean() | ||
| animalUpdates!: boolean; | ||
| } |
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we normally don't write test files for our dtos. this is because we are relying under the assumption that our validators work and will make sure we have valid inputs. our class-validators are coming from nestjs, which we assume already works.
because of this, do you think we could delete the two spec files here?