Skip to content

Commit e32d698

Browse files
committed
Add CustomCollectionControllerTests.test_query
1 parent 9ca577c commit e32d698

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// Copyright Dave Verwer, Sven A. Schmidt, and other contributors.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
import XCTest
16+
17+
@testable import App
18+
19+
import Dependencies
20+
import Vapor
21+
22+
23+
class CustomCollectionControllerTests: AppTestCase {
24+
25+
func test_query() async throws {
26+
// setup
27+
let pkg = Package(id: .id0, url: "1".asGithubUrl.url)
28+
try await pkg.save(on: app.db)
29+
try await Repository(package: pkg, name: "1", owner: "owner").save(on: app.db)
30+
try await Version(package: pkg, latest: .defaultBranch).save(on: app.db)
31+
let collection = CustomCollection(id: .id1, .init(key: "list",
32+
name: "List",
33+
url: "https://github.com/foo/bar/list.json"))
34+
try await collection.save(on: app.db)
35+
try await collection.$packages.attach([pkg], on: app.db)
36+
37+
// MUT
38+
let page = try await CustomCollectionsController.query(on: app.db,
39+
key: "list",
40+
page: 1,
41+
pageSize: 10)
42+
43+
// validation
44+
XCTAssertEqual(page.results.map(\.repository.name), ["1"])
45+
XCTAssertEqual(page.hasMoreResults, false)
46+
}
47+
48+
}

0 commit comments

Comments
 (0)