Skip to content

Commit 7663116

Browse files
committed
Convert Joined3Tests
1 parent d9efc0a commit 7663116

File tree

1 file changed

+68
-60
lines changed

1 file changed

+68
-60
lines changed

Tests/AppTests/Joined3Tests.swift

Lines changed: 68 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -14,89 +14,97 @@
1414

1515
@testable import App
1616

17+
import Testing
1718
import Vapor
18-
import XCTest
1919

20-
class Joined3Tests: AppTestCase {
2120

22-
func test_query_no_version() async throws {
23-
// setup
24-
let p = try await savePackage(on: app.db, "1")
25-
try await Repository(package: p).save(on: app.db)
21+
@Suite struct Joined3Tests {
2622

27-
// MUT
28-
let res = try await Joined3<Package, Repository, Version>.query(on: app.db).all()
29-
30-
// validate
31-
XCTAssertEqual(res.map(\.model.id), [])
32-
}
33-
34-
func test_query_multiple_versions() async throws {
35-
// Ensure multiple versions don't multiply the package selection
36-
// setup
37-
let p = try await savePackage(on: app.db, "1")
38-
try await Repository(package: p).save(on: app.db)
39-
try await Version(package: p, latest: .defaultBranch).save(on: app.db)
40-
try await Version(package: p, latest: .release).save(on: app.db)
41-
42-
// MUT
43-
let res = try await Joined3<Package, Repository, Version>
44-
.query(on: app.db, version: .defaultBranch)
45-
.all()
46-
47-
// validate
48-
XCTAssertEqual(res.map(\.model.id), [p.id])
49-
}
23+
@Test func query_no_version() async throws {
24+
try await withApp { app in
25+
// setup
26+
let p = try await savePackage(on: app.db, "1")
27+
try await Repository(package: p).save(on: app.db)
5028

29+
// MUT
30+
let res = try await Joined3<Package, Repository, Version>.query(on: app.db).all()
5131

52-
func test_query_relationship_properties() async throws {
53-
// Ensure relationship properties are populated by query
54-
// setup
55-
let p = try await savePackage(on: app.db, "1")
56-
try await Repository(package: p, owner: "owner").save(on: app.db)
57-
try await Version(package: p,
58-
latest: .defaultBranch,
59-
packageName: "package name").save(on: app.db)
60-
61-
// MUT
62-
let res = try await Joined3<Package, Repository, Version>
63-
.query(on: app.db, version: .defaultBranch)
64-
.all()
65-
66-
// validate
67-
XCTAssertEqual(res.map { $0.repository.owner }, ["owner"])
68-
XCTAssertEqual(res.map { $0.version.packageName }, ["package name"])
32+
// validate
33+
#expect(res.map(\.model.id) == [])
34+
}
6935
}
7036

71-
func test_query_missing_relations() async throws {
72-
// Neither should be possible in practice, this is just ensuring we cannot
73-
// force unwrap the `repository` or `version` properties in the pathological
74-
// event, because there are no results to access the properties on.
75-
do { // no repository
37+
@Test func query_multiple_versions() async throws {
38+
// Ensure multiple versions don't multiply the package selection
39+
try await withApp { app in
40+
// setup
7641
let p = try await savePackage(on: app.db, "1")
77-
try await Version(package: p,
78-
latest: .defaultBranch,
79-
packageName: "package name").save(on: app.db)
42+
try await Repository(package: p).save(on: app.db)
43+
try await Version(package: p, latest: .defaultBranch).save(on: app.db)
44+
try await Version(package: p, latest: .release).save(on: app.db)
8045

8146
// MUT
8247
let res = try await Joined3<Package, Repository, Version>
8348
.query(on: app.db, version: .defaultBranch)
8449
.all()
8550

86-
// validate - result is empty, `res[0].repository` cannot be called
87-
XCTAssertTrue(res.isEmpty)
51+
// validate
52+
#expect(res.map(\.model.id) == [p.id])
8853
}
89-
do { // no version
90-
let p = try await savePackage(on: app.db, "2")
54+
}
55+
56+
@Test func query_relationship_properties() async throws {
57+
// Ensure relationship properties are populated by query
58+
try await withApp { app in
59+
// setup
60+
let p = try await savePackage(on: app.db, "1")
9161
try await Repository(package: p, owner: "owner").save(on: app.db)
62+
try await Version(package: p,
63+
latest: .defaultBranch,
64+
packageName: "package name").save(on: app.db)
9265

9366
// MUT
9467
let res = try await Joined3<Package, Repository, Version>
9568
.query(on: app.db, version: .defaultBranch)
9669
.all()
9770

98-
// validate - result is empty, `res[0].repository` cannot be called
99-
XCTAssertTrue(res.isEmpty)
71+
// validate
72+
#expect(res.map { $0.repository.owner } == ["owner"])
73+
#expect(res.map { $0.version.packageName } == ["package name"])
74+
}
75+
}
76+
77+
@Test func query_missing_relations() async throws {
78+
// Neither should be possible in practice, this is just ensuring we cannot
79+
// force unwrap the `repository` or `version` properties in the pathological
80+
// event, because there are no results to access the properties on.
81+
try await withApp { app in
82+
do { // no repository
83+
let p = try await savePackage(on: app.db, "1")
84+
try await Version(package: p,
85+
latest: .defaultBranch,
86+
packageName: "package name").save(on: app.db)
87+
88+
// MUT
89+
let res = try await Joined3<Package, Repository, Version>
90+
.query(on: app.db, version: .defaultBranch)
91+
.all()
92+
93+
// validate - result is empty, `res[0].repository` cannot be called
94+
#expect(res.isEmpty)
95+
}
96+
do { // no version
97+
let p = try await savePackage(on: app.db, "2")
98+
try await Repository(package: p, owner: "owner").save(on: app.db)
99+
100+
// MUT
101+
let res = try await Joined3<Package, Repository, Version>
102+
.query(on: app.db, version: .defaultBranch)
103+
.all()
104+
105+
// validate - result is empty, `res[0].repository` cannot be called
106+
#expect(res.isEmpty)
107+
}
100108
}
101109
}
102110

0 commit comments

Comments
 (0)