11import { init_tables , init_views , teardown } from "@db/init_tables" ;
22import { test_knexDb } from "@test/test_knexfile" ;
3- import type { MatchPlayer , MatchQuery , MatchReport } from "@v1/match/schemas" ;
3+ import type { MatchCharacterRecord } from "@v1/match/models" ;
4+ import type { MatchQuery , MatchReport } from "@v1/match/schemas" ;
45import {
56 createMatch ,
67 createMatchCharacter ,
@@ -9,9 +10,8 @@ import {
910 reportMatch ,
1011} from "@v1/match/service" ;
1112import { mock_MatchReport } from "@v1/match/test/mock.schemas" ;
13+ import { MatchReportDerivedRow } from "@v1/match/views" ;
1214import { afterEach , beforeEach , describe , expect , test } from "vitest" ;
13- import type { MatchCharacterRecord , MatchPlayerRecord } from "../models" ;
14- import { MatchReportDerivedRow } from "../views" ;
1515
1616// const _mockMatchReport = MatchReport.parse({
1717// guild_id: "19283746",
@@ -122,12 +122,12 @@ describe("Match DB operations", () => {
122122 const expected_match_characters = ( ) => {
123123 const result = [ ] ;
124124 for ( let p_i = 0 ; p_i < mockMatchReport . players . length ; p_i ++ ) {
125- const player = mockMatchReport . players [ p_i ] ;
126- for ( let c_i = 0 ; c_i < player . character . length ; c_i ++ ) {
127- const fighter_number = player . character [ c_i ] ;
125+ const { user_id , character } = mockMatchReport . players [ p_i ] ;
126+ for ( let c_i = 0 ; c_i < character . length ; c_i ++ ) {
127+ const fighter_number = character [ c_i ] ;
128128 result . push ( {
129129 match_id,
130- user_id : player . user_id ,
130+ user_id,
131131 fighter_number,
132132 } ) ;
133133 }
@@ -165,15 +165,15 @@ describe("Match DB operations", () => {
165165 describe ( "Insert all records for an entire MatchReport (covers all insertion tests)" , async ( ) => {
166166 test ( "Report a match" , async ( ) => {
167167 const match_id = await reportMatch ( mockMatchReport , test_knexDb ) ;
168- const match_record = await test_knexDb ( "Match" ) . first ( ) . where ( { match_id } ) ;
168+ const { guild_id } = mockMatchReport ;
169169 const match_player_records = await test_knexDb ( "MatchPlayer" )
170170 . select ( )
171171 . where ( { match_id } ) ;
172172 const match_character_records = await test_knexDb ( "MatchCharacter" )
173173 . select ( )
174174 . where ( { match_id } ) ;
175175 const expected : MatchReport = {
176- guild_id : match_record . guild_id ,
176+ guild_id,
177177 players : match_player_records . map ( ( { user_id, win_count } ) => ( {
178178 user_id,
179179 win_count,
@@ -203,25 +203,23 @@ describe("Match DB operations", () => {
203203 describe ( "Retrieve a full written MatchReport record" , async ( ) => {
204204 test ( "Retrieve a derived row from MatchReportView by match_id" , async ( ) => {
205205 const match_id = await reportMatch ( mockMatchReport , test_knexDb ) ;
206- const match_record = await test_knexDb ( "Match" )
207- . select ( )
208- . where ( { match_id } ) ;
206+ const { guild_id } = mockMatchReport ;
209207
210208 const match_query : MatchQuery = { match_id } ;
211209 const result = await getMatches ( match_query , test_knexDb ) ;
212210 const created_at = result [ 0 ] . created_at ;
213211
214212 const expected = [ ] ;
215213 for ( let p_i = 0 ; p_i < mockMatchReport . players . length ; p_i ++ ) {
216- const player = mockMatchReport . players [ p_i ] ;
217- for ( let c_i = 0 ; c_i < player . character . length ; c_i ++ ) {
218- const fighter_number = player . character [ c_i ] ;
214+ const { user_id , win_count , character } = mockMatchReport . players [ p_i ] ;
215+ for ( let c_i = 0 ; c_i < character . length ; c_i ++ ) {
216+ const fighter_number = character [ c_i ] ;
219217 expected . push (
220218 MatchReportDerivedRow . parse ( {
221219 match_id,
222- guild_id : mockMatchReport . guild_id ,
223- user_id : player . user_id ,
224- win_count : player . win_count ,
220+ guild_id,
221+ user_id,
222+ win_count,
225223 fighter_number,
226224 created_at,
227225 } ) ,
0 commit comments