You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
101 lines
3.3 KiB
101 lines
3.3 KiB
//
|
|
// PadelClubDataTests.swift
|
|
// PadelClubDataTests
|
|
//
|
|
// Created by Laurent Morvillier on 15/04/2025.
|
|
//
|
|
|
|
import Testing
|
|
@testable import PadelClubData
|
|
@testable import LeStorage
|
|
|
|
enum TestError: Error {
|
|
case notAuthenticated
|
|
case sameDeviceId
|
|
case missingEvent
|
|
case missingTournament
|
|
}
|
|
|
|
struct PadelClubDataTests {
|
|
|
|
let username: String = "UserDataTests"
|
|
let password: String = "MyPass1234--"
|
|
|
|
init() async throws {
|
|
|
|
let conf = Config.server
|
|
|
|
StoreCenter.main.configureURLs(secureScheme: conf.secure, domain: conf.domain)
|
|
StoreCenter.main.tokenKeychain = MockKeychainStore(fileName: "token.json")
|
|
try await self.login()
|
|
}
|
|
|
|
mutating func login() async throws {
|
|
let _: CustomUser = try await StoreCenter.main.service().login(username: self.username, password: self.password)
|
|
}
|
|
|
|
@Test func testAuthentication() {
|
|
#expect(StoreCenter.main.isAuthenticated)
|
|
}
|
|
|
|
@Test func createTournament() async throws {
|
|
|
|
guard let userId = StoreCenter.main.userId else {
|
|
throw TestError.notAuthenticated
|
|
}
|
|
|
|
// Cleanup
|
|
let eventCol: SyncedCollection<Event> = await StoreCenter.main.mainStore.asyncLoadingSynchronizedCollection()
|
|
// let events: [Event] = try await StoreCenter.main.service().get()
|
|
try await eventCol.deleteAsync(contentOfs: Array(eventCol))
|
|
#expect(eventCol.count == 0)
|
|
|
|
let tournamentCol: SyncedCollection<Tournament> = await StoreCenter.main.mainStore.asyncLoadingSynchronizedCollection()
|
|
// let tournaments: [Tournament] = try await StoreCenter.main.service().get()
|
|
try await tournamentCol.deleteAsync(contentOfs: Array(tournamentCol))
|
|
#expect(tournamentCol.count == 0)
|
|
|
|
// Create
|
|
let event: Event = Event(creator: userId, club: nil, name: "test_createTournament")
|
|
try await eventCol.addOrUpdateAsync(instance: event)
|
|
|
|
let tournament: Tournament = Tournament.fake()
|
|
tournament.event = event.id
|
|
try await tournamentCol.addOrUpdateAsync(instance: tournament)
|
|
|
|
// Test server content
|
|
try await eventCol.loadOnceAsync()
|
|
#expect(eventCol.count == 1)
|
|
|
|
try await tournamentCol.loadOnceAsync()
|
|
#expect(tournamentCol.count == 1)
|
|
|
|
}
|
|
|
|
@Test func dualStoreCenter() async throws {
|
|
|
|
let conf = Config.server
|
|
|
|
let secondStoreServer = StoreCenter()
|
|
secondStoreServer.configureURLs(secureScheme: conf.secure, domain: conf.domain)
|
|
secondStoreServer.tokenKeychain = MockKeychainStore(fileName: "token.json")
|
|
|
|
let _: CustomUser = try await secondStoreServer.service().login(username: self.username, password: self.password)
|
|
|
|
#expect(StoreCenter.main.isAuthenticated)
|
|
#expect(secondStoreServer.isAuthenticated)
|
|
|
|
}
|
|
|
|
@Test func testWebsocketSynchronization() async throws {
|
|
|
|
let secondStoreServer = StoreCenter()
|
|
secondStoreServer.configureURLs(secureScheme: false, domain: "127.0.0.1:8000")
|
|
secondStoreServer.tokenKeychain = MockKeychainStore(fileName: "token.json")
|
|
|
|
let events = DataStore.shared.events
|
|
try await DataStore.shared.events.deleteAsync(contentOfs: Array(events))
|
|
|
|
}
|
|
|
|
}
|
|
|