import path from 'path' ; const ROOT = path . join ( __dirname , '..' , '..' , '..' , '..' , '.env' ) ; import { config } from 'dotenv' ; config ( { path : ROOT } ) ; import '../lib/util/ErrorHandler' ; import * as log from '../lib/util/Logger' ; import _ from 'lodash' ; import moment from 'moment' ; import chai from 'chai' ; import cap from 'chai-as-promised' ; chai . use ( cap ) ; const { expect } = chai ; import { IPhase } from '../lib/interfaces/IPhase' ; import { Phase } from '../lib/models/Phase' ; import { PhaseGroup } from '../lib/models/PhaseGroup' ; import { GGSet } from '../lib/models/GGSet' ; import { Entrant } from '../lib/models/Entrant' ; import { Attendee } from '../lib/models/Attendee' ; import Initializer from '../lib/util/Initializer' ; import * as testData from './data/phase.testData' ; const LOG_LEVEL = log . levels . DEBUG ; const ID1 = 111483 ; const EVENT_ID_1 = 25545 ; const PHASE_1_PG_COUNT = 16 ; const PHASE_1_SET_COUNT = 232 ; const PHASE_1_ENTRANT_COUNT = 156 ; const PHASE_1_ATTENDEE_COUNT = 156 ; const ID2 = 45262 ; const EVENT_ID_2 = 11787 ; const PHASE_2_PG_COUNT = 25 ; const PHASE_2_SET_COUNT = 1164 ; const PHASE_2_ENTRANT_COUNT = 429 ; const PHASE_2_ATTENDEE_COUNT = 200 ; const ID3 = 100046 ; const EVENT_ID_3 = 23596 ; const PHASE_3_PG_COUNT = 16 ; const PHASE_3_SET_COUNT = 1164 ; const PHASE_3_ENTRANT_COUNT = 226 ; const PHASE_3_ATTENDEE_COUNT = 226 ; let phase1 ; let phase2 ; let phase3 ; describe ( 'Smash GG Phase' , function ( ) { this . timeout ( 10000 ) ; before ( async ( ) => { log . setLogLevel ( LOG_LEVEL ) ; await Initializer ( process . env . API_TOKEN ! ) ; phase1 = await Phase . get ( ID1 , EVENT_ID_1 ) ; phase2 = await Phase . get ( ID2 , EVENT_ID_2 ) ; phase3 = await Phase . get ( ID3 , EVENT_ID_3 ) ; return ; } ) ; it ( 'should get the correct id of the Phase 1' , ( ) => { expect ( phase1 . getId ( ) ) . to . be . equal ( testData . phase1 . id ) ; } ) ; it ( 'should get the correct id of the Phase 2' , ( ) => { expect ( phase2 . getId ( ) ) . to . be . equal ( testData . phase2 . id ) ; } ) ; it ( 'should get the correct id of the Phase 3' , ( ) => { expect ( phase3 . getId ( ) ) . to . be . equal ( testData . phase3 . id ) ; } ) ; it ( 'should get the name of the Phase 1' , ( ) => { expect ( phase1 . getName ( ) ) . to . be . equal ( testData . phase1 . name ) ; } ) ; it ( 'should get the name of the Phase 2' , ( ) => { expect ( phase2 . getName ( ) ) . to . be . equal ( testData . phase2 . name ) ; } ) ; it ( 'should get the name of the Phase 3' , ( ) => { expect ( phase3 . getName ( ) ) . to . be . equal ( testData . phase3 . name ) ; } ) ; it ( 'should get the event id 1' , ( ) => { expect ( phase1 . getEventId ( ) ) . to . be . equal ( EVENT_ID_1 ) ; } ) ; it ( 'should get the event id 2' , ( ) => { expect ( phase2 . getEventId ( ) ) . to . be . equal ( EVENT_ID_2 ) ; } ) ; it ( 'should get the event id 3' , ( ) => { expect ( phase3 . getEventId ( ) ) . to . be . equal ( EVENT_ID_3 ) ; } ) ; it ( 'should get the Phase num seeds 1' , ( ) => { expect ( phase1 . getNumSeeds ( ) ) . to . be . equal ( testData . phase1 . numSeeds ) ; } ) ; it ( 'should get the Phase num seeds 2' , ( ) => { expect ( phase2 . getNumSeeds ( ) ) . to . be . equal ( testData . phase2 . numSeeds ) ; } ) ; it ( 'should get the Phase num seeds 3' , ( ) => { expect ( phase3 . getNumSeeds ( ) ) . to . be . equal ( testData . phase3 . numSeeds ) ; } ) ; it ( 'should get the Phase group count 1' , ( ) => { expect ( phase1 . getGroupCount ( ) ) . to . be . equal ( testData . phase1 . groupCount ) ; } ) ; it ( 'should get the Phase group count 2' , ( ) => { expect ( phase2 . getGroupCount ( ) ) . to . be . equal ( testData . phase2 . groupCount ) ; } ) ; it ( 'should get the Phase group count 3' , ( ) => { expect ( phase3 . getGroupCount ( ) ) . to . be . equal ( testData . phase3 . groupCount ) ; } ) ; it ( 'should correctly get all sets 1' , async function ( ) { this . timeout ( 60000 ) ; await testSets ( phase1 , PHASE_1_SET_COUNT ) ; return true ; } ) ; xit ( 'should correctly get all sets 2' , async function ( ) { this . timeout ( 120000 ) ; await testSets ( phase2 , PHASE_2_SET_COUNT ) ; return true ; } ) ; xit ( 'should correctly get all sets 3' , async function ( ) { this . timeout ( 60000 ) ; await testSets ( phase3 , PHASE_3_SET_COUNT ) ; return true ; } ) ; it ( 'should correctly get all entrants 1' , async function ( ) { this . timeout ( 60000 ) ; await testEntrants ( phase1 , PHASE_1_ENTRANT_COUNT ) ; return true ; } ) ; xit ( 'should correctly get all entrants 2' , async function ( ) { this . timeout ( 30000 ) ; await testEntrants ( phase2 , PHASE_2_ENTRANT_COUNT ) ; return true ; } ) ; it ( 'should correctly get all entrants 3' , async function ( ) { this . timeout ( 30000 ) ; await testEntrants ( phase3 , PHASE_3_ENTRANT_COUNT ) ; return true ; } ) ; it ( 'should correctly get all attendees 1' , async function ( ) { this . timeout ( 30000 ) ; await testAttendees ( phase1 , PHASE_1_ATTENDEE_COUNT ) ; return true ; } ) ; xit ( 'should correctly get all attendees 2' , async function ( ) { this . timeout ( 30000 ) ; await testAttendees ( phase2 , PHASE_2_ATTENDEE_COUNT ) ; return true ; } ) ; it ( 'should correctly get all attendees 3' , async function ( ) { this . timeout ( 60000 ) ; await testAttendees ( phase3 , PHASE_3_ATTENDEE_COUNT ) ; return true ; } ) ; it ( 'should correctly get all phase groups 1' , async function ( ) { this . timeout ( 30000 ) ; await testPhaseGroups ( phase1 , PHASE_1_PG_COUNT ) ; return true ; } ) ; it ( 'should correctly get all phase groups 2' , async function ( ) { this . timeout ( 30000 ) ; await testPhaseGroups ( phase2 , PHASE_2_PG_COUNT ) ; return true ; } ) ; it ( 'should correctly get all phase groups 3' , async function ( ) { this . timeout ( 30000 ) ; await testPhaseGroups ( phase3 , PHASE_3_PG_COUNT ) ; return true ; } ) ; } ) ; async function testSets ( phase , expected ) { const arr = await phase . getSets ( ) ; arr . forEach ( set => { expect ( set ) . to . be . an . instanceof ( GGSet ) ; expect ( arr . filter ( x => x . getId ( ) === set . getId ( ) ) . length , 'Set array must not have duplicates! Found: ' + set . getId ( ) ) . to . be . equal ( 1 ) ; } ) ; expect ( arr . length ) . to . be . equal ( expected ) ; } async function testEntrants ( phase , expected ) { const arr = await phase . getEntrants ( ) ; arr . forEach ( entrant => { expect ( entrant ) . to . be . an . instanceof ( Entrant ) ; expect ( arr . filter ( x => x . getId ( ) === entrant . getId ( ) ) . length , 'Entrant array must not have duplicates! Found: ' + entrant . getId ( ) ) . to . be . equal ( 1 ) ; } ) ; expect ( arr . length ) . to . be . equal ( expected ) ; } async function testAttendees ( phase , expected ) { const arr = await phase . getAttendees ( ) ; arr . forEach ( attendee => { expect ( attendee ) . to . be . an . instanceof ( Attendee ) ; expect ( arr . filter ( x => x . getId ( ) === attendee . getId ( ) ) . length , 'Attendee array must not have duplicates! Found: ' + attendee . getId ( ) ) . to . be . equal ( 1 ) ; } ) ; expect ( arr . length ) . to . be . equal ( expected ) ; } async function testPhaseGroups ( phase , expected ) { const arr = await phase . getPhaseGroups ( ) ; arr . forEach ( group => { expect ( group ) . to . be . an . instanceof ( PhaseGroup ) ; expect ( arr . filter ( x => x . getId ( ) === group . getId ( ) ) . length , 'Phase Group array must not have duplicates! Found: ' + group . getId ( ) ) . to . be . equal ( 1 ) ; } ) ; expect ( arr . length ) . to . be . equal ( expected ) ; }