<commit_before>const assert = require("assert");
const fs = require("fs");
const path = require("path");

const pify = require("pify");

const nba = require("../../src/");

// for interactive inspection, particularly in browser
global.StatsData = {};
const tested = {};
const methods = {};

const set = (a, b, c) => (a[b] = c, a);

const stats = Object.keys(nba.stats).reduce((prox, k) => {
  methods[k] = true;
  return set(prox, k, (...args) => {
    tested[k] = true;
    return nba.stats[k](...args);
  });
}, {});

// stub for now, will add response shape verification for self-documenting responses
let verifyShape = shape => response => response;

let callMethod = (name, params = {}, shape) => () =>
  stats[name](params).then(r => global.StatsData[name] = r);

const _steph = 201939;
const _dubs = 1610612744;
const steph = {playerId: _steph};
const dubs = {teamId: _dubs};
const game = {gameId: "0021401082"};

// these tests merely ensure that valid stats API calls don't error.
// more comprehensive tests are coming soon.

describe("nba stats methods", function () {

  it("#playerProfile", callMethod("playerProfile", steph));
  it("#playerInfo", callMethod("playerInfo", steph));
  it("#playersInfo", callMethod("playersInfo"));
  it("#teamStats", callMethod("teamStats"));
  it("#teamSplits", callMethod("teamSplits", dubs));
  it("#teamYears", callMethod("teamYears"));
  it("#playerSplits", callMethod("playerSplits", steph));
  it("#shots", callMethod("shots", dubs));
  it("#scoreboard", callMethod("scoreboard", {gameDate: "03/27/2015"}));
  it("#playByPlay", callMethod("playByPlay", game));
  it("#teamHistoricalLeaders", callMethod("teamHistoricalLeaders", {teamId: _dubs, seasonId: "20078"}));
  it("#teamInfoCommon", callMethod("teamInfoCommon", dubs));
  it("#commonTeamRoster", callMethod("commonTeamRoster", dubs));
  it("#teamPlayerDashboard", callMethod("teamPlayerDashboard", {teamId: _dubs, seasonType: "Regular Season"}));
  it("#lineups", callMethod("lineups"));
  it("#playerTracking", callMethod("playerTracking", {ptMeasureType: "CatchShoot"}));

  after(function () {
    return Promise.all(Object.keys(global.StatsData).map(k =>
      pify(fs.writeFile)(path.join(__dirname, "../../responses", k + ".json"), JSON.stringify(global.StatsData[k], null, 2))
    ))
    .catch(() => {});
  });
});

describe("tested all methods", function () {
  it("did test all methods", () => assert.deepEqual(tested, methods));
});<commit_msg>fix "tested all methods"<commit_after>const assert = require("assert");
const fs = require("fs");
const path = require("path");

const pify = require("pify");

const nba = require("../../src/");

// for interactive inspection, particularly in browser
global.StatsData = {};
const tested = {};
const methods = {};

const blacklist = ["withTransport"];

const set = (a, b, c) => (a[b] = c, a);

const stats = Object.keys(nba.stats).reduce((prox, k) => {
  if (!blacklist.includes(k)) {
    methods[k] = true;
  }

  return set(prox, k, (...args) => {
    tested[k] = true;
    return nba.stats[k](...args);
  });
}, {});

// stub for now, will add response shape verification for self-documenting responses
let verifyShape = shape => response => response;

let callMethod = (name, params = {}, shape) => () =>
  stats[name](params).then(r => global.StatsData[name] = r);

const _steph = 201939;
const _dubs = 1610612744;
const steph = {playerId: _steph};
const dubs = {teamId: _dubs};
const game = {gameId: "0021401082"};

// these tests merely ensure that valid stats API calls don't error.
// more comprehensive tests are coming soon.

describe("nba stats methods", function () {

  it("#playerProfile", callMethod("playerProfile", steph));
  it("#playerInfo", callMethod("playerInfo", steph));
  it("#playersInfo", callMethod("playersInfo"));
  it("#teamStats", callMethod("teamStats"));
  it("#teamSplits", callMethod("teamSplits", dubs));
  it("#teamYears", callMethod("teamYears"));
  it("#playerSplits", callMethod("playerSplits", steph));
  it("#shots", callMethod("shots", dubs));
  it("#scoreboard", callMethod("scoreboard", {gameDate: "03/27/2015"}));
  it("#playByPlay", callMethod("playByPlay", game));
  it("#teamHistoricalLeaders", callMethod("teamHistoricalLeaders", {teamId: _dubs, seasonId: "20078"}));
  it("#teamInfoCommon", callMethod("teamInfoCommon", dubs));
  it("#commonTeamRoster", callMethod("commonTeamRoster", dubs));
  it("#teamPlayerDashboard", callMethod("teamPlayerDashboard", {teamId: _dubs, seasonType: "Regular Season"}));
  it("#lineups", callMethod("lineups"));
  it("#playerTracking", callMethod("playerTracking", {ptMeasureType: "CatchShoot"}));

  after(function () {
    return Promise.all(Object.keys(global.StatsData).map(k =>
      pify(fs.writeFile)(path.join(__dirname, "../../responses", k + ".json"), JSON.stringify(global.StatsData[k], null, 2))
    ))
    .catch(() => {});
  });
});

describe("tested all methods", function () {
  it("did test all methods", () => assert.deepEqual(tested, methods));
});
{'fraction_non_alphanumeric': 0.20007971303308092, 'fraction_numerical': 0.015942606616181746, 'mean_word_length': 5.442875481386393, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2101627', 'n_tokens_mistral': 1677, 'n_tokens_neox': 1588, 'n_words': 378}