Skip to content

Commit 0a13c81

Browse files
committed
Convert TargetTests
1 parent bb74a36 commit 0a13c81

File tree

1 file changed

+42
-38
lines changed

1 file changed

+42
-38
lines changed

Tests/AppTests/TargetTests.swift

Lines changed: 42 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -15,54 +15,58 @@
1515
@testable import App
1616

1717
import Fluent
18+
import Testing
1819
import Vapor
19-
import XCTVapor
2020

2121

22-
final class TargetTests: AppTestCase {
22+
@Suite struct TargetTests {
2323

24-
func test_save() async throws {
25-
// setup
26-
let v = Version()
27-
v.commit = "" // required field
28-
v.commitDate = .distantPast // required field
29-
v.reference = .branch("main") // required field
30-
try await v.save(on: app.db)
31-
let t = try Target(version: v, name: "target")
24+
@Test func save() async throws {
25+
try await withApp { app in
26+
// setup
27+
let v = Version()
28+
v.commit = "" // required field
29+
v.commitDate = .distantPast // required field
30+
v.reference = .branch("main") // required field
31+
try await v.save(on: app.db)
32+
let t = try Target(version: v, name: "target")
3233

33-
// MUT
34-
try await t.save(on: app.db)
34+
// MUT
35+
try await t.save(on: app.db)
3536

36-
// validate
37-
let readBack = try await XCTUnwrapAsync(try await Target.query(on: app.db).first())
38-
XCTAssertNotNil(readBack.id)
39-
XCTAssertEqual(readBack.$version.id, v.id)
40-
XCTAssertNotNil(readBack.createdAt)
41-
XCTAssertNotNil(readBack.updatedAt)
42-
XCTAssertEqual(readBack.name, "target")
37+
// validate
38+
let readBack = try await XCTUnwrapAsync(try await Target.query(on: app.db).first())
39+
#expect(readBack.id != nil)
40+
#expect(readBack.$version.id == v.id)
41+
#expect(readBack.createdAt != nil)
42+
#expect(readBack.updatedAt != nil)
43+
#expect(readBack.name == "target")
44+
}
4345
}
4446

45-
func test_delete_cascade() async throws {
46-
// setup
47-
let v = Version()
48-
v.commit = "" // required field
49-
v.commitDate = .distantPast // required field
50-
v.reference = .branch("main") // required field
51-
try await v.save(on: app.db)
52-
let t = try Target(version: v, name: "target")
53-
try await t.save(on: app.db)
54-
do {
55-
let target = try await Target.query(on: app.db).first()
56-
XCTAssertNotNil(target)
57-
}
47+
@Test func delete_cascade() async throws {
48+
try await withApp { app in
49+
// setup
50+
let v = Version()
51+
v.commit = "" // required field
52+
v.commitDate = .distantPast // required field
53+
v.reference = .branch("main") // required field
54+
try await v.save(on: app.db)
55+
let t = try Target(version: v, name: "target")
56+
try await t.save(on: app.db)
57+
do {
58+
let target = try await Target.query(on: app.db).first()
59+
#expect(target != nil)
60+
}
5861

59-
// MUT
60-
try await v.delete(on: app.db)
62+
// MUT
63+
try await v.delete(on: app.db)
6164

62-
// validate
63-
do {
64-
let target = try await Target.query(on: app.db).first()
65-
XCTAssertNil(target)
65+
// validate
66+
do {
67+
let target = try await Target.query(on: app.db).first()
68+
#expect(target == nil)
69+
}
6670
}
6771
}
6872

0 commit comments

Comments
 (0)