adds config to perform tests on various server

sync3
Laurent 6 months ago
parent 17c94f8598
commit 1ed3c66f5d
  1. 2
      PadelClubData/Data/Match.swift
  2. 16
      PadelClubData/Utils/PListReader.swift
  3. 26
      PadelClubDataTests/Config.swift
  4. 29
      PadelClubDataTests/DeletionTests.swift
  5. 5
      PadelClubDataTests/PadelClubDataTests.swift
  6. 6
      PadelClubDataTests/SyncDataAccessTests.swift
  7. 6
      PadelClubDataTests/SynchronizationTests.swift
  8. 25
      PadelClubDataTests/config.plist

@ -34,6 +34,8 @@ final public class Match: BaseMatch, SideStorable {
required public init() {
super.init()
let drawLog = DrawLog()
}
// MARK: - DidSet

@ -10,7 +10,11 @@ import Foundation
public class PListReader {
static func dictionary(plist: String) -> [String: Any]? {
if let plistPath = Bundle.main.path(forResource: plist, ofType: "plist") {
return self.dictionary(plist: plist, bundle: Bundle.main)
}
static func dictionary(plist: String, bundle: Bundle) -> [String: Any]? {
if let plistPath = bundle.path(forResource: plist, ofType: "plist") {
// Read plist file into Data
if let plistData = FileManager.default.contents(atPath: plistPath) {
do {
@ -25,21 +29,21 @@ public class PListReader {
print("Failed to read plist file at path: \(plistPath)")
}
} else {
print("Plist file 'Data.plist' not found in bundle")
print("Plist file '\(plist)' not found in bundle")
}
return nil
}
public static func readString(plist: String, key: String) -> String? {
if let dictionary = self.dictionary(plist: plist) {
public static func readString(plist: String, key: String, bundle: Bundle = Bundle.main) -> String? {
if let dictionary = self.dictionary(plist: plist, bundle: bundle) {
return dictionary[key] as? String
}
return nil
}
public static func readBool(plist: String, key: String) -> Bool? {
if let dictionary = self.dictionary(plist: plist) {
public static func readBool(plist: String, key: String, bundle: Bundle = Bundle.main) -> Bool? {
if let dictionary = self.dictionary(plist: plist, bundle: bundle) {
return dictionary[key] as? Bool
}
return nil

@ -0,0 +1,26 @@
//
// Config.swift
// PadelClubData
//
// Created by Laurent Morvillier on 21/05/2025.
//
@testable import PadelClubData
class Config {
static var server: (secure: Bool, domain: String) {
let bundle = Bundle(for: self)
let secure = PListReader.readBool(plist: "config", key: "secure_server", bundle: bundle)
let domain = PListReader.readString(plist: "config", key: "server_domain", bundle: bundle)
if let secure, let domain {
return (secure, domain)
}
fatalError("no server configuration")
}
}

@ -18,11 +18,14 @@ struct DeletionTests {
init() async throws {
let conf = Config.server
FileManager.default.deleteDirectoryInDocuments(directoryName: "storage")
FileManager.default.deleteDirectoryInDocuments(directoryName: "storage-2")
self.secondStoreCenter = StoreCenter(directoryName: "storage-2")
self.secondStoreCenter.configureURLs(secureScheme: false, domain: "127.0.0.1:8000", webSockets: false, useSynchronization: true)
self.secondStoreCenter.configureURLs(secureScheme: conf.secure, domain: conf.domain, webSockets: false, useSynchronization: true)
self.secondStoreCenter.tokenKeychain = MockKeychainStore(fileName: "storage-2/token.json")
self.secondStoreCenter.deviceKeychain = MockKeychainStore(fileName: "storage-2/device.json")
try self.secondStoreCenter.deviceKeychain.add(value: UUID().uuidString)
@ -34,7 +37,7 @@ struct DeletionTests {
try await self.login(storeCenter: self.secondStoreCenter, username: self.username1, password: self.password1)
}
StoreCenter.main.configureURLs(secureScheme: false, domain: "127.0.0.1:8000", webSockets: false, useSynchronization: true)
StoreCenter.main.configureURLs(secureScheme: conf.secure, domain: conf.domain, webSockets: false, useSynchronization: true)
StoreCenter.main.tokenKeychain = MockKeychainStore(fileName: "storage/token.json")
StoreCenter.main.deviceKeychain = MockKeychainStore(fileName: "storage/device.json")
try StoreCenter.main.deviceKeychain.add(value: UUID().uuidString)
@ -247,12 +250,20 @@ struct DeletionTests {
#expect(clubColB.count == 1)
#expect(eventColB.count == 0)
#expect(tournamentColB.count == 0)
#expect(groupStageColB.count == 0)
#expect(roundColB.count == 0)
#expect(matchColB.count == 0)
#expect(teamRegistrationColB.count == 0)
#expect(teamScoreColB.count == 0)
#expect(playerRegistrationColB.count == 0)
do {
let _ = try self.secondStoreCenter.store(identifier: tournament.id)
Issue.record("should go in the catch because the store has been destroyed")
} catch {
#expect(1 == 1)
}
// #expect(groupStageColB.count == 0)
// #expect(roundColB.count == 0)
// #expect(matchColB.count == 0)
// #expect(teamRegistrationColB.count == 0)
// #expect(teamScoreColB.count == 0)
// #expect(playerRegistrationColB.count == 0)
}
}
@ -282,7 +293,7 @@ actor BoolChecker {
// print("sleep...")
// Wait for 100ms before next check
try? await Task.sleep(for: .milliseconds(100))
try? await Task.sleep(for: .milliseconds(1000))
}
// Throw error if timeout is reached

@ -21,7 +21,10 @@ struct PadelClubDataTests {
let password: String = "MyPass1234--"
init() async throws {
StoreCenter.main.configureURLs(secureScheme: false, domain: "127.0.0.1:8000")
let conf = Config.server
StoreCenter.main.configureURLs(secureScheme: conf.secure, domain: conf.domain)
StoreCenter.main.tokenKeychain = MockKeychainStore(fileName: "token.json")
try await self.login()
}

@ -22,6 +22,8 @@ struct SyncDataAccessTests {
init() async throws {
let conf = Config.server
let dirA = "storageA"
let dirB = "storageB"
@ -32,7 +34,7 @@ struct SyncDataAccessTests {
self.storeCenterB = StoreCenter(directoryName: dirB)
// StoreCenter A
self.storeCenterA.configureURLs(secureScheme: false, domain: "127.0.0.1:8000", webSockets: false, useSynchronization: true)
self.storeCenterA.configureURLs(secureScheme: conf.secure, domain: conf.domain, webSockets: false, useSynchronization: true)
self.storeCenterA.tokenKeychain = MockKeychainStore(fileName: "\(dirA)/token.json")
self.storeCenterA.deviceKeychain = MockKeychainStore(fileName: "\(dirA)/device.json")
try self.storeCenterA.deviceKeychain.add(value: UUID().uuidString)
@ -44,7 +46,7 @@ struct SyncDataAccessTests {
}
// StoreCenter B
self.storeCenterB.configureURLs(secureScheme: false, domain: "127.0.0.1:8000", webSockets: false, useSynchronization: true)
self.storeCenterB.configureURLs(secureScheme: conf.secure, domain: conf.domain, webSockets: false, useSynchronization: true)
self.storeCenterB.tokenKeychain = MockKeychainStore(fileName: "\(dirB)/token.json")
self.storeCenterB.deviceKeychain = MockKeychainStore(fileName: "\(dirB)/device.json")
try self.storeCenterB.deviceKeychain.add(value: UUID().uuidString)

@ -23,11 +23,13 @@ struct SynchronizationTests {
init() async throws {
let conf = Config.server
FileManager.default.deleteDirectoryInDocuments(directoryName: "storage")
FileManager.default.deleteDirectoryInDocuments(directoryName: "storage-2")
self.secondStoreCenter = StoreCenter(directoryName: "storage-2")
self.secondStoreCenter.configureURLs(secureScheme: false, domain: "127.0.0.1:8000", webSockets: false, useSynchronization: true)
self.secondStoreCenter.configureURLs(secureScheme: conf.secure, domain: conf.domain, webSockets: false, useSynchronization: true)
self.secondStoreCenter.tokenKeychain = MockKeychainStore(fileName: "storage-2/token.json")
self.secondStoreCenter.deviceKeychain = MockKeychainStore(fileName: "storage-2/device.json")
try self.secondStoreCenter.deviceKeychain.add(value: UUID().uuidString)
@ -39,7 +41,7 @@ struct SynchronizationTests {
try await self.login(storeCenter: self.secondStoreCenter)
}
StoreCenter.main.configureURLs(secureScheme: false, domain: "127.0.0.1:8000", webSockets: false, useSynchronization: true)
StoreCenter.main.configureURLs(secureScheme: conf.secure, domain: conf.domain, webSockets: false, useSynchronization: true)
StoreCenter.main.tokenKeychain = MockKeychainStore(fileName: "storage/token.json")
StoreCenter.main.deviceKeychain = MockKeychainStore(fileName: "storage/device.json")
try StoreCenter.main.deviceKeychain.add(value: UUID().uuidString)

@ -1,12 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<!--
config.plist
PadelClubData
Created by Laurent Morvillier on 21/05/2025.
Copyright (c) 2025 ___ORGANIZATIONNAME___. All rights reserved.
-->
<plist version="1.0">
<dict/>
<dict>
<key>secure_server</key>
<true/>
<key>server_domain</key>
<string>test1.padelclub.app</string>
<key>references</key>
<dict>
<key>local_server_domain</key>
<string>127.0.0.1:8000</string>
<key>prod_server_domain</key>
<string>padelclub.app</string>
<key>test1_server_domain</key>
<string>test1.padelclub.app</string>
<key>xlr_server_domain</key>
<string>xlr.alwaysdata.net</string>
</dict>
</dict>
</plist>

Loading…
Cancel
Save