Skip to content

Commit 173117d

Browse files
committed
Throw error on missing config
1 parent 9a4a000 commit 173117d

File tree

2 files changed

+34
-14
lines changed

2 files changed

+34
-14
lines changed

plugins/AppConfigPlugin/src/plugin.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ module.exports = (config) => {
99
Object.freeze(config);
1010

1111
req.plugin('config', config);
12+
} else {
13+
throw Error('Missing configuration');
1214
}
1315

1416
next();

plugins/AppConfigPlugin/test/unit.js

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,27 +25,45 @@ describe('AppConfigPlugin', function() {
2525

2626
Utils.setFuncName(route, 'route:index');
2727

28-
const config = {foo: 'bar'};
28+
describe('loaded', function() {
29+
const config = {foo: 'bar'};
2930

30-
stack.middleware = [middleware(config)];
31-
stack.routes = route;
31+
stack.middleware = [middleware(config)];
32+
stack.routes = route;
3233

33-
const req = new Request(event.Records[0].cf.request, {});
34-
const res = new Response({});
34+
const req = new Request(event.Records[0].cf.request, {});
35+
const res = new Response({});
3536

36-
stack.exec(req, res);
37+
stack.exec(req, res);
3738

38-
const result = res.data();
39+
const result = res.data();
3940

40-
it('should not return headers', function() {
41-
expect(result.headers).to.be.empty;
42-
});
41+
it('should not return headers', function() {
42+
expect(result.headers).to.be.empty;
43+
});
44+
45+
it('should return status', function() {
46+
expect(result.status).to.equal(200);
47+
});
4348

44-
it('should return status', function() {
45-
expect(result.status).to.equal(200);
49+
it('should return body', function() {
50+
expect(result.body).to.equal('bar');
51+
});
4652
});
4753

48-
it('should return body', function() {
49-
expect(result.body).to.equal('bar');
54+
describe('error', function() {
55+
const config = null;
56+
57+
stack.middleware = [middleware(config)];
58+
stack.routes = route;
59+
60+
const req = new Request(event.Records[0].cf.request, {});
61+
const res = new Response({});
62+
63+
const result = () => stack.exec(req, res);
64+
65+
it('should throw Error', function() {
66+
expect(result).to.throw(Error, /Missing configuration/);
67+
});
5068
});
5169
});

0 commit comments

Comments
 (0)