|
14 | 14 |
|
15 | 15 | @testable import App |
16 | 16 |
|
| 17 | +import Testing |
17 | 18 | import Vapor |
18 | | -import XCTest |
19 | 19 |
|
20 | | -class Joined3Tests: AppTestCase { |
21 | 20 |
|
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 { |
26 | 22 |
|
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) |
50 | 28 |
|
| 29 | + // MUT |
| 30 | + let res = try await Joined3<Package, Repository, Version>.query(on: app.db).all() |
51 | 31 |
|
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 | + } |
69 | 35 | } |
70 | 36 |
|
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 |
76 | 41 | 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) |
80 | 45 |
|
81 | 46 | // MUT |
82 | 47 | let res = try await Joined3<Package, Repository, Version> |
83 | 48 | .query(on: app.db, version: .defaultBranch) |
84 | 49 | .all() |
85 | 50 |
|
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]) |
88 | 53 | } |
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") |
91 | 61 | 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) |
92 | 65 |
|
93 | 66 | // MUT |
94 | 67 | let res = try await Joined3<Package, Repository, Version> |
95 | 68 | .query(on: app.db, version: .defaultBranch) |
96 | 69 | .all() |
97 | 70 |
|
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 | + } |
100 | 108 | } |
101 | 109 | } |
102 | 110 |
|
|
0 commit comments