BEGIN;
SELECT plan(2);

SELECT has_table('scores');
SELECT has_table('score_categories');

SELECT league_id AS nfl_league_id FROM leagues WHERE name = 'NFL' LIMIT 1 \gset
INSERT INTO seasons (league_id, started_at, ended_at) VALUES (:nfl_league_id, now() - interval '1 day', now() + interval '3 months') RETURNING season_id new_season_id \gset

SELECT league_id AS nfl_league_id FROM leagues WHERE name = 'NFL' LIMIT 1 \gset
SELECT team_id AS seattle FROM teams JOIN league_divisions USING (league_division_id) WHERE teams.name = 'Seattle' AND league_id = :nfl_league_id \gset
SELECT team_id AS buffalo FROM teams JOIN league_divisions USING (league_division_id) WHERE teams.name = 'Buffalo' AND league_id = :nfl_league_id \gset

SELECT record_score(:seattle, 1, :new_season_id, 1, now());
SELECT record_score(:seattle, 2, :new_season_id, 1, now());
SELECT record_score(:buffalo, 2, :new_season_id, 1, now());

SELECT * FROM finish();
ROLLBACK;
