-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsoundwave_clyp_spec.js
More file actions
102 lines (91 loc) · 2.7 KB
/
soundwave_clyp_spec.js
File metadata and controls
102 lines (91 loc) · 2.7 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
// 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, 'gun.mp3');
var title = 'Gun Soundwave';
var description = 'Soundwave Test';
var AudioFileId;
var firstArray;
var secondArray;
//
//////// 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);
/////////////////////////////////
// Test #1 - POST Audio to Clyp.it upload staging
frisby.create('Soundwave 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
})
.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(test2) // If Test #1 Passed, run Test #2 with JSON response from Test #1
.toss();
/* End Test #1 */
// Test #2 - GET Soundwave of POSTed file from apistaging
function test2(json) {
AudioFileId = json.AudioFileId;
frisby.create('Soundwave Test 2: GET Soundwave of POSTed file from from apistaging')
.get(options.getAudioFileResource(AudioFileId) + '/soundwave')
// .inspectJSON()
.afterJSON(function(json) {
firstArray = json;
expect(firstArray.length).toBe(4000);
for(i = 0; i < firstArray.length; i++) {
x = firstArray[i];
expect(x >= 0 && x <= 99).toBe(true);
}
test3();
// console.log(json.length);
})
.toss();
}
// Test #3 - GET Soundwave of POSTed file from soundwavedev
function test3() {
frisby.create('Soundwave Test 3: GET Soundwave of POSTed file from soundwavedev')
.get('https://soundwavedev.clyp.it/' + AudioFileId)
// .inspectJSON()
.afterJSON(function(json) {
secondArray = json;
expect(json.length).toBe(4000);
for(i = 0; i < json.length; i++) {
x = json[i];
expect(x >= 0 && x <= 99).toBe(true);
}
test4();
})
.toss();
}
// // Test #4 - Assert that both soundwaves are the same
function test4() {
for(i = 0; i < 4000; i++) {
expect(firstArray[i] === secondArray[i]).toBe(true);
}
}