@@ -125,7 +125,8 @@ class IngestorTests: AppTestCase {
125
125
Date ( timeIntervalSince1970: 1 ) ,
126
126
] ,
127
127
license: . mit,
128
- openIssues: 1 ,
128
+ openIssues: 1 ,
129
+ parentUrl: nil ,
129
130
openPullRequests: 2 ,
130
131
owner: " foo " ,
131
132
pullRequestsClosedAtDates: [
@@ -155,7 +156,8 @@ class IngestorTests: AppTestCase {
155
156
html: " readme html " ,
156
157
htmlUrl: " readme html url " ,
157
158
imagesToCache: [ ] ) ,
158
- s3Readme: . cached( s3ObjectUrl: " url " , githubEtag: " etag " ) )
159
+ s3Readme: . cached( s3ObjectUrl: " url " , githubEtag: " etag " ) ,
160
+ fork: . parentURL( " https://github.com/foo/bar.git " ) )
159
161
160
162
// validate
161
163
do {
@@ -164,6 +166,7 @@ class IngestorTests: AppTestCase {
164
166
let repo = try await Repository . query ( on: app. db) . first ( ) . unwrap ( )
165
167
XCTAssertEqual ( repo. defaultBranch, " main " )
166
168
XCTAssertEqual ( repo. forks, 1 )
169
+ XCTAssertEqual ( repo. forkedFrom, . parentURL( " https://github.com/foo/bar.git " ) )
167
170
XCTAssertEqual ( repo. fundingLinks, [
168
171
. init( platform: . gitHub, url: " https://github.com/username " ) ,
169
172
. init( platform: . customUrl, url: " https://example.com/username1 " ) ,
@@ -208,6 +211,7 @@ class IngestorTests: AppTestCase {
208
211
issuesClosedAtDates: [ ] ,
209
212
license: . mit,
210
213
openIssues: 1 ,
214
+ parentUrl: nil ,
211
215
openPullRequests: 2 ,
212
216
owner: " foo " ,
213
217
pullRequestsClosedAtDates: [ ] ,
@@ -353,6 +357,7 @@ class IngestorTests: AppTestCase {
353
357
issuesClosedAtDates: [ ] ,
354
358
license: . mit,
355
359
openIssues: 0 ,
360
+ parentUrl: nil ,
356
361
openPullRequests: 0 ,
357
362
owner: " owner " ,
358
363
pullRequestsClosedAtDates: [ ] ,
@@ -594,4 +599,29 @@ class IngestorTests: AppTestCase {
594
599
let postMigrationFetchedRepo = try await XCTUnwrapAsync ( try await Repository . query ( on: app. db) . first ( ) )
595
600
XCTAssertEqual ( postMigrationFetchedRepo. s3Readme, . cached( s3ObjectUrl: " object-url " , githubEtag: " " ) )
596
601
}
602
+
603
+ func test_getFork( ) async throws {
604
+ try await Package ( id: . id0, url: " https://github.com/foo/parent.git " . url, processingStage: . analysis) . save ( on: app. db)
605
+ try await Package ( url: " https://github.com/bar/forked.git " , processingStage: . analysis) . save ( on: app. db)
606
+
607
+ // test lookup when package is in the index
608
+ let fork = await getFork ( on: app. db, parent: . init( url: " https://github.com/foo/parent.git " ) )
609
+ XCTAssertEqual ( fork, . parentId( . id0) )
610
+
611
+ // test lookup when package is in the index but with different case in URL
612
+ let fork2 = await getFork ( on: app. db, parent: . init( url: " https://github.com/Foo/Parent.git " ) )
613
+ XCTAssertEqual ( fork2, . parentId( . id0) )
614
+
615
+ // test whem metadata repo url doesn't have `.git` at end
616
+ let fork3 = await getFork ( on: app. db, parent: . init( url: " https://github.com/Foo/Parent " ) )
617
+ XCTAssertEqual ( fork3, . parentId( . id0) )
618
+
619
+ // test lookup when package is not in the index
620
+ let fork4 = await getFork ( on: app. db, parent: . init( url: " https://github.com/some/other.git " ) )
621
+ XCTAssertEqual ( fork4, . parentURL( " https://github.com/some/other.git " ) )
622
+
623
+ // test lookup when parent url is nil
624
+ let fork5 = await getFork ( on: app. db, parent: nil )
625
+ XCTAssertEqual ( fork5, nil )
626
+ }
597
627
}
0 commit comments