Skip to content

Commit e0c926a

Browse files
author
Tom Kirkpatrick
committed
feat: update to support loopback 3.x
1 parent d3a43ad commit e0c926a

18 files changed

+83
-57
lines changed

package.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
"lodash": "^4.17.4"
3939
},
4040
"peerDependencies": {
41-
"loopback": "^2.25.0",
4241
"loopback-context": "^3.1.0",
4342
"cls-hooked": "^4.1.5"
4443
},
@@ -51,7 +50,7 @@
5150
"dirty-chai": "2.0.1",
5251
"eslint": "^4.1.0",
5352
"eslint-config-fullcube": "^3.0.0",
54-
"loopback": "^2.25.0",
53+
"loopback": "^3.4.0",
5554
"loopback-boot": "^2.24.0",
5655
"loopback-component-explorer": "2.3.0",
5756
"loopback-context": "^3.1.0",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"name": "accessToken",
3+
"plural": "accessTokens",
4+
"base": "AccessToken",
5+
"relations": {
6+
"user": {
7+
"type": "belongsTo",
8+
"model": "user",
9+
"foreignKey": "userId"
10+
}
11+
}
12+
}

test/fixtures/simple-app/common/models/invoice.js

-5
This file was deleted.

test/fixtures/simple-app/common/models/invoice.json

