-
Notifications
You must be signed in to change notification settings - Fork 5
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
feat: ASAP-415 Add Working-Group Public API endpoint #4266
Merged
peterstarling
merged 2 commits into
master
from
feature/ASAP-415-add-working-group-public-api-endpoint
May 9, 2024
Merged
Changes from all commits
Commits
Show all changes
2 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 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
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.
Hey, I think we need more data on members, don't we?
It's listed in ticket
and in the website (https://gp2.org/working-group-directory/) passed as reference we have
so these info seems to be used
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.
as per our discussion - we decided to leave these out and GMMB don't seem to need any extra information embedded for the nested resources