-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpatch_clyp_spec.js
More file actions
152 lines (134 loc) · 3.97 KB
/
patch_clyp_spec.js
File metadata and controls
152 lines (134 loc) · 3.97 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
// Node Dependencies
var frisby = require('./node_modules/frisby');
var fs = require('fs');
var path = require('path');
var FormData = require('form-data');
var form = new FormData();
// Testing Variables
var options = require('./options').create();
var POST_URL= options.uploadResource;
var API_URL = options.apiUrl;
var filePath = path.resolve(__dirname, 'register.mp3');
var title = 'PATCH Title- Start';
var description = 'PATCH Description - Start';
var longitude = -97;
var latitude = 30;
var playlistID;
var playlistUploadToken;
var tmpID;
var audioFileID;
var initialJSON;
var newDescription = 'PATCH Description - End';
var newTitle = 'PATCH Title- End';
/* Create Empty Playlist - Get tmpID Cookie */
frisby.create('PATCH Test - Create Empty Playlist')
.post(API_URL + 'playlist/')
.expectStatus(200)
// .inspectJSON()
.after(function(err, res, body) {
var setCookie = res.headers['set-cookie'];
tmpID = setCookie[0].split(';')[0];
//console.log(tmpID);
})
.afterJSON(post)
.toss();
/* Initial Upload */
function post(json) {
playlistID = json.PlaylistId;
playlistUploadToken = json.PlaylistUploadToken;
// console.log(playlistUploadToken);
// URL Parameters
form.append('audioFile', fs.createReadStream(filePath), {
knownLength: fs.statSync(filePath).size // we need to set the knownLength so we can call form.getLengthSync()
});
form.append('description', description);
form.append('title', title);
form.append('PlaylistId', playlistID);
form.append('PlaylistUploadToken', playlistUploadToken);
frisby.create('PATCH Test - Initial Upload')
.post(POST_URL,
form,
{
json: false,
headers: {
// Add headers for POSTing Audio
'content-type': 'multipart/form-data; boundary=' + form.getBoundary(),
'content-length': form.getLengthSync()
}
})
.expectStatus(200)
.expectJSONTypes({
Successful: Boolean,
Description: String,
Title: String
})
.expectJSON({
// Assert that all the fields we passed in were correctly returned
Successful: true,
Description: description,
Title: title
})
//.inspectJSON() // Prints out response to console
.afterJSON(patchTest)
.toss();
};
/* End Initial Upload */
/* PATCH Test 1- Change Title and Description of previously uploaded file using tmpID cookie */
function patchTest(json) {
// console.log("");
initialJSON = json;
audioFileID = initialJSON.AudioFileId;
frisby.create('PATCH Test 1 - Change Title And Description')
.addHeader('Cookie', tmpID)
.patch(options.getAudioFileResource(audioFileID), {
description: newDescription,
title: newTitle
}, {json: true})
.expectStatus(200)
.expectJSONTypes({
Status: String,
Description: String,
Title: String
})
.expectJSON({
// Assert that all the fields we passed in were correctly returned
Status: 'DownloadDisabled',
Description: newDescription,
Title: newTitle
})
// .inspectJSON()
.afterJSON(patchStatusTest)
.toss();
};
/* End Patch Test 1 */
/* PATCH Test 2- Try to Change Status - Should 401 since we are not authorized */
function patchStatusTest(json) {
// console.log("");
var newStatus = 'Deleted';
frisby.create('PATCH Test 2 - Change Status')
.addHeader('Cookie', tmpID)
.patch(options.getAudioFileResource(audioFileID), {
status: newStatus
}, {json: true})
.expectStatus(401)
.after(patchAllTest)
.toss();
};
/* End Patch Test 2 */
/* PATCH Test 3- Try to Change Status, Title, and Description- Should 401 since we are not authorized */
function patchAllTest() {
console.log("");
newDescription = 'PATCH Description - Status Change';
newTitle = 'PATCH Title - Status Change';
var newStatus = 'Deleted';
frisby.create('PATCH Test 3 - Change Status, Title, and Description')
.addHeader('Cookie', tmpID)
.patch(options.getAudioFileResource(audioFileID), {
status: newStatus,
description: newDescription,
title: newTitle
}, {json: true})
.expectStatus(401)
.toss();
};
/* End Patch Test 3 */