-
Notifications
You must be signed in to change notification settings - Fork 219
/
Copy pathQB-ContentSpec.js
126 lines (99 loc) · 3.52 KB
/
QB-ContentSpec.js
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
var fileId;
describe('Content API', function() {
'use strict';
var REST_REQUESTS_TIMEOUT = 3000;
var UPLOAD_TIMEOUT = 6000;
var isNodeEnv = typeof window === 'undefined' && typeof exports === 'object';
var QB = isNodeEnv ? require('../src/qbMain') : window.QB;
var CREDENTIALS = isNodeEnv ? require('./config').CREDS : window.CREDS;
var QBUser1 = isNodeEnv ? require('./config').QBUser1 : window.QBUser1;
var CONFIG = isNodeEnv ? require('./config').CONFIG : window.CONFIG;
var token,
data = {},
fileUID = '97f5802dcbd34a59a4921d73f6baedd000',
urlToBlobs = 'https://' + CONFIG.endpoints.api + '/blobs/';
beforeAll(function(done){
QB.init(CREDENTIALS.appId, CREDENTIALS.authKey, CREDENTIALS.authSecret, CREDENTIALS.accountKey, CONFIG);
QB.createSession(QBUser1, function(err, session) {
if (err) {
done.fail('Create session error: ' + JSON.stringify(err));
} else {
expect(session).not.toBeNull();
token = session.token;
done();
}
});
}, REST_REQUESTS_TIMEOUT);
it('can create and upload files', function(done) {
function upload(data){
QB.content.createAndUpload(data, function(err, res) {
if (err) {
done.fail('Create and upload files error: ' + JSON.stringify(err));
}else{
fileId = res.id;
expect(res).not.toBeNull();
expect(res.name).toBe(isNodeEnv ? "logo.png" : 'QB.txt');
done();
}
});
}
if(isNodeEnv){
var fs = require('fs');
var imgName = "logo.png";
var srcIMG = 'spec/' + imgName;
fs.stat(srcIMG, function (err, stats) {
fs.readFile(srcIMG, function (err, data) {
if (err) throw err;
var data = {name: imgName, file: data, type: "image/png", size: data.length, public: false};
upload(data);
});
});
}else{
var d = new Date(2015, 10, 13, 14, 30, 30, 600);
var genFile = new File(['Hello QuickBlox'], 'QB.txt', {type: 'text/plain', lastModified: d});
var data = {name: genFile.name, file: genFile, type: genFile.type, size: genFile.size, public: false};
upload(data);
}
}, UPLOAD_TIMEOUT);
it('can get file information by ID', function(done) {
QB.content.getInfo(fileId, function(err, res) {
if (err) {
done.fail("Get file information by ID error: " + JSON.stringify(err));
}else{
expect(res).not.toBeNull();
expect(res.blob.id).toEqual(fileId);
done();
}
});
}, REST_REQUESTS_TIMEOUT);
it('can list content objects', function(done) {
QB.content.list(function(err, res) {
if (err) {
done.fail("List content objects error: " + JSON.stringify(err));
}else{
expect(res).not.toBeNull();
expect(res.items.length).toBeGreaterThan(0);
done();
}
});
}, REST_REQUESTS_TIMEOUT);
it('can delete content objects', function(done) {
QB.content.delete(fileId, function(err, result) {
if (err) {
done.fail('Delete content objects error: ' + JSON.stringify(err));
}else{
expect(result).toEqual(true);
done();
}
});
}, REST_REQUESTS_TIMEOUT);
it('can access public URL', function() {
var publicUrl = QB.content.publicUrl(fileUID);
expect(publicUrl).toEqual(urlToBlobs + fileUID);
});
it('can access private URL', function() {
var privateURL = QB.content.privateUrl(fileUID);
var url = urlToBlobs + fileUID + '?token=';
expect(privateURL).toBe(url + token);
});
});