Adds basic server tests

multistore
Laurent 2 years ago
parent 27beca502b
commit bd35ba54db
  1. 4
      PadelClub.xcodeproj/project.pbxproj
  2. 12
      PadelClub/Data/Court.swift
  3. 3
      PadelClub/Data/GroupStage.swift
  4. 6
      PadelClub/Data/Match.swift
  5. 2
      PadelClub/Data/MockData.swift
  6. 12
      PadelClub/Data/PlayerRegistration.swift
  7. 5
      PadelClub/Data/Round.swift
  8. 10
      PadelClub/Data/TeamRegistration.swift
  9. 11
      PadelClub/Data/TeamScore.swift
  10. 10
      PadelClub/Data/Tournament.swift
  11. 2
      PadelClub/Views/Tournament/Screen/Components/TournamentClubSettingsView.swift
  12. 6
      PadelClubTests/PaymentTests.swift
  13. 417
      PadelClubTests/ServerDataTests.swift

@ -7,6 +7,7 @@
objects = { objects = {
/* Begin PBXBuildFile section */ /* Begin PBXBuildFile section */
C411C9C32BEBA453003017AD /* ServerDataTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C411C9C22BEBA453003017AD /* ServerDataTests.swift */; };
C425D4012B6D249D002A7B48 /* PadelClubApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = C425D4002B6D249D002A7B48 /* PadelClubApp.swift */; }; C425D4012B6D249D002A7B48 /* PadelClubApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = C425D4002B6D249D002A7B48 /* PadelClubApp.swift */; };
C425D4052B6D249E002A7B48 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = C425D4042B6D249E002A7B48 /* Assets.xcassets */; }; C425D4052B6D249E002A7B48 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = C425D4042B6D249E002A7B48 /* Assets.xcassets */; };
C425D4082B6D249E002A7B48 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = C425D4072B6D249E002A7B48 /* Preview Assets.xcassets */; }; C425D4082B6D249E002A7B48 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = C425D4072B6D249E002A7B48 /* Preview Assets.xcassets */; };
@ -300,6 +301,7 @@
/* End PBXCopyFilesBuildPhase section */ /* End PBXCopyFilesBuildPhase section */
/* Begin PBXFileReference section */ /* Begin PBXFileReference section */
C411C9C22BEBA453003017AD /* ServerDataTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ServerDataTests.swift; sourceTree = "<group>"; };
C425D3FD2B6D249D002A7B48 /* PadelClub.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = PadelClub.app; sourceTree = BUILT_PRODUCTS_DIR; }; C425D3FD2B6D249D002A7B48 /* PadelClub.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = PadelClub.app; sourceTree = BUILT_PRODUCTS_DIR; };
C425D4002B6D249D002A7B48 /* PadelClubApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PadelClubApp.swift; sourceTree = "<group>"; }; C425D4002B6D249D002A7B48 /* PadelClubApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PadelClubApp.swift; sourceTree = "<group>"; };
C425D4042B6D249E002A7B48 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; }; C425D4042B6D249E002A7B48 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
@ -645,6 +647,7 @@
children = ( children = (
C425D4112B6D249E002A7B48 /* PadelClubTests.swift */, C425D4112B6D249E002A7B48 /* PadelClubTests.swift */,
C49EF0412BE23BF50077B5AA /* PaymentTests.swift */, C49EF0412BE23BF50077B5AA /* PaymentTests.swift */,
C411C9C22BEBA453003017AD /* ServerDataTests.swift */,
); );
path = PadelClubTests; path = PadelClubTests;
sourceTree = "<group>"; sourceTree = "<group>";
@ -1637,6 +1640,7 @@
files = ( files = (
C49EF0422BE23BF50077B5AA /* PaymentTests.swift in Sources */, C49EF0422BE23BF50077B5AA /* PaymentTests.swift in Sources */,
C425D4122B6D249E002A7B48 /* PadelClubTests.swift in Sources */, C425D4122B6D249E002A7B48 /* PadelClubTests.swift in Sources */,
C411C9C32BEBA453003017AD /* ServerDataTests.swift in Sources */,
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
}; };

