Skip to content

Commit 1572f1f

Browse files
committed
Implement test_reconcile
1 parent 8a20965 commit 1572f1f

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed

Tests/AppTests/ReconcilerTests.swift

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,39 @@ class ReconcilerTests: AppTestCase {
207207
}
208208

209209
func test_reconcile() async throws {
210-
XCTFail("Implement integration test for both parts, main list + custom collection")
210+
let fullPackageList = (1...3).map { URL(string: "\($0)")! }
211+
struct TestError: Error { var message: String }
212+
213+
try await withDependencies {
214+
$0.packageListRepository.fetchCustomCollection = { @Sendable _, url in
215+
if url == "collectionURL" {
216+
return [URL("2")]
217+
} else {
218+
throw TestError(message: "collection not found: \(url)")
219+
}
220+
}
221+
$0.packageListRepository.fetchCustomCollections = { @Sendable _ in
222+
[.init(name: "List", url: "collectionURL")]
223+
}
224+
} operation: {
225+
// setup
226+
Current.fetchPackageList = { _ in fullPackageList }
227+
228+
// MUT
229+
_ = try await reconcile(client: app.client, database: app.db)
230+
231+
// validate
232+
let packages = try await Package.query(on: app.db).all()
233+
XCTAssertEqual(packages.map(\.url).sorted(),
234+
fullPackageList.map(\.absoluteString).sorted())
235+
let count = try await CustomCollection.query(on: app.db).count()
236+
XCTAssertEqual(count, 1)
237+
let collection = try await CustomCollection.query(on: app.db).first().unwrap()
238+
XCTAssertEqual(collection.name, "List")
239+
XCTAssertEqual(collection.url, "collectionURL")
240+
try await collection.$packages.load(on: app.db)
241+
XCTAssertEqual(collection.packages.map(\.url), ["2"])
242+
}
211243
}
212244

213245
}

0 commit comments

Comments
 (0)