Skip to content

Commit 26274b7

Browse files
author
Tom Kirkpatrick
committed
test: add basic test case
1 parent 04013a5 commit 26274b7

13 files changed

+164
-14
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,4 @@
2020
.strong-pm
2121
.nyc_output
2222
node_modules
23+
coverage

package.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
"description": "Loopback Component Model Extender",
55
"main": "index.js",
66
"scripts": {
7-
"test": "mocha test/**/*.test.js"
7+
"test": "nyc --reporter=lcov --reporter=text --reporter=text-summary mocha test/*test.js",
8+
"test:watch": "npm run test -- -w"
89
},
910
"repository": {
1011
"type": "git",
@@ -26,6 +27,11 @@
2627
},
2728
"devDependencies": {
2829
"chai": "3.5.0",
29-
"mocha": "3.1.2"
30+
"cors": "2.8.3",
31+
"loopback": "3.8.0",
32+
"loopback-boot": "2.24.0",
33+
"mocha": "3.1.2",
34+
"nyc": "11.0.2",
35+
"strong-error-handler": "2.1.0"
3036
}
3137
}

test/basic.test.js

Lines changed: 0 additions & 12 deletions
This file was deleted.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"name": "Person",
3+
"base": "PersistedModel",
4+
"idInjection": true,
5+
"options": {
6+
"validateUpsert": true
7+
},
8+
"properties": {
9+
"id": {
10+
"type": "string",
11+
"required": true,
12+
"default": "uuidv4"
13+
}
14+
},
15+
"validations": [],
16+
"relations": {},
17+
"acls": [],
18+
"methods": {}
19+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
'use strict'
2+
3+
module.exports = function person(Person) {
4+
Person.testMethod = () => true
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
'use strict'
2+
3+
module.exports = function person(Person) {
4+
Person.override = () => true
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"../../..": {
3+
"basePath": "test/test-server"
4+
}
5+
}

test/test-server/server/config.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"restApiRoot": "/api",
3+
"host": "0.0.0.0",
4+
"port": 3000,
5+
"remoting": {
6+
"context": false,
7+
"rest": {
8+
"normalizeHttpPath": false,
9+
"xml": false
10+
},
11+
"json": {
12+
"strict": false,
13+
"limit": "100kb"
14+
},
15+
"urlencoded": {
16+
"extended": true,
17+
"limit": "100kb"
18+
},
19+
"cors": false
20+
},
21+
"legacyExplorer": false
22+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"db": {
3+
"name": "db",
4+
"connector": "memory"
5+
}
6+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"initial:before": {
3+
"loopback#favicon": {}
4+
},
5+
"initial": {},
6+
"session": {},
7+
"auth": {},
8+
"parse": {},
9+
"routes": {
10+
"loopback#rest": {
11+
"paths": [
12+
"${restApiRoot}"
13+
]
14+
}
15+
},
16+
"files": {},
17+
"final": {
18+
"loopback#urlNotFound": {}
19+
},
20+
"final:after": {
21+
"strong-error-handler": {}
22+
}
23+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"_meta": {
3+
"sources": [
4+
"loopback/common/models",
5+
"loopback/server/models",
6+
"../common/models",
7+
"./models"
8+
],
9+
"mixins": [
10+
"loopback/common/mixins",
11+
"loopback/server/mixins",
12+
"../common/mixins",
13+
"./mixins"
14+
]
15+
},
16+
17+
"Person": {
18+
"dataSource": "db",
19+
"public": true
20+
}
21+
}

test/test-server/server/server.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
'use strict';
2+
3+
var loopback = require('loopback');
4+
var boot = require('loopback-boot');
5+
6+
var app = module.exports = loopback();
7+
8+
app.start = function() {
9+
// start the web server
10+
return app.listen(function() {
11+
app.emit('started');
12+
var baseUrl = app.get('url').replace(/\/$/, '');
13+
console.log('Web server listening at: %s', baseUrl);
14+
if (app.get('loopback-component-explorer')) {
15+
var explorerPath = app.get('loopback-component-explorer').mountPath;
16+
console.log('Browse your REST API at %s%s', baseUrl, explorerPath);
17+
}
18+
});
19+
};
20+
21+
// Bootstrap the application, configure models, datasources and middleware.
22+
// Sub-apps like REST API are mounted via boot scripts.
23+
boot(app, __dirname, function(err) {
24+
if (err) throw err;
25+
26+
// start the server if `$ node server.js`
27+
if (require.main === module)
28+
app.start();
29+
});

test/test.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
'use strict'
2+
3+
const path = require('path')
4+
const chai = require('chai')
5+
6+
const expect = chai.expect
7+
8+
const TEST_APP = path.join(__dirname, 'test-server')
9+
const app = require(path.join(TEST_APP, 'server/server.js'))
10+
11+
const Person = app.models.Person
12+
13+
describe('Component', function() {
14+
describe('Initialization', function() {
15+
it('should apply model customizations from subdirectories', function() {
16+
expect(Person).to.itself.respondTo('testMethod')
17+
expect(Person).to.itself.respondTo('override')
18+
})
19+
})
20+
})

0 commit comments

Comments
 (0)