Skip to content

Commit db58a08

Browse files
authored
Return empty bylowering event results (#53)
1 parent 478f9e8 commit db58a08

2 files changed

Lines changed: 46 additions & 1 deletion

File tree

routes/api/v1/events.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,7 @@ exports.plugin = {
590590
}
591591

592592
if (results.length === 0) {
593-
return Boom.notFound('No records found' );
593+
return h.response(results).code(200);
594594
}
595595

596596
// --------- Data source filtering

test/routes.api.v1.events.test.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
'use strict';
2+
3+
const Lab = require('@hapi/lab');
4+
const { expect } = require('@hapi/code');
5+
const Glue = require('@hapi/glue');
6+
const { afterEach, beforeEach, describe, it } = exports.lab = Lab.script();
7+
const Manifest = require('../config/manifest');
8+
9+
// Loaded by plugins/dbDevel_lowerings.js in NODE_ENV=test. This lowering's
10+
// fixture events are FISH/CORAL only, so filtering for ASNAP should be empty.
11+
const publicLowering4928ID = '6981f167212b348aed7fa9f5';
12+
const missingEventValue = 'ASNAP';
13+
14+
const initStartedServer = async () => {
15+
16+
const manifest = JSON.parse(JSON.stringify(Manifest));
17+
manifest.server.port = 0;
18+
19+
const server = await Glue.compose(manifest, { relativeTo: __dirname + '/..' });
20+
await server.start();
21+
22+
return server;
23+
};
24+
25+
describe('GET /sealog-server/api/v1/events/bylowering/{id}', () => {
26+
let server;
27+
28+
beforeEach(async () => {
29+
server = await initStartedServer();
30+
});
31+
32+
afterEach(async () => {
33+
await server.stop();
34+
});
35+
36+
it('responds with an empty array when the lowering exists but no events match', async () => {
37+
const res = await server.inject({
38+
method: 'get',
39+
url: `/sealog-server/api/v1/events/bylowering/${publicLowering4928ID}?value=${missingEventValue}`
40+
});
41+
42+
expect(res.statusCode).to.equal(200);
43+
expect(res.result).to.equal([]);
44+
});
45+
});

0 commit comments

Comments
 (0)