|
|
|
|
@ -12,16 +12,28 @@ import LeStorage |
|
|
|
|
final class ServerDataTests: XCTestCase { |
|
|
|
|
|
|
|
|
|
let username: String = "test" |
|
|
|
|
|
|
|
|
|
let password: String = "MyPass1234--" |
|
|
|
|
|
|
|
|
|
override func setUpWithError() throws { |
|
|
|
|
Store.main.synchronizationApiURL = "http://127.0.0.1:8000/api/" |
|
|
|
|
Task { |
|
|
|
|
do { |
|
|
|
|
try await self.login() |
|
|
|
|
} catch { |
|
|
|
|
assertionFailure(error.localizedDescription) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override func tearDownWithError() throws { |
|
|
|
|
// Put teardown code here. This method is called after the invocation of each test method in the class. |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func login() async throws { |
|
|
|
|
// print("LOGIN!") |
|
|
|
|
let _: User = try await Store.main.service().login(username: self.username, password: self.password) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func testClub() async throws { |
|
|
|
|
|
|
|
|
|
let club = Club(name: "Aix Universite Club") |
|
|
|
|
@ -50,45 +62,13 @@ final class ServerDataTests: XCTestCase { |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
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--") |
|
|
|
|
let user: User = try await Store.main.service().login(username: self.username, password: self.password) |
|
|
|
|
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 |
|
|
|
|
@ -110,13 +90,6 @@ final class ServerDataTests: XCTestCase { |
|
|
|
|
|
|
|
|
|
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") |
|
|
|
|
@ -159,13 +132,6 @@ final class ServerDataTests: XCTestCase { |
|
|
|
|
|
|
|
|
|
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") |
|
|
|
|
@ -186,13 +152,6 @@ final class ServerDataTests: XCTestCase { |
|
|
|
|
|
|
|
|
|
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") |
|
|
|
|
@ -214,13 +173,6 @@ final class ServerDataTests: XCTestCase { |
|
|
|
|
|
|
|
|
|
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") |
|
|
|
|
@ -232,7 +184,7 @@ final class ServerDataTests: XCTestCase { |
|
|
|
|
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 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) |
|
|
|
|
|
|
|
|
|
@ -251,21 +203,14 @@ final class ServerDataTests: XCTestCase { |
|
|
|
|
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.lockedWeight == teamRegistration.lockedWeight) |
|
|
|
|
assert(tr.confirmationDate?.formatted() == teamRegistration.confirmationDate?.formatted()) |
|
|
|
|
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") |
|
|
|
|
@ -297,13 +242,6 @@ final class ServerDataTests: XCTestCase { |
|
|
|
|
|
|
|
|
|
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") |
|
|
|
|
@ -331,13 +269,6 @@ final class ServerDataTests: XCTestCase { |
|
|
|
|
|
|
|
|
|
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") |
|
|
|
|
@ -364,15 +295,7 @@ final class ServerDataTests: XCTestCase { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
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") |
|
|
|
|
@ -392,13 +315,6 @@ final class ServerDataTests: XCTestCase { |
|
|
|
|
|
|
|
|
|
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") |
|
|
|
|
@ -414,4 +330,5 @@ final class ServerDataTests: XCTestCase { |
|
|
|
|
assert(di.endDate.formatted() == dateInterval.endDate.formatted()) |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|