Skip to content

Commit

Permalink
feat: added tests
Browse files Browse the repository at this point in the history
added ban types
  • Loading branch information
TheBv committed Nov 15, 2024
1 parent 1bc4440 commit 7f84ffb
Show file tree
Hide file tree
Showing 21 changed files with 2,199 additions and 23 deletions.
24 changes: 24 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"request": "launch",
"name": "Launch Program",
"type": "node",
"cwd": "${workspaceFolder}/javascript-sdk/etf2l/",
"env": {},
"runtimeExecutable": "C:\\Users\\Patrick\\.deno\\bin\\deno.EXE",
"runtimeArgs": [
"test",
"--unstable",
"--inspect-wait",
"--allow-all"
],
"attachSimplePort": 9229,
"outputCapture": "std"
}
]
}
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"github.copilot.inlineSuggest.enable": true
}
3 changes: 2 additions & 1 deletion javascript-sdk/deno.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"exclude": [".git", "coverage", "docs"],
"tasks": {
"ok": "deno lint && deno fmt --check"
"ok": "deno lint && deno fmt --check",
"test": "deno test --allow-net"
},
"workspace": ["./logstf", "./etf2l"]
}
6 changes: 4 additions & 2 deletions javascript-sdk/etf2l/api/etf2l.ts
Original file line number Diff line number Diff line change
Expand Up @@ -360,8 +360,10 @@ export class Etf2l {
params.append("country", country);
}

