Fixes tests

multistore
Laurent 2 years ago
parent 2d896e1b0f
commit efafff9eff
  1. 6
      PadelClub.xcodeproj/project.pbxproj
  2. 1
      PadelClub/Data/Club.swift
  3. 3
      PadelClub/Data/Court.swift
  4. 3
      PadelClub/Data/DateInterval.swift
  5. 3
      PadelClub/Data/Event.swift
  6. 2
      PadelClub/Data/Federal/FederalPlayer.swift
  7. 3
      PadelClub/Data/GroupStage.swift
  8. 2
      PadelClub/Data/Match.swift
  9. 3
      PadelClub/Data/MonthData.swift
  10. 1
      PadelClub/Data/PlayerRegistration.swift
  11. 16
      PadelClub/Data/README.md
  12. 3
      PadelClub/Data/Round.swift
  13. 13
      PadelClub/Data/TeamRegistration.swift
  14. 1
      PadelClub/Data/TeamScore.swift
  15. 5
      PadelClub/Data/Tournament.swift
  16. 7
      PadelClub/Data/User.swift
  17. 19
      PadelClub/Views/Subscription/Purchase.swift
  18. 2
      PadelClub/Views/Subscription/SubscriptionView.swift
  19. 2
      PadelClub/Views/Tournament/Screen/Components/UpdateSourceRankDateView.swift
  20. 123
      PadelClubTests/ServerDataTests.swift
  21. 39
      PadelClubTests/UserDataTests.swift

