Skip to content

Commit 272862f

Browse files
committed
Merge pull request #57 from aisk/fix-test
Fix test
2 parents e06b131 + e85931b commit 272862f

27 files changed

+1375
-1431
lines changed

gulpfile.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,10 @@ gulp.task('compress-docs', ['docs'], function() {
5454
.pipe(tar('js-sdk-api-docs-' + version + '.tar'))
5555
.pipe(gzip())
5656
.pipe(gulp.dest('dist'));
57-
})
58-
59-
AV = require('./lib/av').AV;
57+
});
6058

6159
gulp.task('test', function() {
62-
return gulp.src('tests/*.js', {read: false})
60+
return gulp.src('test/*.js', {read: false})
6361
.pipe(order([
6462
'test.js',
6563
'file.js',
@@ -76,7 +74,6 @@ gulp.task('test', function() {
7674
]))
7775
.pipe(mocha({
7876
timeout: 100000,
79-
globals: ['AV'],
8077
}));
8178
});
8279

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"qiniu": "6.1.3"
1313
},
1414
"devDependencies": {
15+
"debug": "^2.1.1",
1516
"expect.js ": "0.2.0",
1617
"gulp": "^3.8.10",
1718
"gulp-clean": "^0.3.1",

test/acl.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
var GameScore = AV.Object.extend("GameScore");
2+
describe("ObjectACL",function(){
3+
describe("*",function(){
4+
it("set * acl",function(done){
5+
var gameScore = new GameScore();
6+
gameScore.set("score", 2);
7+
gameScore.set("playerName", "sdf");
8+
gameScore.set("cheatMode", false);
9+
10+
var postACL = new AV.ACL();
11+
postACL.setPublicReadAccess(true);
12+
postACL.setPublicWriteAccess(true);
13+
14+
postACL.setReadAccess("546",true);
15+
postACL.setReadAccess("56238",true);
16+
postACL.setWriteAccess("5a061",true);
17+
postACL.setRoleWriteAccess("r6",true);
18+
gameScore.setACL(postACL);
19+
gameScore.save(null, {
20+
success: function(result) {
21+
expect(result.id).to.be.ok();
22+
23+
done();
24+
25+
},
26+
error: function(gameScore, error) {
27+
throw error;
28+
}
29+
});
30+
});
31+
});
32+
});

test/collection.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
var GameScore = AV.Object.extend("GameScore");
2+
var GameScoreCollection = AV.Collection.extend({
3+
model: GameScore
4+
});
5+
var collection;
6+
describe("Collection",function(){
7+
describe("#query",function(){
8+
it("should return collection",function(done){
9+
collection = new GameScoreCollection();
10+
11+
var query = new AV.Query(GameScore);
12+
13+
collection = query.collection();
14+
15+
collection.fetch({
16+
success: function(collection) {
17+
debug(collection);
18+
done();
19+
},
20+
error: function(collection, error) {
21+
throw error;
22+
// The collection could not be retrieved.
23+
}
24+
});
25+
});
26+
});
27+
28+
describe("Modify Collection",function(){
29+
it("add entity",function(done){
30+
collection = new GameScoreCollection();
31+
collection.add({
32+
"score":12,
33+
"playerName":"player2"
34+
});
35+
collection.reset([
36+
{"score": 12},
37+
{"playerName": "Jane"}
38+
]);
39+
done();
40+
});
41+
});
42+
});

test/error.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
var TestError = AV.Object.extend("TestError");
2+
describe("error",function(){
3+
4+
it("return error",function(done){
5+
var test = new TestError();
6+
test.set("num",1);
7+
test.save();
8+
var test1 = new TestError();
9+
test.set("num","s");
10+
test.save(null,{
11+
success:function(obj){
12+
debug(obj);
13+
done();
14+
},
15+
error:function(obj,err){
16+
debug(obj);
17+
debug(err);
18+
done();
19+
}
20+
}
21+
);
22+
});
23+
24+
});
File renamed without changes.

test/file.js

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
2+
describe("files", function() {
3+
describe("#Saving base64", function(){
4+
this.timeout(10000);
5+
it("should be saved", function(done){
6+
var base64 = "d29ya2luZyBhdCBhdm9zY2xvdWQgaXMgZ3JlYXQh";
7+
var file = new AV.File("myfile.txt", { base64: base64 });
8+
file.metaData('format', 'txt file');
9+
file.setACL(new AV.ACL());
10+
file.save().then(function(){
11+
// console.log(file.url());
12+
// console.log(file.id);
13+
expect(file.ownerId()).to.be.ok();
14+
expect(file.id).to.be.ok();
15+
expect(file.metaData('format')).to.be('txt file');
16+
file.destroy().then(function(){
17+
done();
18+
}, function(error){
19+
done(error);
20+
});
21+
}, function(error){
22+
done(error);
23+
});
24+
});
25+
});
26+
27+
describe("#Test withURL", function(){
28+
this.timeout(10000);
29+
it("should be saved", function(done){
30+
var url = "http://i1.wp.com/blog.avoscloud.com/wp-content/uploads/2014/05/screen568x568-1.jpg?resize=202%2C360";
31+
var file = AV.File.withURL('screen.jpg', url);
32+
file.save().then(function(){
33+
// console.log(file.url());
34+
// console.log(file.id);
35+
expect(file.ownerId()).to.be.ok();
36+
expect(file.id).to.be.ok();
37+
expect(file.metaData('__source')).to.be('external');
38+
done();
39+
}, function(error){
40+
done(error);
41+
});
42+
});
43+
});
44+
45+
describe("#Saving buffer in node.js", function(){
46+
it("should be saved", function(done){
47+
if(AV._isNode){
48+
var file = new AV.File('myfile.txt', new Buffer('hello world'));
49+
file.save().then(function(){
50+
// console.log("saved buffer...");
51+
// console.log(file.url());
52+
// console.log(file.id);
53+
// console.log(file.metaData());
54+
expect(file.size()).to.be(11);
55+
expect(file.ownerId()).to.be.ok();
56+
expect(file.id).to.be.ok();
57+
// console.log(file.thumbnailURL(200, 100));
58+
expect(file.thumbnailURL(200, 100)).to.be(file.url() + "?imageView/2/w/200/h/100/q/100/format/png");
59+
file.destroy().then(function(){
60+
done();
61+
}, function(error){
62+
done(error);
63+
});
64+
}, function(error){
65+
done(error);
66+
});
67+
}else{
68+
done();
69+
}
70+
});
71+
});
72+
describe("#Saving array", function(){
73+
it("should be saved", function(done){
74+
var bytes = [ 0xBE, 0xEF, 0xCA, 0xFE ];
75+
var file = new AV.File("myfile.txt", bytes);
76+
file.save().then(function(){
77+
// console.log(file.url());
78+
// console.log(file.id);
79+
// console.log(file.metaData());
80+
expect(file.size()).to.be(4);
81+
expect(file.ownerId()).to.be.ok();
82+
expect(file.id).to.be.ok();
83+
file.destroy().then(function(){
84+
done();
85+
}, function(error){
86+
done(error);
87+
});
88+
}, function(error){
89+
done(error);
90+
});
91+
});
92+
});
93+
describe("#Saving file with object", function(){
94+
it("should be saved", function(done){
95+
var bytes = [ 0xBE, 0xEF, 0xCA, 0xFE ];
96+
var file = new AV.File("myfile.txt", bytes);
97+
file.save().then(function(){
98+
// console.log(file.url());
99+
// console.log(file.id);
100+
var jobApplication = new AV.Object("JobApplication");
101+
jobApplication.set("applicantName", "Joe Smith");
102+
jobApplication.set("applicantResumeFile", file);
103+
jobApplication.save().then(function(result){
104+
expect(result.id).to.be.ok();
105+
var query = new AV.Query("JobApplication");
106+
query.get(result.id, {
107+
success: function(ja) {
108+
expect(ja.id).to.be.ok();
109+
var arf = ja.get("applicantResumeFile");
110+
// console.log(arf.metaData());
111+
expect(arf).to.be.ok();
112+
expect(arf.size()).to.be(4);
113+
expect(arf.ownerId()).to.be.ok();
114+
// console.log(ja.get("applicantResumeFile"));
115+
file.destroy().then(function(){
116+
done();
117+
}, function(error){
118+
done(error);
119+
});
120+
},
121+
error: function(object, error) {
122+
done(error);
123+
}
124+
});
125+
126+
}, function(obj, error){
127+
done(error);
128+
});
129+
}, function(error){
130+
done(error);
131+
});
132+
});
133+
});
134+
});

test/geopoints.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
var post;
2+
var Post = AV.Object.extend("Post");
3+
describe("Geopoints",function(){
4+
it("save object with geopoints",function(done){
5+
// Make a new post
6+
var user = AV.User.current();
7+
8+
post = new Post();
9+
post.set("title", "Post Geopoints");
10+
post.set("body", " Geopoints content.");
11+
post.set("user", user);
12+
13+
var point = new AV.GeoPoint({latitude: 40.0, longitude: -30.0});
14+
post.set("location",point);
15+
post.save(null, {
16+
success: function(post) {
17+
done();
18+
},
19+
error: function(err){
20+
throw err;
21+
}
22+
});
23+
24+
});
25+
});
26+
27+
describe("near",function(){
28+
it("",function(done){
29+
30+
var postGeoPoint = post.get("location");
31+
// Create a query for places
32+
var query = new AV.Query(Post);
33+
// Interested in locations near user.
34+
query.near("location", postGeoPoint);
35+
// Limit what could be a lot of points.
36+
query.limit(10);
37+
// Final list of objects
38+
query.find({
39+
success: function(placesObjects) {
40+
done();
41+
},
42+
err:function(err){
43+
throw err;
44+
}
45+
});
46+
});
47+
});

0 commit comments

Comments
 (0)