Skip to content

Commit 54462a3

Browse files
committed
refactor(test): run tests in us region within ci
1 parent fa4de58 commit 54462a3

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
@@ -310,7 +310,6 @@ describe('Objects', function(){
310310

311311
var Person=AV.Object.extend("Person");
312312
var p;
313-
var posts=[];
314313

315314
it("should create a Person",function(){
316315
var Person = AV.Object.extend("Person");
@@ -320,13 +319,12 @@ describe('Objects', function(){
320319
});
321320

322321
it("should create many to many relations",function(){
323-
var query = new AV.Query(Person);
324-
return query.first().then(function(result){
325-
var p=result;
322+
return Promise.all([
323+
new AV.Query(Post).first(),
324+
new AV.Query(Person).first(),
325+
]).then(function([post, p]){
326326
var relation = p.relation("likes");
327-
for(var i=0;i<posts.length;i++){
328-
relation.add(posts[i]);
329-
}
327+
relation.add(post);
330328
p.set("pname","plike1");
331329
return p.save();
332330
}).then(function() {
@@ -375,6 +373,7 @@ describe('Objects', function(){
375373
});
376374
});
377375

376+
// 需要在控制台配置 Person company 默认值为 'leancloud'
378377
it("should fetch when save when creating new object.", function(){
379378
var p= new Person();
380379
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

@@ -168,35 +168,6 @@ describe("User", function() {
168168
});
169169
});
170170

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

0 commit comments

Comments
 (0)