From 12e19e36eaa93c80cf9789b0d513b36af1b9b874 Mon Sep 17 00:00:00 2001 From: Raymond Feng Date: Mon, 20 Apr 2015 09:23:44 -0700 Subject: [PATCH] Upgrade test fixtures to use LB 2.x layout --- package.json | 2 +- test/access-control.integration.js | 2 +- test/access-token.test.js | 2 + test/fixtures/access-control/app.json | 4 - .../common/models/access-token.json | 19 ++ .../access-control/common/models/account.json | 42 +++++ .../access-control/common/models/alert.json | 12 ++ .../access-control/common/models/bank.json | 28 +++ .../access-control/common/models/email.json | 12 ++ .../common/models/transaction.json | 12 ++ .../access-control/common/models/user.json | 23 +++ test/fixtures/access-control/models.json | 171 ------------------ .../access-control/server/config.json | 5 + .../{ => server}/datasources.json | 2 - .../access-control/server/model-config.json | 48 +++++ .../{app.js => server/server.js} | 4 +- test/fixtures/e2e/{ => server}/models.js | 2 +- .../fixtures/e2e/{app.js => server/server.js} | 9 +- test/fixtures/simple-app/app.json | 4 - test/fixtures/simple-app/common/models/bar.js | 3 + .../simple-app/common/models/bar.json | 4 + .../simple-app/common/models/foo.json | 4 + test/fixtures/simple-app/models.json | 5 - test/fixtures/simple-app/models/bar.js | 1 - test/fixtures/simple-app/server/config.json | 5 + .../simple-app/{ => server}/datasources.json | 0 .../simple-app/server/model-config.json | 31 ++++ .../common/models/access-token.json | 4 + .../common/models/appointment.json | 20 ++ .../common/models/customer.json | 16 ++ .../common/models/email.json | 12 ++ .../common/models/patient.json | 16 ++ .../common/models/physician.json | 14 ++ .../common/models/profile.json | 9 + .../common/models/store.json | 17 ++ .../common/models/user.json | 11 ++ .../common/models/widget.json | 10 + .../simple-integration-app/models.json | 145 --------------- .../{app.json => server/config.json} | 3 +- .../{ => server}/datasources.json | 2 - .../server/model-config.json | 60 ++++++ .../{app.js => server/server.js} | 6 +- test/relations.integration.js | 2 +- test/remoting.integration.js | 2 +- test/user.test.js | 79 ++++---- 45 files changed, 495 insertions(+), 389 deletions(-) delete mode 100644 test/fixtures/access-control/app.json create mode 100644 test/fixtures/access-control/common/models/access-token.json create mode 100644 test/fixtures/access-control/common/models/account.json create mode 100644 test/fixtures/access-control/common/models/alert.json create mode 100644 test/fixtures/access-control/common/models/bank.json create mode 100644 test/fixtures/access-control/common/models/email.json create mode 100644 test/fixtures/access-control/common/models/transaction.json create mode 100644 test/fixtures/access-control/common/models/user.json delete mode 100644 test/fixtures/access-control/models.json create mode 100644 test/fixtures/access-control/server/config.json rename test/fixtures/access-control/{ => server}/datasources.json (58%) create mode 100644 test/fixtures/access-control/server/model-config.json rename test/fixtures/access-control/{app.js => server/server.js} (73%) rename test/fixtures/e2e/{ => server}/models.js (74%) rename test/fixtures/e2e/{app.js => server/server.js} (52%) delete mode 100644 test/fixtures/simple-app/app.json create mode 100644 test/fixtures/simple-app/common/models/bar.js create mode 100644 test/fixtures/simple-app/common/models/bar.json create mode 100644 test/fixtures/simple-app/common/models/foo.json delete mode 100644 test/fixtures/simple-app/models.json delete mode 100644 test/fixtures/simple-app/models/bar.js create mode 100644 test/fixtures/simple-app/server/config.json rename test/fixtures/simple-app/{ => server}/datasources.json (100%) create mode 100644 test/fixtures/simple-app/server/model-config.json create mode 100644 test/fixtures/simple-integration-app/common/models/access-token.json create mode 100644 test/fixtures/simple-integration-app/common/models/appointment.json create mode 100644 test/fixtures/simple-integration-app/common/models/customer.json create mode 100644 test/fixtures/simple-integration-app/common/models/email.json create mode 100644 test/fixtures/simple-integration-app/common/models/patient.json create mode 100644 test/fixtures/simple-integration-app/common/models/physician.json create mode 100644 test/fixtures/simple-integration-app/common/models/profile.json create mode 100644 test/fixtures/simple-integration-app/common/models/store.json create mode 100644 test/fixtures/simple-integration-app/common/models/user.json create mode 100644 test/fixtures/simple-integration-app/common/models/widget.json delete mode 100644 test/fixtures/simple-integration-app/models.json rename test/fixtures/simple-integration-app/{app.json => server/config.json} (87%) rename test/fixtures/simple-integration-app/{ => server}/datasources.json (58%) create mode 100644 test/fixtures/simple-integration-app/server/model-config.json rename test/fixtures/simple-integration-app/{app.js => server/server.js} (50%) diff --git a/package.json b/package.json index 22678afe..a814c2f5 100644 --- a/package.json +++ b/package.json @@ -79,7 +79,7 @@ "karma-mocha": "^0.1.10", "karma-phantomjs-launcher": "^0.1.4", "karma-script-launcher": "^0.1.0", - "loopback-boot": "^1.1.0", + "loopback-boot": "^2.7.0", "loopback-datasource-juggler": "^2.19.1", "loopback-testing": "^1.1.0", "mocha": "^2.1.0", diff --git a/test/access-control.integration.js b/test/access-control.integration.js index 01fd2a16..3125a653 100644 --- a/test/access-control.integration.js +++ b/test/access-control.integration.js @@ -4,7 +4,7 @@ var loopback = require('../'); var lt = require('loopback-testing'); var path = require('path'); var ACCESS_CONTROL_APP = path.join(__dirname, 'fixtures', 'access-control'); -var app = require(path.join(ACCESS_CONTROL_APP, 'app.js')); +var app = require(path.join(ACCESS_CONTROL_APP, 'server/server.js')); var assert = require('assert'); var USER = {email: 'test@test.test', password: 'test'}; var CURRENT_USER = {email: 'current@test.test', password: 'test'}; diff --git a/test/access-token.test.js b/test/access-token.test.js index 11988c28..82723f1b 100644 --- a/test/access-token.test.js +++ b/test/access-token.test.js @@ -1,6 +1,8 @@ var loopback = require('../'); var extend = require('util')._extend; var Token = loopback.AccessToken.extend('MyToken'); +var ds = loopback.createDataSource({connector: loopback.Memory}); +Token.attachTo(ds); var ACL = loopback.ACL; describe('loopback.token(options)', function() { diff --git a/test/fixtures/access-control/app.json b/test/fixtures/access-control/app.json deleted file mode 100644 index ffc18ffd..00000000 --- a/test/fixtures/access-control/app.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "port": 3000, - "host": "0.0.0.0" -} \ No newline at end of file diff --git a/test/fixtures/access-control/common/models/access-token.json b/test/fixtures/access-control/common/models/access-token.json new file mode 100644 index 00000000..6b42d503 --- /dev/null +++ b/test/fixtures/access-control/common/models/access-token.json @@ -0,0 +1,19 @@ +{ + "name": "accessToken", + "base": "AccessToken", + "baseUrl": "access-tokens", + "acls": [ + { + "accessType": "*", + "permission": "DENY", + "principalType": "ROLE", + "principalId": "$everyone" + }, + { + "permission": "ALLOW", + "principalType": "ROLE", + "principalId": "$everyone", + "property": "create" + } + ] +} \ No newline at end of file diff --git a/test/fixtures/access-control/common/models/account.json b/test/fixtures/access-control/common/models/account.json new file mode 100644 index 00000000..4607adfc --- /dev/null +++ b/test/fixtures/access-control/common/models/account.json @@ -0,0 +1,42 @@ +{ + "name": "account", + "relations": { + "transactions": { + "model": "transaction", + "type": "hasMany" + }, + "user": { + "model": "user", + "type": "belongsTo", + "foreignKey": "userId" + } + }, + "acls": [ + { + "accessType": "*", + "permission": "DENY", + "principalType": "ROLE", + "principalId": "$everyone" + }, + { + "accessType": "*", + "permission": "ALLOW", + "principalType": "ROLE", + "principalId": "$owner" + }, + { + "permission": "DENY", + "principalType": "ROLE", + "principalId": "$owner", + "property": "deleteById" + }, + { + "accessType": "*", + "permission": "DENY", + "property": "find", + "principalType": "ROLE", + "principalId": "$dummy" + } + ], + "properties": {} +} \ No newline at end of file diff --git a/test/fixtures/access-control/common/models/alert.json b/test/fixtures/access-control/common/models/alert.json new file mode 100644 index 00000000..38b93c37 --- /dev/null +++ b/test/fixtures/access-control/common/models/alert.json @@ -0,0 +1,12 @@ +{ + "name": "alert", + "acls": [ + { + "accessType": "WRITE", + "permission": "DENY", + "principalType": "ROLE", + "principalId": "$everyone" + } + ], + "properties": {} +} \ No newline at end of file diff --git a/test/fixtures/access-control/common/models/bank.json b/test/fixtures/access-control/common/models/bank.json new file mode 100644 index 00000000..a06555b8 --- /dev/null +++ b/test/fixtures/access-control/common/models/bank.json @@ -0,0 +1,28 @@ +{ + "name": "bank", + "relations": { + "users": { + "model": "user", + "type": "hasMany" + }, + "accounts": { + "model": "account", + "type": "hasMany" + } + }, + "acls": [ + { + "accessType": "*", + "permission": "DENY", + "principalType": "ROLE", + "principalId": "$everyone" + }, + { + "accessType": "READ", + "permission": "ALLOW", + "principalType": "ROLE", + "principalId": "$everyone" + } + ], + "properties": {} +} \ No newline at end of file diff --git a/test/fixtures/access-control/common/models/email.json b/test/fixtures/access-control/common/models/email.json new file mode 100644 index 00000000..6100775b --- /dev/null +++ b/test/fixtures/access-control/common/models/email.json @@ -0,0 +1,12 @@ +{ + "name": "email", + "base": "Email", + "acls": [ + { + "accessType": "*", + "permission": "DENY", + "principalType": "ROLE", + "principalId": "$everyone" + } + ] +} \ No newline at end of file diff --git a/test/fixtures/access-control/common/models/transaction.json b/test/fixtures/access-control/common/models/transaction.json new file mode 100644 index 00000000..d7580e1b --- /dev/null +++ b/test/fixtures/access-control/common/models/transaction.json @@ -0,0 +1,12 @@ +{ + "name": "transaction", + "acls": [ + { + "accessType": "*", + "permission": "DENY", + "principalType": "ROLE", + "principalId": "$everyone" + } + ], + "properties": {} +} \ No newline at end of file diff --git a/test/fixtures/access-control/common/models/user.json b/test/fixtures/access-control/common/models/user.json new file mode 100644 index 00000000..7ecfb373 --- /dev/null +++ b/test/fixtures/access-control/common/models/user.json @@ -0,0 +1,23 @@ +{ + "name": "user", + "base": "User", + "relations": { + "accessTokens": { + "model": "accessToken", + "type": "hasMany", + "foreignKey": "userId" + }, + "transactions": { + "model": "transaction", + "type": "hasMany" + } + }, + "acls": [ + { + "accessType": "*", + "permission": "DENY", + "principalType": "ROLE", + "principalId": "$everyone" + } + ] +} \ No newline at end of file diff --git a/test/fixtures/access-control/models.json b/test/fixtures/access-control/models.json deleted file mode 100644 index e6b1c292..00000000 --- a/test/fixtures/access-control/models.json +++ /dev/null @@ -1,171 +0,0 @@ -{ - "email": { - "options": { - "base": "Email", - "acls": [ - { - "accessType": "*", - "permission": "DENY", - "principalType": "ROLE", - "principalId": "$everyone" - } - ] - }, - "dataSource": "mail", - "public": false - }, - "user": { - "options": { - "base": "User", - "relations": { - "accessTokens": { - "model": "accessToken", - "type": "hasMany", - "foreignKey": "userId" - }, - "transactions": { - "model": "transaction", - "type": "hasMany" - } - }, - "acls": [ - { - "accessType": "*", - "permission": "DENY", - "principalType": "ROLE", - "principalId": "$everyone" - } - ] - }, - "dataSource": "db", - "public": true - }, - "accessToken": { - "options": { - "base": "AccessToken", - "baseUrl": "access-tokens", - "acls": [ - { - "accessType": "*", - "permission": "DENY", - "principalType": "ROLE", - "principalId": "$everyone" - }, - { - "permission": "ALLOW", - "principalType": "ROLE", - "principalId": "$everyone", - "property": "create" - } - ] - }, - "dataSource": "db", - "public": true - }, - "bank": { - "options": { - "relations": { - "users": { - "model": "user", - "type": "hasMany" - }, - "accounts": { - "model": "account", - "type": "hasMany" - } - }, - "acls": [ - { - "accessType": "*", - "permission": "DENY", - "principalType": "ROLE", - "principalId": "$everyone" - }, - { - "accessType": "READ", - "permission": "ALLOW", - "principalType": "ROLE", - "principalId": "$everyone" - } - ] - }, - "properties": {}, - "public": true, - "dataSource": "db" - }, - "account": { - "options": { - "relations": { - "transactions": { - "model": "transaction", - "type": "hasMany" - }, - "user": { - "model": "user", - "type": "belongsTo", - "foreignKey": "userId" - } - }, - "acls": [ - { - "accessType": "*", - "permission": "DENY", - "principalType": "ROLE", - "principalId": "$everyone" - }, - { - "accessType": "*", - "permission": "ALLOW", - "principalType": "ROLE", - "principalId": "$owner" - }, - { - "permission": "DENY", - "principalType": "ROLE", - "principalId": "$owner", - "property": "deleteById" - }, - { - "accessType": "*", - "permission": "DENY", - "property": "find", - "principalType": "ROLE", - "principalId": "$dummy" - } - ] - }, - "properties": {}, - "public": true, - "dataSource": "db" - }, - "transaction": { - "options": { - "acls": [ - { - "accessType": "*", - "permission": "DENY", - "principalType": "ROLE", - "principalId": "$everyone" - } - ] - }, - "properties": {}, - "public": true, - "dataSource": "db" - }, - "alert": { - "options": { - "acls": [ - { - "accessType": "WRITE", - "permission": "DENY", - "principalType": "ROLE", - "principalId": "$everyone" - } - ] - }, - "properties": {}, - "public": true, - "dataSource": "db" - } -} diff --git a/test/fixtures/access-control/server/config.json b/test/fixtures/access-control/server/config.json new file mode 100644 index 00000000..67364ab4 --- /dev/null +++ b/test/fixtures/access-control/server/config.json @@ -0,0 +1,5 @@ +{ + "port": 3000, + "host": "0.0.0.0", + "legacyExplorer": false +} \ No newline at end of file diff --git a/test/fixtures/access-control/datasources.json b/test/fixtures/access-control/server/datasources.json similarity index 58% rename from test/fixtures/access-control/datasources.json rename to test/fixtures/access-control/server/datasources.json index 9f97a8d3..59ea72a4 100644 --- a/test/fixtures/access-control/datasources.json +++ b/test/fixtures/access-control/server/datasources.json @@ -1,10 +1,8 @@ { "db": { - "defaultForType": "db", "connector": "memory" }, "mail": { - "defaultForType": "mail", "connector": "mail" } } \ No newline at end of file diff --git a/test/fixtures/access-control/server/model-config.json b/test/fixtures/access-control/server/model-config.json new file mode 100644 index 00000000..2a48ed23 --- /dev/null +++ b/test/fixtures/access-control/server/model-config.json @@ -0,0 +1,48 @@ +{ + "_meta": { + "sources": [ + "../common/models", + "./models" + ] + }, + "ACL": { + "dataSource": "db", + "public": false + }, + "RoleMapping": { + "dataSource": "db", + "public": false + }, + "Role": { + "dataSource": "db", + "public": false + }, + "email": { + "dataSource": "mail", + "public": false + }, + "user": { + "dataSource": "db", + "public": true + }, + "accessToken": { + "dataSource": "db", + "public": true + }, + "bank": { + "public": true, + "dataSource": "db" + }, + "account": { + "public": true, + "dataSource": "db" + }, + "transaction": { + "public": true, + "dataSource": "db" + }, + "alert": { + "public": true, + "dataSource": "db" + } +} diff --git a/test/fixtures/access-control/app.js b/test/fixtures/access-control/server/server.js similarity index 73% rename from test/fixtures/access-control/app.js rename to test/fixtures/access-control/server/server.js index a8736a44..ef251648 100644 --- a/test/fixtures/access-control/app.js +++ b/test/fixtures/access-control/server/server.js @@ -1,12 +1,10 @@ -var loopback = require('../../../'); +var loopback = require('../../../..'); var boot = require('loopback-boot'); -var path = require('path'); var app = module.exports = loopback(); boot(app, __dirname); var apiPath = '/api'; -app.use(loopback.cookieParser('secret')); app.use(loopback.token({model: app.models.accessToken})); app.use(apiPath, loopback.rest()); diff --git a/test/fixtures/e2e/models.js b/test/fixtures/e2e/server/models.js similarity index 74% rename from test/fixtures/e2e/models.js rename to test/fixtures/e2e/server/models.js index 3574c5bc..dc36ca03 100644 --- a/test/fixtures/e2e/models.js +++ b/test/fixtures/e2e/server/models.js @@ -1,4 +1,4 @@ -var loopback = require('../../../'); +var loopback = require('../../../../index'); var PersistedModel = loopback.PersistedModel; exports.TestModel = PersistedModel.extend('TestModel', {}, { diff --git a/test/fixtures/e2e/app.js b/test/fixtures/e2e/server/server.js similarity index 52% rename from test/fixtures/e2e/app.js rename to test/fixtures/e2e/server/server.js index 608b3d7e..bd8a9411 100644 --- a/test/fixtures/e2e/app.js +++ b/test/fixtures/e2e/server/server.js @@ -1,11 +1,8 @@ -var loopback = require('../../../'); -var path = require('path'); +var loopback = require('../../../../index'); var app = module.exports = loopback(); var models = require('./models'); var TestModel = models.TestModel; -// var explorer = require('loopback-explorer'); -app.use(loopback.cookieParser({secret: app.get('cookieSecret')})); var apiPath = '/api'; app.use(apiPath, loopback.rest()); @@ -13,8 +10,6 @@ TestModel.attachTo(loopback.memory()); app.model(TestModel); app.model(TestModel.getChangeModel()); -// app.use('/explorer', explorer(app, {basePath: apiPath})); - -app.use(loopback.static(path.join(__dirname, 'public'))); +// app.use(loopback.static(path.join(__dirname, 'public'))); app.use(loopback.urlNotFound()); app.use(loopback.errorHandler()); diff --git a/test/fixtures/simple-app/app.json b/test/fixtures/simple-app/app.json deleted file mode 100644 index 8358c75f..00000000 --- a/test/fixtures/simple-app/app.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "port": 3000, - "host": "127.0.0.1" -} diff --git a/test/fixtures/simple-app/common/models/bar.js b/test/fixtures/simple-app/common/models/bar.js new file mode 100644 index 00000000..10a3d968 --- /dev/null +++ b/test/fixtures/simple-app/common/models/bar.js @@ -0,0 +1,3 @@ +module.exports = function(Bar) { + process.loadedBarJS = true; +}; diff --git a/test/fixtures/simple-app/common/models/bar.json b/test/fixtures/simple-app/common/models/bar.json new file mode 100644 index 00000000..47e94ee8 --- /dev/null +++ b/test/fixtures/simple-app/common/models/bar.json @@ -0,0 +1,4 @@ +{ + "name": "bar", + "properties": {} +} \ No newline at end of file diff --git a/test/fixtures/simple-app/common/models/foo.json b/test/fixtures/simple-app/common/models/foo.json new file mode 100644 index 00000000..9f28272a --- /dev/null +++ b/test/fixtures/simple-app/common/models/foo.json @@ -0,0 +1,4 @@ +{ + "name": "foo", + "properties": {} +} \ No newline at end of file diff --git a/test/fixtures/simple-app/models.json b/test/fixtures/simple-app/models.json deleted file mode 100644 index 3a22f139..00000000 --- a/test/fixtures/simple-app/models.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "foo": { - "dataSource": "db" - } -} diff --git a/test/fixtures/simple-app/models/bar.js b/test/fixtures/simple-app/models/bar.js deleted file mode 100644 index 0eef5d94..00000000 --- a/test/fixtures/simple-app/models/bar.js +++ /dev/null @@ -1 +0,0 @@ -process.loadedBarJS = true; diff --git a/test/fixtures/simple-app/server/config.json b/test/fixtures/simple-app/server/config.json new file mode 100644 index 00000000..b8d6d71e --- /dev/null +++ b/test/fixtures/simple-app/server/config.json @@ -0,0 +1,5 @@ +{ + "port": 3000, + "host": "127.0.0.1", + "legacyExplorer": false +} diff --git a/test/fixtures/simple-app/datasources.json b/test/fixtures/simple-app/server/datasources.json similarity index 100% rename from test/fixtures/simple-app/datasources.json rename to test/fixtures/simple-app/server/datasources.json diff --git a/test/fixtures/simple-app/server/model-config.json b/test/fixtures/simple-app/server/model-config.json new file mode 100644 index 00000000..08448d73 --- /dev/null +++ b/test/fixtures/simple-app/server/model-config.json @@ -0,0 +1,31 @@ +{ + "_meta": { + "sources": [ + "../common/models", + "./models" + ] + }, + "User": { + "dataSource": "db", + "public": false + }, + "AccessToken": { + "dataSource": "db", + "public": false + }, + "ACL": { + "dataSource": "db", + "public": false + }, + "RoleMapping": { + "dataSource": "db", + "public": false + }, + "Role": { + "dataSource": "db", + "public": false + }, + "foo": { + "dataSource": "db" + } +} diff --git a/test/fixtures/simple-integration-app/common/models/access-token.json b/test/fixtures/simple-integration-app/common/models/access-token.json new file mode 100644 index 00000000..c131ba23 --- /dev/null +++ b/test/fixtures/simple-integration-app/common/models/access-token.json @@ -0,0 +1,4 @@ +{ + "name": "accessToken", + "base": "AccessToken" +} \ No newline at end of file diff --git a/test/fixtures/simple-integration-app/common/models/appointment.json b/test/fixtures/simple-integration-app/common/models/appointment.json new file mode 100644 index 00000000..7ebe61ce --- /dev/null +++ b/test/fixtures/simple-integration-app/common/models/appointment.json @@ -0,0 +1,20 @@ +{ + "name": "appointment", + "properties": { + "date": "date" + }, + "options": { + "relations": { + "physician": { + "model": "physician", + "type": "belongsTo", + "foreignKey": "physicianId" + }, + "patient": { + "model": "patient", + "type": "belongsTo", + "foreignKey": "patientId" + } + } + } +} \ No newline at end of file diff --git a/test/fixtures/simple-integration-app/common/models/customer.json b/test/fixtures/simple-integration-app/common/models/customer.json new file mode 100644 index 00000000..dc874eb3 --- /dev/null +++ b/test/fixtures/simple-integration-app/common/models/customer.json @@ -0,0 +1,16 @@ +{ + "name": "customer", + "base": "PersistedModel", + "properties": { + "name": { + "type": "string", + "required": true + } + }, + "relations": { + "profile": { + "type": "hasOne", + "model": "profile" + } + } +} \ No newline at end of file diff --git a/test/fixtures/simple-integration-app/common/models/email.json b/test/fixtures/simple-integration-app/common/models/email.json new file mode 100644 index 00000000..6100775b --- /dev/null +++ b/test/fixtures/simple-integration-app/common/models/email.json @@ -0,0 +1,12 @@ +{ + "name": "email", + "base": "Email", + "acls": [ + { + "accessType": "*", + "permission": "DENY", + "principalType": "ROLE", + "principalId": "$everyone" + } + ] +} \ No newline at end of file diff --git a/test/fixtures/simple-integration-app/common/models/patient.json b/test/fixtures/simple-integration-app/common/models/patient.json new file mode 100644 index 00000000..fe7dfa43 --- /dev/null +++ b/test/fixtures/simple-integration-app/common/models/patient.json @@ -0,0 +1,16 @@ +{ + "name": "patient", + "properties": { + "name": "string" + }, + "options": { + "relations": { + "physicians": { + "model": "physician", + "type": "hasMany", + "through": "appointment", + "foreignKey": "physicianId" + } + } + } +} \ No newline at end of file diff --git a/test/fixtures/simple-integration-app/common/models/physician.json b/test/fixtures/simple-integration-app/common/models/physician.json new file mode 100644 index 00000000..835ffda8 --- /dev/null +++ b/test/fixtures/simple-integration-app/common/models/physician.json @@ -0,0 +1,14 @@ +{ + "name": "physician", + "properties": { + "name": "string" + }, + "relations": { + "patients": { + "model": "patient", + "type": "hasMany", + "through": "appointment", + "foreignKey": "patientId" + } + } +} diff --git a/test/fixtures/simple-integration-app/common/models/profile.json b/test/fixtures/simple-integration-app/common/models/profile.json new file mode 100644 index 00000000..1b5108ca --- /dev/null +++ b/test/fixtures/simple-integration-app/common/models/profile.json @@ -0,0 +1,9 @@ +{ + "name": "profile", + "base": "PersistedModel", + "properties": { + "points": { + "type": "number" + } + } +} \ No newline at end of file diff --git a/test/fixtures/simple-integration-app/common/models/store.json b/test/fixtures/simple-integration-app/common/models/store.json new file mode 100644 index 00000000..3dc1220d --- /dev/null +++ b/test/fixtures/simple-integration-app/common/models/store.json @@ -0,0 +1,17 @@ +{ + "name": "store", + "properties": {}, + "scopes": { + "superStores": { + "where": { + "size": "super" + } + } + }, + "relations": { + "widgets": { + "model": "widget", + "type": "hasMany" + } + } +} \ No newline at end of file diff --git a/test/fixtures/simple-integration-app/common/models/user.json b/test/fixtures/simple-integration-app/common/models/user.json new file mode 100644 index 00000000..14a6fa8c --- /dev/null +++ b/test/fixtures/simple-integration-app/common/models/user.json @@ -0,0 +1,11 @@ +{ + "name": "user", + "base": "User", + "relations": { + "accessTokens": { + "model": "accessToken", + "type": "hasMany", + "foreignKey": "userId" + } + } +} \ No newline at end of file diff --git a/test/fixtures/simple-integration-app/common/models/widget.json b/test/fixtures/simple-integration-app/common/models/widget.json new file mode 100644 index 00000000..018c0e1d --- /dev/null +++ b/test/fixtures/simple-integration-app/common/models/widget.json @@ -0,0 +1,10 @@ +{ + "name": "widget", + "properties": {}, + "relations": { + "store": { + "model": "store", + "type": "belongsTo" + } + } +} \ No newline at end of file diff --git a/test/fixtures/simple-integration-app/models.json b/test/fixtures/simple-integration-app/models.json deleted file mode 100644 index af1cd590..00000000 --- a/test/fixtures/simple-integration-app/models.json +++ /dev/null @@ -1,145 +0,0 @@ -{ - "email": { - "dataSource": "mail", - "public": false, - "options": { - "base": "Email" - } - }, - "user": { - "dataSource": "db", - "public": true, - "options": { - "base": "User", - "relations": { - "accessTokens": { - "model": "accessToken", - "type": "hasMany", - "foreignKey": "userId" - } - } - } - }, - "accessToken": { - "dataSource": "db", - "public": true, - "options": { - "base": "AccessToken" - } - }, - "widget": { - "properties": {}, - "public": true, - "dataSource": "db", - "options": { - "relations": { - "store": { - "model": "store", - "type": "belongsTo" - } - } - } - }, - "store": { - "properties": {}, - "public": true, - "dataSource": "db", - "options": { - "scopes": { - "superStores": { - "where": { - "size": "super" - } - } - }, - "relations": { - "widgets": { - "model": "widget", - "type": "hasMany" - } - } - } - }, - "physician": { - "dataSource": "db", - "public": true, - "properties": { - "name": "string" - }, - "options": { - "relations": { - "patients": { - "model": "patient", - "type": "hasMany", - "through": "appointment", - "foreignKey": "patientId" - } - } - } - }, - "patient": { - "dataSource": "db", - "public": true, - "properties": { - "name": "string" - }, - "options": { - "relations": { - "physicians": { - "model": "physician", - "type": "hasMany", - "through": "appointment", - "foreignKey": "physicianId" - } - } - } - }, - "appointment": { - "dataSource": "db", - "public": true, - "properties": { - "date": "date" - }, - "options": { - "relations": { - "physician": { - "model": "physician", - "type": "belongsTo", - "foreignKey": "physicianId" - }, - "patient": { - "model": "patient", - "type": "belongsTo", - "foreignKey": "patientId" - } - } - } - }, - "customer": { - "base": "PersistedModel", - "dataSource": "db", - "public": true, - "properties": { - "name": { - "type": "string", - "required": true - } - }, - "relations": { - "profile": { - "type": "hasOne", - "model": "profile" - } - } - }, - "profile": { - "base": "PersistedModel", - "dataSource": "db", - "public": true, - "properties": { - "points": { - "type": "number" - } - } - } -} diff --git a/test/fixtures/simple-integration-app/app.json b/test/fixtures/simple-integration-app/server/config.json similarity index 87% rename from test/fixtures/simple-integration-app/app.json rename to test/fixtures/simple-integration-app/server/config.json index c1cd9fb7..c7cce73e 100644 --- a/test/fixtures/simple-integration-app/app.json +++ b/test/fixtures/simple-integration-app/server/config.json @@ -10,5 +10,6 @@ "urlencoded": { "limit": "8kb" } - } + }, + "legacyExplorer": false } \ No newline at end of file diff --git a/test/fixtures/simple-integration-app/datasources.json b/test/fixtures/simple-integration-app/server/datasources.json similarity index 58% rename from test/fixtures/simple-integration-app/datasources.json rename to test/fixtures/simple-integration-app/server/datasources.json index 9f97a8d3..59ea72a4 100644 --- a/test/fixtures/simple-integration-app/datasources.json +++ b/test/fixtures/simple-integration-app/server/datasources.json @@ -1,10 +1,8 @@ { "db": { - "defaultForType": "db", "connector": "memory" }, "mail": { - "defaultForType": "mail", "connector": "mail" } } \ No newline at end of file diff --git a/test/fixtures/simple-integration-app/server/model-config.json b/test/fixtures/simple-integration-app/server/model-config.json new file mode 100644 index 00000000..f5d34f28 --- /dev/null +++ b/test/fixtures/simple-integration-app/server/model-config.json @@ -0,0 +1,60 @@ +{ + "_meta": { + "sources": [ + "../common/models", + "./models" + ] + }, + "ACL": { + "dataSource": "db", + "public": false + }, + "RoleMapping": { + "dataSource": "db", + "public": false + }, + "Role": { + "dataSource": "db", + "public": false + }, + "email": { + "dataSource": "mail", + "public": false + }, + "user": { + "dataSource": "db", + "public": true + }, + "accessToken": { + "dataSource": "db", + "public": true + }, + "widget": { + "public": true, + "dataSource": "db" + }, + "store": { + "public": true, + "dataSource": "db" + }, + "physician": { + "dataSource": "db", + "public": true + }, + "patient": { + "dataSource": "db", + "public": true + }, + "appointment": { + "dataSource": "db", + "public": true + }, + "customer": { + "dataSource": "db", + "public": true + }, + "profile": { + "dataSource": "db", + "public": true + } +} diff --git a/test/fixtures/simple-integration-app/app.js b/test/fixtures/simple-integration-app/server/server.js similarity index 50% rename from test/fixtures/simple-integration-app/app.js rename to test/fixtures/simple-integration-app/server/server.js index a4cbb2a4..d3f1c09c 100644 --- a/test/fixtures/simple-integration-app/app.js +++ b/test/fixtures/simple-integration-app/server/server.js @@ -1,13 +1,9 @@ -var loopback = require('../../../'); +var loopback = require('../../../../index'); var boot = require('loopback-boot'); -var path = require('path'); var app = module.exports = loopback(); boot(app, __dirname); -app.use(loopback.favicon()); -app.use(loopback.cookieParser({secret: app.get('cookieSecret')})); var apiPath = '/api'; app.use(apiPath, loopback.rest()); -app.use(loopback.static(path.join(__dirname, 'public'))); app.use(loopback.urlNotFound()); app.use(loopback.errorHandler()); diff --git a/test/relations.integration.js b/test/relations.integration.js index e81689ca..8c0766af 100644 --- a/test/relations.integration.js +++ b/test/relations.integration.js @@ -4,7 +4,7 @@ var loopback = require('../'); var lt = require('loopback-testing'); var path = require('path'); var SIMPLE_APP = path.join(__dirname, 'fixtures', 'simple-integration-app'); -var app = require(path.join(SIMPLE_APP, 'app.js')); +var app = require(path.join(SIMPLE_APP, 'server/server.js')); var assert = require('assert'); var expect = require('chai').expect; var debug = require('debug')('loopback:test:relations.integration'); diff --git a/test/remoting.integration.js b/test/remoting.integration.js index 59a553af..a5bc6389 100644 --- a/test/remoting.integration.js +++ b/test/remoting.integration.js @@ -2,7 +2,7 @@ var loopback = require('../'); var lt = require('loopback-testing'); var path = require('path'); var SIMPLE_APP = path.join(__dirname, 'fixtures', 'simple-integration-app'); -var app = require(path.join(SIMPLE_APP, 'app.js')); +var app = require(path.join(SIMPLE_APP, 'server/server.js')); var assert = require('assert'); describe('remoting - integration', function() { diff --git a/test/user.test.js b/test/user.test.js index 682b2f46..3841055e 100644 --- a/test/user.test.js +++ b/test/user.test.js @@ -1,5 +1,7 @@ +require('./support'); +var loopback = require('../'); var User; -var AccessToken = loopback.AccessToken; +var AccessToken; var MailConnector = require('../lib/connectors/mail'); var userMemory = loopback.createDataSource({ @@ -16,14 +18,21 @@ describe('User', function() { var invalidCredentials = {email: 'foo1@bar.com', password: 'invalid'}; var incompleteCredentials = {password: 'bar1'}; + var defaultApp; + beforeEach(function() { - User = loopback.User.extend('user'); + // FIXME: [rfeng] Remove loopback.User.app so that remote hooks don't go + // to the wrong app instance + defaultApp = loopback.User.app; + loopback.User.app = null; + User = loopback.User.extend('TestUser', {}, {http: {path: 'test-users'}}); + AccessToken = loopback.AccessToken.extend('TestAccessToken'); User.email = loopback.Email.extend('email'); loopback.autoAttach(); // Update the AccessToken relation to use the subclass of User - AccessToken.belongsTo(User); - User.hasMany(AccessToken); + AccessToken.belongsTo(User, {as: 'user', foreignKey: 'userId'}); + User.hasMany(AccessToken, {as: 'accessTokens', foreignKey: 'userId'}); // allow many User.afterRemote's to be called User.setMaxListeners(0); @@ -32,7 +41,7 @@ describe('User', function() { beforeEach(function(done) { app.enableAuth(); - app.use(loopback.token()); + app.use(loopback.token({model: AccessToken})); app.use(loopback.rest()); app.model(User); @@ -42,6 +51,7 @@ describe('User', function() { }); afterEach(function(done) { + loopback.User.app = defaultApp; User.destroyAll(function(err) { User.accessToken.destroyAll(done); }); @@ -78,7 +88,7 @@ describe('User', function() { assert(err); assert.equal(err.name, 'ValidationError'); assert.equal(err.statusCode, 422); - assert.equal(err.details.context, 'user'); + assert.equal(err.details.context, User.modelName); assert.deepEqual(err.details.codes.email, [ 'presence', 'format.null' @@ -152,7 +162,7 @@ describe('User', function() { beforeEach(function() { defaultHashPassword = User.hashPassword; - defaultValidatePassword = User.defaultValidatePassword; + defaultValidatePassword = User.validatePassword; User.hashPassword = function(plain) { return plain.toUpperCase(); @@ -168,6 +178,7 @@ describe('User', function() { afterEach(function() { User.hashPassword = defaultHashPassword; + User.validatePassword = defaultValidatePassword; }); it('Reports invalid password', function() { @@ -187,7 +198,7 @@ describe('User', function() { it('Create a user over REST should remove emailVerified property', function(done) { request(app) - .post('/users') + .post('/test-users') .expect('Content-Type', /json/) .expect(200) .send(validCredentialsEmailVerifiedOverREST) @@ -299,7 +310,7 @@ describe('User', function() { it('Login a user over REST by providing credentials', function(done) { request(app) - .post('/users/login') + .post('/test-users/login') .expect('Content-Type', /json/) .expect(200) .send(validCredentials) @@ -320,7 +331,7 @@ describe('User', function() { it('Login a user over REST by providing invalid credentials', function(done) { request(app) - .post('/users/login') + .post('/test-users/login') .expect('Content-Type', /json/) .expect(401) .send(invalidCredentials) @@ -336,7 +347,7 @@ describe('User', function() { it('Login a user over REST by providing incomplete credentials', function(done) { request(app) - .post('/users/login') + .post('/test-users/login') .expect('Content-Type', /json/) .expect(400) .send(incompleteCredentials) @@ -352,7 +363,7 @@ describe('User', function() { it('Login a user over REST with the wrong Content-Type', function(done) { request(app) - .post('/users/login') + .post('/test-users/login') .set('Content-Type', null) .expect('Content-Type', /json/) .expect(400) @@ -369,7 +380,7 @@ describe('User', function() { it('Returns current user when `include` is `USER`', function(done) { request(app) - .post('/users/login?include=USER') + .post('/test-users/login?include=USER') .send(validCredentials) .expect(200) .expect('Content-Type', /json/) @@ -387,7 +398,7 @@ describe('User', function() { it('should handle multiple `include`', function(done) { request(app) - .post('/users/login?include=USER&include=Post') + .post('/test-users/login?include=USER&include=Post') .send(validCredentials) .expect(200) .expect('Content-Type', /json/) @@ -447,7 +458,7 @@ describe('User', function() { it('Login a user over REST when email verification is required', function(done) { request(app) - .post('/users/login') + .post('/test-users/login') .expect('Content-Type', /json/) .expect(200) .send(validCredentialsEmailVerified) @@ -466,7 +477,7 @@ describe('User', function() { it('Login a user over REST require complete and valid credentials for email verification error message', function(done) { request(app) - .post('/users/login') + .post('/test-users/login') .expect('Content-Type', /json/) .expect(401) .send({ email: validCredentialsEmail }) @@ -485,7 +496,7 @@ describe('User', function() { it('Login a user over REST without email verification when it is required', function(done) { request(app) - .post('/users/login') + .post('/test-users/login') .expect('Content-Type', /json/) .expect(401) .send(validCredentials) @@ -513,8 +524,8 @@ describe('User', function() { loopback.autoAttach(); // Update the AccessToken relation to use the subclass of User - AccessToken.belongsTo(User); - User.hasMany(AccessToken); + AccessToken.belongsTo(User, {as: 'user', foreignKey: 'userId'}); + User.hasMany(AccessToken, {as: 'accessTokens', foreignKey: 'userId'}); // allow many User.afterRemote's to be called User.setMaxListeners(0); @@ -683,7 +694,7 @@ describe('User', function() { login(logout); function login(fn) { request(app) - .post('/users/login') + .post('/test-users/login') .expect('Content-Type', /json/) .expect(200) .send({email: 'foo@bar.com', password: 'bar'}) @@ -702,7 +713,7 @@ describe('User', function() { function logout(err, token) { request(app) - .post('/users/logout') + .post('/test-users/logout') .set('Authorization', token) .expect(204) .end(verify(token, done)); @@ -792,14 +803,14 @@ describe('User', function() { assert(result.email.response); assert(result.token); var msg = result.email.response.toString('utf-8'); - assert(~msg.indexOf('/api/users/confirm')); + assert(~msg.indexOf('/api/test-users/confirm')); assert(~msg.indexOf('To: bar@bat.com')); done(); }); }); request(app) - .post('/users') + .post('/test-users') .expect('Content-Type', /json/) .expect(200) .send({email: 'bar@bat.com', password: 'bar'}) @@ -832,7 +843,7 @@ describe('User', function() { }); request(app) - .post('/users') + .post('/test-users') .expect('Content-Type', /json/) .expect(200) .send({email: 'bar@bat.com', password: 'bar'}) @@ -878,7 +889,7 @@ describe('User', function() { }); request(app) - .post('/users') + .post('/test-users') .expect('Content-Type', /json/) .expect(200) .send({email: 'bar@bat.com', password: 'bar'}) @@ -917,7 +928,7 @@ describe('User', function() { }); request(app) - .post('/users') + .post('/test-users') .expect('Content-Type', /json/) .expect(200) .send({email: 'bar@bat.com', password: 'bar'}) @@ -955,7 +966,7 @@ describe('User', function() { }); request(app) - .post('/users') + .post('/test-users') .expect('Content-Type', /json/) .expect(302) .send({email: 'bar@bat.com', password: 'bar'}) @@ -969,7 +980,7 @@ describe('User', function() { it('Confirm a user verification', function(done) { testConfirm(function(result, done) { request(app) - .get('/users/confirm?uid=' + (result.uid) + + .get('/test-users/confirm?uid=' + (result.uid) + '&token=' + encodeURIComponent(result.token) + '&redirect=' + encodeURIComponent(options.redirect)) .expect(302) @@ -985,7 +996,7 @@ describe('User', function() { it('Should report 302 when redirect url is set', function(done) { testConfirm(function(result, done) { request(app) - .get('/users/confirm?uid=' + (result.uid) + + .get('/test-users/confirm?uid=' + (result.uid) + '&token=' + encodeURIComponent(result.token) + '&redirect=http://foo.com/bar') .expect(302) @@ -997,7 +1008,7 @@ describe('User', function() { it('Should report 204 when redirect url is not set', function(done) { testConfirm(function(result, done) { request(app) - .get('/users/confirm?uid=' + (result.uid) + + .get('/test-users/confirm?uid=' + (result.uid) + '&token=' + encodeURIComponent(result.token)) .expect(204) .end(done); @@ -1007,7 +1018,7 @@ describe('User', function() { it('Report error for invalid user id during verification', function(done) { testConfirm(function(result, done) { request(app) - .get('/users/confirm?uid=' + (result.uid + '_invalid') + + .get('/test-users/confirm?uid=' + (result.uid + '_invalid') + '&token=' + encodeURIComponent(result.token) + '&redirect=' + encodeURIComponent(options.redirect)) .expect(404) @@ -1026,7 +1037,7 @@ describe('User', function() { it('Report error for invalid token during verification', function(done) { testConfirm(function(result, done) { request(app) - .get('/users/confirm?uid=' + result.uid + + .get('/test-users/confirm?uid=' + result.uid + '&token=' + encodeURIComponent(result.token) + '_invalid' + '&redirect=' + encodeURIComponent(options.redirect)) .expect(400) @@ -1081,7 +1092,7 @@ describe('User', function() { it('Password reset over REST rejected without email address', function(done) { request(app) - .post('/users/reset') + .post('/test-users/reset') .expect('Content-Type', /json/) .expect(400) .send({ }) @@ -1098,7 +1109,7 @@ describe('User', function() { it('Password reset over REST requires email address', function(done) { request(app) - .post('/users/reset') + .post('/test-users/reset') .expect('Content-Type', /json/) .expect(204) .send({ email: email })