Skip to content

Commit

Permalink
feat(tournament): Tournament-V5 & fixes (#471)
Browse files Browse the repository at this point in the history
* feat(tournament): tournamentV5 endpoints and some fixes

* refactor: removed un-used code

* ci(github): auth github registry before npm install

* fix(deps): install riot-rate-limiter from public npm

* refactor: remove un-used types

* test(e2e): fix e2e to use latest matchIds

* test(e2e): fixed resp.info check
  • Loading branch information
OllieJennings authored Oct 5, 2023
1 parent 3131dcc commit 29cb9c7
Show file tree
Hide file tree
Showing 6 changed files with 1,186 additions and 595 deletions.
35 changes: 26 additions & 9 deletions __tests__/e2e/match_v5.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
jest.unmock("@fightmegg/riot-rate-limiter");

import { count } from "console";
import "jest-extended";
import { PlatformId, RiotAPI } from "../../src/index";

jest.unmock("@fightmegg/riot-rate-limiter");

const riotAPIKey = process.env.X_RIOT_API_KEY || "";

describe("E2E", () => {
Expand All @@ -26,19 +25,29 @@ describe("E2E", () => {
test("getMatchById", async () => {
const rAPI = new RiotAPI(riotAPIKey);

const matchId = "EUW1_5350514472";
const matchIds = await rAPI.matchV5.getIdsByPuuid({
cluster: PlatformId.EUROPE,
puuid:
"8bJQbDi6uFIgefQA6Y79yxff_1bCHNopb1eHlq3p7Ic2oeXgYTvNnfGahtWyJ6qqAue3uK6wiZmMWQ",
params: {
start: 0,
count: 5,
},
});

const resp = await rAPI.matchV5.getMatchById({
cluster: PlatformId.EUROPE,
matchId,
matchId: matchIds[0],
});

expect(resp).toContainAllKeys(["metadata", "info"]);
expect(resp.info).toContainAllKeys([
"gameCreation",
"gameDuration",
"gameId",
"gameMode",
"gameName",
"gameEndTimestamp",
"gameStartTimestamp",
"gameType",
"gameVersion",
Expand All @@ -49,17 +58,25 @@ describe("E2E", () => {
"teams",
"tournamentCode",
]);
expect(resp.metadata.matchId).toEqual(matchId);
expect(resp.metadata.matchId).toEqual(matchIds[0]);
});

test("getMatchTimelineById", async () => {
const rAPI = new RiotAPI(riotAPIKey);

const matchId = "EUW1_5350514472";
const matchIds = await rAPI.matchV5.getIdsByPuuid({
cluster: PlatformId.EUROPE,
puuid:
"8bJQbDi6uFIgefQA6Y79yxff_1bCHNopb1eHlq3p7Ic2oeXgYTvNnfGahtWyJ6qqAue3uK6wiZmMWQ",
params: {
start: 0,
count: 5,
},
});

const resp = await rAPI.matchV5.getMatchTimelineById({
cluster: PlatformId.EUROPE,
matchId,
matchId: matchIds[0],
});
expect(resp).toContainAllKeys(["metadata", "info"]);
expect(resp.info).toContainAnyKeys([
Expand All @@ -68,7 +85,7 @@ describe("E2E", () => {
"gameId",
"participants",
]);
expect(resp.metadata.matchId).toEqual(matchId);
expect(resp.metadata.matchId).toEqual(matchIds[0]);
});
});
});
210 changes: 210 additions & 0 deletions __tests__/unit/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1638,6 +1638,216 @@ describe("RiotAPI", () => {
);
});

describe("tournamentStub_V5", () => {
test.each([
[
"createCodes",
{
params: { tournamentId: 22, count: 1 },
body: { mapType: RiotAPITypes.TournamentV5.MAPTYPE.SUMMONERS_RIFT },
},
[
PlatformId.AMERICAS,
RiotAPITypes.METHOD_KEY.TOURNAMENT_STUB_V5.POST_CREATE_CODES,
{},
{
id: "americas.tournamentStubV5.createCodes.22",
params: { tournamentId: 22, count: 1 },
method: "POST",
body: { mapType: RiotAPITypes.TournamentV5.MAPTYPE.SUMMONERS_RIFT },
},
],
],
[
"getByTournamentCode",
{
tournamentCode: "1",
},
[
PlatformId.AMERICAS,
RiotAPITypes.METHOD_KEY.TOURNAMENT_STUB_V5.GET_TOURNAMENT_BY_CODE,
{ tournamentCode: "1" },
{
id: "americas.tournamentStubV5.getByTournamentCode.1",
priority: 0,
},
],
],
[
"getLobbyEventsByTournamentCode",
{
tournamentCode: "1",
},
[
PlatformId.AMERICAS,
RiotAPITypes.METHOD_KEY.TOURNAMENT_STUB_V5
.GET_LOBBY_EVENTS_BY_TOURNAMENT_CODE,
{ tournamentCode: "1" },
{
id: "americas.tournamentStubV5.getLobbyEventsByTournamentCode.1",
},
],
],
[
"createProvider",
{
body: { region: PlatformId.EUW1 },
},
[
PlatformId.AMERICAS,
RiotAPITypes.METHOD_KEY.TOURNAMENT_STUB_V5.POST_CREATE_PROVIDER,
{},
{
id: "americas.tournamentStubV5.createProvider",
method: "POST",
body: { region: PlatformId.EUW1 },
},
],
],
[
"createTournament",
{
body: { name: "test" },
},
[
PlatformId.AMERICAS,
RiotAPITypes.METHOD_KEY.TOURNAMENT_STUB_V5.POST_CREATE_TOURNAMENT,
{},
{
id: "americas.tournamentStubV5.createTournament",
method: "POST",
body: { name: "test" },
},
],
],
])(
"%s - calls request with correct params",
async (name, input, params) => {
const rAPI = new RiotAPI("1234");
rAPI.request = jest.fn().mockResolvedValue(null);

await getKeyValue(rAPI.tournamentStubV5)(name as any)(input as any);
expect(rAPI.request).toHaveBeenCalledWith(...params);
}
);
});

describe("tournament_V5", () => {
test.each([
[
"createCodes",
{
params: { tournamentId: 22, count: 1 },
body: { mapType: RiotAPITypes.TournamentV5.MAPTYPE.SUMMONERS_RIFT },
},
[
PlatformId.AMERICAS,
RiotAPITypes.METHOD_KEY.TOURNAMENT_V5.POST_CREATE_CODES,
{},
{
id: "americas.tournamentV5.createCodes.22",
params: { tournamentId: 22, count: 1 },
method: "POST",
body: { mapType: RiotAPITypes.TournamentV5.MAPTYPE.SUMMONERS_RIFT },
priority: 0,
},
],
],
[
"getByTournamentCode",
{
tournamentCode: "1",
},
[
PlatformId.AMERICAS,
RiotAPITypes.METHOD_KEY.TOURNAMENT_V5.GET_TOURNAMENT_BY_CODE,
{ tournamentCode: "1" },
{
id: "americas.tournamentV5.getByTournamentCode.1",
priority: 0,
},
],
],
[
"updateByTournamentCode",
{
tournamentCode: "1",
body: { mapType: RiotAPITypes.TournamentV5.MAPTYPE.SUMMONERS_RIFT },
},
[
PlatformId.AMERICAS,
RiotAPITypes.METHOD_KEY.TOURNAMENT_V5.GET_TOURNAMENT_BY_CODE,
{ tournamentCode: "1" },
{
id: "americas.tournamentV5.updateByTournamentCode.1",
method: "POST",
body: { mapType: RiotAPITypes.TournamentV5.MAPTYPE.SUMMONERS_RIFT },
priority: 0,
},
],
],
[
"getLobbyEventsByTournamentCode",
{
tournamentCode: "1",
},
[
PlatformId.AMERICAS,
RiotAPITypes.METHOD_KEY.TOURNAMENT_V5
.GET_LOBBY_EVENTS_BY_TOURNAMENT_CODE,
{ tournamentCode: "1" },
{
id: "americas.tournamentV5.getLobbyEventsByTournamentCode.1",
priority: 0,
},
],
],
[
"createProvider",
{
body: { region: PlatformId.EUW1 },
},
[
PlatformId.AMERICAS,
RiotAPITypes.METHOD_KEY.TOURNAMENT_V5.POST_CREATE_PROVIDER,
{},
{
id: "americas.tournamentV5.createProvider",
method: "POST",
body: { region: PlatformId.EUW1 },
priority: 0,
},
],
],
[
"createTournament",
{
body: { name: "test" },
},
[
PlatformId.AMERICAS,
RiotAPITypes.METHOD_KEY.TOURNAMENT_V5.POST_CREATE_TOURNAMENT,
{},
{
id: "americas.tournamentV5.createTournament",
method: "POST",
body: { name: "test" },
priority: 0,
},
],
],
])(
"%s - calls request with correct params",
async (name, input, params) => {
const rAPI = new RiotAPI("1234");
rAPI.request = jest.fn().mockResolvedValue(null);

await getKeyValue(rAPI.tournamentV5)(name as any)(input as any);
expect(rAPI.request).toHaveBeenCalledWith(...params);
}
);
});

describe("valContent", () => {
test.each([
[
Expand Down
Loading

0 comments on commit 29cb9c7

Please sign in to comment.