Skip to content

Commit

Permalink
feat: update to support loopback 3.x
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom Kirkpatrick committed Jul 13, 2017
1 parent d3a43ad commit e0c926a
Show file tree
Hide file tree
Showing 18 changed files with 83 additions and 57 deletions.
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
"lodash": "^4.17.4"
},
"peerDependencies": {
"loopback": "^2.25.0",
"loopback-context": "^3.1.0",
"cls-hooked": "^4.1.5"
},
Expand All @@ -51,7 +50,7 @@
"dirty-chai": "2.0.1",
"eslint": "^4.1.0",
"eslint-config-fullcube": "^3.0.0",
"loopback": "^2.25.0",
"loopback": "^3.4.0",
"loopback-boot": "^2.24.0",
"loopback-component-explorer": "2.3.0",
"loopback-context": "^3.1.0",
Expand Down
12 changes: 12 additions & 0 deletions test/fixtures/simple-app/common/models/access-token.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "accessToken",
"plural": "accessTokens",
"base": "AccessToken",
"relations": {
"user": {
"type": "belongsTo",
"model": "user",
"foreignKey": "userId"
}
}
}
5 changes: 0 additions & 5 deletions test/fixtures/simple-app/common/models/invoice.js

This file was deleted.

15 changes: 5 additions & 10 deletions test/fixtures/simple-app/common/models/invoice.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
{
"name": "Invoice",
"base": "PersistedModel",
"idInjection": true,
"options": {
"validateUpsert": true
"idInjection": true,
"validateUpsert": true,
"forceId": false,
"replaceOnPUT": false
},
"properties": {
"storeId": {
Expand Down Expand Up @@ -59,14 +61,7 @@
"principalType": "ROLE",
"principalId": "$group:manager",
"permission": "ALLOW",
"property": "updateAttributes"
},
{
"accessType": "WRITE",
"principalType": "ROLE",
"principalId": "$group:manager",
"permission": "ALLOW",
"property": "upsert"
"property": ["patchOrCreate", "replaceOrCreate", "replaceById", "updateOrCreate", "updateAttributes", "patchAttributes"]
},
{
"accessType": "*",
Expand Down
5 changes: 0 additions & 5 deletions test/fixtures/simple-app/common/models/store.js

This file was deleted.

6 changes: 4 additions & 2 deletions test/fixtures/simple-app/common/models/store.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
{
"name": "Store",
"base": "PersistedModel",
"idInjection": true,
"options": {
"validateUpsert": true
"idInjection": true,
"validateUpsert": true,
"forceId": false,
"replaceOnPUT": false
},
"properties": {
"id": {
Expand Down
5 changes: 0 additions & 5 deletions test/fixtures/simple-app/common/models/team.js

This file was deleted.

6 changes: 4 additions & 2 deletions test/fixtures/simple-app/common/models/team.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
{
"name": "Team",
"base": "PersistedModel",
"idInjection": true,
"options": {
"validateUpsert": true
"idInjection": true,
"validateUpsert": true,
"forceId": false,
"replaceOnPUT": false
},
"properties": {
"storeId": {
Expand Down
5 changes: 0 additions & 5 deletions test/fixtures/simple-app/common/models/transaction.js

This file was deleted.

6 changes: 4 additions & 2 deletions test/fixtures/simple-app/common/models/transaction.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
{
"name": "Transaction",
"base": "PersistedModel",
"idInjection": true,
"options": {
"validateUpsert": true
"idInjection": true,
"validateUpsert": true,
"forceId": false,
"replaceOnPUT": false
},
"properties": {
"storeId": {
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/simple-app/common/models/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ module.exports = function userCustomizer(user) {
user.currentUser = function(cb) {
return process.nextTick(() => cb(null, user.getCurrentUser()))
}
return user

}
15 changes: 12 additions & 3 deletions test/fixtures/simple-app/common/models/user.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
{
"name": "user",
"base": "User",
"idInjection": true,
"options": {
"idInjection": true,
"validateUpsert": true,
"saltWorkFactor": 1
"forceId": false,
"saltWorkFactor": 1,
"replaceOnPUT": false
},
"mixins": {
"GetCurrentUser": true
Expand All @@ -18,6 +20,14 @@
},
"validations": [],
"relations": {
"accessTokens": {
"type": "hasMany",
"model": "accessToken",
"foreignKey": "userId",
"options": {
"disableInclude": true
}
},
"stores": {
"type": "hasMany",
"model": "Store",
Expand Down Expand Up @@ -55,7 +65,6 @@
"methods": {
"currentUser": {
"description": "Get the current user.",
"isStatic": true,
"http": {
"path": "/currentUser",
"verb": "get"
Expand Down
5 changes: 1 addition & 4 deletions test/fixtures/simple-app/server/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@
"extended": true,
"limit": "100kb"
},
"cors": false,
"errorHandler": {
"disableStackTrace": false
}
"cors": false
},
"legacyExplorer": false,
"logoutSessionsOnSensitiveChanges": true
Expand Down
10 changes: 10 additions & 0 deletions test/fixtures/simple-app/server/middleware.development.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"final:after": {
"strong-error-handler": {
"params": {
"debug": true,
"log": true
}
}
}
}
13 changes: 9 additions & 4 deletions test/fixtures/simple-app/server/middleware.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
{
"initial:before": {
"loopback#token": {
"params": {
"model": "accessToken"
}
}
},
"initial": {
"loopback-context#per-request": {
"params": {
Expand All @@ -7,9 +14,7 @@
}
},
"session": {},
"auth": {
"loopback#token": {}
},
"auth": {},
"parse": {},
"routes": {
"loopback#rest": {
Expand All @@ -23,6 +28,6 @@
"loopback#urlNotFound": {}
},
"final:after": {
"loopback#errorHandler": {}
"strong-error-handler": {}
}
}
12 changes: 7 additions & 5 deletions test/fixtures/simple-app/server/model-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,25 @@
"../../../../lib/mixins"
]
},
"AccessToken": {

"accessToken": {
"dataSource": "db",
"public": true
},
"ACL": {
"user": {
"dataSource": "db",
"public": true
},
"RoleMapping": {

"ACL": {
"dataSource": "db",
"public": true
},
"Role": {
"RoleMapping": {
"dataSource": "db",
"public": true
},
"user": {
"Role": {
"dataSource": "db",
"public": true
},
Expand Down
2 changes: 0 additions & 2 deletions test/fixtures/simple-app/server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ const loopback = require('loopback')
const boot = require('loopback-boot')
const app = loopback()

global.Promise = require('bluebird')

app.start = function() {
// start the web server
return app.listen(function() {
Expand Down
13 changes: 13 additions & 0 deletions test/mixin-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,19 @@ function json(verb, url, data) {
.expect('Content-Type', /json/)
}

/**
* Initialise the application for the test suite.
*/
before(done => {
function finishBoot() {
return done()
}
if (app.booting) {
return app.once('booted', finishBoot)
}
return finishBoot()
})

describe('Current User Mixin.', function() {
describe('Smoke test', function() {
it('should add a getCurrentUser model method', function() {
Expand Down

0 comments on commit e0c926a

Please sign in to comment.