@balldontlie/sdk
Version:
Official TypeScript/JavaScript SDK for the balldontlie API
212 lines (211 loc) • 10.7 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const src_1 = require("../src");
const chai_1 = require("chai");
const API_KEY = process.env.BALLDONTLIE_API_KEY;
if (!API_KEY) {
throw new Error("BALLDONTLIE_API_KEY environment variable is required");
}
describe("EPL API", () => {
let api;
before(() => {
api = new src_1.BalldontlieAPI({ apiKey: API_KEY });
});
describe("Games", () => {
it("should get games with pagination and filters", () => __awaiter(void 0, void 0, void 0, function* () {
var _a;
const games = yield api.epl.getGames({
per_page: 5,
season: 2023,
week: 1,
});
(0, chai_1.expect)(games.data).to.be.an("array");
(0, chai_1.expect)(games.data).to.have.lengthOf(5);
games.data.forEach((game) => {
(0, chai_1.expect)(game.season).to.equal(2023);
(0, chai_1.expect)(game.week).to.equal(1);
});
(0, chai_1.expect)((_a = games.meta) === null || _a === void 0 ? void 0 : _a.next_cursor).to.be.a("number");
}));
it("should get game lineups", () => __awaiter(void 0, void 0, void 0, function* () {
const games = yield api.epl.getGames({
per_page: 1,
season: 2024,
week: 1,
});
const gameId = games.data[0].id;
const lineups = yield api.epl.getGameLineups(gameId);
(0, chai_1.expect)(lineups.data).to.be.an("array");
lineups.data.forEach((lineup) => {
(0, chai_1.expect)(lineup.team_id).to.be.a("number");
(0, chai_1.expect)(lineup.player).to.have.property("id");
(0, chai_1.expect)(lineup.substitute).to.be.a("boolean");
(0, chai_1.expect)(lineup.captain).to.be.a("boolean");
});
}));
it("should get game goals", () => __awaiter(void 0, void 0, void 0, function* () {
const games = yield api.epl.getGames({
per_page: 1,
week: 1,
season: 2024,
});
const gameId = games.data[0].id;
const goals = yield api.epl.getGameGoals(gameId);
(0, chai_1.expect)(goals.data).to.be.an("array");
goals.data.forEach((goal) => {
(0, chai_1.expect)(goal.game_id).to.equal(gameId);
(0, chai_1.expect)(goal.scorer).to.have.property("id");
(0, chai_1.expect)(goal.clock).to.be.a("number");
});
}));
it("should get game team stats", () => __awaiter(void 0, void 0, void 0, function* () {
const games = yield api.epl.getGames({
per_page: 1,
week: 1,
season: 2024,
});
const gameId = games.data[0].id;
const stats = yield api.epl.getGameTeamStats(gameId);
(0, chai_1.expect)(stats.data.game_id).to.equal(gameId);
(0, chai_1.expect)(stats.data.teams).to.be.an("array");
stats.data.teams.forEach((team) => {
(0, chai_1.expect)(team.team_id).to.be.a("number");
(0, chai_1.expect)(team.stats).to.be.an("array");
});
}));
it("should get game player stats", () => __awaiter(void 0, void 0, void 0, function* () {
const games = yield api.epl.getGames({
per_page: 1,
week: 1,
season: 2024,
});
const gameId = games.data[0].id;
const stats = yield api.epl.getGamePlayerStats(gameId);
(0, chai_1.expect)(stats.data.game_id).to.equal(gameId);
(0, chai_1.expect)(stats.data.players).to.be.an("array");
stats.data.players.forEach((player) => {
(0, chai_1.expect)(player.team_id).to.be.a("number");
(0, chai_1.expect)(player.player_id).to.be.a("number");
(0, chai_1.expect)(player.stats).to.be.an("array");
const stat = player.stats[0];
(0, chai_1.expect)(stat.name).to.be.a("string");
(0, chai_1.expect)(stat.value).to.be.a("number");
});
}));
});
describe("Players", () => {
it("should get players with pagination and filters", () => __awaiter(void 0, void 0, void 0, function* () {
const players = yield api.epl.getPlayers({
per_page: 5,
season: 2023,
first_name: "Heung-Min",
});
(0, chai_1.expect)(players.data).to.be.an("array");
(0, chai_1.expect)(players.data).to.have.lengthOf(1);
}));
it("should get player season stats", () => __awaiter(void 0, void 0, void 0, function* () {
const id = 295;
const stats = yield api.epl.getPlayerSeasonStats(id, { season: 2024 });
(0, chai_1.expect)(stats.data).to.be.an("array");
const stat = stats.data[0];
(0, chai_1.expect)(stat.name).to.be.a("string");
(0, chai_1.expect)(stat.value).to.be.a("number");
}));
});
describe("Leaders", () => {
describe("players", () => {
it("should get player stats leaders", () => __awaiter(void 0, void 0, void 0, function* () {
const leaders = yield api.epl.getPlayerStatsLeaders({
season: 2023,
type: "goals",
per_page: 5,
});
(0, chai_1.expect)(leaders.data).to.be.an("array");
(0, chai_1.expect)(leaders.data).to.have.lengthOf(5);
(0, chai_1.expect)(leaders.data[0].rank).to.be.lessThan(leaders.data[1].rank);
leaders.data.forEach((leader) => {
(0, chai_1.expect)(leader.season).to.equal(2023);
(0, chai_1.expect)(leader.name).to.equal("goals");
(0, chai_1.expect)(leader.value).to.be.a("number");
(0, chai_1.expect)(leader.rank).to.be.a("number");
(0, chai_1.expect)(leader.player).to.have.property("id");
});
}));
});
describe("teams", () => {
it("should get team stats leaders", () => __awaiter(void 0, void 0, void 0, function* () {
const leaders = yield api.epl.getTeamStatsLeaders({
season: 2023,
type: "goals",
per_page: 5,
});
(0, chai_1.expect)(leaders.data).to.be.an("array");
(0, chai_1.expect)(leaders.data).to.have.lengthOf(5);
(0, chai_1.expect)(leaders.data[0].rank).to.be.lessThan(leaders.data[1].rank);
leaders.data.forEach((leader) => {
(0, chai_1.expect)(leader.season).to.equal(2023);
(0, chai_1.expect)(leader.name).to.equal("goals");
(0, chai_1.expect)(leader.value).to.be.a("number");
(0, chai_1.expect)(leader.rank).to.be.a("number");
(0, chai_1.expect)(leader.team).to.have.property("id");
});
}));
});
});
describe("Standings", () => {
it("should get standings", () => __awaiter(void 0, void 0, void 0, function* () {
const standings = yield api.epl.getStandings({ season: 2023 });
(0, chai_1.expect)(standings.data).to.be.an("array");
standings.data.forEach((standing) => {
(0, chai_1.expect)(standing.season).to.equal(2023);
(0, chai_1.expect)(standing.team).to.have.property("id");
(0, chai_1.expect)(standing.position).to.be.a("number");
(0, chai_1.expect)(standing.overall_points).to.be.a("number");
(0, chai_1.expect)(standing.overall_played).to.be.a("number");
(0, chai_1.expect)(standing.overall_won).to.be.a("number");
(0, chai_1.expect)(standing.overall_lost).to.be.a("number");
(0, chai_1.expect)(standing.overall_drawn).to.be.a("number");
(0, chai_1.expect)(standing.home_points).to.be.a("number");
(0, chai_1.expect)(standing.away_points).to.be.a("number");
});
}));
});
describe("Teams", () => {
it("should get teams", () => __awaiter(void 0, void 0, void 0, function* () {
const teams = yield api.epl.getTeams({ season: 2023 });
(0, chai_1.expect)(teams.data).to.be.an("array");
teams.data.forEach((team) => {
(0, chai_1.expect)(team).to.have.all.keys("id", "name", "short_name", "abbr", "city", "stadium");
});
}));
it("should get team players", () => __awaiter(void 0, void 0, void 0, function* () {
const teams = yield api.epl.getTeams({ season: 2023 });
const teamId = teams.data[0].id;
const players = yield api.epl.getTeamPlayers(teamId, { season: 2023 });
(0, chai_1.expect)(players.data).to.be.an("array");
players.data.forEach((player) => {
(0, chai_1.expect)(player.id).to.be.a("number");
});
}));
it("should get team season stats", () => __awaiter(void 0, void 0, void 0, function* () {
const teams = yield api.epl.getTeams({ season: 2023 });
const teamId = teams.data[0].id;
const stats = yield api.epl.getTeamSeasonStats(teamId, { season: 2023 });
(0, chai_1.expect)(stats.data).to.be.an("array");
stats.data.forEach((stat) => {
(0, chai_1.expect)(stat.season).to.equal(2023);
(0, chai_1.expect)(stat.value).to.be.a("number");
(0, chai_1.expect)(stat.rank).to.be.a("number");
});
}));
});
});