+5-10
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
{
22
"name": "Invoice",
33
"base": "PersistedModel",
4-
"idInjection": true,
54
"options": {
6-
"validateUpsert": true
5+
"idInjection": true,
6+
"validateUpsert": true,
7+
"forceId": false,
8+
"replaceOnPUT": false
79
},
810
"properties": {
911
"storeId": {
@@ -59,14 +61,7 @@
5961
"principalType": "ROLE",
6062
"principalId": "$group:manager",
6163
"permission": "ALLOW",
62-
"property": "updateAttributes"
63-
},
64-
{
65-
"accessType": "WRITE",
66-
"principalType": "ROLE",
67-
"principalId": "$group:manager",
68-
"permission": "ALLOW",
69-
"property": "upsert"
64+
"property": ["patchOrCreate", "replaceOrCreate", "replaceById", "updateOrCreate", "updateAttributes", "patchAttributes"]
7065
},
7166
{
7267
"accessType": "*",

test/fixtures/simple-app/common/models/store.js

-5
This file was deleted.

test/fixtures/simple-app/common/models/store.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
{
22
"name": "Store",
33
"base": "PersistedModel",
4-
"idInjection": true,
54
"options": {
6-
"validateUpsert": true
5+
"idInjection": true,
6+
"validateUpsert": true,
7+
"forceId": false,
8+
"replaceOnPUT": false
79
},
810
"properties": {
911
"id": {

test/fixtures/simple-app/common/models/team.js

-5
This file was deleted.

test/fixtures/simple-app/common/models/team.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
{
22
"name": "Team",
33
"base": "PersistedModel",
4-
"idInjection": true,
54
"options": {
6-
"validateUpsert": true
5+
"idInjection": true,
6+
"validateUpsert": true,
7+
"forceId": false,
8+
"replaceOnPUT": false
79
},
810
"properties": {
911
"storeId": {

test/fixtures/simple-app/common/models/transaction.js

-5
This file was deleted.

test/fixtures/simple-app/common/models/transaction.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
{
22
"name": "Transaction",
33
"base": "PersistedModel",
4-
"idInjection": true,
54
"options": {
6-
"validateUpsert": true
5+
"idInjection": true,
6+
"validateUpsert": true,
7+
"forceId": false,
8+
"replaceOnPUT": false
79
},
810
"properties": {
911
"storeId": {

test/fixtures/simple-app/common/models/user.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ module.exports = function userCustomizer(user) {
44
user.currentUser = function(cb) {
55
return process.nextTick(() => cb(null, user.getCurrentUser()))
66
}
7-
return user
7+
88
}

test/fixtures/simple-app/common/models/user.json

+12-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
{
22
"name": "user",
33
"base": "User",
4-
"idInjection": true,
54
"options": {
5+
"idInjection": true,
66
"validateUpsert": true,
7-
"saltWorkFactor": 1
7+
"forceId": false,
8+
"saltWorkFactor": 1,
9+
"replaceOnPUT": false
810
},
911
"mixins": {
1012
"GetCurrentUser": true
@@ -18,6 +20,14 @@
1820
},
1921
"validations": [],
2022
"relations": {
23+
"accessTokens": {
24+
"type": "hasMany",
25+
"model": "accessToken",
26+
"foreignKey": "userId",
27+
"options": {
28+
"disableInclude": true
29+
}
30+
},
2131
"stores": {
2232
"type": "hasMany",
2333
"model": "Store",
@@ -55,7 +65,6 @@
5565
"methods": {
5666
"currentUser": {
5767
"description": "Get the current user.",
58-
"isStatic": true,
5968
"http": {
6069
"path": "/currentUser",
6170
"verb": "get"

test/fixtures/simple-app/server/config.json

+1-4
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,7 @@
1616
"extended": true,
1717
"limit": "100kb"
1818
},
19-
"cors": false,
20-
"errorHandler": {
21-
"disableStackTrace": false
22-
}
19+
"cors": false
2320
},
2421
"legacyExplorer": false,
2522
"logoutSessionsOnSensitiveChanges": true
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"final:after": {
3+
"strong-error-handler": {
4+
"params": {
5+
"debug": true,
6+
"log": true
7+
}
8+
}
9+
}
10+
}

test/fixtures/simple-app/server/middleware.json

+9-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11
{
2+
"initial:before": {
3+
"loopback#token": {
4+
"params": {
5+
"model": "accessToken"
6+
}
7+
}
8+
},
29
"initial": {
310
"loopback-context#per-request": {
411
"params": {
@@ -7,9 +14,7 @@
714
}
815
},
916
"session": {},
10-
"auth": {
11-
"loopback#token": {}
12-
},
17+
"auth": {},
1318
"parse": {},
1419
"routes": {
1520
"loopback#rest": {
@@ -23,6 +28,6 @@
2328
"loopback#urlNotFound": {}
2429
},
2530
"final:after": {
26-
"loopback#errorHandler": {}
31+
"strong-error-handler": {}
2732
}
2833
}

test/fixtures/simple-app/server/model-config.json

+7-5
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,25 @@
1414
"../../../../lib/mixins"
1515
]
1616
},
17-
"AccessToken": {
17+
18+
"accessToken": {
1819
"dataSource": "db",
1920
"public": true
2021
},
21-
"ACL": {
22+
"user": {
2223
"dataSource": "db",
2324
"public": true
2425
},
25-
"RoleMapping": {
26+
27+
"ACL": {
2628
"dataSource": "db",
2729
"public": true
2830
},
29-
"Role": {
31+
"RoleMapping": {
3032
"dataSource": "db",
3133
"public": true
3234
},
33-
"user": {
35+
"Role": {
3436
"dataSource": "db",
3537
"public": true
3638
},

test/fixtures/simple-app/server/server.js

-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ const loopback = require('loopback')
66
const boot = require('loopback-boot')
77
const app = loopback()
88

9-
global.Promise = require('bluebird')
10-
119
app.start = function() {
1210
// start the web server
1311
return app.listen(function() {

test/mixin-test.js

+13
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,19 @@ function json(verb, url, data) {
2121
.expect('Content-Type', /json/)
2222
}
2323

24+
/**
25+
* Initialise the application for the test suite.
26+
*/
27+
before(done => {
28+
function finishBoot() {
29+
return done()
30+
}
31+
if (app.booting) {
32+
return app.once('booted', finishBoot)
33+
}
34+
return finishBoot()
35+
})
36+
2437
describe('Current User Mixin.', function() {
2538
describe('Smoke test', function() {
2639
it('should add a getCurrentUser model method', function() {

0 commit comments

Comments
 (0)