From 6bd24af2ffbea91db1b10a5d5258980ce2068c7f Mon Sep 17 00:00:00 2001
From: sadbeast <sadbeast@sadbeast.com>
Date: Tue, 16 Jul 2024 18:16:29 -0700
Subject: let's go

---
 test/db/seasons.sql | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)
 create mode 100644 test/db/seasons.sql

(limited to 'test/db/seasons.sql')

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;
-- 
cgit v1.2.3

