-
Notifications
You must be signed in to change notification settings - Fork 1
/
leaderboard-vendor-spec.js
58 lines (46 loc) · 1.89 KB
/
leaderboard-vendor-spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
describe("stackoverflow", function(){
describe( "when calling SO API", function(){
it( "should return obejcts in the form we expect", function(){
$.ajax({
url: "http://api.stackoverflow.com/2.2/users/268618?site=stackoverflow&pagesize=100&page=1&order=desc&sort=reputation&jsonp=?",
dataType: "jsonp",
async: false,
success: function( resp ){
expect ( resp.users ).toBeDefined();
expect ( resp.users.length ).toEqual(1);
// we use 268618 as he doesn't have many medals
var user268618 = resp.users[0];
expect ( user268618 ).toBeDefined();
expect ( user268618.user_id ).toBeDefined();
expect ( user268618.reputation ).toBeDefined();
expect ( user268618.email_hash ).toBeDefined();
expect ( user268618.badge_counts ).toBeDefined();
expect ( user268618.badge_counts.gold ).toBeDefined();
expect ( user268618.badge_counts.silver ).toBeDefined();
expect ( user268618.badge_counts.bronze ).toBeDefined();
expect ( user268618.profile_image ).toBeDefined();
},
});
var example_so_user = {
"user_id": 1,
"display_name": "Jeff Atwood",
"reputation": 15160,
"email_hash": "51d623f33f8b83095db84ff35e15dbe",
"badge_counts": {
"gold": 21,
"silver": 65,
"bronze": 79
},
profile_image: "https://www.gravatar.com/avatar/df2385041c2449f404071930e98c9c28?s=128&d=identicon&r=PG",
"ANY_OTHER_CRAP": "IS_IGNORED"
}
var user = Leaderboard.convertSoUser(0, example_so_user);
expect( user.realname ).toEqual( "Jeff Atwood" );
expect( user.reputation ).toEqual( 15160 );
expect( user.scores.gold ).toEqual( 21 );
expect( user.scores.silver ).toEqual( 65 );
expect( user.scores.bronze ).toEqual( 79 );
expect( user.profileImage ).toEqual( "https://www.gravatar.com/avatar/df2385041c2449f404071930e98c9c28?s=128&d=identicon&r=PG" );
});
});
});