-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: ASAP-415 Add Working-Group Public API endpoint (#4266)
* add new public endpoints * add publish date and version to the responses
- Loading branch information
1 parent
b82c520
commit d8c3ee8
Showing
7 changed files
with
208 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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 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 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,49 @@ | ||
import { Router, Response } from 'express'; | ||
import { gp2 as gp2Model } from '@asap-hub/model'; | ||
import WorkingGroupController from '../../controllers/working-group.controller'; | ||
|
||
export const workingGroupRouteFactory = ( | ||
workingGroupController: WorkingGroupController, | ||
): Router => { | ||
const workingGroupRoutes = Router(); | ||
|
||
workingGroupRoutes.get( | ||
'/working-groups', | ||
async (_req, res: Response<gp2Model.ListPublicWorkingGroupResponse>) => { | ||
const result = await workingGroupController.fetch(); | ||
|
||
res.json({ | ||
total: result.total, | ||
items: result.items.map(mapWorkingGroupToPublicWorkingGroup), | ||
}); | ||
}, | ||
); | ||
|
||
workingGroupRoutes.get( | ||
'/working-groups/:workingGroupId', | ||
async (req, res: Response<gp2Model.PublicWorkingGroupResponse>) => { | ||
const { workingGroupId } = req.params; | ||
|
||
const workingGroup = | ||
await workingGroupController.fetchById(workingGroupId); | ||
|
||
res.json(mapWorkingGroupToPublicWorkingGroup(workingGroup)); | ||
}, | ||
); | ||
|
||
return workingGroupRoutes; | ||
}; | ||
|
||
const mapWorkingGroupToPublicWorkingGroup = ( | ||
workingGroup: gp2Model.WorkingGroupResponse, | ||
): gp2Model.PublicWorkingGroupResponse => ({ | ||
id: workingGroup.id, | ||
description: workingGroup.description, | ||
members: workingGroup.members, | ||
shortDescription: workingGroup.shortDescription, | ||
title: workingGroup.title, | ||
primaryEmail: workingGroup.primaryEmail, | ||
secondaryEmail: workingGroup.secondaryEmail, | ||
publishDate: workingGroup.publishDate, | ||
systemPublishedVersion: workingGroup.systemPublishedVersion, | ||
}); |
This file contains 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
82 changes: 82 additions & 0 deletions
82
apps/gp2-server/test/routes/public/working-group.route.test.ts
This file contains 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,82 @@ | ||
import { NotFoundError } from '@asap-hub/errors'; | ||
import supertest from 'supertest'; | ||
import { publicAppFactory } from '../../../src/publicApp'; | ||
import { | ||
getListPublicWorkingGroupResponse, | ||
getListWorkingGroupsResponse, | ||
getPublicWorkingGroupResponse, | ||
getWorkingGroupResponse, | ||
} from '../../fixtures/working-group.fixtures'; | ||
import { workingGroupControllerMock } from '../../mocks/working-group.controller.mock'; | ||
|
||
describe('/working-groups/ route', () => { | ||
const publicApp = publicAppFactory({ | ||
workingGroupController: workingGroupControllerMock, | ||
}); | ||
|
||
afterEach(jest.clearAllMocks); | ||
|
||
describe('GET /working-groups', () => { | ||
test('Should return 200 when no working-group exists', async () => { | ||
workingGroupControllerMock.fetch.mockResolvedValueOnce({ | ||
items: [], | ||
total: 0, | ||
}); | ||
const response = await supertest(publicApp).get('/public/working-groups'); | ||
|
||
expect(response.status).toBe(200); | ||
expect(response.body).toEqual({ | ||
total: 0, | ||
items: [], | ||
}); | ||
}); | ||
|
||
test('Should return the results correctly', async () => { | ||
const listWorkingGroupResponse = getListWorkingGroupsResponse(); | ||
const listPublicWorkingGroupResponse = | ||
getListPublicWorkingGroupResponse(); | ||
|
||
workingGroupControllerMock.fetch.mockResolvedValueOnce( | ||
listWorkingGroupResponse, | ||
); | ||
|
||
const response = await supertest(publicApp).get('/public/working-groups'); | ||
|
||
expect(response.body).toEqual(listPublicWorkingGroupResponse); | ||
}); | ||
}); | ||
|
||
describe('GET /working-groups/:workingGroupId', () => { | ||
test('Should return 404 when working-group does not exist', async () => { | ||
workingGroupControllerMock.fetchById.mockRejectedValueOnce( | ||
new NotFoundError(undefined, 'working-group with id not found'), | ||
); | ||
|
||
const response = await supertest(publicApp).get( | ||
'/public/working-groups/working-group-id', | ||
); | ||
|
||
expect(response.status).toBe(404); | ||
expect(response.body).toEqual({ | ||
error: 'Not Found', | ||
message: 'working-group with id not found', | ||
statusCode: 404, | ||
}); | ||
}); | ||
|
||
test('Should return the working-group correctly', async () => { | ||
const workingGroupResponse = getWorkingGroupResponse(); | ||
const publicWorkingGroupResponse = getPublicWorkingGroupResponse(); | ||
|
||
workingGroupControllerMock.fetchById.mockResolvedValueOnce( | ||
workingGroupResponse, | ||
); | ||
|
||
const response = await supertest(publicApp).get( | ||
`/public/working-groups/${workingGroupResponse!.id}`, | ||
); | ||
|
||
expect(response.body).toEqual(publicWorkingGroupResponse); | ||
}); | ||
}); | ||
}); |
This file contains 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 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