-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPTG_clyp_spec.js
More file actions
212 lines (187 loc) · 6.06 KB
/
PTG_clyp_spec.js
File metadata and controls
212 lines (187 loc) · 6.06 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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
// PTG - POST, Then Get
// CLYP API Test to assure that uploading and retrieving files works correctly
// 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 filePath = path.resolve(__dirname, 'register.mp3');
var title = 'Register';
var description = 'POST Test';
var longitude = -97;
var latitude = 30;
var testTwoJson;
//
//////// Test #1 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('longitude', longitude);
form.append('latitude', latitude);
/////////////////////////////////
// Test #1 - POST Audio to Clyp.it upload staging
frisby.create('PTG Test 1: POST Audio to Clyp.it upload staging')
.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,
Longitude: Number,
Latitude: Number,
PlaylistId: String,
PlaylistUploadToken: String
})
.expectJSON({
// Assert that all the fields we passed in were correctly returned
Successful: true,
Description: description,
Title: title,
Longitude: longitude,
Latitude: latitude
})
//.inspectJSON() // Prints out response to console
.afterJSON(test2) // If Test #1 Passed, run Test #2 with JSON response from Test #1
.toss();
/* End Test #1 */
//Test #2 - POST Audio to Playlist created by Test #1
function test2(json) {
// First Test Passed, Retrieve PlaylistId and Token and Save JSON for Test #4
var playlistID = json.PlaylistId;
var playlistUploadToken = json.PlaylistUploadToken;
testTwoJson = json;
// Set variables for new test
form = new FormData(); // Wipe Multi-Part Form-Data clean
filePath = path.resolve(__dirname, 'gun.mp3');
title = 'gun';
description = 'MP5 Sub-Machinegun Noise';
// New 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('title', title);
form.append('description', description);
form.append('PlaylistId', playlistID);
form.append('PlaylistUploadToken', playlistUploadToken);
form.append('longitude', longitude);
form.append('latitude', latitude);
frisby.create('PTG Test 2: Add new audio file to playlist we created')
.post(POST_URL,
form,
{
json: false,
headers: {
// Add headers for POSTing Audio
'content-type': 'multipart/form-data; boundary=' + form.getBoundary(),
'content-length': form.getLengthSync()
}
})
//.inspectJSON()
.expectStatus(200)
.expectJSONTypes({
Successful: Boolean,
Title: String,
Description: String,
Longitude: Number,
Latitude: Number,
PlaylistId: String,
PlaylistUploadToken: String
})
.expectJSON({
Successful: true,
Title: title,
Description: description,
Longitude: longitude,
Latitude: latitude,
PlaylistId: playlistID, // Make sure the playlistID that is returned is the same as in Test #1
PlaylistUploadToken: playlistUploadToken
})
.afterJSON(test3)
.toss();
};
/* End Test #2 */
// Test #3 - GET JSON By Passing in AudioFileID from Test #2
function test3(json) {
var test3AudioFileID = json.AudioFileId;
frisby.create('PTG Test 3: GET Previous Upload')
.get(options.getAudioFileResource(test3AudioFileID))
.expectStatus(200)
.expectJSONTypes({
Status: String,
AudioFileId: String,
Title: String,
Description: String,
Duration: Number,
Url: String,
Mp3Url: String,
SecureMp3Url: String,
OggUrl: String,
SecureOggUrl: String,
})
.expectJSON({
// Make sure all fields match the response from the previous POST
Status: 'DownloadDisabled',
AudioFileId: test3AudioFileID,
Title: json.title,
Description: json.description,
Duration: json.duration,
Url: json.Url,
Mp3Url: json.Mp3Url,
SecureMp3Url: json.SecureMp3Url,
OggUrl: json.OggUrl,
SecureOggUrl: json.SecureOggUrl,
})
//.inspectJSON()
.afterJSON(test4)
.toss();
};
/* End Test #3 */
// Test #4 - GET Playlist JSON By Passing in AudioFileID
function test4(json) {
frisby.create('PTG Test 4: GET Playlist')
.get(options.getAudioFileResource(json.AudioFileId) + '/playlist')
.expectStatus(200)
.expectJSON({
AudioFiles:
[ { Status: 'DownloadDisabled', // testTwoJson is the saved data that test 2 returned
AudioFileId: testTwoJson.AudioFileId,
Title: testTwoJson.title,
Description: testTwoJson.description,
Duration: testTwoJson.duration,
Url: testTwoJson.Url,
Mp3Url: testTwoJson.Mp3Url,
SecureMp3Url: testTwoJson.SecureMp3Url,
OggUrl: testTwoJson.OggUrl,
SecureOggUrl: testTwoJson.SecureOggUrl },
{ Status: 'DownloadDisabled', // This JSON is what test 3 returned
AudioFileId: json.AudioFileId,
Title: json.title,
Description: json.description,
Duration: json.duration,
Url: json.Url,
Mp3Url: json.Mp3Url,
SecureMp3Url: json.SecureMp3Url,
OggUrl: json.OggUrl,
SecureOggUrl: json.SecureOggUrl } ],
Modifiable: false,
ContentAdministrator: false
})
//.inspectJSON()
.toss();
};
/* End Test #4 */