Skip to content

Commit 3e0e3e8

Browse files
committed
Wire up custom collection generation
1 parent 6196bd0 commit 3e0e3e8

File tree

4 files changed

+134
-3
lines changed

4 files changed

+134
-3
lines changed

Sources/App/Controllers/PackageCollectionController.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,13 @@ enum PackageCollectionController {
3333
authorName: "\(owner) via the Swift Package Index"
3434
)
3535
case let .custom(name):
36-
fatalError("FIXME")
36+
return try await SignedCollection.generate(
37+
db: req.db,
38+
filterBy: .customCollection(name),
39+
authorName: "Swift Package Index",
40+
collectionName: name,
41+
overview: "A custom package collection generated by the Swift Package Index"
42+
)
3743
}
3844
} catch PackageCollection.Error.noResults {
3945
throw Abort(.notFound)

Tests/AppTests/ApiTests.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -809,7 +809,6 @@ class ApiTests: AppTestCase {
809809
try await v.save(on: app.db)
810810
try await Product(version: v, type: .library(.automatic), name: "lib")
811811
.save(on: app.db)
812-
try await Search.refresh(on: app.db)
813812

814813
let event = App.ActorIsolated<TestEvent?>(nil)
815814
Current.postPlausibleEvent = { @Sendable _, kind, path, _ in
@@ -897,7 +896,6 @@ class ApiTests: AppTestCase {
897896
try await Product(version: v, type: .library(.automatic), name: "p2")
898897
.save(on: app.db)
899898
}
900-
try await Search.refresh(on: app.db)
901899

902900
do { // MUT
903901
let body: ByteBuffer = .init(string: """

Tests/AppTests/PackageCollectionControllerTests.swift

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,62 @@ class PackageCollectionControllerTests: AppTestCase {
7474
}
7575
}
7676

77+
func test_custom_request() async throws {
78+
try XCTSkipIf(!isRunningInCI && Current.collectionSigningPrivateKey() == nil, "Skip test for local user due to unset COLLECTION_SIGNING_PRIVATE_KEY env variable")
79+
try await withDependencies {
80+
$0.date.now = .t0
81+
} operation: {
82+
let p = try await savePackage(on: app.db, "https://github.com/foo/1")
83+
do {
84+
let v = try Version(id: UUID(),
85+
package: p,
86+
packageName: "P1-main",
87+
reference: .branch("main"),
88+
toolsVersion: "5.0")
89+
try await v.save(on: app.db)
90+
try await Product(version: v, type: .library(.automatic), name: "P1Lib")
91+
.save(on: app.db)
92+
}
93+
do {
94+
let v = try Version(id: UUID(),
95+
package: p,
96+
latest: .release,
97+
packageName: "P1-tag",
98+
reference: .tag(1, 2, 3),
99+
toolsVersion: "5.1")
100+
try await v.save(on: app.db)
101+
try await Product(version: v, type: .library(.automatic), name: "P1Lib", targets: ["t1"])
102+
.save(on: app.db)
103+
try await Build(version: v,
104+
platform: .iOS,
105+
status: .ok,
106+
swiftVersion: .init(5, 6, 0)).save(on: app.db)
107+
try await Target(version: v, name: "t1").save(on: app.db)
108+
}
109+
try await Repository(package: p,
110+
defaultBranch: "main",
111+
license: .mit,
112+
licenseUrl: "https://foo/mit",
113+
owner: "foo",
114+
summary: "summary 1").create(on: app.db)
115+
let collection = CustomCollection(id: .id2, .init(name: "Custom Collection", url: "https://github.com/foo/bar/list.json"))
116+
try await collection.save(on: app.db)
117+
try await collection.$packages.attach(p, on: app.db)
118+
119+
// MUT
120+
let encoder = self.encoder
121+
try await app.test(
122+
.GET,
123+
"collections/Custom%20Collection/collection.json",
124+
afterResponse: { @MainActor res async throws in
125+
// validation
126+
XCTAssertEqual(res.status, .ok)
127+
let json = try res.content.decode(PackageCollection.self)
128+
assertSnapshot(of: json, as: .json(encoder))
129+
})
130+
}
131+
}
132+
77133
func test_nonexisting_404() throws {
78134
// Ensure a request for a non-existing collection returns a 404
79135
// MUT
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
{
2+
"formatVersion" : "1.0",
3+
"generatedAt" : "1970-01-01T00:00:00Z",
4+
"generatedBy" : {
5+
"name" : "Swift Package Index"
6+
},
7+
"name" : "Custom Collection",
8+
"overview" : "A custom package collection generated by the Swift Package Index",
9+
"packages" : [
10+
{
11+
"license" : {
12+
"name" : "MIT",
13+
"url" : "https:\/\/foo\/mit"
14+
},
15+
"summary" : "summary 1",
16+
"url" : "https:\/\/github.com\/foo\/1",
17+
"versions" : [
18+
{
19+
"defaultToolsVersion" : "5.1",
20+
"license" : {
21+
"name" : "MIT",
22+
"url" : "https:\/\/foo\/mit"
23+
},
24+
"manifests" : {
25+
"5.1" : {
26+
"minimumPlatformVersions" : [
27+
28+
],
29+
"packageName" : "P1-tag",
30+
"products" : [
31+
{
32+
"name" : "P1Lib",
33+
"targets" : [
34+
"t1"
35+
],
36+
"type" : {
37+
"library" : [
38+
"automatic"
39+
]
40+
}
41+
}
42+
],
43+
"targets" : [
44+
{
45+
"moduleName" : "t1",
46+
"name" : "t1"
47+
}
48+
],
49+
"toolsVersion" : "5.1"
50+
}
51+
},
52+
"signer" : {
53+
"commonName" : "Swift Package Index",
54+
"organizationName" : "Swift Package Index",
55+
"organizationalUnitName" : "Swift Package Index",
56+
"type" : "ADP"
57+
},
58+
"verifiedCompatibility" : [
59+
{
60+
"platform" : {
61+
"name" : "ios"
62+
},
63+
"swiftVersion" : "5.6"
64+
}
65+
],
66+
"version" : "1.2.3"
67+
}
68+
]
69+
}
70+
]
71+
}

0 commit comments

Comments
 (0)