@ -28,12 +28,20 @@ class Court : ModelObject, Storable, Hashable {
var exitAllowed: Bool = false var exitAllowed: Bool = false
var indoor: Bool = false var indoor: Bool = false
internal init(club: String, name: String? = nil, index: Int) { init(index: Int, club: String, name: String? = nil, exitAllowed: Bool = false, indoor: Bool = false) {
self.index = index
self.club = club self.club = club
self.name = name self.name = name
self.index = index self.exitAllowed = exitAllowed
self.indoor = indoor
} }
// internal init(club: String, name: String? = nil, index: Int) {
// self.club = club
// self.name = name
// self.index = index
// }
func courtTitle() -> String { func courtTitle() -> String {
self.name ?? courtIndexTitle() self.name ?? courtIndexTitle()
} }

@ -31,12 +31,13 @@ class GroupStage: ModelObject, Storable {
} }
} }
internal init(tournament: String, index: Int, size: Int, matchFormat: MatchFormat? = nil, startDate: Date? = nil) { internal init(tournament: String, index: Int, size: Int, matchFormat: MatchFormat? = nil, startDate: Date? = nil, name: String? = nil) {
self.tournament = tournament self.tournament = tournament
self.index = index self.index = index
self.size = size self.size = size
self.format = matchFormat self.format = matchFormat
self.startDate = startDate self.startDate = startDate
self.name = name
} }
func teamAt(groupStagePosition: Int) -> TeamRegistration? { func teamAt(groupStagePosition: Int) -> TeamRegistration? {

@ -30,7 +30,7 @@ class Match: ModelObject, Storable {
var disabled: Bool = false var disabled: Bool = false
private(set) var courtIndex: Int? private(set) var courtIndex: Int?
internal init(round: String? = nil, groupStage: String? = nil, startDate: Date? = nil, endDate: Date? = nil, index: Int, matchFormat: MatchFormat? = nil, servingTeamId: String? = nil, winningTeamId: String? = nil, losingTeamId: String? = nil) { internal init(round: String? = nil, groupStage: String? = nil, startDate: Date? = nil, endDate: Date? = nil, index: Int, matchFormat: MatchFormat? = nil, servingTeamId: String? = nil, winningTeamId: String? = nil, losingTeamId: String? = nil, disabled: Bool = false, courtIndex: Int? = nil) {
self.round = round self.round = round
self.groupStage = groupStage self.groupStage = groupStage
self.startDate = startDate self.startDate = startDate
@ -41,6 +41,10 @@ class Match: ModelObject, Storable {
self.servingTeamId = servingTeamId self.servingTeamId = servingTeamId
self.winningTeamId = winningTeamId self.winningTeamId = winningTeamId
self.losingTeamId = losingTeamId self.losingTeamId = losingTeamId
self.disabled = disabled
self.courtIndex = courtIndex
// self.broadcasted = broadcasted // self.broadcasted = broadcasted
// self.name = name // self.name = name
// self.order = order // self.order = order

@ -9,7 +9,7 @@ import Foundation
extension Court { extension Court {
static func mock() -> Court { static func mock() -> Court {
Court(club: "", name: "Test", index: 0) Court(index: 0, club: "", name: "Test")
} }
} }

@ -36,7 +36,7 @@ class PlayerRegistration: ModelObject, Storable {
var hasArrived: Bool = false var hasArrived: Bool = false
internal init(teamRegistration: String? = nil, firstName: String, lastName: String, licenceId: String? = nil, rank: Int? = nil, paymentType: PlayerPaymentType? = nil, sex: PlayerSexType?, source: PlayerDataSource? = nil) { init(teamRegistration: String? = nil, firstName: String, lastName: String, licenceId: String? = nil, rank: Int? = nil, paymentType: PlayerPaymentType? = nil, sex: PlayerSexType? = nil, tournamentPlayed: Int? = nil, points: Double? = nil, clubName: String? = nil, ligueName: String? = nil, assimilation: String? = nil, phoneNumber: String? = nil, email: String? = nil, birthdate: String? = nil, computedRank: Int = 0, source: PlayerDataSource? = nil, hasArrived: Bool = false) {
self.teamRegistration = teamRegistration self.teamRegistration = teamRegistration
self.firstName = firstName self.firstName = firstName
self.lastName = lastName self.lastName = lastName
@ -44,7 +44,17 @@ class PlayerRegistration: ModelObject, Storable {
self.rank = rank self.rank = rank
self.paymentType = paymentType self.paymentType = paymentType
self.sex = sex self.sex = sex
self.tournamentPlayed = tournamentPlayed
self.points = points
self.clubName = clubName
self.ligueName = ligueName
self.assimilation = assimilation
self.phoneNumber = phoneNumber
self.email = email
self.birthdate = birthdate
self.computedRank = computedRank
self.source = source self.source = source
self.hasArrived = hasArrived
} }
internal init(importedPlayer: ImportedPlayer) { internal init(importedPlayer: ImportedPlayer) {

@ -17,14 +17,15 @@ class Round: ModelObject, Storable {
var tournament: String var tournament: String
var index: Int var index: Int
var parent: String? var parent: String?
private var format: MatchFormat? private(set) var format: MatchFormat?
var startDate: Date? var startDate: Date?
internal init(tournament: String, index: Int, parent: String? = nil, matchFormat: MatchFormat? = nil) { internal init(tournament: String, index: Int, parent: String? = nil, matchFormat: MatchFormat? = nil, startDate: Date? = nil) {
self.tournament = tournament self.tournament = tournament
self.index = index self.index = index
self.parent = parent self.parent = parent
self.format = matchFormat self.format = matchFormat
self.startDate = startDate
} }
var matchFormat: MatchFormat { var matchFormat: MatchFormat {

@ -33,7 +33,7 @@ class TeamRegistration: ModelObject, Storable {
var confirmationDate: Date? var confirmationDate: Date?
var qualified: Bool = false var qualified: Bool = false
internal init(tournament: String, groupStage: String? = nil, registrationDate: Date? = nil, callDate: Date? = nil, bracketPosition: Int? = nil, groupStagePosition: Int? = nil, comment: String? = nil, source: String? = nil, sourceValue: String? = nil, logo: String? = nil, name: String? = nil) { init(tournament: String, groupStage: String? = nil, registrationDate: Date? = nil, callDate: Date? = nil, bracketPosition: Int? = nil, groupStagePosition: Int? = nil, comment: String? = nil, source: String? = nil, sourceValue: String? = nil, logo: String? = nil, name: String? = nil, walkOut: Bool = false, wildCardBracket: Bool = false, wildCardGroupStage: Bool = false, weight: Int = 0, lockWeight: Int? = nil, confirmationDate: Date? = nil, qualified: Bool = false) {
self.tournament = tournament self.tournament = tournament
self.groupStage = groupStage self.groupStage = groupStage
self.registrationDate = registrationDate self.registrationDate = registrationDate
@ -45,6 +45,13 @@ class TeamRegistration: ModelObject, Storable {
self.sourceValue = sourceValue self.sourceValue = sourceValue
self.logo = logo self.logo = logo
self.name = name self.name = name
self.walkOut = walkOut
self.wildCardBracket = wildCardBracket
self.wildCardGroupStage = wildCardGroupStage
self.weight = weight
self.lockWeight = lockWeight
self.confirmationDate = confirmationDate
self.qualified = qualified
} }
func isSeedable() -> Bool { func isSeedable() -> Bool {
@ -339,6 +346,7 @@ class TeamRegistration: ModelObject, Storable {
case _confirmationDate = "confirmationDate" case _confirmationDate = "confirmationDate"
case _qualified = "qualified" case _qualified = "qualified"
} }
} }
extension TeamRegistration: Hashable { extension TeamRegistration: Hashable {

@ -21,7 +21,16 @@ class TeamScore: ModelObject, Storable {
var walkOut: Int? var walkOut: Int?
var luckyLoser: Int? var luckyLoser: Int?
internal init(match: String, team: TeamRegistration?) { init(match: String, teamRegistration: String? = nil, playerRegistrations: [String], score: String? = nil, walkOut: Int? = nil, luckyLoser: Int? = nil) {
self.match = match
self.teamRegistration = teamRegistration
self.playerRegistrations = playerRegistrations
self.score = score
self.walkOut = walkOut
self.luckyLoser = luckyLoser
}
init(match: String, team: TeamRegistration?) {
self.match = match self.match = match
if let team { if let team {
self.teamRegistration = team.id self.teamRegistration = team.id

@ -19,9 +19,9 @@ class Tournament : ModelObject, Storable {
var endDate: Date? var endDate: Date?
private(set) var creationDate: Date private(set) var creationDate: Date
var isPrivate: Bool var isPrivate: Bool
private var groupStageFormat: MatchFormat? private(set) var groupStageFormat: MatchFormat?
private var roundFormat: MatchFormat? private(set) var roundFormat: MatchFormat?
private var loserRoundFormat: MatchFormat? private(set) var loserRoundFormat: MatchFormat?
var groupStageSortMode: GroupStageOrderingMode var groupStageSortMode: GroupStageOrderingMode
var groupStageCount: Int var groupStageCount: Int
var rankSourceDate: Date? var rankSourceDate: Date?
@ -83,7 +83,7 @@ class Tournament : ModelObject, Storable {
case _payment = "globalId" case _payment = "globalId"
} }
internal init(event: String? = nil, name: String? = nil, startDate: Date = Date(), endDate: Date? = nil, creationDate: Date = Date(), isPrivate: Bool = true, groupStageFormat: MatchFormat? = nil, roundFormat: MatchFormat? = nil, loserRoundFormat: MatchFormat? = nil, groupStageSortMode: GroupStageOrderingMode, groupStageCount: Int = 4, rankSourceDate: Date? = nil, dayDuration: Int = 1, teamCount: Int = 24, teamSorting: TeamSortingType? = nil, federalCategory: TournamentCategory, federalLevelCategory: TournamentLevel, federalAgeCategory: FederalTournamentAge, groupStageCourtCount: Int? = nil, closedRegistrationDate: Date? = nil, groupStageAdditionalQualified: Int = 0, courtCount: Int = 2, prioritizeClubMembers: Bool = false, qualifiedPerGroupStage: Int = 1, teamsPerGroupStage: Int = 4, entryFee: Double? = nil) { internal init(event: String? = nil, name: String? = nil, startDate: Date = Date(), endDate: Date? = nil, creationDate: Date = Date(), isPrivate: Bool = true, groupStageFormat: MatchFormat? = nil, roundFormat: MatchFormat? = nil, loserRoundFormat: MatchFormat? = nil, groupStageSortMode: GroupStageOrderingMode, groupStageCount: Int = 4, rankSourceDate: Date? = nil, dayDuration: Int = 1, teamCount: Int = 24, teamSorting: TeamSortingType? = nil, federalCategory: TournamentCategory, federalLevelCategory: TournamentLevel, federalAgeCategory: FederalTournamentAge, groupStageCourtCount: Int? = nil, closedRegistrationDate: Date? = nil, groupStageAdditionalQualified: Int = 0, courtCount: Int = 2, prioritizeClubMembers: Bool = false, qualifiedPerGroupStage: Int = 1, teamsPerGroupStage: Int = 4, entryFee: Double? = nil, additionalEstimationDuration: Int = 0, isDeleted: Bool = false) {
self.event = event self.event = event
self.name = name self.name = name
self.startDate = startDate self.startDate = startDate
@ -110,6 +110,8 @@ class Tournament : ModelObject, Storable {
self.qualifiedPerGroupStage = qualifiedPerGroupStage self.qualifiedPerGroupStage = qualifiedPerGroupStage
self.teamsPerGroupStage = teamsPerGroupStage self.teamsPerGroupStage = teamsPerGroupStage
self.entryFee = entryFee self.entryFee = entryFee
self.additionalEstimationDuration = additionalEstimationDuration
self.isDeleted = isDeleted
} }
required init(from decoder: Decoder) throws { required init(from decoder: Decoder) throws {

@ -100,7 +100,7 @@ struct TournamentClubSettingsView: View {
} else { } else {
LabeledContent { LabeledContent {
FooterButtonView("personnaliser") { FooterButtonView("personnaliser") {
let court = Court(club: tournamentClub.id, index: index) let court = Court(index: index, club: tournamentClub.id)
try? dataStore.courts.addOrUpdate(instance: court) try? dataStore.courts.addOrUpdate(instance: court)
selectedCourt = court selectedCourt = court
} }

@ -67,12 +67,6 @@ final class PaymentTests: XCTestCase {
assertionFailure(error.localizedDescription) assertionFailure(error.localizedDescription)
} }
// tournament.setCanceled(true)
// assert(tournament.decryptCanceled() == true)
// tournament.setCanceled(false)
// assert(tournament.decryptCanceled() == false)
} }
} }

@ -0,0 +1,417 @@
//
// ServerDataTests.swift
// PadelClubTests
//
// Created by Laurent Morvillier on 08/05/2024.
//
import XCTest
import LeStorage
@testable import PadelClub
final class ServerDataTests: XCTestCase {
let username: String = "test"
override func setUpWithError() throws {
Store.main.synchronizationApiURL = "http://127.0.0.1:8000/api/"
}
override func tearDownWithError() throws {
// Put teardown code here. This method is called after the invocation of each test method in the class.
}
func testClub() async throws {
let club = Club(name: "Aix Universite Club")
club.acronym = "AUC"
club.city = "Aix en provence"
club.zipCode = "13100"
club.code = "abc"
club.address = "2 avenue de la vie"
club.latitude = 13
club.longitude = 10
club.phone = "061234567890"
let inserted_club: Club = try await Store.main.service().post(club)
assert(inserted_club.name == club.name)
assert(inserted_club.acronym == club.acronym)
assert(inserted_club.zipCode == club.zipCode)
assert(inserted_club.address == club.address)
assert(inserted_club.latitude == club.latitude)
assert(inserted_club.longitude == club.longitude)
assert(inserted_club.phone == club.phone)
inserted_club.phone = "123456"
let updated_club: Club = try await Store.main.service().put(inserted_club)
assert(updated_club.phone == inserted_club.phone)
}
func testUserCreation() async throws {
let userCreationForm = UserCreationForm(username: self.username, password: "MyPass1234--", firstName: "jean", lastName: "coco", email: "laurent@staxriver.com", phone: "0123", country: "France")
let user: User = try await Store.main.service().createAccount(user: userCreationForm)
assert(user.username == userCreationForm.username)
assert(user.firstName == userCreationForm.firstName)
assert(user.lastName == userCreationForm.lastName)
assert(user.email == userCreationForm.email)
assert(user.phone == userCreationForm.phone)
assert(user.country == userCreationForm.country)
}
func createUser() async throws -> User {
let userCreationForm = UserCreationForm(username: "test", password: "MyPass1234--", firstName: "jean", lastName: "coco", email: "laurent@staxriver.com", phone: "0123", country: "France")
return try await Store.main.service().createAccount(user: userCreationForm)
}
func testLogin() async throws {
let user: User = try await Store.main.service().login(username: "test", password: "MyPass1234--")
assert(user.username == "test")
}
func login() async throws {
let _: User = try await Store.main.service().login(username: "test", password: "MyPass1234--")
}
func testEvent() async throws {
do {
try await self.login()
} catch {
let _ = try await self.createUser()
try await self.login()
}
guard let userId = Store.main.currentUserUUID?.uuidString else {
assertionFailure("missing user UUID")
return
}
let clubs: [Club] = try await Store.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)
assert(e.name == event.name)
assert(e.tenupId == event.tenupId)
}
func testTournament() async throws {
do {
try await self.login()
} catch {
let _ = try await self.createUser()
try await self.login()
}
let event: [Event] = try await Store.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, groupStageCourtCount: 6, closedRegistrationDate: Date(), groupStageAdditionalQualified: 4, courtCount: 9, prioritizeClubMembers: true, qualifiedPerGroupStage: 1, teamsPerGroupStage: 2, entryFee: 30.0, additionalEstimationDuration: 5, isDeleted: true)
let t = try await Store.main.service().post(tournament)
assert(t.event == tournament.event)
assert(t.name == tournament.name)
assert(t.startDate.formatted() == tournament.startDate.formatted())
assert(t.endDate?.formatted() == tournament.endDate?.formatted())
assert(t.creationDate.formatted() == tournament.creationDate.formatted())
assert(t.isPrivate == tournament.isPrivate)
assert(t.groupStageFormat == tournament.groupStageFormat)
assert(t.roundFormat == tournament.roundFormat)
assert(t.loserRoundFormat == tournament.loserRoundFormat)
assert(t.groupStageSortMode == tournament.groupStageSortMode)
assert(t.groupStageCount == tournament.groupStageCount)
assert(t.rankSourceDate?.formatted() == tournament.rankSourceDate?.formatted())
assert(t.dayDuration == tournament.dayDuration)
assert(t.teamCount == tournament.teamCount)
assert(t.teamSorting == tournament.teamSorting)
assert(t.federalCategory == tournament.federalCategory)
assert(t.federalLevelCategory == tournament.federalLevelCategory)
assert(t.federalAgeCategory == tournament.federalAgeCategory)
assert(t.groupStageCourtCount == tournament.groupStageCourtCount)
assert(t.closedRegistrationDate?.formatted() == tournament.closedRegistrationDate?.formatted())
assert(t.groupStageAdditionalQualified == tournament.groupStageAdditionalQualified)
assert(t.courtCount == tournament.courtCount)
assert(t.prioritizeClubMembers == tournament.prioritizeClubMembers)
assert(t.qualifiedPerGroupStage == tournament.qualifiedPerGroupStage)
assert(t.teamsPerGroupStage == tournament.teamsPerGroupStage)
assert(t.entryFee == tournament.entryFee)
assert(t.additionalEstimationDuration == tournament.additionalEstimationDuration)
assert(t.isDeleted == tournament.isDeleted)
}
func testGroupStage() async throws {
do {
try await self.login()
} catch {
let _ = try await self.createUser()
try await self.login()
}
let tournament: [Tournament] = try await Store.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)
assert(gs.tournament == groupStage.tournament)
assert(gs.name == groupStage.name)
assert(gs.index == groupStage.index)
assert(gs.size == groupStage.size)
assert(gs.matchFormat == groupStage.matchFormat)
assert(gs.startDate != nil)
}
func testRound() async throws {
do {
try await self.login()
} catch {
let _ = try await self.createUser()
try await self.login()
}
let tournament: [Tournament] = try await Store.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 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)
assert(r.tournament == round.tournament)
assert(r.index == round.index)
assert(r.parent == round.parent)
assert(r.matchFormat == round.matchFormat)
assert(r.startDate != nil)
}
func testTeamRegistration() async throws {
do {
try await self.login()
} catch {
let _ = try await self.createUser()
try await self.login()
}
let tournament: [Tournament] = try await Store.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()
guard let groupStageId = groupStages.first?.id else {
assertionFailure("missing groupStage in database")
return
}
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, lockWeight: 11, confirmationDate: Date(), qualified: true)
let tr: TeamRegistration = try await Store.main.service().post(teamRegistration)
assert(tr.tournament == teamRegistration.tournament)
assert(tr.groupStage == teamRegistration.groupStage)
assert(tr.registrationDate != nil)
assert(tr.callDate != nil)
assert(tr.bracketPosition == teamRegistration.bracketPosition)
assert(tr.groupStagePosition == teamRegistration.groupStagePosition)
assert(tr.comment == teamRegistration.comment)
assert(tr.source == teamRegistration.source)
assert(tr.sourceValue == teamRegistration.sourceValue)
assert(tr.logo == teamRegistration.logo)
assert(tr.name == teamRegistration.name)
assert(tr.walkOut == teamRegistration.walkOut)
assert(tr.wildCardBracket == teamRegistration.wildCardBracket)
assert(tr.wildCardGroupStage == teamRegistration.wildCardGroupStage)
assert(tr.weight == teamRegistration.weight)
assert(tr.lockWeight == teamRegistration.lockWeight)
// assert(tr.confirmationDate != nil)
assert(tr.qualified == teamRegistration.qualified)
}
func testPlayerRegistration() async throws {
do {
try await self.login()
} catch {
let _ = try await self.createUser()
try await self.login()
}
let teamRegistrations: [TeamRegistration] = try await Store.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)
assert(pr.teamRegistration == playerRegistration.teamRegistration)
assert(pr.firstName == playerRegistration.firstName)
assert(pr.lastName == playerRegistration.lastName)
assert(pr.licenceId == playerRegistration.licenceId)
assert(pr.rank == playerRegistration.rank)
assert(pr.paymentType == playerRegistration.paymentType)
assert(pr.sex == playerRegistration.sex)
assert(pr.tournamentPlayed == playerRegistration.tournamentPlayed)
assert(pr.points == playerRegistration.points)
assert(pr.clubName == playerRegistration.clubName)
assert(pr.ligueName == playerRegistration.ligueName)
assert(pr.assimilation == playerRegistration.assimilation)
assert(pr.phoneNumber == playerRegistration.phoneNumber)
assert(pr.birthdate == playerRegistration.birthdate)
assert(pr.computedRank == playerRegistration.computedRank)
assert(pr.source == playerRegistration.source)
assert(pr.hasArrived == playerRegistration.hasArrived)
}
func testMatch() async throws {
do {
try await self.login()
} catch {
let _ = try await self.createUser()
try await self.login()
}
let teamRegistrations: [TeamRegistration] = try await Store.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 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)
let m: Match = try await Store.main.service().post(match)
assert(m.round == match.round)
assert(m.groupStage == match.groupStage)
assert(m.startDate != nil)
assert(m.endDate != nil)
assert(m.index == match.index)
assert(m.matchFormat == match.matchFormat)
assert(m.servingTeamId == match.servingTeamId)
assert(m.winningTeamId == match.winningTeamId)
assert(m.losingTeamId == match.losingTeamId)
assert(m.disabled == match.disabled)
assert(m.courtIndex == match.courtIndex)
}
func testTeamScore() async throws {
do {
try await self.login()
} catch {
let _ = try await self.createUser()
try await self.login()
}
let matches: [Match] = try await Store.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()
guard let teamRegistrationId = teamRegistrations.first?.id else {
assertionFailure("missing teamRegistrations in database")
return
}
let playerRegistrations: [PlayerRegistration] = try await Store.main.service().get()
let regs = playerRegistrations.prefix(upTo: 2).map { $0.id }
let teamScore = TeamScore(match: matchId, teamRegistration: teamRegistrationId, playerRegistrations: regs, score: "6/6", walkOut: 1, luckyLoser: 1)
let ts: TeamScore = try await Store.main.service().post(teamScore)
assert(ts.match == teamScore.match)
assert(ts.teamRegistration == teamScore.teamRegistration)
assert(ts.playerRegistrations == teamScore.playerRegistrations)
assert(ts.score == teamScore.score)
assert(ts.walkOut == teamScore.walkOut)
assert(ts.luckyLoser == teamScore.luckyLoser)
}
func testCourt() async throws {
do {
try await self.login()
} catch {
let _ = try await self.createUser()
try await self.login()
}
let clubs: [Club] = try await Store.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)
assert(c.club == court.club)
assert(c.name == court.name)
assert(c.index == court.index)
assert(c.exitAllowed == court.exitAllowed)
assert(c.indoor == court.indoor)
}
func testDateInterval() async throws {
do {
try await self.login()
} catch {
let _ = try await self.createUser()
try await self.login()
}
let event: [Event] = try await Store.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)
assert(di.event == dateInterval.event)
assert(di.courtIndex == dateInterval.courtIndex)
assert(di.startDate.formatted() == dateInterval.startDate.formatted())
assert(di.endDate.formatted() == dateInterval.endDate.formatted())
}
}
Loading…
Cancel
Save