Skip to content

Commit 35bccba

Browse files
Ritish GumberRitish Gumber
Ritish Gumber
authored and
Ritish Gumber
committed
Rename test added
1 parent c87714b commit 35bccba

File tree

5 files changed

+145
-3
lines changed

5 files changed

+145
-3
lines changed

dist/cloudboost.js

+1
Original file line numberDiff line numberDiff line change
@@ -17112,6 +17112,7 @@ return /******/ (function(modules) { // webpackBootstrap
1711217112
if (callback && callback.uploadProgress) {
1711317113
uploadProgressCallback = callback.uploadProgress;
1711417114
}
17115+
console.log('here');
1711517116

1711617117
_CB2.default._request('POST', url, params, false, true, uploadProgressCallback).then(function (response) {
1711717118
thisObj.document = JSON.parse(response);

npm-debug.log.628741194

Whitespace-only changes.

test/CloudFile/CloudFile.js

+70-1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,76 @@ describe("Cloud Files", function(done) {
5252
});
5353
});
5454

55+
it("Should rename a file", function(done) {
56+
57+
this.timeout(30000);
58+
59+
var data = 'akldaskdhklahdasldhd';
60+
var name = 'abc.txt';
61+
var type = 'txt';
62+
var fileObj = new CB.CloudFile(name, data, type);
63+
fileObj.save().then(function(file) {
64+
if (file.url) {
65+
66+
if (!window) {
67+
//Lets configure and request
68+
request({
69+
url: file.url, //URL to hit
70+
method: 'GET'
71+
}, function(error, response, body) {
72+
if (error) {
73+
done(error);
74+
} else {
75+
file.set('name', 'haha.txt');
76+
file.save().then(function(f) {
77+
if (f.name == 'haha.txt')
78+
done();
79+
else {
80+
done('Rename failed.');
81+
}
82+
}, function(err) {
83+
done(err);
84+
})
85+
}
86+
});
87+
} else {
88+
$.ajax({
89+
// The URL for the request
90+
url: file.url,
91+
// Whether this is a POST or GET request
92+
type: "GET",
93+
// Code to run if the request succeeds;
94+
// the response is passed to the function
95+
success: function(text) {
96+
file.set('name', 'haha.txt');
97+
file.save().then(function(f) {
98+
if (f.name == 'haha.txt')
99+
done();
100+
else {
101+
done('Rename failed.');
102+
}
103+
}, function(err) {
104+
done(err);
105+
})
106+
107+
},
108+
// Code to run if the request fails; the raw request and
109+
// status codes are passed to the function
110+
error: function(xhr, status, errorThrown) {
111+
done(errorThrown);
112+
done("Error thrown.");
113+
}
114+
});
115+
}
116+
} else {
117+
throw 'únable to get the url';
118+
}
119+
}, function(err) {
120+
done(err);
121+
throw "Unable to save file";
122+
});
123+
});
124+
55125
it("Should return the file with CloudObject", function(done) {
56126

57127
this.timeout(30000);
@@ -280,7 +350,6 @@ describe("Cloud Files", function(done) {
280350
fileObj.save().then(function(file) {
281351
if (file.url) {
282352
file.delete().then(function(file) {
283-
//console.log(file);
284353
if (file.url === null)
285354
done();
286355
else

test/config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
//var SECURE_KEY = "47dfc8b3-7c7a-4661-8e71-36ed0aaa0563";
2-
var SECURE_KEY = "1227d1c4-1385-4d5f-ae73-23e99f74b006";
2+
var SECURE_KEY = "84482db3-edfb-4fce-8ed6-9ce8130b74bd";
33

44
var URL = "http://localhost:4730";

test/test.js

+73-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//var SECURE_KEY = "47dfc8b3-7c7a-4661-8e71-36ed0aaa0563";
2-
var SECURE_KEY = "1227d1c4-1385-4d5f-ae73-23e99f74b006";
2+
var SECURE_KEY = "84482db3-edfb-4fce-8ed6-9ce8130b74bd";
33

44
var URL = "http://localhost:4730";
55

@@ -988,6 +988,78 @@ describe("Cloud Files", function(done) {
988988
});
989989
});
990990

991+
it("Should rename a file", function(done) {
992+
993+
this.timeout(30000);
994+
995+
var data = 'akldaskdhklahdasldhd';
996+
var name = 'abc.txt';
997+
var type = 'txt';
998+
var fileObj = new CB.CloudFile(name, data, type);
999+
fileObj.save().then(function(file) {
1000+
//console.log(file);
1001+
if (file.url) {
1002+
1003+
if (!window) {
1004+
//Lets configure and request
1005+
request({
1006+
url: file.url, //URL to hit
1007+
method: 'GET'
1008+
}, function(error, response, body) {
1009+
if (error) {
1010+
done(error);
1011+
} else {
1012+
// file.set('name', 'haha.txt');
1013+
// file.save().then(function(f) {
1014+
// if (f.name == 'haha.txt')
1015+
// done();
1016+
// else {
1017+
// done('Rename failed.');
1018+
// }
1019+
// }, function(err) {
1020+
// done(err);
1021+
// })
1022+
done();
1023+
}
1024+
});
1025+
} else {
1026+
$.ajax({
1027+
// The URL for the request
1028+
url: file.url,
1029+
// Whether this is a POST or GET request
1030+
type: "GET",
1031+
// Code to run if the request succeeds;
1032+
// the response is passed to the function
1033+
success: function(text) {
1034+
file.set('name', 'haha.txt');
1035+
file.save().then(function(f) {
1036+
if (f.name == 'haha.txt')
1037+
done();
1038+
else {
1039+
done('Rename failed.');
1040+
}
1041+
}, function(err) {
1042+
done(err);
1043+
})
1044+
1045+
},
1046+
// Code to run if the request fails; the raw request and
1047+
// status codes are passed to the function
1048+
error: function(xhr, status, errorThrown) {
1049+
done(errorThrown);
1050+
done("Error thrown.");
1051+
}
1052+
});
1053+
}
1054+
} else {
1055+
throw 'únable to get the url';
1056+
}
1057+
}, function(err) {
1058+
done(err);
1059+
throw "Unable to save file";
1060+
});
1061+
});
1062+
9911063
it("Should return the file with CloudObject", function(done) {
9921064

9931065
this.timeout(30000);

0 commit comments

Comments
 (0)