hmpo-model 3.2.0 → 4.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.circleci/config.yml +21 -0
- package/README.md +86 -40
- package/lib/local-model.js +38 -42
- package/lib/remote-model.js +158 -93
- package/package.json +11 -10
- package/test/lib/spec.local-model.js +36 -18
- package/test/lib/spec.remote-model.js +316 -92
- package/.travis.yml +0 -8
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hmpo-model",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.1",
|
|
4
4
|
"description": "Simple model for interacting with http/rest apis.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -25,19 +25,20 @@
|
|
|
25
25
|
},
|
|
26
26
|
"homepage": "https://github.com/UKHomeOffice/passports-model",
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
-
"
|
|
31
|
-
"
|
|
28
|
+
"debug": "^4.3.3",
|
|
29
|
+
"got": "^11.8.3",
|
|
30
|
+
"hpagent": "^0.1.2",
|
|
31
|
+
"lodash.kebabcase": "^4.1.1"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
|
-
"chai": "^4.3.
|
|
35
|
-
"eslint": "^
|
|
36
|
-
"
|
|
34
|
+
"chai": "^4.3.4",
|
|
35
|
+
"eslint": "^8.3.0",
|
|
36
|
+
"hmpo-logger": "^4.1.3",
|
|
37
|
+
"mocha": "^9.1.3",
|
|
37
38
|
"nyc": "^15.1.0",
|
|
38
39
|
"proxyquire": "^2.0.0",
|
|
39
|
-
"sinon": "^
|
|
40
|
-
"sinon-chai": "^3.
|
|
40
|
+
"sinon": "^12.0.1",
|
|
41
|
+
"sinon-chai": "^3.7.0"
|
|
41
42
|
},
|
|
42
43
|
"nyc": {
|
|
43
44
|
"all": true,
|
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
const Model = require('../../lib/local-model');
|
|
4
4
|
|
|
5
|
+
describe('Local Model', () => {
|
|
5
6
|
let model;
|
|
6
7
|
|
|
7
8
|
beforeEach(() => {
|
|
8
|
-
|
|
9
|
-
let Model = require('../../lib/local-model');
|
|
10
|
-
|
|
11
9
|
model = new Model();
|
|
12
10
|
});
|
|
13
11
|
|
|
@@ -18,7 +16,7 @@ describe('Local Model', () => {
|
|
|
18
16
|
});
|
|
19
17
|
|
|
20
18
|
it('has an attributes property of type object', () => {
|
|
21
|
-
model.attributes.
|
|
19
|
+
expect(model.attributes).to.be.an('object');
|
|
22
20
|
});
|
|
23
21
|
|
|
24
22
|
describe('constructor', () => {
|
|
@@ -54,20 +52,28 @@ describe('Local Model', () => {
|
|
|
54
52
|
describe('set', () => {
|
|
55
53
|
|
|
56
54
|
beforeEach(() => {
|
|
57
|
-
model
|
|
58
|
-
name: 'Test name'
|
|
59
|
-
};
|
|
55
|
+
model = new Model({ name: 'Test name' });
|
|
60
56
|
});
|
|
61
57
|
|
|
62
58
|
it('adds a key to the model attributes if the key is a string', () => {
|
|
63
|
-
model.set('age', 20)
|
|
59
|
+
model.set('age', 20);
|
|
60
|
+
expect(model.attributes).to.eql({
|
|
64
61
|
name: 'Test name',
|
|
65
62
|
age: 20
|
|
66
63
|
});
|
|
67
64
|
});
|
|
68
65
|
|
|
69
66
|
it('accepts an object as the key', () => {
|
|
70
|
-
model.set( { placeOfBirth: 'London' } )
|
|
67
|
+
model.set( { placeOfBirth: 'London' } );
|
|
68
|
+
expect(model.attributes).to.eql({
|
|
69
|
+
name: 'Test name',
|
|
70
|
+
placeOfBirth: 'London'
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it('accepts a Map as the key', () => {
|
|
75
|
+
model.set( new Map([['placeOfBirth', 'London']]));
|
|
76
|
+
expect(model.attributes).to.eql({
|
|
71
77
|
name: 'Test name',
|
|
72
78
|
placeOfBirth: 'London'
|
|
73
79
|
});
|
|
@@ -141,17 +147,17 @@ describe('Local Model', () => {
|
|
|
141
147
|
|
|
142
148
|
it('removes properties from model when passed a string', () => {
|
|
143
149
|
model.unset('a');
|
|
144
|
-
model.toJSON().
|
|
150
|
+
expect(model.toJSON()).to.eql({ b: 2, c: 3 });
|
|
145
151
|
});
|
|
146
152
|
|
|
147
153
|
it('removes properties from model when passed an array', () => {
|
|
148
154
|
model.unset(['a', 'b']);
|
|
149
|
-
model.toJSON().
|
|
155
|
+
expect(model.toJSON()).to.eql({ c: 3 });
|
|
150
156
|
});
|
|
151
157
|
|
|
152
158
|
it('does nothing if passed a property that does not exist', () => {
|
|
153
159
|
model.unset('foo');
|
|
154
|
-
model.toJSON().
|
|
160
|
+
expect(model.toJSON()).to.eql({ a: 1, b: 2, c: 3 });
|
|
155
161
|
});
|
|
156
162
|
|
|
157
163
|
it('emits a change event', () => {
|
|
@@ -225,7 +231,7 @@ describe('Local Model', () => {
|
|
|
225
231
|
|
|
226
232
|
it('clears model attributes', () => {
|
|
227
233
|
model.reset();
|
|
228
|
-
model.toJSON().
|
|
234
|
+
expect(model.toJSON()).to.eql({});
|
|
229
235
|
expect(model.get('name')).to.be.undefined;
|
|
230
236
|
expect(model.get('age')).to.be.undefined;
|
|
231
237
|
});
|
|
@@ -244,9 +250,9 @@ describe('Local Model', () => {
|
|
|
244
250
|
model.on('change:age', listener2);
|
|
245
251
|
model.reset();
|
|
246
252
|
listener1.should.have.been.calledOnce;
|
|
247
|
-
listener1.should.have.been.calledWithExactly(undefined);
|
|
253
|
+
listener1.should.have.been.calledWithExactly(undefined, 'John');
|
|
248
254
|
listener2.should.have.been.calledOnce;
|
|
249
|
-
listener2.should.have.been.calledWithExactly(undefined);
|
|
255
|
+
listener2.should.have.been.calledWithExactly(undefined, 30);
|
|
250
256
|
});
|
|
251
257
|
|
|
252
258
|
it('emits no events if called with silent: true', () => {
|
|
@@ -266,10 +272,22 @@ describe('Local Model', () => {
|
|
|
266
272
|
};
|
|
267
273
|
});
|
|
268
274
|
|
|
269
|
-
it('returns
|
|
270
|
-
model.toJSON()
|
|
275
|
+
it('returns a bare object that\'s the same as the attributes property', () => {
|
|
276
|
+
const result = model.toJSON(true);
|
|
277
|
+
expect(result).to.eql({
|
|
271
278
|
name: 'Test name'
|
|
272
279
|
});
|
|
280
|
+
|
|
281
|
+
expect(result.constructor).to.be.undefined;
|
|
282
|
+
});
|
|
283
|
+
|
|
284
|
+
it('returns an object that\'s the same as the attributes property with object prototype', () => {
|
|
285
|
+
const result = model.toJSON();
|
|
286
|
+
expect(result).to.eql({
|
|
287
|
+
name: 'Test name'
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
expect(result.constructor).to.be.a('function');
|
|
273
291
|
});
|
|
274
292
|
});
|
|
275
293
|
|