Skip to content

Commit 9a439f1

Browse files
committed
Add tests for migrations
1 parent f231b7d commit 9a439f1

File tree

4 files changed

+97
-25
lines changed

4 files changed

+97
-25
lines changed

Package.swift

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,21 +38,24 @@ let package = Package(
3838
.testTarget(
3939
name: "FluentWalletTests",
4040
dependencies: [
41-
.target(name: "FluentWallet")
41+
.target(name: "FluentWallet"),
42+
.product(name: "XCTFluent", package: "fluent-kit"),
4243
],
4344
swiftSettings: swiftSettings
4445
),
4546
.testTarget(
4647
name: "FluentPassesTests",
4748
dependencies: [
48-
.target(name: "FluentPasses")
49+
.target(name: "FluentPasses"),
50+
.product(name: "XCTFluent", package: "fluent-kit"),
4951
],
5052
swiftSettings: swiftSettings
5153
),
5254
.testTarget(
5355
name: "FluentOrdersTests",
5456
dependencies: [
55-
.target(name: "FluentOrders")
57+
.target(name: "FluentOrders"),
58+
.product(name: "XCTFluent", package: "fluent-kit"),
5659
],
5760
swiftSettings: swiftSettings
5861
),
Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,38 @@
11
import FluentOrders
22
import FluentWallet
33
import Testing
4+
import XCTFluent
45

56
import struct Foundation.UUID
67

78
@Suite("FluentOrders Tests")
89
struct FluentOrdersTests {
10+
let test = ArrayTestDatabase()
11+
912
@Test("Order Concrete Model")
1013
func order() async throws {
14+
let migration = CreateOrder()
15+
try await migration.prepare(on: test.db)
16+
1117
let typeIdentifier = "Test Type Identifier"
1218
let authenticationToken = "Test Authentication Token"
1319

14-
let order = Order(typeIdentifier: typeIdentifier, authenticationToken: authenticationToken)
20+
test.append([
21+
TestOutput(Order(typeIdentifier: typeIdentifier, authenticationToken: authenticationToken))
22+
])
23+
24+
let fetchedOrder = try #require(await Order.query(on: test.db).first())
25+
#expect(fetchedOrder._$typeIdentifier.value == typeIdentifier)
26+
#expect(fetchedOrder._$authenticationToken.value == authenticationToken)
1527

16-
#expect(order._$typeIdentifier.value == typeIdentifier)
17-
#expect(order._$authenticationToken.value == authenticationToken)
28+
try await migration.revert(on: test.db)
1829
}
1930

2031
@Test("OrdersRegistration Concrete Model")
2132
func ordersRegistration() async throws {
33+
let migration = CreateOrdersRegistration()
34+
try await migration.prepare(on: test.db)
35+
2236
let device = Device()
2337
device._$id.value = 1
2438
let order = Order()
@@ -27,8 +41,14 @@ struct FluentOrdersTests {
2741
let ordersRegistration = OrdersRegistration()
2842
ordersRegistration.$device.id = device.id!
2943
ordersRegistration.$order.id = order.id!
44+
test.append([
45+
TestOutput(ordersRegistration)
46+
])
47+
48+
let fetchedOrdersRegistration = try #require(await OrdersRegistration.query(on: test.db).first())
49+
#expect(fetchedOrdersRegistration._$device.id == device.id)
50+
#expect(fetchedOrdersRegistration._$order.id == order.id)
3051

31-
#expect(ordersRegistration._$device.id == device.id)
32-
#expect(ordersRegistration._$order.id == order.id)
52+
try await migration.revert(on: test.db)
3353
}
3454
}

Tests/FluentPassesTests/FluentPassesTests.swift

Lines changed: 42 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,43 @@
11
import FluentPasses
22
import FluentWallet
33
import Testing
4+
import XCTFluent
45

56
import struct Foundation.UUID
67

78
@Suite("FluentPasses Tests")
89
struct FluentPassesTests {
10+
let test = ArrayTestDatabase()
11+
912
@Test("Pass Concrete Model")
1013
func pass() async throws {
14+
let migration = CreatePass()
15+
try await migration.prepare(on: test.db)
16+
1117
let typeIdentifier = "Test Type Identifier"
1218
let authenticationToken = "Test Authentication Token"
1319
let personalization = Personalization()
1420
personalization._$id.value = 1
1521

1622
let pass = Pass(typeIdentifier: typeIdentifier, authenticationToken: authenticationToken)
1723
pass.$personalization.id = personalization.id!
24+
test.append([
25+
TestOutput(pass)
26+
])
1827

19-
#expect(pass._$typeIdentifier.value == typeIdentifier)
20-
#expect(pass._$authenticationToken.value == authenticationToken)
21-
#expect(pass._$personalization.id == personalization.id)
28+
let fetchedPass = try #require(await Pass.query(on: test.db).first())
29+
#expect(fetchedPass._$typeIdentifier.value == typeIdentifier)
30+
#expect(fetchedPass._$authenticationToken.value == authenticationToken)
31+
#expect(fetchedPass._$personalization.id == personalization.id)
32+
33+
try await migration.revert(on: test.db)
2234
}
2335

2436
@Test("PassesRegistration Concrete Model")
2537
func passesRegistration() async throws {
38+
let migration = CreatePassesRegistration()
39+
try await migration.prepare(on: test.db)
40+
2641
let device = Device()
2742
device._$id.value = 1
2843
let pass = Pass()
@@ -31,13 +46,22 @@ struct FluentPassesTests {
3146
let passesRegistration = PassesRegistration()
3247
passesRegistration.$device.id = device.id!
3348
passesRegistration.$pass.id = pass.id!
49+
test.append([
50+
TestOutput(passesRegistration)
51+
])
3452

35-
#expect(passesRegistration._$device.id == device.id)
36-
#expect(passesRegistration._$pass.id == pass.id)
53+
let fetchedPassesRegistration = try #require(await PassesRegistration.query(on: test.db).first())
54+
#expect(fetchedPassesRegistration._$device.id == device.id)
55+
#expect(fetchedPassesRegistration._$pass.id == pass.id)
56+
57+
try await migration.revert(on: test.db)
3758
}
3859

3960
@Test("Personalization Concrete Model")
4061
func personalization() async throws {
62+
let migration = CreatePersonalization()
63+
try await migration.prepare(on: test.db)
64+
4165
let fullName = "Test Name"
4266
let givenName = String(fullName.prefix(4))
4367
let familyName = String(fullName.suffix(4))
@@ -54,14 +78,20 @@ struct FluentPassesTests {
5478
personalization.postalCode = postalCode
5579
personalization.isoCountryCode = isoCountryCode
5680
personalization.phoneNumber = phoneNumber
81+
test.append([
82+
TestOutput(personalization)
83+
])
84+
85+
let fetchedPersonalization = try #require(await Personalization.query(on: test.db).first())
86+
#expect(fetchedPersonalization._$fullName.value == fullName)
87+
#expect(fetchedPersonalization._$givenName.value == givenName)
88+
#expect(fetchedPersonalization._$familyName.value == familyName)
89+
#expect(fetchedPersonalization._$emailAddress.value == emailAddress)
90+
#expect(fetchedPersonalization._$postalCode.value == postalCode)
91+
#expect(fetchedPersonalization._$isoCountryCode.value == isoCountryCode)
92+
#expect(fetchedPersonalization._$phoneNumber.value == phoneNumber)
5793

58-
#expect(personalization._$fullName.value == fullName)
59-
#expect(personalization._$givenName.value == givenName)
60-
#expect(personalization._$familyName.value == familyName)
61-
#expect(personalization._$emailAddress.value == emailAddress)
62-
#expect(personalization._$postalCode.value == postalCode)
63-
#expect(personalization._$isoCountryCode.value == isoCountryCode)
64-
#expect(personalization._$phoneNumber.value == phoneNumber)
94+
try await migration.revert(on: test.db)
6595
}
6696

6797
@Test("PersonalizationJSON initialization")
Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,44 @@
11
import FluentWallet
22
import Testing
3+
import XCTFluent
34

45
@Suite("FluentWallet Tests")
56
struct FluentWalletTests {
7+
let test = ArrayTestDatabase()
8+
69
@Test("Device Concrete Model")
710
func devices() async throws {
11+
let migration = CreateDevice()
12+
try await migration.prepare(on: test.db)
13+
814
let libraryIdentifier = "Test Library Identifier"
915
let pushToken = "Test Push Token"
1016

11-
let device = Device(libraryIdentifier: libraryIdentifier, pushToken: pushToken)
17+
test.append([
18+
TestOutput(Device(libraryIdentifier: libraryIdentifier, pushToken: pushToken))
19+
])
20+
21+
let fetchedDevice = try #require(await Device.query(on: test.db).first())
22+
#expect(fetchedDevice._$libraryIdentifier.value == libraryIdentifier)
23+
#expect(fetchedDevice._$pushToken.value == pushToken)
1224

13-
#expect(device._$libraryIdentifier.value == libraryIdentifier)
14-
#expect(device._$pushToken.value == pushToken)
25+
try await migration.revert(on: test.db)
1526
}
1627

1728
@Test("LogEntry Concrete Model")
1829
func logEntries() async throws {
30+
let migration = CreateLogEntry()
31+
try await migration.prepare(on: test.db)
32+
1933
let message = "Test message"
2034

21-
let logEntry = LogEntry(message: message)
35+
test.append([
36+
TestOutput(LogEntry(message: message))
37+
])
38+
39+
let fetchedLogEntry = try #require(await LogEntry.query(on: test.db).first())
40+
#expect(fetchedLogEntry._$message.value == message)
2241

23-
#expect(logEntry._$message.value == message)
42+
try await migration.revert(on: test.db)
2443
}
2544
}

0 commit comments

Comments
 (0)