@balldontlie/sdk
Version:
Official TypeScript/JavaScript SDK for the balldontlie API
141 lines (140 loc) • 6.95 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("NFL API", () => {
let api;
before(() => {
api = new src_1.BalldontlieAPI({ apiKey: API_KEY });
});
describe("Teams", () => {
it("should get all teams", () => __awaiter(void 0, void 0, void 0, function* () {
const teams = yield api.nfl.getTeams();
(0, chai_1.expect)(teams.data).to.be.an("array");
(0, chai_1.expect)(teams.data[0]).to.have.all.keys("id", "conference", "division", "location", "name", "full_name", "abbreviation");
}));
it("should filter teams by conference", () => __awaiter(void 0, void 0, void 0, function* () {
const teams = yield api.nfl.getTeams({ conference: "AFC" });
(0, chai_1.expect)(teams.data).to.be.an("array");
teams.data.forEach((team) => {
(0, chai_1.expect)(team.conference).to.equal("AFC");
});
}));
it("should get a single team", () => __awaiter(void 0, void 0, void 0, function* () {
const teams = yield api.nfl.getTeams();
const teamId = teams.data[0].id;
const team = yield api.nfl.getTeam(teamId);
(0, chai_1.expect)(team.data).to.have.property("id", teamId);
}));
});
describe("Injuries", () => {
it("should get injuries", () => __awaiter(void 0, void 0, void 0, function* () {
const injuries = yield api.nfl.getPlayerInjuries();
(0, chai_1.expect)(injuries.data).to.be.an("array");
}));
});
describe("Players", () => {
it("should get players with pagination", () => __awaiter(void 0, void 0, void 0, function* () {
const players = yield api.nfl.getPlayers({ per_page: 5 });
(0, chai_1.expect)(players.data).to.be.an("array");
(0, chai_1.expect)(players.data).to.have.lengthOf(5);
}));
it("should search players by name", () => __awaiter(void 0, void 0, void 0, function* () {
const players = yield api.nfl.getPlayers({ search: "lamar jackson" });
(0, chai_1.expect)(players.data).to.be.an("array");
players.data.forEach((player) => {
(0, chai_1.expect)(player.first_name.toLowerCase()).to.include("lamar");
(0, chai_1.expect)(player.last_name.toLowerCase()).to.include("lamar");
});
}));
it("should get active players", () => __awaiter(void 0, void 0, void 0, function* () {
const players = yield api.nfl.getActivePlayers();
(0, chai_1.expect)(players.data).to.be.an("array");
}));
});
describe("Games", () => {
it("should get games with filters", () => __awaiter(void 0, void 0, void 0, function* () {
const games = yield api.nfl.getGames({
seasons: [2023],
weeks: [1],
per_page: 5,
});
(0, chai_1.expect)(games.data).to.be.an("array");
games.data.forEach((game) => {
(0, chai_1.expect)(game.season).to.equal(2023);
(0, chai_1.expect)(game.week).to.equal(1);
});
}));
it("should get a specific game", () => __awaiter(void 0, void 0, void 0, function* () {
const games = yield api.nfl.getGames();
const gameId = games.data[0].id;
const game = yield api.nfl.getGame(gameId);
(0, chai_1.expect)(game.data).to.have.property("id", gameId);
}));
});
describe("Standings", () => {
it("should get standings", () => __awaiter(void 0, void 0, void 0, function* () {
const res = yield api.nfl.getStandings({ season: 2023 });
const standing = res.data[0];
(0, chai_1.expect)(standing.season).to.equal(2023);
}));
});
describe("Stats", () => {
it("should get player stats", () => __awaiter(void 0, void 0, void 0, function* () {
const stats = yield api.nfl.getStats({
seasons: [2023],
per_page: 5,
});
(0, chai_1.expect)(stats.data).to.be.an("array");
(0, chai_1.expect)(stats.data[0]).to.have.property("player");
}));
it("should get season stats", () => __awaiter(void 0, void 0, void 0, function* () {
const stats = yield api.nfl.getSeasonStats({
season: 2023,
});
(0, chai_1.expect)(stats.data).to.be.an("array");
}));
describe("Advanced Stats", () => {
it("should get rushing stats", () => __awaiter(void 0, void 0, void 0, function* () {
const stats = yield api.nfl.getAdvancedRushingStats({
season: 2023,
});
(0, chai_1.expect)(stats.data).to.be.an("array");
}));
it("should get passing stats", () => __awaiter(void 0, void 0, void 0, function* () {
const stats = yield api.nfl.getAdvancedPassingStats({
season: 2023,
week: 1,
});
(0, chai_1.expect)(stats.data).to.be.an("array");
(0, chai_1.expect)(stats.data[0].week).to.equal(1);
(0, chai_1.expect)(stats.data[0].season).to.equal(2023);
(0, chai_1.expect)(stats.data[0].player).to.not.be.undefined;
}));
it("should get receiving stats", () => __awaiter(void 0, void 0, void 0, function* () {
const stats = yield api.nfl.getAdvancedReceivingStats({
season: 2023,
week: 2,
});
(0, chai_1.expect)(stats.data).to.be.an("array");
const data = stats.data[0];
(0, chai_1.expect)(data.week).to.equal(2);
(0, chai_1.expect)(data.season).to.equal(2023);
(0, chai_1.expect)(data.player).to.not.be.undefined;
}));
});
});
});