diff --git a/PadelClubTests/ServerDataTests.swift b/PadelClubTests/ServerDataTests.swift index 5a0d348..3614a8b 100644 --- a/PadelClubTests/ServerDataTests.swift +++ b/PadelClubTests/ServerDataTests.swift @@ -48,25 +48,27 @@ final class ServerDataTests: XCTestCase { club.phone = "061234567890" club.courtCount = 3 - let inserted_club: Club = try await StoreCenter.main.service().post(club) - assert(inserted_club.lastUpdate == club.lastUpdate) - 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) - assert(inserted_club.courtCount == club.courtCount) - assert(inserted_club.broadcastCode != nil) - assert(inserted_club.timezone != club.timezone) - - inserted_club.phone = "123456" - inserted_club.lastUpdate = Date() - - let updated_club: Club = try await StoreCenter.main.service().put(inserted_club) - assert(updated_club.phone == inserted_club.phone) - + if let inserted_club: Club = try await StoreCenter.main.service().post(club) { + assert(inserted_club.lastUpdate == club.lastUpdate) + 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) + assert(inserted_club.courtCount == club.courtCount) + assert(inserted_club.broadcastCode != nil) + assert(inserted_club.timezone != club.timezone) + + inserted_club.phone = "123456" + inserted_club.lastUpdate = Date() + + let updated_club: Club = try await StoreCenter.main.service().put(inserted_club) + assert(updated_club.phone == inserted_club.phone) + } else { + XCTFail("missing data") + } } func testLogin() async throws { @@ -88,12 +90,14 @@ final class ServerDataTests: XCTestCase { } let event = Event(creator: userId, club: clubId, name: "Roland Garros", tenupId: "abc") - let e = try await StoreCenter.main.service().post(event) - - assert(e.name == event.name) - assert(e.lastUpdate == event.lastUpdate) - assert(e.tenupId == event.tenupId) - + if let e = try await StoreCenter.main.service().post(event){ + + assert(e.name == event.name) + assert(e.lastUpdate == event.lastUpdate) + assert(e.tenupId == event.tenupId) + } else { + XCTFail("missing data") + } } func testTournament() async throws { @@ -105,54 +109,59 @@ final class ServerDataTests: XCTestCase { } 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, loserBracketMode: .manual, initialSeedRound: 8, initialSeedCount: 4, accountIsRequired: false, licenseIsRequired: false, minimumPlayerPerTeam: 3, maximumPlayerPerTeam: 5, information: "Super") - let t = try await StoreCenter.main.service().post(tournament) - assert(t.lastUpdate.formatted() == tournament.lastUpdate.formatted()) - 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.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) - assert(t.publishTeams == tournament.publishTeams) - assert(t.publishSummons == tournament.publishSummons) - assert(t.publishGroupStages == tournament.publishGroupStages) - assert(t.publishBrackets == tournament.publishBrackets) - assert(t.shouldVerifyBracket == tournament.shouldVerifyBracket) - assert(t.shouldVerifyGroupStage == tournament.shouldVerifyGroupStage) - assert(t.hideTeamsWeight == tournament.hideTeamsWeight) - assert(t.publishTournament == tournament.publishTournament) - assert(t.hidePointsEarned == tournament.hidePointsEarned) - assert(t.publishRankings == tournament.publishRankings) - assert(t.loserBracketMode == tournament.loserBracketMode) - assert(t.initialSeedCount == tournament.initialSeedCount) - assert(t.initialSeedRound == tournament.initialSeedRound) - assert(t.accountIsRequired == tournament.accountIsRequired) - assert(t.licenseIsRequired == tournament.licenseIsRequired) - assert(t.minimumPlayerPerTeam == tournament.minimumPlayerPerTeam) - assert(t.maximumPlayerPerTeam == tournament.maximumPlayerPerTeam) - assert(t.information == tournament.information) + if let t = try await StoreCenter.main.service().post(tournament) { + + assert(t.lastUpdate.formatted() == tournament.lastUpdate.formatted()) + 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.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) + assert(t.publishTeams == tournament.publishTeams) + assert(t.publishSummons == tournament.publishSummons) + assert(t.publishGroupStages == tournament.publishGroupStages) + assert(t.publishBrackets == tournament.publishBrackets) + assert(t.shouldVerifyBracket == tournament.shouldVerifyBracket) + assert(t.shouldVerifyGroupStage == tournament.shouldVerifyGroupStage) + assert(t.hideTeamsWeight == tournament.hideTeamsWeight) + assert(t.publishTournament == tournament.publishTournament) + assert(t.hidePointsEarned == tournament.hidePointsEarned) + assert(t.publishRankings == tournament.publishRankings) + assert(t.loserBracketMode == tournament.loserBracketMode) + assert(t.initialSeedCount == tournament.initialSeedCount) + assert(t.initialSeedRound == tournament.initialSeedRound) + assert(t.accountIsRequired == tournament.accountIsRequired) + assert(t.licenseIsRequired == tournament.licenseIsRequired) + assert(t.minimumPlayerPerTeam == tournament.minimumPlayerPerTeam) + assert(t.maximumPlayerPerTeam == tournament.maximumPlayerPerTeam) + assert(t.information == tournament.information) + + } else { + XCTFail("missing data") + } } func testGroupStage() async throws { @@ -165,18 +174,20 @@ final class ServerDataTests: XCTestCase { let groupStage = GroupStage(tournament: tournamentId, index: 2, size: 3, format: MatchFormat.nineGames, startDate: Date(), name: "Yeah!", step: 1) groupStage.storeId = "123" - let gs: GroupStage = try await StoreCenter.main.service().post(groupStage) - - assert(gs.tournament == groupStage.tournament) - assert(gs.storeId == groupStage.storeId) - assert(gs.lastUpdate == groupStage.lastUpdate) - assert(gs.name == groupStage.name) - assert(gs.index == groupStage.index) - assert(gs.size == groupStage.size) - assert(gs.matchFormat == groupStage.matchFormat) - assert(gs.startDate != nil) - assert(gs.step == groupStage.step) - + if let gs: GroupStage = try await StoreCenter.main.service().post(groupStage) { + + assert(gs.tournament == groupStage.tournament) + assert(gs.storeId == groupStage.storeId) + assert(gs.lastUpdate == groupStage.lastUpdate) + assert(gs.name == groupStage.name) + assert(gs.index == groupStage.index) + assert(gs.size == groupStage.size) + assert(gs.matchFormat == groupStage.matchFormat) + assert(gs.startDate != nil) + assert(gs.step == groupStage.step) + } else { + XCTFail("missing data") + } } @@ -192,18 +203,20 @@ final class ServerDataTests: XCTestCase { let round = Round(tournament: tournamentId, index: 1, parent: parentRoundId, matchFormat: MatchFormat.nineGames, startDate: Date(), groupStageLoserBracket: false, loserBracketMode: .manual) round.storeId = "abc" - let r: Round = try await StoreCenter.main.service().post(round) - - assert(r.storeId == round.storeId) - assert(r.tournament == round.tournament) - assert(r.lastUpdate == round.lastUpdate) - assert(r.index == round.index) - assert(r.parent == round.parent) - assert(r.matchFormat == round.matchFormat) - assert(r.startDate != nil) - assert(r.groupStageLoserBracket == round.groupStageLoserBracket) - assert(r.loserBracketMode == round.loserBracketMode) - + if let r: Round = try await StoreCenter.main.service().post(round) { + + assert(r.storeId == round.storeId) + assert(r.tournament == round.tournament) + assert(r.lastUpdate == round.lastUpdate) + assert(r.index == round.index) + assert(r.parent == round.parent) + assert(r.matchFormat == round.matchFormat) + assert(r.startDate != nil) + assert(r.groupStageLoserBracket == round.groupStageLoserBracket) + assert(r.loserBracketMode == round.loserBracketMode) + } else { + XCTFail("missing data") + } } func testTeamRegistration() async throws { @@ -222,30 +235,33 @@ 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) teamRegistration.storeId = "123" - let tr: TeamRegistration = try await StoreCenter.main.service().post(teamRegistration) - - assert(tr.storeId == teamRegistration.storeId) - assert(tr.tournament == teamRegistration.tournament) - assert(tr.lastUpdate == teamRegistration.lastUpdate) - 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.lockedWeight == teamRegistration.lockedWeight) - assert(tr.confirmationDate?.formatted() == teamRegistration.confirmationDate?.formatted()) - assert(tr.qualified == teamRegistration.qualified) - assert(tr.finalRanking == teamRegistration.finalRanking) - assert(tr.pointsEarned == teamRegistration.pointsEarned) + if let tr: TeamRegistration = try await StoreCenter.main.service().post(teamRegistration) { + + assert(tr.storeId == teamRegistration.storeId) + assert(tr.tournament == teamRegistration.tournament) + assert(tr.lastUpdate == teamRegistration.lastUpdate) + 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.lockedWeight == teamRegistration.lockedWeight) + assert(tr.confirmationDate?.formatted() == teamRegistration.confirmationDate?.formatted()) + assert(tr.qualified == teamRegistration.qualified) + assert(tr.finalRanking == teamRegistration.finalRanking) + assert(tr.pointsEarned == teamRegistration.pointsEarned) + } else { + XCTFail("missing data") + } } func testPlayerRegistration() async throws { @@ -259,31 +275,33 @@ final class ServerDataTests: XCTestCase { let playerRegistration = PlayerRegistration(teamRegistration: teamRegistrationId, firstName: "juan", lastName: "lebron", licenceId: "123", rank: 11, paymentType: PlayerPaymentType.cash, sex: 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) playerRegistration.storeId = "123" - let pr: PlayerRegistration = try await StoreCenter.main.service().post(playerRegistration) - - assert(pr.storeId == playerRegistration.storeId) - assert(pr.lastName == playerRegistration.lastName) - 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) - assert(pr.captain == playerRegistration.captain) - assert(pr.coach == playerRegistration.coach) - assert(pr.registeredOnline == playerRegistration.registeredOnline) - + if let pr: PlayerRegistration = try await StoreCenter.main.service().post(playerRegistration) { + + assert(pr.storeId == playerRegistration.storeId) + assert(pr.lastName == playerRegistration.lastName) + 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) + assert(pr.captain == playerRegistration.captain) + assert(pr.coach == playerRegistration.coach) + assert(pr.registeredOnline == playerRegistration.registeredOnline) + } else { + XCTFail("missing data") + } } func testMatch() async throws { @@ -298,23 +316,25 @@ final class ServerDataTests: XCTestCase { let match: Match = Match(round: parentRoundId, groupStage: nil, startDate: Date(), endDate: Date(), index: 2, format: MatchFormat.twoSets, servingTeamId: teamRegistrationId, winningTeamId: teamRegistrationId, losingTeamId: teamRegistrationId, disabled: true, courtIndex: 1, confirmed: true) match.storeId = "123" - let m: Match = try await StoreCenter.main.service().post(match) - - assert(m.storeId == match.storeId) - assert(m.lastUpdate == match.lastUpdate) - 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) - assert(m.confirmed == match.confirmed) - + if let m: Match = try await StoreCenter.main.service().post(match) { + + assert(m.storeId == match.storeId) + assert(m.lastUpdate == match.lastUpdate) + 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) + assert(m.confirmed == match.confirmed) + } else { + XCTFail("missing data") + } } func testTeamScore() async throws { @@ -331,16 +351,18 @@ final class ServerDataTests: XCTestCase { } let teamScore = TeamScore(match: matchId, teamRegistration: teamRegistrationId, score: "6/6", walkOut: 1, luckyLoser: 1) teamScore.storeId = "!23" - let ts: TeamScore = try await StoreCenter.main.service().post(teamScore) - - assert(ts.storeId == teamScore.storeId) - assert(ts.lastUpdate == teamScore.lastUpdate) - assert(ts.match == teamScore.match) - assert(ts.teamRegistration == teamScore.teamRegistration) - assert(ts.score == teamScore.score) - assert(ts.walkOut == teamScore.walkOut) - assert(ts.luckyLoser == teamScore.luckyLoser) - + if let ts: TeamScore = try await StoreCenter.main.service().post(teamScore) { + + assert(ts.storeId == teamScore.storeId) + assert(ts.lastUpdate == teamScore.lastUpdate) + assert(ts.match == teamScore.match) + assert(ts.teamRegistration == teamScore.teamRegistration) + assert(ts.score == teamScore.score) + assert(ts.walkOut == teamScore.walkOut) + assert(ts.luckyLoser == teamScore.luckyLoser) + } else { + XCTFail("missing data") + } } func testCourt() async throws { @@ -352,15 +374,17 @@ final class ServerDataTests: XCTestCase { } let court = Court(index: 1, club: clubId, name: "Philippe Chatrier", exitAllowed: true, indoor: true) - let c: Court = try await StoreCenter.main.service().post(court) - - assert(c.lastUpdate == court.lastUpdate) - 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) - + if let c: Court = try await StoreCenter.main.service().post(court) { + + assert(c.lastUpdate == court.lastUpdate) + 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) + } else { + XCTFail("missing data") + } } func testDateInterval() async throws { @@ -372,14 +396,16 @@ final class ServerDataTests: XCTestCase { } let dateInterval = DateInterval(event: eventId, courtIndex: 1, startDate: Date(), endDate: Date()) - let di: PadelClub.DateInterval = try await StoreCenter.main.service().post(dateInterval) - - assert(di.lastUpdate == dateInterval.lastUpdate) - assert(di.event == dateInterval.event) - assert(di.courtIndex == dateInterval.courtIndex) - assert(di.startDate.formatted() == dateInterval.startDate.formatted()) - assert(di.endDate.formatted() == dateInterval.endDate.formatted()) - + if let di: PadelClub.DateInterval = try await StoreCenter.main.service().post(dateInterval) { + + assert(di.lastUpdate == dateInterval.lastUpdate) + assert(di.event == dateInterval.event) + assert(di.courtIndex == dateInterval.courtIndex) + assert(di.startDate.formatted() == dateInterval.startDate.formatted()) + assert(di.endDate.formatted() == dateInterval.endDate.formatted()) + } else { + XCTFail("missing data") + } } func testPurchase() async throws { @@ -394,17 +420,19 @@ final class ServerDataTests: XCTestCase { 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.lastUpdate == purchase.lastUpdate) - assert(p.user == purchase.user) - assert(p.productId == purchase.productId) - assert(p.purchaseDate.formatted() == purchase.purchaseDate.formatted()) - assert(p.quantity == purchase.quantity) - assert(p.revocationDate?.formatted() == purchase.revocationDate?.formatted()) - assert(p.expirationDate?.formatted() == purchase.expirationDate?.formatted()) - + if let p: Purchase = try await StoreCenter.main.service().post(purchase) { + + assert(p.id == purchase.id) + assert(p.lastUpdate == purchase.lastUpdate) + assert(p.user == purchase.user) + assert(p.productId == purchase.productId) + assert(p.purchaseDate.formatted() == purchase.purchaseDate.formatted()) + assert(p.quantity == purchase.quantity) + assert(p.revocationDate?.formatted() == purchase.revocationDate?.formatted()) + assert(p.expirationDate?.formatted() == purchase.expirationDate?.formatted()) + } else { + XCTFail("missing data") + } } func testDrawLog() async throws { @@ -416,14 +444,19 @@ final class ServerDataTests: XCTestCase { } let drawLog = DrawLog(tournament: tournamentId, drawSeed: 1, drawMatchIndex: 1, drawTeamPosition: .two, drawType: .court) - let d: DrawLog = try await StoreCenter.main.service().post(drawLog) - - assert(d.tournament == drawLog.tournament) - assert(d.drawDate.formatted() == drawLog.drawDate.formatted()) - assert(d.drawSeed == drawLog.drawSeed) - assert(d.drawTeamPosition == drawLog.drawTeamPosition) - assert(d.drawMatchIndex == drawLog.drawMatchIndex) - assert(d.drawType == drawLog.drawType) + drawLog.storeId = "!23" + + if let d: DrawLog = try await StoreCenter.main.service().post(drawLog) { + + assert(d.tournament == drawLog.tournament) + assert(d.drawDate.formatted() == drawLog.drawDate.formatted()) + assert(d.drawSeed == drawLog.drawSeed) + assert(d.drawTeamPosition == drawLog.drawTeamPosition) + assert(d.drawMatchIndex == drawLog.drawMatchIndex) + assert(d.drawType == drawLog.drawType) + } else { + XCTFail("missing data") + } } } diff --git a/PadelClubTests/SynchronizationTests.swift b/PadelClubTests/SynchronizationTests.swift index 1312527..8d35757 100644 --- a/PadelClubTests/SynchronizationTests.swift +++ b/PadelClubTests/SynchronizationTests.swift @@ -15,7 +15,7 @@ struct SynchronizationTests { let password: String = "StaxKikoo12" init() { - StoreCenter.main.configureURLs(httpScheme: "http://", domain: "127.0.0.1:8000") + StoreCenter.main.configureURLs(secureScheme: false, domain: "127.0.0.1:8000") } @Test func synchronizationTest() async throws { diff --git a/PadelClubTests/TokenExemptionTests.swift b/PadelClubTests/TokenExemptionTests.swift index 7160028..458e48b 100644 --- a/PadelClubTests/TokenExemptionTests.swift +++ b/PadelClubTests/TokenExemptionTests.swift @@ -31,8 +31,11 @@ final class TokenExemptionTests: XCTestCase { let club: Club = Club(name: "mon club 2", acronym: "MC", phone: "132", code: "456", address: "l'adresse", city: "la ville", zipCode: "13131", latitude: 13.11111, longitude: 1.121212) - let c = try await StoreCenter.main.service().post(club) - assert(c.id == club.id) + if let c = try await StoreCenter.main.service().post(club) { + assert(c.id == club.id) + } else { + XCTFail("missing data") + } do { _ = try await StoreCenter.main.service().put(club)