Skip to content

Commit 3467394

Browse files
committed
Test Modules: Update testing of module properties, fix error response in Github
1 parent 8803dc7 commit 3467394

File tree

3 files changed

+39
-44
lines changed

3 files changed

+39
-44
lines changed

src/modules/github.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ function formatError(o,code){
88
if( (code===401||code===403) ){
99
o.error = {
1010
code : "access_denied",
11-
message : o.message
11+
message : o.message || (o.data?o.data.message:"Could not get response")
1212
};
1313
delete o.message;
1414
}

tests/karma.conf.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ module.exports = function (karma) {
1818

1919
// list of files to exclude
2020
exclude: [
21-
'karma.conf.js'
21+
'karma.conf.js',
22+
'../src/temp/*.js'
2223
],
2324

2425

tests/test-modules.js

+36-42
Original file line numberDiff line numberDiff line change
@@ -3,65 +3,59 @@
33
//
44
// Modules are of the following formats
55
//
6-
describe('Modules all', function(){
76

8-
var MATCH_URL = /^https?\:\/\//;
7+
// Loop through all services
8+
for(var name in hello.services){
9+
setup_module_tests(hello.services[name], name);
10+
}
911

10-
it('contain oauth or url.auth paths', function(){
12+
function setup_module_tests(module, name){
1113

12-
// Loop through all services
13-
for(var name in hello.services){
14-
var path = hello.services[name].oauth.auth;
14+
describe( module.name || name + ' Module', function(){
15+
16+
var MATCH_URL = /^https?\:\/\//;
17+
18+
it('contain oauth.auth path', function(){
19+
var path = module.oauth.auth;
1520
expect( path ).to.match( /^https?\:\/\// );
16-
}
17-
});
21+
});
22+
23+
it('specify a base url', function(){
24+
// Loop through all services
25+
expect( module.base ).to.match( /^https?\:\/\// );
26+
});
1827

1928

20-
it('using OAuth1 contain, auth, request, token properties', function(){
29+
it('using OAuth1 contain, auth, request, token properties', function(){
2130

22-
// Loop through all services
23-
for(var name in hello.services){
24-
var oauth = hello.services[name].oauth;
31+
// Loop through all services
32+
var oauth = module.oauth;
2533
if(oauth && parseInt(oauth.version,10) === 1 ){
2634
expect( oauth.auth ).to.match( MATCH_URL );
2735
expect( oauth.token ).to.match( MATCH_URL );
2836
expect( oauth.request ).to.match( MATCH_URL );
2937
}
30-
}
31-
});
32-
33-
it('return error object when an api request is made with an unverified user', function(done){
34-
35-
this.timeout(60000);
36-
37-
var i=0;
38+
});
3839

39-
function contains_error_callback(data){
40+
it('return error object when an api request is made with an unverified user', function(done){
4041

41-
expect(data).to.be.a("object");
42-
expect(data).to.have.property("error");
43-
expect(data.error).to.have.property("code");
44-
expect(data.error).to.have.property("message");
45-
expect(data.error.code).to.not.be.an("object");
46-
expect(data.error.message).to.not.be.an("object");
47-
48-
if(--i <= 0){
49-
done();
50-
}
51-
}
52-
53-
// Loop through all services
54-
for(var name in hello.services){
55-
// i++
56-
i++;
42+
this.timeout(60000);
5743

5844
// ensure user is signed out
5945
hello.logout(name);
6046

6147
// Make a request that returns an error object
62-
hello(name).api('me', contains_error_callback);
63-
}
64-
});
65-
/**/
48+
hello(name).api('me', function(data){
49+
expect(data).to.be.a("object");
50+
expect(data).to.have.property("error");
51+
expect(data.error).to.have.property("code");
52+
expect(data.error).to.have.property("message");
53+
expect(data.error.code).to.not.be.an("object");
54+
expect(data.error.message).to.not.be.an("object");
55+
done();
56+
});
57+
});
58+
/**/
6659

67-
});
60+
});
61+
}

0 commit comments

Comments
 (0)