Skip to content

Commit c76ba13

Browse files
misleading host prefix and better tests
1 parent f392fff commit c76ba13

2 files changed

Lines changed: 29 additions & 11 deletions

File tree

packages/opencrvs/src/Utils.js

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,7 @@ export const prepareNextState = (state, response, callback = s => s) => {
5757
return callback(nextState);
5858
};
5959

60-
const HOST_PREFIX = {
61-
gateway: 'gateway',
62-
register: 'register',
63-
countryconfig: 'countryconfig',
64-
};
60+
const VALID_HOSTS = new Set(['gateway', 'register', 'countryconfig']);
6561

6662
export async function request(configuration, method, path, opts) {
6763
const { domain, access_token } = configuration;
@@ -70,12 +66,11 @@ export async function request(configuration, method, path, opts) {
7066

7167
assertRelativeUrl(path);
7268

73-
const prefix = HOST_PREFIX[host];
74-
if (!prefix) {
69+
if (!VALID_HOSTS.has(host)) {
7570
throw new Error(
76-
`Unknown OpenCRVS host '${host}'. Expected one of: ${Object.keys(
77-
HOST_PREFIX
78-
).join(', ')}`
71+
`Unknown OpenCRVS host '${host}'. Expected one of: ${[
72+
...VALID_HOSTS,
73+
].join(', ')}`
7974
);
8075
}
8176

@@ -87,7 +82,7 @@ export async function request(configuration, method, path, opts) {
8782
},
8883
query: params,
8984
parseAs,
90-
baseUrl: `https://${prefix}.${domain}`,
85+
baseUrl: `https://${host}.${domain}`,
9186
};
9287

9388
return commonRequest(method, path, options).then(logResponse);

packages/opencrvs/test/Adaptor.test.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,29 @@ describe('submitBirthNotification', () => {
510510
trackingId: 'TRK99',
511511
});
512512
});
513+
514+
it('throws if createEvent response is missing an id', async () => {
515+
registerServer
516+
.intercept({ path: '/api/events/events', method: 'POST' })
517+
.reply(200, {});
518+
519+
let error;
520+
try {
521+
await execute(
522+
submitBirthNotification(
523+
{ 'child.name': { firstname: 'Test', surname: 'Baby' } },
524+
{ createdAtLocation: 'loc-1' }
525+
)
526+
)(state);
527+
} catch (e) {
528+
error = e;
529+
}
530+
531+
expect(error).to.exist;
532+
expect(error.message).to.match(
533+
/createEvent response did not include an id/
534+
);
535+
});
513536
});
514537

515538
describe('getLocations', () => {

0 commit comments

Comments
 (0)