@ -15,7 +15,7 @@ final class ServerDataTests: XCTestCase {
let password : String = " MyPass1234-- "
override func setUpWithError ( ) throws {
Store . main . synchronizationApiURL = " http://127.0.0.1:8000/roads/ "
StoreCenter . main . synchronizationApiURL = " http://127.0.0.1:8000/roads/ "
Task {
do {
try await self . login ( )
@ -31,7 +31,7 @@ final class ServerDataTests: XCTestCase {
func login ( ) async throws {
// p r i n t ( " L O G I N ! " )
let _ : User = try await Store . main . service ( ) . login ( username : self . username , password : self . password )
let _ : User = try await StoreCenter . main . service ( ) . login ( username : self . username , password : self . password )
}
func testClub ( ) async throws {
@ -47,7 +47,7 @@ final class ServerDataTests: XCTestCase {
club . phone = " 061234567890 "
club . courtCount = 3
let inserted_club : Club = try await Store . main . service ( ) . post ( club )
let inserted_club : Club = try await StoreCenter . main . service ( ) . post ( club )
assert ( inserted_club . name = = club . name )
assert ( inserted_club . acronym = = club . acronym )
assert ( inserted_club . zipCode = = club . zipCode )
@ -60,13 +60,13 @@ final class ServerDataTests: XCTestCase {
inserted_club . phone = " 123456 "
let updated_club : Club = try await Store . main . service ( ) . put ( inserted_club )
let updated_club : Club = try await StoreCenter . main . service ( ) . put ( inserted_club )
assert ( updated_club . phone = = inserted_club . phone )
}
func testLogin ( ) async throws {
let user : User = try await Store . main . service ( ) . login ( username : self . username , password : self . password )
let user : User = try await StoreCenter . main . service ( ) . login ( username : self . username , password : self . password )
assert ( user . username = = " test " )
}
@ -77,14 +77,14 @@ final class ServerDataTests: XCTestCase {
return
}
let clubs : [ Club ] = try await Store . main . service ( ) . get ( )
let clubs : [ Club ] = try await StoreCenter . main . service ( ) . get ( )
guard let clubId = clubs . first ? . id else {
assertionFailure ( " missing club in database " )
return
}
let event = Event ( creator : userId , club : clubId , name : " Roland Garros " , tenupId : " abc " )
let e = try await Store . main . service ( ) . post ( event )
let e = try await StoreCenter . main . service ( ) . post ( event )
assert ( e . name = = event . name )
assert ( e . tenupId = = event . tenupId )
@ -93,14 +93,14 @@ final class ServerDataTests: XCTestCase {
func testTournament ( ) async throws {
let event : [ Event ] = try await Store . main . service ( ) . get ( )
let event : [ Event ] = try await StoreCenter . main . service ( ) . get ( )
guard let eventId = event . first ? . id else {
assertionFailure ( " missing event in database " )
return
}
let tournament = Tournament ( event : eventId , name : " RG Homme " , startDate : Date ( ) , endDate : nil , creationDate : Date ( ) , isPrivate : false , groupStageFormat : MatchFormat . megaTie , roundFormat : MatchFormat . nineGames , loserRoundFormat : MatchFormat . nineGamesDecisivePoint , groupStageSortMode : GroupStageOrderingMode . snake , groupStageCount : 2 , rankSourceDate : Date ( ) , dayDuration : 5 , teamCount : 3 , teamSorting : TeamSortingType . rank , federalCategory : TournamentCategory . mix , federalLevelCategory : TournamentLevel . p1000 , federalAgeCategory : FederalTournamentAge . a45 , closedRegistrationDate : Date ( ) , groupStageAdditionalQualified : 4 , courtCount : 9 , prioritizeClubMembers : true , qualifiedPerGroupStage : 1 , teamsPerGroupStage : 2 , entryFee : 30.0 , additionalEstimationDuration : 5 , isDeleted : true , publishTeams : true , publishSummons : true , publishGroupStages : true , publishBrackets : true , shouldVerifyBracket : true , shouldVerifyGroupStage : true , hideTeamsWeight : true , publishTournament : true , hidePointsEarned : true , publishRankings : true )
let t = try await Store . main . service ( ) . post ( tournament )
let t = try await StoreCenter . main . service ( ) . post ( tournament )
assert ( t . event = = tournament . event )
assert ( t . name = = tournament . name )
@ -143,14 +143,14 @@ final class ServerDataTests: XCTestCase {
func testGroupStage ( ) async throws {
let tournament : [ Tournament ] = try await Store . main . service ( ) . get ( )
let tournament : [ Tournament ] = try await StoreCenter . main . service ( ) . get ( )
guard let tournamentId = tournament . first ? . id else {
assertionFailure ( " missing tournament in database " )
return
}
let groupStage = GroupStage ( tournament : tournamentId , index : 2 , size : 3 , matchFormat : MatchFormat . nineGames , startDate : Date ( ) , name : " Yeah! " )
let gs : GroupStage = try await Store . main . service ( ) . post ( groupStage )
let gs : GroupStage = try await StoreCenter . main . service ( ) . post ( groupStage )
assert ( gs . tournament = = groupStage . tournament )
assert ( gs . name = = groupStage . name )
@ -163,16 +163,16 @@ final class ServerDataTests: XCTestCase {
func testRound ( ) async throws {
let tournament : [ Tournament ] = try await Store . main . service ( ) . get ( )
let tournament : [ Tournament ] = try await StoreCenter . main . service ( ) . get ( )
guard let tournamentId = tournament . first ? . id else {
assertionFailure ( " missing tournament in database " )
return
}
let rounds : [ Round ] = try await Store . main . service ( ) . get ( )
let rounds : [ Round ] = try await StoreCenter . main . service ( ) . get ( )
let parentRoundId = rounds . first ? . id
let round = Round ( tournament : tournamentId , index : 1 , parent : parentRoundId , matchFormat : MatchFormat . nineGames , startDate : Date ( ) )
let r : Round = try await Store . main . service ( ) . post ( round )
let r : Round = try await StoreCenter . main . service ( ) . post ( round )
assert ( r . tournament = = round . tournament )
assert ( r . index = = round . index )
@ -184,12 +184,12 @@ final class ServerDataTests: XCTestCase {
func testTeamRegistration ( ) async throws {
let tournament : [ Tournament ] = try await Store . main . service ( ) . get ( )
let tournament : [ Tournament ] = try await StoreCenter . main . service ( ) . get ( )
guard let tournamentId = tournament . first ? . id else {
assertionFailure ( " missing tournament in database " )
return
}
let groupStages : [ GroupStage ] = try await Store . main . service ( ) . get ( )
let groupStages : [ GroupStage ] = try await StoreCenter . main . service ( ) . get ( )
guard let groupStageId = groupStages . first ? . id else {
assertionFailure ( " missing groupStage in database " )
return
@ -197,7 +197,7 @@ final class ServerDataTests: XCTestCase {
let teamRegistration = TeamRegistration ( tournament : tournamentId , groupStage : groupStageId , registrationDate : Date ( ) , callDate : Date ( ) , bracketPosition : 1 , groupStagePosition : 2 , comment : " comment " , source : " source " , sourceValue : " source V " , logo : " logo " , name : " Stax " , walkOut : true , wildCardBracket : true , wildCardGroupStage : true , weight : 1 , lockedWeight : 11 , confirmationDate : Date ( ) , qualified : true )
let tr : TeamRegistration = try await Store . main . service ( ) . post ( teamRegistration )
let tr : TeamRegistration = try await StoreCenter . main . service ( ) . post ( teamRegistration )
assert ( tr . tournament = = teamRegistration . tournament )
assert ( tr . groupStage = = teamRegistration . groupStage )
@ -222,14 +222,14 @@ final class ServerDataTests: XCTestCase {
func testPlayerRegistration ( ) async throws {
let teamRegistrations : [ TeamRegistration ] = try await Store . main . service ( ) . get ( )
let teamRegistrations : [ TeamRegistration ] = try await StoreCenter . main . service ( ) . get ( )
guard let teamRegistrationId = teamRegistrations . first ? . id else {
assertionFailure ( " missing teamRegistrations in database " )
return
}
let playerRegistration = PlayerRegistration ( teamRegistration : teamRegistrationId , firstName : " juan " , lastName : " lebron " , licenceId : " 123 " , rank : 11 , paymentType : PlayerRegistration . PlayerPaymentType . cash , sex : PlayerRegistration . PlayerSexType . male , tournamentPlayed : 2 , points : 33 , clubName : " le club " , ligueName : " la league " , assimilation : " ass " , phoneNumber : " 123123 " , email : " email@email.com " , birthdate : nil , computedRank : 222 , source : PlayerRegistration . PlayerDataSource . frenchFederation , hasArrived : true )
let pr : PlayerRegistration = try await Store . main . service ( ) . post ( playerRegistration )
let pr : PlayerRegistration = try await StoreCenter . main . service ( ) . post ( playerRegistration )
assert ( pr . teamRegistration = = playerRegistration . teamRegistration )
assert ( pr . firstName = = playerRegistration . firstName )
@ -253,16 +253,16 @@ final class ServerDataTests: XCTestCase {
func testMatch ( ) async throws {
let teamRegistrations : [ TeamRegistration ] = try await Store . main . service ( ) . get ( )
let teamRegistrations : [ TeamRegistration ] = try await StoreCenter . main . service ( ) . get ( )
guard let teamRegistrationId = teamRegistrations . first ? . id else {
assertionFailure ( " missing teamRegistrations in database " )
return
}
let rounds : [ Round ] = try await Store . main . service ( ) . get ( )
let rounds : [ Round ] = try await StoreCenter . main . service ( ) . get ( )
let parentRoundId = rounds . first ? . id
let match : Match = Match ( round : parentRoundId , groupStage : nil , startDate : Date ( ) , endDate : Date ( ) , index : 2 , matchFormat : MatchFormat . twoSets , servingTeamId : teamRegistrationId , winningTeamId : teamRegistrationId , losingTeamId : teamRegistrationId , disabled : true , courtIndex : 1 , confirmed : true )
let m : Match = try await Store . main . service ( ) . post ( match )
let m : Match = try await StoreCenter . main . service ( ) . post ( match )
assert ( m . round = = match . round )
assert ( m . groupStage = = match . groupStage )
@ -281,18 +281,18 @@ final class ServerDataTests: XCTestCase {
func testTeamScore ( ) async throws {
let matches : [ Match ] = try await Store . main . service ( ) . get ( )
let matches : [ Match ] = try await StoreCenter . main . service ( ) . get ( )
guard let matchId = matches . first ? . id else {
assertionFailure ( " missing match in database " )
return
}
let teamRegistrations : [ TeamRegistration ] = try await Store . main . service ( ) . get ( )
let teamRegistrations : [ TeamRegistration ] = try await StoreCenter . main . service ( ) . get ( )
guard let teamRegistrationId = teamRegistrations . first ? . id else {
assertionFailure ( " missing teamRegistrations in database " )
return
}
let teamScore = TeamScore ( match : matchId , teamRegistration : teamRegistrationId , score : " 6/6 " , walkOut : 1 , luckyLoser : 1 )
let ts : TeamScore = try await Store . main . service ( ) . post ( teamScore )
let ts : TeamScore = try await StoreCenter . main . service ( ) . post ( teamScore )
assert ( ts . match = = teamScore . match )
assert ( ts . teamRegistration = = teamScore . teamRegistration )
@ -304,14 +304,14 @@ final class ServerDataTests: XCTestCase {
func testCourt ( ) async throws {
let clubs : [ Club ] = try await Store . main . service ( ) . get ( )
let clubs : [ Club ] = try await StoreCenter . main . service ( ) . get ( )
guard let clubId = clubs . first ? . id else {
assertionFailure ( " missing club in database " )
return
}
let court = Court ( index : 1 , club : clubId , name : " Philippe Chatrier " , exitAllowed : true , indoor : true )
let c : Court = try await Store . main . service ( ) . post ( court )
let c : Court = try await StoreCenter . main . service ( ) . post ( court )
assert ( c . club = = court . club )
assert ( c . name = = court . name )
@ -323,14 +323,14 @@ final class ServerDataTests: XCTestCase {
func testDateInterval ( ) async throws {
let event : [ Event ] = try await Store . main . service ( ) . get ( )
let event : [ Event ] = try await StoreCenter . main . service ( ) . get ( )
guard let eventId = event . first ? . id else {
assertionFailure ( " missing event in database " )
return
}
let dateInterval = DateInterval ( event : eventId , courtIndex : 1 , startDate : Date ( ) , endDate : Date ( ) )
let di : PadelClub . DateInterval = try await Store . main . service ( ) . post ( dateInterval )
let di : PadelClub . DateInterval = try await StoreCenter . main . service ( ) . post ( dateInterval )
assert ( di . event = = dateInterval . event )
assert ( di . courtIndex = = dateInterval . courtIndex )
@ -346,16 +346,19 @@ final class ServerDataTests: XCTestCase {
return
}
let purchase : Purchase = Purchase ( user : userId , identifier : 1234 , purchaseDate : Date ( ) , productId : " productId " , quantity : 3 , revocationDate : Date ( ) )
let p : Purchase = try await Store . main . service ( ) . post ( purchase )
let transactionId = UInt64 . random ( in : 0. . . 100000 )
let quantity = Int . random ( in : 0. . . 10 )
let purchase : Purchase = Purchase ( user : userId , transactionId : transactionId , purchaseDate : Date ( ) , productId : " app.padelclub.productId " , quantity : quantity , revocationDate : Date ( ) , expirationDate : Date ( ) )
let p : Purchase = try await StoreCenter . main . service ( ) . post ( purchase )
assert ( p . id = = purchase . id )
assert ( p . identifier = = purchase . identifier )
assert ( p . us er = = purchase . us er)
assert ( p . productId = = purchase . productId )
assert ( p . purchaseDate . formatted ( ) = = purchase . purchaseDate . formatted ( ) )
assert ( p . quantity = = purchase . quantity )
assert ( p . user = = purchase . user )
assert ( p . revocationDate ? . formatted ( ) = = purchase . revocationDate ? . formatted ( ) )
assert ( p . expirationDate ? . formatted ( ) = = purchase . expirationDate ? . formatted ( ) )
}