Skip to content

Commit 58b6bb3

Browse files
committed
refactor(test): run tests in us region within ci
1 parent bd5aee3 commit 58b6bb3

File tree

7 files changed

+30
-51
lines changed

7 files changed

+30
-51
lines changed

.travis.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,15 @@ node_js:
44
- "4"
55

66
sudo: false
7-
7+
env:
8+
global:
9+
- REGION=us
10+
- APPID=QvNM6AG2khJtBQo6WRMWqfLV-gzGzoHsz
11+
- APPKEY=be2YmUduiuEnCB2VR9bLRnnV
12+
- MASTERKEY=1AqFJWElESSui6JKqHiKnLTY
13+
- HOOKKEY=Y7RVPi20qOKQg4Lp8CyY35Lq
14+
- STATUS_TARGET_USER_ID=57d7b3c28a51a2004eb9b31d
15+
- FILE_ID=577258d732070000567dea7e
816
before_install:
917
- if [[ `npm -v` != 3* ]]; then npm i -g npm; fi
1018
install:

test/file.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ describe('File', function() {
124124
});
125125

126126
describe('#fetch', function() {
127-
var fileId = '52f9dd5ae4b019816c865985';
127+
const fileId = process.env.FILE_ID || '52f9dd5ae4b019816c865985';
128128
it('createWithoutData() should return a File', function() {
129129
var file = AV.File.createWithoutData(fileId);
130130
expect(file).to.be.a(AV.File);

test/object.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,6 @@ describe('Objects', function(){
462462

463463
var Person=AV.Object.extend("Person");
464464
var p;
465-
var posts=[];
466465

467466
it("should create a Person",function(){
468467
var Person = AV.Object.extend("Person");
@@ -472,13 +471,12 @@ describe('Objects', function(){
472471
});
473472

474473
it("should create many to many relations",function(){
475-
var query = new AV.Query(Person);
476-
return query.first().then(function(result){
477-
var p=result;
474+
return Promise.all([
475+
new AV.Query(Post).first(),
476+
new AV.Query(Person).first(),
477+
]).then(function([post, p]){
478478
var relation = p.relation("likes");
479-
for(var i=0;i<posts.length;i++){
480-
relation.add(posts[i]);
481-
}
479+
relation.add(post);
482480
p.set("pname","plike1");
483481
return p.save();
484482
}).then(function() {
@@ -527,6 +525,7 @@ describe('Objects', function(){
527525
});
528526
});
529527

528+
// 需要在控制台配置 Person company 默认值为 'leancloud'
530529
it("should fetch when save when creating new object.", function(){
531530
var p= new Person();
532531
p.set('pname', 'dennis');

test/query.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ describe('Queries', function () {
4545
});
4646

4747
it('#File Query', () => {
48-
const fileId = '52f9dd5ae4b019816c865985';
48+
const fileId = process.env.FILE_ID || '52f9dd5ae4b019816c865985';
4949
query = new AV.Query(AV.File);
5050
query.equalTo('objectId', fileId);
5151
return query.find().then(([file]) => {

test/status.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict';
22

33
describe("AV.Status",function(){
4+
var targetUser = process.env.STATUS_TARGET_USER_ID || '5627906060b22ef9c464cc99';
45
before(function() {
56
var userName = this.userName = 'StatusTest' + Date.now();
67
return AV.User.signUp(userName, userName).then(user => {
@@ -18,7 +19,7 @@ describe("AV.Status",function(){
1819

1920
it("should send private status to an user.",function(){
2021
var status = new AV.Status('image url', 'message');
21-
return AV.Status.sendPrivateStatus(status, '5627906060b22ef9c464cc99');
22+
return AV.Status.sendPrivateStatus(status, targetUser);
2223
});
2324

2425
it("should send status to a female user.",function(){
@@ -30,7 +31,7 @@ describe("AV.Status",function(){
3031
});
3132

3233
describe("Query statuses.", function(){
33-
const user = AV.Object.createWithoutData('_User', '5627906060b22ef9c464cc99');
34+
const user = AV.Object.createWithoutData('_User', targetUser);
3435
it("should return unread count.", function(){
3536
return AV.Status.countUnreadStatuses().then(function(response){
3637
expect(response.total).to.be.a('number');
@@ -62,9 +63,6 @@ describe("AV.Status",function(){
6263
});
6364

6465
describe("Status guide test.", function(){
65-
//follow 5627906060b22ef9c464cc99
66-
//unfolow 5627906060b22ef9c464cc99
67-
var targetUser = '5627906060b22ef9c464cc99';
6866
it("should follow/unfollow successfully.", function(){
6967
return AV.User.current().follow(targetUser).then(function(){
7068
var query = AV.User.current().followeeQuery();
@@ -73,7 +71,7 @@ describe("AV.Status",function(){
7371
}).then(function(followees){
7472
debug(followees);
7573
expect(followees.length).to.be(1);
76-
expect(followees[0].id).to.be('5627906060b22ef9c464cc99');
74+
expect(followees[0].id).to.be(targetUser);
7775
expect(followees[0].get('username')).to.be('leeyeh');
7876
return AV.User.current().unfollow(targetUser);
7977
}).then(function(){

test/test.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
'use strict';
22

3+
if (!process) process = { env: {}};
4+
35
if (typeof require !== 'undefined') {
46
global.debug = require('debug')('test');
57
global.expect = require('expect.js');
@@ -13,9 +15,10 @@ if (typeof require !== 'undefined') {
1315
// masterKey: 'l0n9wu3kwnrtf2cg1b6w2l87nphzpypgff6240d0lxui2mm4'
1416
// });
1517
AV.init({
16-
appId: '95TNUaOSUd8IpKNW0RSqSEOm-9Nh9j0Va',
17-
appKey: 'gNAE1iHowdQvV7cqpfCMGaGN',
18-
masterKey: 'ue9M9nqwD4MQNXD3oiN5rAOv',
19-
hookKey: '2iCbUZDgEF0siKxmCn2kVQXV'
18+
appId: process.env.APPID || '95TNUaOSUd8IpKNW0RSqSEOm-9Nh9j0Va',
19+
appKey: process.env.APPKEY || 'gNAE1iHowdQvV7cqpfCMGaGN',
20+
masterKey: process.env.MASTERKEY || 'ue9M9nqwD4MQNXD3oiN5rAOv',
21+
hookKey: process.env.HOOKKEY || '2iCbUZDgEF0siKxmCn2kVQXV',
22+
region: process.env.REGION || 'cn',
2023
});
2124
AV.setProduction(true);

test/user.js

Lines changed: 2 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ describe("User", function() {
122122
it("should return conditoinal users", function() {
123123
var query = new AV.Query(AV.User);
124124
query.equalTo("gender", "female"); // find all the women
125-
return query.find();
125+
return query.find({useMasterKey: true});
126126
});
127127
});
128128

@@ -170,35 +170,6 @@ describe("User", function() {
170170
});
171171
});
172172

173-
describe("Follow/unfollow users", function() {
174-
it("should follow/unfollow", function() {
175-
var user = AV.User.current();
176-
return user.follow('53fb0fd6e4b074a0f883f08a').then(function() {
177-
var query = user.followeeQuery();
178-
return query.find();
179-
}).then(function(results) {
180-
expect(results.length).to.be(1);
181-
debug(results);
182-
expect(results[0].id).to.be('53fb0fd6e4b074a0f883f08a');
183-
var followerQuery = AV.User.followerQuery('53fb0fd6e4b074a0f883f08a');
184-
return followerQuery.find();
185-
}).then(function(results) {
186-
expect(results.filter(function(result) {
187-
return result.id === user.id;
188-
})).not.to.be(0);
189-
debug(results);
190-
//unfollow
191-
return user.unfollow('53fb0fd6e4b074a0f883f08a');
192-
}).then(function() {
193-
//query should be emtpy
194-
var query = user.followeeQuery();
195-
return query.find();
196-
}).then(function(results) {
197-
expect(results.length).to.be(0);
198-
});
199-
});
200-
});
201-
202173
describe("User logInAnonymously", function() {
203174
it("should create anonymous user, and login with AV.User.signUpOrlogInWithAuthData()", function() {
204175
var getFixedId = function () {
@@ -227,7 +198,7 @@ describe("User", function() {
227198
return AV.User.logIn(username, password);
228199
}).then(function (loginedUser) {
229200
return AV.User.associateWithAuthData(loginedUser, 'weixin', {
230-
openid: 'aaabbbccc123123',
201+
openid: 'aaabbbccc123123'+username,
231202
access_token: 'a123123aaabbbbcccc',
232203
expires_in: 1382686496,
233204
});

0 commit comments

Comments
 (0)