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.
 
 
PadelClub/PadelClubTests/PaymentTests.swift

72 lines
2.3 KiB

//
// PaymentTests.swift
// PadelClubTests
//
// Created by Laurent Morvillier on 01/05/2024.
//
import XCTest
@testable import PadelClub
final class PaymentTests: XCTestCase {
override func setUpWithError() throws {
// Put setup code here. This method is called before the invocation of each test method in the class.
}
override func tearDownWithError() throws {
// Put teardown code here. This method is called after the invocation of each test method in the class.
}
func testPayments() throws {
let tournament = Tournament.fake()
do {
tournament.payment = .free
var encoded = try JSONEncoder().encode(tournament)
var decoded = try JSONDecoder().decode(Tournament.self, from: encoded)
assert(decoded.payment == .free)
tournament.payment = .subscriptionUnit
encoded = try JSONEncoder().encode(tournament)
decoded = try JSONDecoder().decode(Tournament.self, from: encoded)
assert(decoded.payment == .subscriptionUnit)
tournament.payment = .unit
encoded = try JSONEncoder().encode(tournament)
decoded = try JSONDecoder().decode(Tournament.self, from: encoded)
assert(decoded.payment == .unit)
tournament.payment = .unlimited
encoded = try JSONEncoder().encode(tournament)
decoded = try JSONDecoder().decode(Tournament.self, from: encoded)
assert(decoded.payment == .unlimited)
} catch {
assertionFailure(error.localizedDescription)
}
}
func testCanceled() throws {
let tournament = Tournament.fake()
do {
tournament.isCanceled = false
var encoded = try JSONEncoder().encode(tournament)
var decoded = try JSONDecoder().decode(Tournament.self, from: encoded)
assert(decoded.isCanceled == false)
tournament.isCanceled = true
encoded = try JSONEncoder().encode(tournament)
decoded = try JSONDecoder().decode(Tournament.self, from: encoded)
assert(decoded.isCanceled == true)
} catch {
assertionFailure(error.localizedDescription)
}
}
}