-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathlearningResource.spec.js
More file actions
89 lines (76 loc) · 1.91 KB
/
Copy pathlearningResource.spec.js
File metadata and controls
89 lines (76 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/* 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);