Skip to content

Commit

Permalink
fix(typing): Fix region typing & DDragon tests (#425)
Browse files Browse the repository at this point in the history
* fix(typing): Fix regional typings & ddragon tests

* test(ddragon): Updated DDragon tests
  • Loading branch information
OllieJennings authored Apr 27, 2023
1 parent c6f39d3 commit 558fc28
Show file tree
Hide file tree
Showing 7 changed files with 117 additions and 31 deletions.
62 changes: 61 additions & 1 deletion __tests__/e2e/ddragon.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DDragon, RiotAPI } from "../../src/index";
import { DDragon, RiotAPI, RiotAPITypes } from "../../src/index";

describe("E2E", () => {
describe("DDragon", () => {
Expand All @@ -9,9 +9,39 @@ describe("E2E", () => {
const aatrox = await ddragon.champion.byName({
championName: "Aatrox",
});

const aatroxImage: RiotAPITypes.DDragon.DDragonImageDTO = {
full: "Aatrox.png",
sprite: "champion0.png",
group: "champion",
x: 0,
y: 0,
w: 48,
h: 48,
};

expect(aatrox.type).toEqual("champion");
expect(aatrox.format).toEqual("standAloneComplex");
expect(aatrox.data.Aatrox.id).toEqual("Aatrox");
expect(aatrox.data.Aatrox.image).toEqual(aatroxImage);
});

test("profileIcons", async () => {
const ddragon = new DDragon();
const profileIcons = await ddragon.profileIcons();
const profilIcon: RiotAPITypes.DDragon.DDragonImageWrapperDTO = {
id: 1000,
image: {
full: "1000.png",
sprite: "profileicon0.png",
group: "profileicon",
x: 96,
y: 0,
w: 48,
h: 48,
},
};
expect(profileIcons.data["1000"]).toEqual(profilIcon);
});
});
});
Expand All @@ -24,9 +54,39 @@ describe("E2E", () => {
const aatrox = await rAPI.ddragon.champion.byName({
championName: "Aatrox",
});

const aatroxImage: RiotAPITypes.DDragon.DDragonImageDTO = {
full: "Aatrox.png",
sprite: "champion0.png",
group: "champion",
x: 0,
y: 0,
w: 48,
h: 48,
};

expect(aatrox.type).toEqual("champion");
expect(aatrox.format).toEqual("standAloneComplex");
expect(aatrox.data.Aatrox.id).toEqual("Aatrox");
expect(aatrox.data.Aatrox.image).toEqual(aatroxImage);
});

test("profileIcons", async () => {
const rAPI = new RiotAPI("XXXX");
const profileIcons = await rAPI.ddragon.profileIcons();
const profilIcon: RiotAPITypes.DDragon.DDragonImageWrapperDTO = {
id: 1000,
image: {
full: "1000.png",
sprite: "profileicon0.png",
group: "profileicon",
x: 96,
y: 0,
w: 48,
h: 48,
},
};
expect(profileIcons.data["1000"]).toEqual(profilIcon);
});
});
});
Expand Down
8 changes: 4 additions & 4 deletions __tests__/unit/ddragon.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ describe("DDragon", () => {
jest.clearAllMocks();
});

const getKeyValue =
<T extends object, U extends keyof T>(obj: T) =>
(key: U) =>
obj[key];
// const getKeyValue =
// <T extends object, U extends keyof T>(obj: T) =>
// (key: U) =>
// obj[key];

const mockedFetch = jest.mocked(fetch);

