@@ -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}
0 commit comments