Skip to content

Commit 4403b23

Browse files
committed
Add test_CustomCollection_reconcile_caseSensitive
1 parent 592ff8b commit 4403b23

File tree

2 files changed

+58
-10
lines changed

2 files changed

+58
-10
lines changed

Tests/AppTests/CustomCollectionTests.swift

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -234,27 +234,27 @@ class CustomCollectionTests: AppTestCase {
234234
// Test reconciliation of a custom collection against a list of package URLs
235235
let collection = CustomCollection(id: .id0, .init(name: "List", url: "https://github.com/foo/bar/list.json"))
236236
try await collection.save(on: app.db)
237-
try await Package(id: .id1, url: URL("https://a")).save(on: app.db)
238-
try await Package(id: .id2, url: URL("https://b")).save(on: app.db)
237+
try await Package(id: .id1, url: URL("a")).save(on: app.db)
238+
try await Package(id: .id2, url: URL("b")).save(on: app.db)
239239

240240
do { // Initial set of URLs
241241
// MUT
242-
try await collection.reconcile(on: app.db, packageURLs: [URL("https://a")])
242+
try await collection.reconcile(on: app.db, packageURLs: [URL("a")])
243243

244244
do { // validate
245245
let count = try await CustomCollectionPackage.query(on: app.db).count()
246246
XCTAssertEqual(count, 1)
247247
let collection = try await CustomCollection.find(.id0, on: app.db).unwrap()
248248
try await collection.$packages.load(on: app.db)
249-
XCTAssertEqual(collection.packages.map(\.url), ["https://a"])
249+
XCTAssertEqual(collection.packages.map(\.url), ["a"])
250250
}
251251
}
252252

253253
do { // Add more URLs
254254
// MUT
255255
try await collection.reconcile(on: app.db, packageURLs: [
256-
URL("https://a"),
257-
URL("https://b")
256+
URL("a"),
257+
URL("b")
258258
])
259259

260260
do { // validate
@@ -263,26 +263,48 @@ class CustomCollectionTests: AppTestCase {
263263
let collection = try await CustomCollection.find(.id0, on: app.db).unwrap()
264264
try await collection.$packages.load(on: app.db)
265265
XCTAssertEqual(collection.packages.map(\.url).sorted(), [
266-
"https://a",
267-
"https://b"
266+
"a",
267+
"b"
268268
])
269269
}
270270
}
271271

272272
do { // Remove URLs
273273
// MUT
274274
try await collection.reconcile(on: app.db, packageURLs: [
275-
URL("https://b")
275+
URL("b")
276276
])
277277

278278
do { // validate
279279
let count = try await CustomCollectionPackage.query(on: app.db).count()
280280
XCTAssertEqual(count, 1)
281281
let collection = try await CustomCollection.find(.id0, on: app.db).unwrap()
282282
try await collection.$packages.load(on: app.db)
283-
XCTAssertEqual(collection.packages.map(\.url), ["https://b"])
283+
XCTAssertEqual(collection.packages.map(\.url), ["b"])
284284
}
285285
}
286286
}
287287

288+
func test_CustomCollection_reconcile_caseSensitive() async throws {
289+
// Test reconciliation with a case-insensitive matching URL
290+
let collection = CustomCollection(id: .id0, .init(name: "List", url: "https://github.com/foo/bar/list.json"))
291+
try await collection.save(on: app.db)
292+
try await Package(id: .id1, url: URL("a")).save(on: app.db)
293+
294+
// MUT
295+
try await collection.reconcile(on: app.db, packageURLs: [URL("A")])
296+
297+
do { // validate
298+
// The package is not added to the custom collection, because it is not an
299+
// exact match for the package URL.
300+
// This is currently a limiting of the Fluent ~~ operator in the query
301+
// filter(\.$url ~~ urls.map(\.absoluteString))
302+
let count = try await CustomCollectionPackage.query(on: app.db).count()
303+
XCTAssertEqual(count, 0)
304+
let collection = try await CustomCollection.find(.id0, on: app.db).unwrap()
305+
try await collection.$packages.load(on: app.db)
306+
XCTAssertEqual(collection.packages.map(\.url), [])
307+
}
308+
}
309+
288310
}

Tests/AppTests/ReconcilerTests.swift

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,4 +180,30 @@ class ReconcilerTests: AppTestCase {
180180
}
181181
}
182182

183+
func test_reconcileCustomCollections_limit() async throws {
184+
// Test custom collection reconciliation size limit
185+
// setup
186+
let fullPackageList = (1...60).map { URL(string: "\($0)")! }
187+
for url in fullPackageList { try await Package(url: url).save(on: app.db) }
188+
189+
try await withDependencies {
190+
$0.packageListRepository.fetchCustomCollection = { @Sendable _, _ in
191+
fullPackageList
192+
}
193+
} operation: {
194+
// MUT
195+
try await reconcileCustomCollection(client: app.client,
196+
database: app.db,
197+
fullPackageList: fullPackageList,
198+
.init(name: "List", url: "url"))
199+
200+
// validate
201+
let collection = try await CustomCollection.query(on: app.db).first().unwrap()
202+
try await collection.$packages.load(on: app.db)
203+
XCTAssertEqual(collection.packages.count, 50)
204+
XCTAssertEqual(collection.packages.first?.url, "1")
205+
XCTAssertEqual(collection.packages.last?.url, "50")
206+
}
207+
}
208+
183209
}

0 commit comments

Comments
 (0)