Expand Down
4 changes: 2 additions & 2 deletions __tests__/unit/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1285,15 +1285,15 @@ describe("RiotAPI", () => {
{
region: PlatformId.EUROPE,
puuid: "1",
params: { count: 10 },
params: { count: 10, start: 10, endTime: 131311, startTime: 1111 },
},
[
PlatformId.EUROPE,
RiotAPITypes.METHOD_KEY.TFT_MATCH.GET_MATCH_IDS_BY_PUUID,
{ puuid: "1" },
{
id: "europe.tftMatch.getMatchIdsByPUUID.1",
params: { count: 10 },
params: { count: 10, start: 10, endTime: 131311, startTime: 1111 },
},
],
],
Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
},
"homepage": "https://github.com/fightmegg/riot-api#readme",
"dependencies": {
"@fightmegg/riot-rate-limiter": "0.0.16",
"@fightmegg/riot-rate-limiter": "0.0.18",
"debug": "^4.3.4",
"ioredis": "^5.3.2",
"node-fetch": "^2.6.1",
Expand Down
20 changes: 17 additions & 3 deletions src/@types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,17 @@ export namespace RiotAPITypes {
| PlatformId.EU
| PlatformId.KR
| PlatformId.LATAM
| PlatformId.NA;
| PlatformId.NA
| PlatformId.ESPORTS;

export type LORCluster =
| PlatformId.AMERICAS
| PlatformId.ASIA
| PlatformId.EUROPE
| PlatformId.SEA
| PlatformId.APAC;

export type TFTCluster =
| PlatformId.AMERICAS
| PlatformId.ASIA
| PlatformId.EUROPE
Expand All @@ -86,7 +94,8 @@ export namespace RiotAPITypes {
| PlatformId.EUROPE
| PlatformId.AMERICAS
| PlatformId.ASIA
| PlatformId.SEA;
| PlatformId.SEA
| PlatformId.ESPORTS;

export type LoLRegion =
| PlatformId.BR1
Expand All @@ -99,7 +108,12 @@ export namespace RiotAPITypes {
| PlatformId.NA1
| PlatformId.OC1
| PlatformId.RU
| PlatformId.TR1;
| PlatformId.TR1
| PlatformId.PH2
| PlatformId.SG2
| PlatformId.TH2
| PlatformId.TW2
| PlatformId.VN2;

export namespace METHOD_KEY {
export namespace ACCOUNT {
Expand Down
44 changes: 28 additions & 16 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ export class RiotAPI {
region,
puuid,
}: {
region: RiotAPITypes.Cluster;
region: Exclude<RiotAPITypes.Cluster, PlatformId.SEA>;
puuid: string;
}): Promise<RiotAPITypes.Account.AccountDTO> =>
this.request(
Expand All @@ -158,7 +158,7 @@ export class RiotAPI {
gameName,
tagLine,
}: {
region: RiotAPITypes.Cluster;
region: Exclude<RiotAPITypes.Cluster, PlatformId.SEA>;
gameName: string;
tagLine: string;
}): Promise<RiotAPITypes.Account.AccountDTO> =>
Expand All @@ -175,7 +175,7 @@ export class RiotAPI {
region,
accessToken,
}: {
region: RiotAPITypes.Cluster;
region: Exclude<RiotAPITypes.Cluster, PlatformId.SEA>;
accessToken: string;
}): Promise<RiotAPITypes.Account.AccountDTO> =>
this.request(
Expand All @@ -192,7 +192,7 @@ export class RiotAPI {
game,
puuid,
}: {
region: RiotAPITypes.Cluster;
region: Exclude<RiotAPITypes.Cluster, PlatformId.SEA>;
game: "val" | "lor";
puuid: string;
}): Promise<RiotAPITypes.Account.ActiveShardDTO> =>
Expand Down Expand Up @@ -585,7 +585,10 @@ export class RiotAPI {
region,
accessToken,
}: {
region: RiotAPITypes.LORCluster;
region: Exclude<
RiotAPITypes.LORCluster,
PlatformId.ASIA | PlatformId.APAC
>;
accessToken: string;
}): Promise<RiotAPITypes.LorDeck.DeckDTO[]> =>
this.request(
Expand All @@ -602,7 +605,7 @@ export class RiotAPI {
accessToken,
body,
}: {
region: RiotAPITypes.LORCluster;
region: Exclude<RiotAPITypes.LORCluster, PlatformId.ASIA>;
accessToken: string;
body: RiotAPITypes.LorDeck.NewDeckDTO;
}): Promise<string> =>
Expand All @@ -626,7 +629,10 @@ export class RiotAPI {
region,
accessToken,
}: {
region: RiotAPITypes.LORCluster;
region: Exclude<
RiotAPITypes.LORCluster,
PlatformId.ASIA | PlatformId.APAC
>;
accessToken: string;
}): Promise<RiotAPITypes.LorInventory.CardDTO[]> =>
this.request(
Expand All @@ -647,7 +653,7 @@ export class RiotAPI {
region,
puuid,
}: {
region: RiotAPITypes.LORCluster;
region: Exclude<RiotAPITypes.LORCluster, PlatformId.ASIA>;
puuid: string;
}): Promise<string[]> =>
this.request(
Expand All @@ -660,7 +666,7 @@ export class RiotAPI {
region,
matchId,
}: {
region: RiotAPITypes.LORCluster;
region: Exclude<RiotAPITypes.LORCluster, PlatformId.ASIA>;
matchId: string;
}): Promise<RiotAPITypes.LorMatch.MatchDTO> =>
this.request(
Expand All @@ -677,7 +683,10 @@ export class RiotAPI {
getMasterTier: ({
region,
}: {
region: RiotAPITypes.LORCluster;
region: Exclude<
RiotAPITypes.LORCluster,
PlatformId.ASIA | PlatformId.APAC
>;
}): Promise<RiotAPITypes.LorRanked.LeaderboardDTO> =>
this.request(
region,
Expand Down Expand Up @@ -784,7 +793,7 @@ export class RiotAPI {
puuid,
params,
}: {
cluster: RiotAPITypes.Cluster;
cluster: Exclude<RiotAPITypes.Cluster, PlatformId.ESPORTS>;
puuid: string;
params?: {
queue?: number;
Expand All @@ -808,7 +817,7 @@ export class RiotAPI {
cluster,
matchId,
}: {
cluster: RiotAPITypes.Cluster;
cluster: Exclude<RiotAPITypes.Cluster, PlatformId.ESPORTS>;
matchId: string;
}): Promise<RiotAPITypes.MatchV5.MatchDTO> =>
this.request(
Expand All @@ -823,7 +832,7 @@ export class RiotAPI {
cluster,
matchId,
}: {
cluster: RiotAPITypes.Cluster;
cluster: Exclude<RiotAPITypes.Cluster, PlatformId.ESPORTS>;
matchId: string;
}): Promise<RiotAPITypes.MatchV5.MatchTimelineDTO> =>
this.request(
Expand Down Expand Up @@ -1058,9 +1067,12 @@ export class RiotAPI {
puuid,
params,
}: {
region: RiotAPITypes.Cluster;
region: RiotAPITypes.TFTCluster;
puuid: string;
params?: {
start?: number;
endTime?: number;
startTime?: number;
count?: number;
};
}): Promise<string[]> =>
Expand All @@ -1074,7 +1086,7 @@ export class RiotAPI {
region,
matchId,
}: {
region: RiotAPITypes.Cluster;
region: RiotAPITypes.TFTCluster;
matchId: string;
}): Promise<RiotAPITypes.TftMatch.MatchDTO> =>
this.request(
Expand Down Expand Up @@ -1425,7 +1437,7 @@ export class RiotAPI {
queue,
params,
}: {
region: RiotAPITypes.VALCluster;
region: Exclude<RiotAPITypes.VALCluster, PlatformId.ESPORTS>;
queue: string;
params?: {
size?: number;
Expand Down

0 comments on commit 558fc28

Please sign in to comment.