Repository navigation
Pk/mspca 46 animal availability frontend endpoint #30
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
pujitakalinadhabhotla
wants to merge
9
commits into
main
Choose a base branch
from
pk/mspca-46-animal-availability-frontend-endpoint
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
9 commits
Select commit
Hold shift + click to select a range
d558e32
added animal entity
shreeyaadhikari 574967c
add migration to create animal table
shreeyaadhikari d6f7cbf
added animal service logic w chameloen id existence checks
shreeyaadhikari 13af06a
validate animal exists in post/recommendations
shreeyaadhikari c01e1ec
validate animal exists in post/matches
shreeyaadhikari 4d31981
validate added animals exist in patch/volunteers/id/animal-preference
shreeyaadhikari 2f8c81a
Add animal availability page with filters, animal card, and modal
pujitakalinadhabhotla 3d04de3
Merge main and address review feedback on animal availability
pujitakalinadhabhotla b0280f6
Update animal availability UI to match latest designs
pujitakalinadhabhotla 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| import { Test, TestingModule } from '@nestjs/testing'; | ||
| import { AnimalsController } from './animals.controller'; | ||
| import { AnimalsService } from './animals.service'; | ||
| import { Animal } from './animals.entity'; | ||
|
|
||
| describe('AnimalsController', () => { | ||
| let controller: AnimalsController; | ||
| let service: { findAll: jest.Mock }; | ||
|
|
||
| beforeEach(async () => { | ||
| service = { findAll: jest.fn() }; | ||
|
|
||
| const module: TestingModule = await Test.createTestingModule({ | ||
| controllers: [AnimalsController], | ||
| providers: [{ provide: AnimalsService, useValue: service }], | ||
| }).compile(); | ||
|
|
||
| controller = module.get<AnimalsController>(AnimalsController); | ||
| }); | ||
|
|
||
| it('should be defined', () => { | ||
| expect(controller).toBeDefined(); | ||
| }); | ||
|
|
||
| describe('getAnimals', () => { | ||
| it('returns the animals from the service', async () => { | ||
| const animals = [{ animalId: 1 }, { animalId: 2 }] as Animal[]; | ||
| service.findAll.mockResolvedValue(animals); | ||
|
|
||
| await expect(controller.getAnimals()).resolves.toBe(animals); | ||
| expect(service.findAll).toHaveBeenCalledTimes(1); | ||
| }); | ||
|
|
||
| it('returns an empty array when there are no animals', async () => { | ||
| service.findAll.mockResolvedValue([]); | ||
|
|
||
| await expect(controller.getAnimals()).resolves.toEqual([]); | ||
| }); | ||
|
|
||
| it('propagates service errors', async () => { | ||
| service.findAll.mockRejectedValue(new Error('db down')); | ||
|
|
||
| await expect(controller.getAnimals()).rejects.toThrow('db down'); | ||
| }); | ||
| }); | ||
| }); |
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,25 @@ | ||
| import { Controller, Get, HttpStatus } from '@nestjs/common'; | ||
| import { ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger'; | ||
| import { AnimalsService } from './animals.service'; | ||
| import { Animal } from './animals.entity'; | ||
|
|
||
| @ApiTags('Animals') | ||
| @Controller('animals') | ||
| export class AnimalsController { | ||
| constructor(private animalsService: AnimalsService) {} | ||
|
|
||
| @Get() | ||
| @ApiOperation({ | ||
| summary: 'Get all available animals', | ||
| description: | ||
| 'Returns every animal. All animals in the database are currently treated as available.', | ||
| }) | ||
| @ApiResponse({ | ||
| status: HttpStatus.OK, | ||
| description: 'The animals, or an empty array when none are available.', | ||
| type: [Animal], | ||
| }) | ||
| async getAnimals(): Promise<Animal[]> { | ||
| return this.animalsService.findAll(); | ||
| } | ||
| } |
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
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
17 changes: 17 additions & 0 deletions
17
apps/backend/src/migrations/1793300000000-AddMatchAdditionalComments.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,17 @@ | ||
| import { MigrationInterface, QueryRunner } from 'typeorm'; | ||
|
|
||
| export class AddMatchAdditionalComments1793300000000 | ||
| implements MigrationInterface | ||
| { | ||
| public async up(queryRunner: QueryRunner): Promise<void> { | ||
| await queryRunner.query( | ||
| `ALTER TABLE "matches" ADD COLUMN "additional_comments" text`, | ||
| ); | ||
| } | ||
|
|
||
| public async down(queryRunner: QueryRunner): Promise<void> { | ||
| await queryRunner.query( | ||
| `ALTER TABLE "matches" DROP COLUMN "additional_comments"`, | ||
| ); | ||
| } | ||
| } |
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 |
|---|---|---|
|
|
@@ -24,6 +24,7 @@ import { CoordinatorUpdateVolunteerDto } from './dtos/coordinator-update-volunte | |
| import { Homebase } from '../types'; | ||
| import { UpdateHomebaseDto } from './dtos/update-homebase.dto'; | ||
| import { UpdateAnimalPreferencesDto } from './dtos/update-animal-preferences.dto'; | ||
| import { AnimalsService } from '../animals/animals.service'; | ||
|
|
||
| describe('VolunteersController', () => { | ||
| let controller: VolunteersController; | ||
|
|
@@ -55,6 +56,7 @@ describe('VolunteersController', () => { | |
| coordinatorUpdateVolunteerById: jest.Mock; | ||
| }; | ||
| let mockMatchesService: { findByVolunteerId: jest.Mock }; | ||
| let mockAnimalsService: { checkAllExistOrFail: jest.Mock }; | ||
|
|
||
| const mockVolunteers = [ | ||
| { volunteerId: 1, firstName: 'Jane', lastName: 'Doe' }, | ||
|
|
@@ -77,12 +79,14 @@ describe('VolunteersController', () => { | |
| coordinatorUpdateVolunteerById: jest.fn(), | ||
| }; | ||
| mockMatchesService = { findByVolunteerId: jest.fn() }; | ||
| mockAnimalsService = { checkAllExistOrFail: jest.fn() }; | ||
|
|
||
| const module: TestingModule = await Test.createTestingModule({ | ||
| controllers: [VolunteersController], | ||
| providers: [ | ||
| { provide: VolunteersService, useValue: mockVolunteersService }, | ||
| { provide: MatchesService, useValue: mockMatchesService }, | ||
| { provide: AnimalsService, useValue: mockAnimalsService }, | ||
| ], | ||
| }).compile(); | ||
|
|
||
|
|
@@ -564,6 +568,27 @@ describe('VolunteersController', () => { | |
| ).toHaveBeenCalledWith(1, dto); | ||
| }); | ||
|
|
||
| it('does not update preferences when an added animal does not exist', async () => { | ||
| const error = new NotFoundException( | ||
| 'Animals with Chameleon IDs not found: 998, 999', | ||
|
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. nit: this error should be A998 and A999 |
||
| ); | ||
| mockAnimalsService.checkAllExistOrFail.mockRejectedValue(error); | ||
|
|
||
| await expect( | ||
| controller.updateAnimalPreferences(1, { | ||
| added: ['A55', 'A998', 'A999'], | ||
| }), | ||
| ).rejects.toThrow(error); | ||
| expect(mockAnimalsService.checkAllExistOrFail).toHaveBeenCalledWith([ | ||
| 'A55', | ||
| 'A998', | ||
| 'A999', | ||
| ]); | ||
| expect( | ||
| mockVolunteersService.updateAnimalPreferences, | ||
| ).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it.each([{}, { added: [] }, { removed: [] }, { added: [], removed: [] }])( | ||
| 'throws BadRequestException when neither list has IDs: %j', | ||
| async (body) => { | ||
|
|
||
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.
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 should move this check into the service as well, and therefore we shouldnt have a diff for this file or the controller tests