Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.idea
node_modules
server/datasources.local.json
2 changes: 2 additions & 0 deletions common/models/learningResource.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module.exports = function(LearningResource) {
};
27 changes: 27 additions & 0 deletions common/models/learningResource.json
Original file line number Diff line number Diff line change
@@ -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": []
}
13 changes: 7 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
13 changes: 13 additions & 0 deletions server/datasources.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
4 changes: 4 additions & 0 deletions server/model-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,9 @@
"Role": {
"dataSource": "db",
"public": false
},
"learningResource": {
"dataSource": "fullstack",
"public": true
}
}
3 changes: 3 additions & 0 deletions spec/api/contact.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/**
* Created by russia on 1/18/15.
*/
89 changes: 89 additions & 0 deletions spec/api/learningResource.spec.js
Original file line number Diff line number Diff line change
@@ -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);