@ -8,6 +8,7 @@
/* Begin PBXBuildFile section */
C411C9C32BEBA453003017AD /* ServerDataTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C411C9C22BEBA453003017AD /* ServerDataTests.swift */; };
C411C9C92BF219CB003017AD /* UserDataTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C411C9C82BF219CB003017AD /* UserDataTests.swift */; };
C425D4012B6D249D002A7B48 /* PadelClubApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = C425D4002B6D249D002A7B48 /* PadelClubApp.swift */; };
C425D4052B6D249E002A7B48 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = C425D4042B6D249E002A7B48 /* Assets.xcassets */; };
C425D4082B6D249E002A7B48 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = C425D4072B6D249E002A7B48 /* Preview Assets.xcassets */; };
@ -302,6 +303,8 @@
/* Begin PBXFileReference section */
C411C9C22BEBA453003017AD /* ServerDataTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ServerDataTests.swift; sourceTree = "<group>"; };
C411C9C82BF219CB003017AD /* UserDataTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserDataTests.swift; sourceTree = "<group>"; };
C411C9CC2BF21DAF003017AD /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = "<group>"; };
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>"; };
C425D4042B6D249E002A7B48 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
@ -648,6 +651,7 @@
C425D4112B6D249E002A7B48 /* PadelClubTests.swift */,
C49EF0412BE23BF50077B5AA /* PaymentTests.swift */,
C411C9C22BEBA453003017AD /* ServerDataTests.swift */,
C411C9C82BF219CB003017AD /* UserDataTests.swift */,
);
path = PadelClubTests;
sourceTree = "<group>";
@ -672,6 +676,7 @@
C4A47D5F2B6D3B2D00ADC637 /* Data */ = {
isa = PBXGroup;
children = (
C411C9CC2BF21DAF003017AD /* README.md */,
C4A47D5D2B6D38EC00ADC637 /* DataStore.swift */,
C4A47DAC2B85FCCD00ADC637 /* User.swift */,
C4A47D592B6D383C00ADC637 /* Tournament.swift */,
@ -1640,6 +1645,7 @@
files = (
C49EF0422BE23BF50077B5AA /* PaymentTests.swift in Sources */,
C425D4122B6D249E002A7B48 /* PadelClubTests.swift in Sources */,
C411C9C92BF219CB003017AD /* UserDataTests.swift in Sources */,
C411C9C32BEBA453003017AD /* ServerDataTests.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;

@ -13,6 +13,7 @@ import LeStorage
class Club : ModelObject, Storable, Hashable {
static func resourceName() -> String { return "clubs" }
static func requestsRequiresToken() -> Bool { return false }
static func == (lhs: Club, rhs: Club) -> Bool {
lhs.id == rhs.id

@ -12,7 +12,8 @@ import LeStorage
@Observable
class Court : ModelObject, Storable, Hashable {
static func resourceName() -> String { return "courts" }
static func requestsRequiresToken() -> Bool { return true }
static func == (lhs: Court, rhs: Court) -> Bool {
lhs.id == rhs.id
}

@ -12,7 +12,8 @@ import LeStorage
@Observable
class DateInterval: ModelObject, Storable {
static func resourceName() -> String { return "date-intervals" }
static func requestsRequiresToken() -> Bool { return true }
var id: String = Store.randomId()
var event: String
var courtIndex: Int

@ -12,7 +12,8 @@ import SwiftUI
@Observable
class Event: ModelObject, Storable {
static func resourceName() -> String { return "events" }
static func requestsRequiresToken() -> Bool { return true }
var id: String = Store.randomId()
var creator: String?
var club: String?

@ -139,7 +139,7 @@ struct FederalPlayer: Decodable {
$0.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty
}))
print(result)
// print(result)
if result.count < 11 {
return nil
}

@ -13,7 +13,8 @@ import SwiftUI
@Observable
class GroupStage: ModelObject, Storable {
static func resourceName() -> String { "group-stages" }
static func requestsRequiresToken() -> Bool { return true }
var id: String = Store.randomId()
var tournament: String
var index: Int

@ -11,6 +11,8 @@ import LeStorage
@Observable
class Match: ModelObject, Storable {
static func resourceName() -> String { "matches" }
static func requestsRequiresToken() -> Bool { return true }
var byeState: Bool = false
var id: String = Store.randomId()

@ -13,7 +13,8 @@ import LeStorage
class MonthData : ModelObject, Storable {
static func resourceName() -> String { return "month-data" }
static func requestsRequiresToken() -> Bool { return false }
private(set) var id: String = Store.randomId()
private(set) var monthKey: String
private(set) var creationDate: Date

@ -11,6 +11,7 @@ import LeStorage
@Observable
class PlayerRegistration: ModelObject, Storable {
static func resourceName() -> String { "player-registrations" }
static func requestsRequiresToken() -> Bool { return true }
var id: String = Store.randomId()
var teamRegistration: String?

@ -0,0 +1,16 @@
# Procédure d'ajout de champ dans une classe
Dans Swift:
- Ajouter le champ dans classe
- Ajouter le champ dans le constructeur si possible
- Ajouter la codingKey correspondante
- Pour la classe **Tournament**, ajouter le champ dans l'encoding/decoding
- Ouvrir **ServerDataTests** et ajouter un test sur le champ
Dans Django:
- Ajouter le champ dans la classe
- Faire le *makemigrations* + *migrate*
- S'il c'est un champ dans **CustomUser**, s’assurer que ca casse pas la creation de user dans serializers.py
Enfin, revenir dans Xcode, ouvrir ServerDataTests et lancer le test mis à jour

@ -12,7 +12,8 @@ import SwiftUI
@Observable
class Round: ModelObject, Storable {
static func resourceName() -> String { "rounds" }
static func requestsRequiresToken() -> Bool { return true }
var id: String = Store.randomId()
var tournament: String
var index: Int

@ -11,7 +11,8 @@ import LeStorage
@Observable
class TeamRegistration: ModelObject, Storable {
static func resourceName() -> String { "team-registrations" }
static func requestsRequiresToken() -> Bool { return true }
var id: String = Store.randomId()
var tournament: String
var groupStage: String?
@ -29,11 +30,11 @@ class TeamRegistration: ModelObject, Storable {
var wildCardBracket: Bool = false
var wildCardGroupStage: Bool = false
var weight: Int = 0
var lockWeight: Int?
var lockedWeight: Int?
var confirmationDate: Date?
var qualified: Bool = false
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) {
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, lockedWeight: Int? = nil, confirmationDate: Date? = nil, qualified: Bool = false) {
self.tournament = tournament
self.groupStage = groupStage
self.registrationDate = registrationDate
@ -49,7 +50,7 @@ class TeamRegistration: ModelObject, Storable {
self.wildCardBracket = wildCardBracket
self.wildCardGroupStage = wildCardGroupStage
self.weight = weight
self.lockWeight = lockWeight
self.lockedWeight = lockedWeight
self.confirmationDate = confirmationDate
self.qualified = qualified
}
@ -65,7 +66,7 @@ class TeamRegistration: ModelObject, Storable {
var initialWeight: Int {
lockWeight ?? weight
lockedWeight ?? weight
}
func called() -> Bool {
@ -342,7 +343,7 @@ class TeamRegistration: ModelObject, Storable {
case _wildCardGroupStage = "wildCardGroupStage"
case _weight = "weight"
case _walkOut = "walkOut"
case _lockWeight = "lockWeight"
case _lockedWeight = "lockedWeight"
case _confirmationDate = "confirmationDate"
case _qualified = "qualified"
}

@ -12,6 +12,7 @@ import LeStorage
class TeamScore: ModelObject, Storable {
static func resourceName() -> String { "team-scores" }
static func requestsRequiresToken() -> Bool { return true }
var id: String = Store.randomId()
var match: String

@ -11,7 +11,8 @@ import LeStorage
@Observable
class Tournament : ModelObject, Storable {
static func resourceName() -> String { "tournaments" }
static func requestsRequiresToken() -> Bool { return true }
var id: String = Store.randomId()
var event: String?
var name: String?
@ -839,7 +840,7 @@ class Tournament : ModelObject, Storable {
}
let teams = unsortedTeams()
teams.forEach { team in
team.lockWeight = team.weight
team.lockedWeight = team.weight
}
try? DataStore.shared.teamRegistrations.addOrUpdate(contentOfs: teams)
}

@ -15,11 +15,12 @@ enum UserRight: Int, Codable {
}
@Observable
class User: UserBase, Storable {
class User: ModelObject, UserBase, Storable {
static func resourceName() -> String { "users" }
func deleteDependencies() throws { }
static func requestsRequiresToken() -> Bool { return false }
// func deleteDependencies() throws { }
public var id: String = Store.randomId()
public var username: String

@ -8,18 +8,19 @@
import Foundation
import LeStorage
public class Purchase: ModelObject, Storable {
public static func resourceName() -> String { return "purchases" }
class Purchase: ModelObject, Storable {
static func resourceName() -> String { return "purchases" }
static func requestsRequiresToken() -> Bool { return true }
public var id: String = Store.randomId()
var id: String = Store.randomId()
public var user: String
public var identifier: UInt64
public var purchaseDate: Date
public var productId: String
public var quantity: Int?
var user: String
var identifier: UInt64
var purchaseDate: Date
var productId: String
var quantity: Int?
public init(user: String, identifier: UInt64, purchaseDate: Date, productId: String, quantity: Int? = nil) {
init(user: String, identifier: UInt64, purchaseDate: Date, productId: String, quantity: Int? = nil) {
self.user = user
self.identifier = identifier
self.purchaseDate = purchaseDate

@ -78,7 +78,7 @@ class SubscriptionModel: ObservableObject, StoreDelegate {
}
Task {
if product.item.isConsumable {
if let result = try await self.storeManager?.purchase(product, quantity: self.quantity) {
if let _ = try await self.storeManager?.purchase(product, quantity: self.quantity) {
self.showSuccessfulPurchaseView = true
}
} else {

@ -48,7 +48,7 @@ struct UpdateSourceRankDateView: View {
tournament.unsortedTeams().forEach { team in
team.setWeight(from: team.players(), inTournamentCategory: tournament.tournamentCategory)
if forceRefreshLockWeight {
team.lockWeight = team.weight
team.lockedWeight = team.weight
}
}

@ -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())
}
}

@ -0,0 +1,39 @@
//
// UserDataTests.swift
// PadelClubTests
//
// Created by Laurent Morvillier on 13/05/2024.
//
import XCTest
import LeStorage
@testable import PadelClub
final class UserDataTests: XCTestCase {
let username: String = "test"
let password: String = "MyPass1234--"
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 testUserCreation() async throws {
let userCreationForm = UserCreationForm(username: self.username, password: self.password, 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)
}
}
Loading…
Cancel
Save