|
| 1 | +package sc2 |
| 2 | + |
| 3 | +import ( |
| 4 | + "fmt" |
| 5 | + "net/http" |
| 6 | + "testing" |
| 7 | + "reflect" |
| 8 | +) |
| 9 | + |
| 10 | +const sc2ProfileResp = `{ "characters": |
| 11 | + [{ |
| 12 | + "id": 1234567, |
| 13 | + "realm": 1, |
| 14 | + "displayName": "foobar", |
| 15 | + "clanName": "foobar", |
| 16 | + "clanTag": "foobar", |
| 17 | + "profilePath": "/profile/1234567/1/foobar/", |
| 18 | + "portrait": { |
| 19 | + "x": -10, |
| 20 | + "y": -10, |
| 21 | + "w": 10, |
| 22 | + "h": 10, |
| 23 | + "offset": 10, |
| 24 | + "url": "http://media.blizzard.com/sc2/portraits/dummy.jpg" |
| 25 | + }, |
| 26 | + "career": { |
| 27 | + "primaryRace": "PROTOSS", |
| 28 | + "terranWins": 0, |
| 29 | + "protossWins": 0, |
| 30 | + "zergWins": 0, |
| 31 | + "highest1v1Rank": "DIAMOND", |
| 32 | + "seasonTotalGames": 0, |
| 33 | + "careerTotalGames": 100 |
| 34 | + }, |
| 35 | + "swarmLevels": { |
| 36 | + "level": 10, |
| 37 | + "terran": { |
| 38 | + "level": 1, |
| 39 | + "totalLevelXP": 1000, |
| 40 | + "currentLevelXP": 0 |
| 41 | + }, |
| 42 | + "zerg": { |
| 43 | + "level": 2, |
| 44 | + "totalLevelXP": 1000, |
| 45 | + "currentLevelXP": 0 |
| 46 | + }, |
| 47 | + "protoss": { |
| 48 | + "level": 3, |
| 49 | + "totalLevelXP": 1000, |
| 50 | + "currentLevelXP": 0 |
| 51 | + } |
| 52 | + }, |
| 53 | + "campaign": {}, |
| 54 | + "season": { |
| 55 | + "seasonId": 123, |
| 56 | + "seasonNumber": 1, |
| 57 | + "seasonYear": 2017, |
| 58 | + "totalGamesThisSeason": 0 |
| 59 | + }, |
| 60 | + "rewards": { |
| 61 | + "selected": [12345678, 12345678], |
| 62 | + "earned": [12345678, 12345678] |
| 63 | + }, |
| 64 | + "achievements": { |
| 65 | + "points": { |
| 66 | + "totalPoints": 1234, |
| 67 | + "categoryPoints": {} |
| 68 | + }, |
| 69 | + "achievements": [{ |
| 70 | + "achievementId": 123456789, |
| 71 | + "completionDate": 123456789 |
| 72 | + }] |
| 73 | + } |
| 74 | + }] |
| 75 | + }` |
| 76 | + |
| 77 | +func TestProfileService_Profile(t *testing.T) { |
| 78 | + setup() |
| 79 | + defer teardown() |
| 80 | + mux.HandleFunc("/sc2/1234567/1/foobar", func(w http.ResponseWriter, r *http.Request) { |
| 81 | + testMethod(t, r, "GET") |
| 82 | + fmt.Fprint(w, sc2ProfileResp) |
| 83 | + }) |
| 84 | + actual, _, err := client.Profile().Profile(1234567,1, "foobar" ) |
| 85 | + if err != nil { |
| 86 | + t.Fatalf("err: %s", err) |
| 87 | + } |
| 88 | + if actual.Characters == nil { |
| 89 | + t.Fatal("err: This user has no Starcraft 2 profile.") |
| 90 | + } |
| 91 | + want := SC2Character{ |
| 92 | + ID: 1234567, |
| 93 | + Realm: 1, |
| 94 | + DisplayName: "foobar", |
| 95 | + ClanName: "foobar", |
| 96 | + ClanTag: "foobar", |
| 97 | + ProfilePath: "/profile/1234567/1/foobar/", |
| 98 | + Portrait: CharacterImage{-10, -10, 10, 10, 10, |
| 99 | + "http://media.blizzard.com/sc2/portraits/dummy.jpg"}, |
| 100 | + Career: Career{"PROTOSS", 0, 0, 0, |
| 101 | + "DIAMOND", 0, 100}, |
| 102 | + SwarmLevels: SwarmLevels{10, |
| 103 | + Level{1, 1000, 0}, |
| 104 | + Level{2, 1000, 0}, |
| 105 | + Level{3, 1000, 0}}, |
| 106 | + Season: Season{123, 1, 2017, 0}, |
| 107 | + Rewards: Rewards{[]int{12345678, 12345678}, []int{12345678, 12345678}}, |
| 108 | + Achievements: Achievements{Points{1234}, |
| 109 | + []Achievement{Achievement{123456789, 123456789}}}, |
| 110 | + } |
| 111 | + if !reflect.DeepEqual(actual.Characters[0], want) { |
| 112 | + t.Fatalf("returned %+v, want %+v", actual.Characters[0], want) |
| 113 | + } |
| 114 | +} |
0 commit comments