Skip to content

Commit

Permalink
Enhance the REST API response for /services (#1031)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ndpnt authored Nov 27, 2023
2 parents 0db9b50 + fd84d26 commit 2907fe8
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 3 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@

All changes that impact users of this module are documented in this file, in the [Common Changelog](https://common-changelog.org) format with some additional specifications defined in the CONTRIBUTING file. This codebase adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Unreleased
## Unreleased [minor]

_Full changeset and discussions: [#1031](https://github.com/OpenTermsArchive/engine/pull/1031)._

> Development of this release was [supported](https://nlnet.nl/project/TOSDR-OTA/) by the [NGI0 Entrust Fund](https://nlnet.nl/entrust), a fund established by [NLnet](https://nlnet.nl/) with financial support from the European Commission's [Next Generation Internet](https://www.ngi.eu) programme, under the aegis of DG CNECT under grant agreement N°101069594.
### Added

- Add `terms` attribute to `/services` API response, containing declared term types for each service

## 0.32.1 - 2023-10-18

Expand Down
1 change: 0 additions & 1 deletion src/api/routes/docs.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ describe('Docs API', () => {
context('When requested as HTML', () => {
before(async () => {
response = await request(app).get(`${basePath}/v1/docs/`);
console.log(response);
});

it('responds with 200 status code', () => {
Expand Down
19 changes: 18 additions & 1 deletion src/api/routes/services.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,29 @@ const router = express.Router();
* schema:
* type: array
* items:
* $ref: '#/components/schemas/Service'
* type: object
* properties:
* id:
* type: string
* description: The ID of the service.
* name:
* type: string
* description: The name of the service.
* terms:
* type: array
* description: The declared terms types for this service.
* items:
* type: object
* properties:
* type:
* type: string
* description: The type of terms.
*/
router.get('/services', (req, res) => {
res.status(200).json(Object.values(services).map(service => ({
id: service.id,
name: service.name,
terms: service.getTermsTypes().map(type => ({ type })),
})));
});

Expand Down
14 changes: 14 additions & 0 deletions src/api/routes/services.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,20 @@ describe('Services API', () => {
expect(service).to.have.property('name');
});
});

it('each service should have a terms array', () => {
response.body.forEach(service => {
expect(service).to.have.property('terms').that.is.an('array');
});
});

it('each terms should have a type', () => {
response.body.forEach(service => {
service.terms.forEach(terms => {
expect(terms).to.have.property('type');
});
});
});
});

describe('GET /service/:serviceId', () => {
Expand Down

0 comments on commit 2907fe8

Please sign in to comment.