1- import { init_tables , init_views , seed_db } from "@db/init_tables" ;
1+ import { InsertSeedSource } from "@db/CustomSeedSource" ;
2+ import { init_tables , init_views } from "@db/init_tables" ;
23import { knexDb } from "@db/knexfile" ;
34import type { GuildSeasonRecord } from "@v1/guild/models" ;
45import {
@@ -12,23 +13,6 @@ import type { Knex } from "knex";
1213import { afterEach , beforeEach , describe , expect , test } from "vitest" ;
1314import { guildSeasonRecordFactory } from "./models.factories" ;
1415
15- export class TestSeedSource {
16- seeds : Array < ( knex : Knex ) => Promise < void > > ;
17- constructor ( seeds : Array < ( knex : Knex ) => Promise < void > > ) {
18- this . seeds = seeds ;
19- }
20-
21- getSeeds ( ) {
22- return Promise . resolve ( this . seeds ) ;
23- }
24-
25- async getSeed ( seed : ( knex : Knex ) => Promise < void > ) {
26- return {
27- seed,
28- } ;
29- }
30- }
31-
3216beforeEach ( async ( ) => {
3317 await init_tables ( knexDb ) ;
3418 await init_views ( knexDb ) ;
@@ -47,14 +31,9 @@ describe("GuildSeason table operations", () => {
4731 let guild_id : string ;
4832 beforeEach ( async ( ) => {
4933 season_record = currentSeasonRecordFactory ( ) ;
50- await seed_db (
51- new TestSeedSource ( [
52- async ( knex : Knex ) => {
53- await knex ( "Season" ) . insert ( season_record ) ;
54- } ,
55- ] ) ,
56- knexDb ,
57- ) ;
34+ await knexDb . seed . run ( {
35+ seedSource : new InsertSeedSource ( { Season : [ season_record ] } ) ,
36+ } ) ;
5837
5938 season_id = await knexDb ( "Season" )
6039 . first ( )
@@ -63,14 +42,11 @@ describe("GuildSeason table operations", () => {
6342
6443 guild_season_record = guildSeasonRecordFactory ( { season_id } ) ;
6544 guild_id = guild_season_record . guild_id ;
66- await seed_db (
67- new TestSeedSource ( [
68- async ( knex : Knex ) => {
69- await knex ( "GuildSeason" ) . insert ( guild_season_record ) ;
70- } ,
71- ] ) ,
72- knexDb ,
73- ) ;
45+ await knexDb . seed . run ( {
46+ seedSource : new InsertSeedSource ( {
47+ GuildSeason : [ guild_season_record ] ,
48+ } ) ,
49+ } ) ;
7450 } ) ;
7551 test ( "Nominal" , async ( ) => {
7652 expect (
@@ -85,14 +61,9 @@ describe("GuildSeason table operations", () => {
8561 let season_id : number ;
8662 beforeEach ( async ( ) => {
8763 season_record = currentSeasonRecordFactory ( ) ;
88- await seed_db (
89- new TestSeedSource ( [
90- async ( knex : Knex ) => {
91- await knex ( "Season" ) . insert ( season_record ) ;
92- } ,
93- ] ) ,
94- knexDb ,
95- ) ;
64+ await knexDb . seed . run ( {
65+ seedSource : new InsertSeedSource ( { Season : [ season_record ] } ) ,
66+ } ) ;
9667
9768 season_id = await knexDb ( "Season" )
9869 . first ( )
@@ -131,15 +102,11 @@ describe("GuildSeason table operations", () => {
131102 beforeEach ( async ( ) => {
132103 old_season_record = currentSeasonRecordFactory ( ) ;
133104 new_season_record = currentSeasonRecordFactory ( ) ;
134- await seed_db (
135- new TestSeedSource ( [
136- async ( knex : Knex ) => {
137- await knex ( "Season" ) . insert ( old_season_record ) ;
138- await knex ( "Season" ) . insert ( new_season_record ) ;
139- } ,
140- ] ) ,
141- knexDb ,
142- ) ;
105+ await knexDb . seed . run ( {
106+ seedSource : new InsertSeedSource ( {
107+ Season : [ old_season_record , new_season_record ] ,
108+ } ) ,
109+ } ) ;
143110 const old_season_id = await await knexDb ( "Season" )
144111 . first ( )
145112 . where ( new_season_record )
@@ -152,14 +119,11 @@ describe("GuildSeason table operations", () => {
152119 guild_season_record = guildSeasonRecordFactory ( {
153120 season_id : old_season_id ,
154121 } ) ;
155- await seed_db (
156- new TestSeedSource ( [
157- async ( knex : Knex ) => {
158- await knex ( "GuildSeason" ) . insert ( guild_season_record ) ;
159- } ,
160- ] ) ,
161- knexDb ,
162- ) ;
122+ await knexDb . seed . run ( {
123+ seedSource : new InsertSeedSource ( {
124+ GuildSeason : [ guild_season_record ] ,
125+ } ) ,
126+ } ) ;
163127 } ) ;
164128 describe ( "Updating an existing `GuildSeason` record" , ( ) => {
165129 test ( "Nominal" , async ( ) => {
0 commit comments