Skip to content

Commit c491936

Browse files
committed
Convert BuildMonitorIndexModelTests
1 parent 3ba365d commit c491936

File tree

1 file changed

+106
-96
lines changed

1 file changed

+106
-96
lines changed

Tests/AppTests/BuildMonitorIndexModelTests.swift

Lines changed: 106 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -15,111 +15,121 @@
1515
@testable import App
1616

1717
import Plot
18-
import XCTVapor
19-
20-
class BuildMonitorIndexModelTests: AppTestCase {
21-
22-
func test_init_from_Build() async throws {
23-
do {
24-
let package = try await savePackage(on: app.db, "https://github.com/daveverwer/LeftPad")
25-
let version = try Version(package: package,
26-
latest: .defaultBranch,
27-
packageName: "LeftPad from Version.packageName",
28-
reference: .branch("main"))
29-
try await version.save(on: app.db)
30-
try await Build(id: .id0,
31-
version: version,
32-
platform: .macosXcodebuild,
33-
status: .ok,
34-
swiftVersion: .init(5, 6, 0)).save(on: app.db)
35-
try await Repository(package: package,
36-
ownerName: "Dave Verwer from Repository.ownerName").save(on: app.db)
18+
import Testing
19+
20+
21+
@Suite struct BuildMonitorIndexModelTests {
22+
23+
@Test func init_from_Build() async throws {
24+
try await withApp { app in
25+
do {
26+
let package = try await savePackage(on: app.db, "https://github.com/daveverwer/LeftPad")
27+
let version = try Version(package: package,
28+
latest: .defaultBranch,
29+
packageName: "LeftPad from Version.packageName",
30+
reference: .branch("main"))
31+
try await version.save(on: app.db)
32+
try await Build(id: .id0,
33+
version: version,
34+
platform: .macosXcodebuild,
35+
status: .ok,
36+
swiftVersion: .init(5, 6, 0)).save(on: app.db)
37+
try await Repository(package: package,
38+
ownerName: "Dave Verwer from Repository.ownerName").save(on: app.db)
39+
}
40+
41+
// Query results back through the Joined4
42+
let buildResult = try await BuildResult.query(on: app.db).first().unwrap()
43+
44+
// MUT
45+
let model = try #require(BuildMonitorIndex.Model(buildResult: buildResult))
46+
47+
#expect(model.buildId == .id0)
48+
#expect(model.packageName == "LeftPad from Version.packageName")
49+
#expect(model.repositoryOwnerName == "Dave Verwer from Repository.ownerName")
50+
#expect(model.platform == .macosXcodebuild)
51+
#expect(model.swiftVersion == .init(5, 6, 0))
52+
#expect(model.reference == .branch("main"))
53+
#expect(model.referenceKind == .defaultBranch)
54+
#expect(model.status == .ok)
3755
}
38-
39-
// Query results back through the Joined4
40-
let buildResult = try await BuildResult.query(on: app.db).first().unwrap()
41-
42-
// MUT
43-
let model = try XCTUnwrap(BuildMonitorIndex.Model(buildResult: buildResult))
44-
45-
XCTAssertEqual(model.buildId, .id0)
46-
XCTAssertEqual(model.packageName, "LeftPad from Version.packageName")
47-
XCTAssertEqual(model.repositoryOwnerName, "Dave Verwer from Repository.ownerName")
48-
XCTAssertEqual(model.platform, .macosXcodebuild)
49-
XCTAssertEqual(model.swiftVersion, .init(5, 6, 0))
50-
XCTAssertEqual(model.reference, .branch("main"))
51-
XCTAssertEqual(model.referenceKind, .defaultBranch)
52-
XCTAssertEqual(model.status, .ok)
5356
}
5457

55-
func test_init_from_Build_without_repository_name() async throws {
56-
do {
57-
let package = try await savePackage(on: app.db, "https://github.com/daveverwer/LeftPad")
58-
let version = try Version(package: package,
59-
packageName: nil) // Deliberately missing a `packageName`
60-
try await version.save(on: app.db)
61-
try await Build(version: version,
62-
platform: .macosXcodebuild,
63-
status: .ok,
64-
swiftVersion: .init(5, 6, 0)).save(on: app.db)
65-
try await Repository(package: package,
66-
name: "LeftPad from Repository.name").save(on: app.db)
58+
@Test func init_from_Build_without_repository_name() async throws {
59+
try await withApp { app in
60+
do {
61+
let package = try await savePackage(on: app.db, "https://github.com/daveverwer/LeftPad")
62+
let version = try Version(package: package,
63+
packageName: nil) // Deliberately missing a `packageName`
64+
try await version.save(on: app.db)
65+
try await Build(version: version,
66+
platform: .macosXcodebuild,
67+
status: .ok,
68+
swiftVersion: .init(5, 6, 0)).save(on: app.db)
69+
try await Repository(package: package,
70+
name: "LeftPad from Repository.name").save(on: app.db)
71+
}
72+
73+
// Query results back through the Joined4
74+
let buildResult = try await BuildResult.query(on: app.db).first().unwrap()
75+
76+
// MUT
77+
let model = try #require(BuildMonitorIndex.Model(buildResult: buildResult))
78+
79+
#expect(model.packageName == "LeftPad from Repository.name")
6780
}
68-
69-
// Query results back through the Joined4
70-
let buildResult = try await BuildResult.query(on: app.db).first().unwrap()
71-
72-
// MUT
73-
let model = try XCTUnwrap(BuildMonitorIndex.Model(buildResult: buildResult))
74-
75-
XCTAssertEqual(model.packageName, "LeftPad from Repository.name")
7681
}
7782

78-
func test_init_from_Build_with_no_package_name() async throws {
79-
do {
80-
let package = try await savePackage(on: app.db, "https://github.com/daveverwer/LeftPad")
81-
let version = try Version(package: package,
82-
packageName: nil) // Deliberately missing a `packageName`
83-
try await version.save(on: app.db)
84-
try await Build(version: version,
85-
platform: .macosXcodebuild,
86-
status: .ok,
87-
swiftVersion: .init(5, 6, 0)).save(on: app.db)
88-
try await Repository(package: package,
89-
name: nil) // Deliberately missing a `name`
90-
.save(on: app.db)
83+
@Test func init_from_Build_with_no_package_name() async throws {
84+
try await withApp { app in
85+
do {
86+
let package = try await savePackage(on: app.db, "https://github.com/daveverwer/LeftPad")
87+
let version = try Version(package: package,
88+
packageName: nil) // Deliberately missing a `packageName`
89+
try await version.save(on: app.db)
90+
try await Build(version: version,
91+
platform: .macosXcodebuild,
92+
status: .ok,
93+
swiftVersion: .init(5, 6, 0)).save(on: app.db)
94+
try await Repository(package: package,
95+
name: nil) // Deliberately missing a `name`
96+
.save(on: app.db)
97+
}
98+
99+
// Query results back through the Joined4
100+
let buildResult = try await BuildResult.query(on: app.db).first().unwrap()
101+
102+
// MUT
103+
let model = try #require(BuildMonitorIndex.Model(buildResult: buildResult))
104+
105+
#expect(model.packageName == "Unknown Package")
91106
}
92-
93-
// Query results back through the Joined4
94-
let buildResult = try await BuildResult.query(on: app.db).first().unwrap()
95-
96-
// MUT
97-
let model = try XCTUnwrap(BuildMonitorIndex.Model(buildResult: buildResult))
98-
99-
XCTAssertEqual(model.packageName, "Unknown Package")
100107
}
101108

102-
func test_init_from_Build_without_ownerName() async throws {
103-
do {
104-
let package = try await savePackage(on: app.db, "https://github.com/daveverwer/LeftPad")
105-
let version = try Version(package: package)
106-
try await version.save(on: app.db)
107-
try await Build(version: version,
108-
platform: .macosXcodebuild,
109-
status: .ok,
110-
swiftVersion: .init(5, 6, 0)).save(on: app.db)
111-
try await Repository(package: package,
112-
owner: "daveverwer from Repository.owner",
113-
ownerName: nil) // Deliberately missing an `ownerName`
114-
.save(on: app.db)
109+
@Test func init_from_Build_without_ownerName() async throws {
110+
try await withApp { app in
111+
do {
112+
let package = try await savePackage(on: app.db, "https://github.com/daveverwer/LeftPad")
113+
let version = try Version(package: package)
114+
try await version.save(on: app.db)
115+
try await Build(version: version,
116+
platform: .macosXcodebuild,
117+
status: .ok,
118+
swiftVersion: .init(5, 6, 0)).save(on: app.db)
119+
try await Repository(package: package,
120+
owner: "daveverwer from Repository.owner",
121+
ownerName: nil) // Deliberately missing an `ownerName`
122+
.save(on: app.db)
123+
}
124+
125+
// Query results back through the Joined4
126+
let buildResult = try await BuildResult.query(on: app.db).first().unwrap()
127+
128+
// MUT
129+
let model = try #require(BuildMonitorIndex.Model(buildResult: buildResult))
130+
131+
#expect(model.repositoryOwnerName == "daveverwer from Repository.owner")
115132
}
116-
117-
// Query results back through the Joined4
118-
let buildResult = try await BuildResult.query(on: app.db).first().unwrap()
119-
120-
// MUT
121-
let model = try XCTUnwrap(BuildMonitorIndex.Model(buildResult: buildResult))
122-
123-
XCTAssertEqual(model.repositoryOwnerName, "daveverwer from Repository.owner")
124133
}
134+
125135
}

0 commit comments

Comments
 (0)