@@ -11,8 +11,9 @@ struct RelationshipTests {
11
11
private var job : Job !
12
12
13
13
init ( ) async throws {
14
- try await DB . shutdown ( )
15
- try await DB . fake ( migrations: [ WorkflowMigration ( ) ] )
14
+ let db = Database . memory
15
+ try await db. migrate ( [ WorkflowMigration ( ) ] )
16
+ Container . main. set ( db)
16
17
17
18
/*
18
19
========== STRUCTURE ==========
@@ -51,31 +52,43 @@ struct RelationshipTests {
51
52
@Test func hasMany( ) async throws {
52
53
let repositories = try await user. refresh ( ) . repositories
53
54
#expect( repositories. map ( \. id) == [ 5 , 6 ] )
55
+
56
+ try await _cleanup ( )
54
57
}
55
58
56
59
@Test func hasOne( ) async throws {
57
60
let manager = try await user. report
58
61
#expect( manager? . id == 4 )
62
+
63
+ try await _cleanup ( )
59
64
}
60
65
61
66
@Test func belongsTo( ) async throws {
62
67
let user = try await repository. user
63
68
#expect( user. id == 3 )
69
+
70
+ try await _cleanup ( )
64
71
}
65
72
66
73
@Test func through( ) async throws {
67
74
let jobs = try await user. jobs. get ( )
68
75
#expect( jobs. map ( \. id) == [ 9 , 10 ] )
76
+
77
+ try await _cleanup ( )
69
78
}
70
79
71
80
@Test func pivot( ) async throws {
72
81
let organizations = try await user. organizations
73
82
#expect( organizations. map ( \. id) == [ 1 , 2 ] )
83
+
84
+ try await _cleanup ( )
74
85
}
75
86
76
87
@Test func fetchWhere( ) async throws {
77
88
let organizations = try await organization. usersOver30. get ( )
78
89
#expect( organizations. map ( \. id) == [ 4 ] )
90
+
91
+ try await _cleanup ( )
79
92
}
80
93
81
94
// MARK: - Eager Loading
@@ -84,19 +97,25 @@ struct RelationshipTests {
84
97
let user = try await User . where ( " id " == 3 ) . with ( \. $repositories) . first ( )
85
98
#expect( user != nil )
86
99
#expect( throws: Never . self) { try user? . $repositories. require ( ) }
100
+
101
+ try await _cleanup ( )
87
102
}
88
103
89
104
@Test func autoCache( ) async throws {
90
105
#expect( throws: Error . self) { try user. $repositories. require ( ) }
91
106
_ = try await user. $repositories. value ( )
92
107
#expect( user. $repositories. isLoaded == true )
93
108
#expect( throws: Never . self) { try user. $repositories. require ( ) }
109
+
110
+ try await _cleanup ( )
94
111
}
95
112
96
113
@Test func whereCache( ) async throws {
97
114
_ = try await organization. users
98
115
#expect( organization. $users. isLoaded == true )
99
116
#expect( organization. usersOver30. isLoaded == false )
117
+
118
+ try await _cleanup ( )
100
119
}
101
120
102
121
@Test func sync( ) async throws {
@@ -106,6 +125,8 @@ struct RelationshipTests {
106
125
#expect( user. $report. isLoaded == true )
107
126
#expect( try await user. report? . id == 4 )
108
127
#expect( try await user. $report. load ( ) == nil )
128
+
129
+ try await _cleanup ( )
109
130
}
110
131
111
132
// MARK: - CRUD
@@ -125,6 +146,10 @@ struct RelationshipTests {
125
146
@Test ( . disabled( ) )
126
147
func pivotReplace( ) async throws {
127
148
}
149
+
150
+ private func _cleanup( ) async throws {
151
+ try await DB . shutdown ( )
152
+ }
128
153
}
129
154
130
155
@Model
0 commit comments