diff --git a/.gitignore b/.gitignore index 7a1537b..9774f0c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .idea node_modules +server/datasources.local.json diff --git a/common/models/learningResource.js b/common/models/learningResource.js new file mode 100644 index 0000000..d6bad7f --- /dev/null +++ b/common/models/learningResource.js @@ -0,0 +1,2 @@ +module.exports = function(LearningResource) { +}; diff --git a/common/models/learningResource.json b/common/models/learningResource.json new file mode 100644 index 0000000..02a7595 --- /dev/null +++ b/common/models/learningResource.json @@ -0,0 +1,27 @@ +{ + "name": "learningResource", + "base": "PersistedModel", + "idInjection": true, + "properties": { + "title": { + "type": "string", + "required": true + }, + "resourceType": { + "type":"string", + "required": true + }, + "description": { + "type": "string", + "required": true + }, + "authors":{ + "type": "string", + "required": true + } +}, + "validations": [], + "relations": {}, + "acls": [], + "methods": [] +} diff --git a/package.json b/package.json index 38f1f8c..8fb7317 100644 --- a/package.json +++ b/package.json @@ -39,20 +39,21 @@ "loopback-explorer": "^1.1.0" }, "devDependencies": { + "casperjs": "^1.1.0-beta3", + "frisby": "^0.8.5", "gulp": "^3.8.10", - "jshint": "^2.5.6", - "strongloop": "^2.10.2", "gulp-develop-server": "^0.2.5", "gulp-jasmine": "^2.0.0", "gulp-jshint": "^1.9.0", "gulp-sequence": "^0.3.1", "gulp-util": "^3.0.2", + "jasmine-core": "^2.1.3", + "jasmine-jquery-matchers": "0.0.1", + "jshint": "^2.5.6", "karma": "^0.12.31", - "frisby": "git+https://github.com/vlucas/frisby.git", + "karma-browserify": "^2.0.0", "karma-chrome-launcher": "^0.1.7", "karma-jasmine": "^0.3.5", - "karma-browserify": "^2.0.0", - "jasmine-core": "^2.1.3", - "jasmine-jquery-matchers": "0.0.1" + "strongloop": "^2.10.2" } } diff --git a/server/datasources.json b/server/datasources.json index d6caf56..fd80320 100644 --- a/server/datasources.json +++ b/server/datasources.json @@ -2,5 +2,18 @@ "db": { "name": "db", "connector": "memory" + }, + "yes": { + "name": "yes", + "connector": "memory" + }, + "fullstack": { + "host": "localhost", + "port": 27017, + "database": "test", + "username": "tester", + "password": "tester", + "name": "fullstack", + "connector": "memory" } } diff --git a/server/model-config.json b/server/model-config.json index 6b39153..43c9f69 100644 --- a/server/model-config.json +++ b/server/model-config.json @@ -25,5 +25,9 @@ "Role": { "dataSource": "db", "public": false + }, + "learningResource": { + "dataSource": "fullstack", + "public": true } } diff --git a/spec/api/contact.spec.js b/spec/api/contact.spec.js new file mode 100644 index 0000000..10ac94a --- /dev/null +++ b/spec/api/contact.spec.js @@ -0,0 +1,3 @@ +/** + * Created by russia on 1/18/15. + */ diff --git a/spec/api/learningResource.spec.js b/spec/api/learningResource.spec.js new file mode 100644 index 0000000..481683c --- /dev/null +++ b/spec/api/learningResource.spec.js @@ -0,0 +1,89 @@ + + +/* jshint quotmark:false */ + +var frisby = require('frisby'); +var url = 'http://localhost:3000/api/learningResources/'; +var initialRecord = { + "title": "Javascript 101", + "resourceType": "Digital Textbook", + "description": "Interactive Textbook", + "authors": "John Doe" +}; + +var changedRecord = { + "title": "Mongo 101", + "resourceType": "Textbook", + "description": "Textbook", + "authors": "Jane Doe" +}; + +var badRecord = { + // empty record +}; + +//Create a record with Post +function postRecord() { + frisby.create('Create learningResource with post') + .post(url, initialRecord, {json: true}) + //{"title": "Javascript 101"},{json: true}) + .expectStatus(200) + .expectHeaderContains('Content-Type', 'application/json') + .expectJSON(initialRecord) + .afterJSON(function(json) { + getRecord(json.id); + }) + .toss(); +} + +// Read Record with Get +function getRecord(id) { + frisby.create('Get learningResource using id') + .get(url + id) + .expectStatus(200) + .expectJSON(initialRecord) + .afterJSON(function(json) { + putRecord(json.id); + }) + .toss(); +} + +// Update Record with Put +function putRecord(id){ + frisby.create('Put learningResource using id') + .put(url + id, changedRecord, {json: true}) + .expectStatus(200) + .expectJSON(changedRecord) + .toss(); +} + +// Test Validation +function postBadRecord(){ + frisby.create('Enforce mandatory fields when creating') + .post(url, badRecord, {json: true}) + .expectStatus(422) + .expectHeaderContains('Content-Type', 'application/json') + .expectJSON({ + error: { + name: 'ValidationError', + details: { + codes: { + title: [ + 'presence' + ], + resourceType: [ + 'presence' + ], + description: [ + 'presence' + ] + }}}}) + .toss(); +} + +// Post a record that will return an error + + +postRecord(); +postBadRecord(badRecord); +