Skip to content

Commit 82709fa

Browse files
committed
Merge remote-tracking branch 'origin/master' into split-file
2 parents 75f7a25 + 272862f commit 82709fa

27 files changed

+1397
-1426
lines changed

gulpfile.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@ var gulp = require('gulp');
33
var clean = require('gulp-clean');
44
var concat = require("gulp-concat");
55
var gzip = require('gulp-gzip');
6+
var mocha = require('gulp-mocha');
67
var jsdoc = require("gulp-jsdoc");
78
var order = require("gulp-order");
89
var rename = require('gulp-rename');
910
var shell = require('gulp-shell');
1011
var tar = require('gulp-tar');
1112
var uglify = require('gulp-uglify');
13+
var order = require('gulp-order');
1214

1315
getAVVersion = function() {
1416
return require('./lib/AV.js').AV.VERSION.replace('js', '');
@@ -83,6 +85,27 @@ gulp.task('compress-docs', ['docs'], function() {
8385
.pipe(gulp.dest('dist'));
8486
});
8587

88+
gulp.task('test', function() {
89+
return gulp.src('test/*.js', {read: false})
90+
.pipe(order([
91+
'test.js',
92+
'file.js',
93+
'error.js',
94+
'object.js',
95+
'collection.js',
96+
'user.js',
97+
'query.js',
98+
'geopoint.js',
99+
'acl.js',
100+
'master_key.js',
101+
'status.js',
102+
'sms.js',
103+
]))
104+
.pipe(mocha({
105+
timeout: 100000,
106+
}));
107+
});
108+
86109
gulp.task('clean', function() {
87110
gulp.src(['dist/'])
88111
.pipe(clean({force: true}));

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@
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",
1819
"gulp-concat": "^2.4.3",
1920
"gulp-gzip": "0.0.8",
2021
"gulp-jsdoc": "^0.1.4",
22+
"gulp-mocha": "^2.0.0",
2123
"gulp-order": "^1.1.1",
2224
"gulp-rename": "^1.2.0",
2325
"gulp-shell": "^0.2.11",

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)