diff options
author | sadbeast <sadbeast@sadbeast.com> | 2024-07-16 18:16:29 -0700 |
---|---|---|
committer | sadbeast <sadbeast@sadbeast.com> | 2024-10-05 16:40:55 -0700 |
commit | 6bd24af2ffbea91db1b10a5d5258980ce2068c7f (patch) | |
tree | 66634833f2d45260be5fcaf9111400eda12f03cc /test/db/seasons.sql | |
download | teamdraft-6bd24af2ffbea91db1b10a5d5258980ce2068c7f.tar.gz teamdraft-6bd24af2ffbea91db1b10a5d5258980ce2068c7f.tar.bz2 |
Diffstat (limited to 'test/db/seasons.sql')
-rw-r--r-- | test/db/seasons.sql | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/test/db/seasons.sql b/test/db/seasons.sql new file mode 100644 index 0000000..605f842 --- /dev/null +++ b/test/db/seasons.sql @@ -0,0 +1,28 @@ +BEGIN; +SELECT plan(12); + +SELECT has_table('seasons'); +SELECT columns_are('seasons', ARRAY[ 'season_id', 'league_id', 'started_at', 'ended_at', 'created_at', 'modified_at']); +SELECT has_sequence('seasons_season_id_seq'); +SELECT has_index('teamdraft', 'seasons', 'seasons_pk', 'season_id'); + +SELECT league_id AS nfl_league_id FROM leagues WHERE name = 'NFL' LIMIT 1 \gset +SELECT create_season(:nfl_league_id, now() - interval '1 day', now() + interval '3 months') new_season_id \gset + +SELECT is(1, (SELECT count(1)::int FROM seasons WHERE season_id = :new_season_id)); +SELECT is(:new_season_id, (SELECT current_season_id(:nfl_league_id))); + +-- rankings + +SELECT has_table('rankings'); +SELECT columns_are('rankings', ARRAY[ 'ranking_id', 'season_id', 'team_id', 'rank', 'created_at', 'modified_at']); +SELECT has_sequence('rankings_ranking_id_seq'); +SELECT has_index('teamdraft', 'rankings', 'rankings_pk', 'ranking_id primary key'); + +SELECT is((SELECT count(1) FROM teams JOIN league_divisions USING(league_division_id) WHERE league_id = :nfl_league_id), (SELECT count(1)::bigint FROM current_rankings WHERE season_id = :new_season_id)); +SELECT results_eq('SELECT season_id, league_id, name FROM current_rankings WHERE season_id = current_season_id(' || :'nfl_league_id' || ') ORDER BY rank LIMIT 2', + 'VALUES (' || :'new_season_id' || ',' || :'nfl_league_id' || $$, 'Buffalo'), ($$ || :'new_season_id' || ',' || :'nfl_league_id' || $$, 'Miami')$$, + 'current nfl season rankings'); + +SELECT * FROM finish(); +ROLLBACK; |