if (player_class) {
params.append("class", `[${player_class.toString()}]`);
if (player_class && player_class.length > 0) {
for (const p_class of player_class) {
params.append("class", p_class);
}
}

if (skill) {
Expand Down
3 changes: 3 additions & 0 deletions javascript-sdk/etf2l/deno.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
{
"name": "@tf2software/etf2l",
"version": "0.0.1-alpha1",
"tasks": {
"gen-type-guards": "deno run --allow-env --allow-sys --no-lock --allow-read --allow-write npm:ts-auto-guard ./tests/etf2lTypeGuards.ts --debug --project=./tests --import-extension=ts"
},
"exports": {
".": "./mod.ts",
"./api": "./mod.ts",
Expand Down
1,951 changes: 1,951 additions & 0 deletions javascript-sdk/etf2l/tests/etf2lTypeGuards.guard.ts

Large diffs are not rendered by default.

62 changes: 62 additions & 0 deletions javascript-sdk/etf2l/tests/etf2lTypeGuards.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import type { Etf2lBan, Etf2lCompetitionDetails, Etf2lCompetitionList, Etf2lCompetitionMatches, Etf2lCompetitionResults, Etf2lCompetitionTables, Etf2lCompetitionTeams, Etf2lDemos, Etf2lMatch, Etf2lMatchDetails, Etf2lPlayer, Etf2lPlayerResults, Etf2lPlayerTransfers, Etf2lRecruitmentPlayers, Etf2lRecruitmentTeams, Etf2lTeam, Etf2lTeamMatches, Etf2lTeamResults, Etf2lTeamTransfers, Etf2lWhitelists } from "../types/mod.ts";

/** @see {isEtf2lBan} ts-auto-guard:type-guard */
export type Etf2lBanG = Etf2lBan;

/** @see {isEtf2lCompetitionDetails} ts-auto-guard:type-guard */
export type Etf2lCompetitionDetailsG = Etf2lCompetitionDetails;

/** @see {isEtf2lCompetitionList} ts-auto-guard:type-guard */
export type Etf2lCompetitionListG = Etf2lCompetitionList;

/** @see {isEtf2lCompetitionMatches} ts-auto-guard:type-guard */
export type Etf2lCompetitionMatchesG = Etf2lCompetitionMatches;

/** @see {isEtf2lCompetitionResults} ts-auto-guard:type-guard */
export type Etf2lCompetitionResultsG = Etf2lCompetitionResults;

/** @see {isEtf2lCompetitionTeams} ts-auto-guard:type-guard */
export type Etf2lCompetitionTeamsG = Etf2lCompetitionTeams;

/** @see {isEtf2lCompetitionTables} ts-auto-guard:type-guard */
export type Etf2lCompetitionTablesG = Etf2lCompetitionTables;

/** @see {isEtf2lDemos} ts-auto-guard:type-guard */
export type Etf2lDemosG = Etf2lDemos;

/** @see {isEtf2lMatch} ts-auto-guard:type-guard */
export type Etf2lMatchG = Etf2lMatch;

/** @see {isEtf2lMatchDetails} ts-auto-guard:type-guard */
export type Etf2lMatchDetailsG = Etf2lMatchDetails;

/** @see {isEtf2lPlayer} ts-auto-guard:type-guard */
export type Etf2lPlayerG = Etf2lPlayer;

/** @see {isEtf2lPlayerResults} ts-auto-guard:type-guard */
export type Etf2lPlayerResultsG = Etf2lPlayerResults;

/** @see {isEtf2lPlayerTransfers} ts-auto-guard:type-guard */
export type Etf2lPlayerTransfersG = Etf2lPlayerTransfers;

/** @see {isEtf2lRecruitmentPlayers} ts-auto-guard:type-guard */
export type Etf2lRecruitmentPlayersG = Etf2lRecruitmentPlayers;

/** @see {isEtf2lRecruitmentTeams} ts-auto-guard:type-guard */
export type Etf2lRecruitmentTeamsG = Etf2lRecruitmentTeams;

/** @see {isEtf2lTeam} ts-auto-guard:type-guard */
export type Etf2lTeamG = Etf2lTeam;

/** @see {isEtf2lTeamMatches} ts-auto-guard:type-guard */
export type Etf2lTeamMatchesG = Etf2lTeamMatches;

/** @see {isEtf2lTeamResults} ts-auto-guard:type-guard */
export type Etf2lTeamResultsG = Etf2lTeamResults;

/** @see {isEtf2lTeamTransfers} ts-auto-guard:type-guard */
export type Etf2lTeamTransfersG = Etf2lTeamTransfers;

/** @see {isEtf2lWhitelists} ts-auto-guard:type-guard */
export type Etf2lWhitelistsG = Etf2lWhitelists;

100 changes: 100 additions & 0 deletions javascript-sdk/etf2l/tests/test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
import { describe, it, beforeAll } from "jsr:@std/testing/bdd";
import { expect } from "jsr:@std/expect";
import { Etf2l } from "./../api/mod.ts";
import { isEtf2lBan, isEtf2lCompetitionDetails, isEtf2lCompetitionList, isEtf2lCompetitionResults, isEtf2lCompetitionTables, isEtf2lCompetitionTeams, isEtf2lDemos, isEtf2lMatch, isEtf2lMatchDetails, isEtf2lPlayer, isEtf2lPlayerResults, isEtf2lPlayerTransfers, isEtf2lRecruitmentPlayers, isEtf2lRecruitmentTeams, isEtf2lTeam, isEtf2lTeamMatches, isEtf2lTeamResults, isEtf2lTeamTransfers, isEtf2lWhitelists } from "./etf2lTypeGuards.guard.ts";

describe("etf2l", () => {
let etf2l: Etf2l;
let playerId: number;
let matchId: number;
let competitionId: number;
let teamId: number;

beforeAll(() => {
etf2l = new Etf2l();
playerId = 123;
matchId = 123;
competitionId = 10;
teamId = 123;
});

describe("returns correct types", () => {
it("ban types", async () => {
const bans = await etf2l.bans();
expect(isEtf2lBan(bans)).toBe(true);
});
it("competitionList types", async () => {
const competitions = await etf2l.competitionList();
expect(isEtf2lCompetitionList(competitions)).toBe(true);
});
it("competitionDetails types", async () => {
const competition = await etf2l.competitionDetails(competitionId);
expect(isEtf2lCompetitionDetails(competition)).toBe(true);
});
it("competitionResults types", async () => {
const competition = await etf2l.competitionResults(competitionId);
expect(isEtf2lCompetitionResults(competition)).toBe(true);
});
it("competitionTeams types", async () => {
const competition = await etf2l.competitionTeams(competitionId);
expect(isEtf2lCompetitionTeams(competition)).toBe(true);
});
it("competitionTables types", async () => {
const competition = await etf2l.competitionTables(competitionId);
expect(isEtf2lCompetitionTables(competition)).toBe(true);
});
it("demos types", async () => {
const demos = await etf2l.demos();
expect(isEtf2lDemos(demos)).toBe(true);
});
it("matches types", async () => {
const matches = await etf2l.matches();
expect(isEtf2lMatch(matches)).toBe(true);
});
it("matchDetails types", async () => {
const match = await etf2l.matchDetails(matchId);
expect(isEtf2lMatchDetails(match)).toBe(true);
});
it("player types", async () => {
const player = await etf2l.player(playerId);
expect(isEtf2lPlayer(player)).toBe(true);
});
it("playerTransfers types", async () => {
const transfers = await etf2l.playerTransfers(playerId);
expect(isEtf2lPlayerTransfers(transfers)).toBe(true);
});
it("playerResults types", async () => {
const results = await etf2l.playerResults(playerId);
expect(isEtf2lPlayerResults(results)).toBe(true);
});
it("playerRecruitment types", async () => {
const recruitment = await etf2l.playerRecruitment({country: null, player_class: ["soldier"], skill: null, type: null, user: null});
expect(isEtf2lRecruitmentPlayers(recruitment)).toBe(true);
});
it("teamRecruitment types", async () => {
const recruitment = await etf2l.teamRecruitment();
expect(isEtf2lRecruitmentTeams(recruitment)).toBe(true);
});
it("team types", async () => {
const team = await etf2l.team(teamId);
expect(isEtf2lTeam(team)).toBe(true);
});
it("teamTransfers types", async () => {
const transfers = await etf2l.teamTransfers(teamId);
expect(isEtf2lTeamTransfers(transfers)).toBe(true);
});
it("teamResults types", async () => {
const results = await etf2l.teamResults(teamId);
expect(isEtf2lTeamResults(results)).toBe(true);
});
it("teamMatches types", async () => {
const matches = await etf2l.teamMatches(teamId);
expect(isEtf2lTeamMatches(matches)).toBe(true);
});
it("whitelists types", async () => {
const whitelists = await etf2l.whitelists();
expect(isEtf2lWhitelists(whitelists)).toBe(true);
});
});
});

15 changes: 15 additions & 0 deletions javascript-sdk/etf2l/tests/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
This tsconfig file is only needed for ts-auto-guard
**/

{
"compilerOptions": {
"module": "ESNext",
"target": "ESNext",
"emitDecoratorMetadata": false,
"skipLibCheck": true,
"strictNullChecks": true,
"lib": ["ESNext"],
"removeComments": true
}
}
13 changes: 13 additions & 0 deletions javascript-sdk/etf2l/types/common/ban.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export type SmallBan = {
start: number;
end: number;
reason: string;
}

export type Ban = SmallBan & {
name: string;
steamid: string;
steamid64: string;
profile: string;
expired: boolean
}
4 changes: 2 additions & 2 deletions javascript-sdk/etf2l/types/common/multiPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import type { MultiPageSmall } from "./multiPageSmall.ts";
export type MultiPage = MultiPageSmall & {
current_page: number;
first_page_url: string;
from: number;
from: number | null;
last_page: number;
last_page_url: string;
links: Link[];
next_page_url: string | null;
path: string;
per_page: number;
prev_page_url: string | null;
to: number;
to: number | null;
total: number;
};
4 changes: 2 additions & 2 deletions javascript-sdk/etf2l/types/common/multiPageSmall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import type { Link } from "./link.ts";

export type MultiPageSmall = {
current_page: number;
from: number;
from: number | null;
last_page: number;
links: Link[];
path: string;
per_page: number;
to: number;
to: number | null;
total: number;
};
2 changes: 1 addition & 1 deletion javascript-sdk/etf2l/types/competition/competitionTable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export type CompetitionTable = {
maps_lost: number;
penalty_points: number;
score: number;
ach: number;
ach: number | null;
byes: number;
seeded_points: number;
};
9 changes: 7 additions & 2 deletions javascript-sdk/etf2l/types/endpoints/player/etf2lBan.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
import type { PlayerData } from "../../player/mod.ts";
import type { Ban } from "../../common/ban.ts";
import type { MultiPage } from "../../mod.ts";

export type Etf2lBan = PlayerData;
export type Etf2lBan = {
bans: MultiPage & {
data: Ban[];
};
};
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { RecruitmentPlayer } from "../../recruitment/recruitmentPlayer.ts";
//import type { Status } from "types/common/status";
import type { Status } from "../../common/status.ts";

export type Etf2lRecruitmentPlayers = {
recruitment: RecruitmentPlayer;
status: { status: number; message: string }; // Status;
status: Status;
};
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//import type { Status } from "types/common/status.ts";
import type { Status } from "../../common/status.ts";
import type { RecruitmentTeam } from "../../recruitment/mod.ts";

export type Etf2lRecruitmentTeams = {
recruitment: RecruitmentTeam;
status: { status: number; message: string }; // Status;
status: Status;
};
2 changes: 1 addition & 1 deletion javascript-sdk/etf2l/types/endpoints/team/etf2lTeam.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Status } from "../../common/status.ts";
import type { Team } from "../../team/team";
import type { Team } from "../../team/team.ts";

export type Etf2lTeam = {
team: Team;
Expand Down
6 changes: 3 additions & 3 deletions javascript-sdk/etf2l/types/matches/matchData.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Clan } from "types/common/clan";
import type { CompetitionResultsCompetition } from "types/competition/competitionResultsCompetition";
import type { CompetitionResultsDivision } from "types/competition/competitionResultsDivision";
import type { Clan } from "../../types/common/clan.ts";
import type { CompetitionResultsCompetition } from "../../types/competition/competitionResultsCompetition.ts";
import type { CompetitionResultsDivision } from "../../types/competition/competitionResultsDivision.ts";

export type MatchData = {
clan1: Clan;
Expand Down
2 changes: 0 additions & 2 deletions javascript-sdk/etf2l/types/matches/matchDataDetails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import type { MatchPlayer } from "./matchPlayer.ts";
export type MatchDataDetails = {
clan1: Clan;
clan2: Clan;
//TODO:
competition: CompetitionResultsCompetition;
defaultwin: boolean | null;
division: CompetitionResultsDivision | null;
Expand All @@ -22,7 +21,6 @@ export type MatchDataDetails = {
self: string;
api: string;
};
//TODO:
players: MatchPlayer[];
bye_week: boolean;
demos: [];
Expand Down
4 changes: 2 additions & 2 deletions javascript-sdk/etf2l/types/player/playerData.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import type { SmallBan } from "../common/ban.ts";
import type { Classes } from "../enums/classes.ts";
import type { PlayerSteamData } from "./playerSteamData.ts";
import type { PlayerTeam } from "./playerTeam.ts";

export type PlayerData = {
//TODO:
bans: null;
bans: SmallBan | null;
classes: Classes[];
country: string;
id: number;
Expand Down
1 change: 0 additions & 1 deletion javascript-sdk/etf2l/types/player/playerTransferTeam.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ export type PlayerTransferTeam = {
avatar: string;
group: string | null;
};
//TODO: Create enum
type: string;
url: string;
};

0 comments on commit 7f84ffb

Please sign in to comment.