Skip to content

Commit 2321871

Browse files
authored
Merge pull request #142 from onlicar/v1
Moved config loading from constructor to methods
2 parents 293a083 + 90aff86 commit 2321871

File tree

3 files changed

+21
-12
lines changed

3 files changed

+21
-12
lines changed

index.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ class ServerlessDynamodbLocal {
1010
this.serverless = serverless;
1111
this.service = serverless.service;
1212
this.serverlessLog = serverless.cli.log.bind(serverless.cli);
13-
this.config = this.service.custom && this.service.custom.dynamodb || {};
1413
this.options = options;
1514
this.provider = "aws";
1615
this.commands = {
@@ -108,13 +107,13 @@ class ServerlessDynamodbLocal {
108107
}
109108

110109
get port() {
111-
const config = this.config;
110+
const config = this.service.custom && this.service.custom.dynamodb || {};
112111
const port = _.get(config, "start.port", 8000);
113112
return port;
114113
}
115114

116115
get host() {
117-
const config = this.config;
116+
const config = this.service.custom && this.service.custom.dynamodb || {};
118117
const host = _.get(config, "start.host", "localhost");
119118
return host;
120119
}
@@ -177,7 +176,7 @@ class ServerlessDynamodbLocal {
177176
}
178177

179178
startHandler() {
180-
const config = this.config;
179+
const config = this.service.custom && this.service.custom.dynamodb || {};
181180
const options = _.merge({
182181
sharedDb: this.options.sharedDb || true
183182
},

test/indexTest.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,19 @@ const expect = require("chai").expect;
66
const should = require("should");
77
const aws = require ("aws-sdk");
88
const seeder = require("../src/seeder.js");
9-
const dataApp = require("../index.js");
9+
const Plugin = require("../index.js");
10+
11+
const serverlessMock = require("./serverlessMock");
1012

1113
describe("Port function",function(){
1214
it("Port should return number",function(){
13-
let myport = dataApp.prototype.port;
14-
assert(typeof myport, "number");
15+
let service = new Plugin(serverlessMock, {});
16+
assert(typeof service.port, "number");
1517
});
1618

1719
it("Port value should be >= 0 and < 65536",function(done){
18-
http.get(`http://localhost:${dataApp.prototype.port}/shell/`, function (response) {
20+
let service = new Plugin(serverlessMock, {});
21+
http.get(`http://localhost:${service.port}/shell/`, function (response) {
1922
assert.equal(response.statusCode, 200);
2023
done();
2124
});
@@ -34,29 +37,29 @@ describe("Check the dynamodb function",function(){
3437
});
3538

3639
it("Should be an object",function(){
37-
let dynamoOptions = dataApp.prototype.dynamodbOptions;
40+
let dynamoOptions = Plugin.prototype.dynamodbOptions;
3841
let raw = new aws.DynamoDB(dynamoOptions);
3942
raw.should.be.type("object");
4043
});
4144

4245
it("Should be an object",function(){
43-
let dynamoOptions = dataApp.prototype.dynamodbOptions;
46+
let dynamoOptions = Plugin.prototype.dynamodbOptions;
4447
let doc = new aws.DynamoDB(dynamoOptions);
4548
doc.should.be.type("object");
4649
});
4750
});
4851

4952
describe ("Start handler function",function(){
5053
it ("Should not be null",function(){
51-
let handler = dataApp.prototype.startHandler;
54+
let handler = Plugin.prototype.startHandler;
5255
assert(handler =! null);
5356
});
5457
});
5558

5659

5760
describe ("createTable functon",function(){
5861
it ("Should check as a function",function(){
59-
const tbl = dataApp.prototype.createTable;
62+
const tbl = Plugin.prototype.createTable;
6063
assert.equal(typeof tbl, "function");
6164
});
6265
});

test/serverlessMock.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module.exports = {
2+
service: {},
3+
cli: {
4+
log: () => {}
5+
},
6+
custom: {}
7+
};

0 commit comments

Comments
 (0)