Skip to content

Commit 64ff8e7

Browse files
committed
Convert ProductTests
1 parent d3a0823 commit 64ff8e7

File tree

1 file changed

+55
-55
lines changed

1 file changed

+55
-55
lines changed

Tests/AppTests/ProductTests.swift

Lines changed: 55 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -12,93 +12,93 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
import Foundation
16+
1517
@testable import App
1618

17-
import XCTVapor
19+
import Testing
1820

1921

20-
class ProductTests: AppTestCase {
22+
@Suite struct ProductTests {
2123

22-
func test_ProductType_Codable() throws {
24+
@Test func ProductType_Codable() throws {
2325
// Ensure ProductType is Codable in a way that's forward compatible with Swift 5.5's Codable synthesis for enums with associated types (SE-0295)
2426
let exe: ProductType = .executable
2527
let lib: ProductType = .library(.automatic)
2628
let test: ProductType = .test
2729
do { // encoding
28-
XCTAssertEqual(
29-
String(decoding: try JSONEncoder().encode(exe), as: UTF8.self),
30-
#"{"executable":{}}"#
30+
#expect(
31+
String(decoding: try JSONEncoder().encode(exe), as: UTF8.self) == #"{"executable":{}}"#
3132
)
32-
XCTAssertEqual(
33-
String(decoding: try JSONEncoder().encode(lib), as: UTF8.self),
34-
#"{"library":{"_0":"automatic"}}"#
33+
#expect(
34+
String(decoding: try JSONEncoder().encode(lib), as: UTF8.self) == #"{"library":{"_0":"automatic"}}"#
3535
)
36-
XCTAssertEqual(
37-
String(decoding: try JSONEncoder().encode(test), as: UTF8.self),
38-
#"{"test":{}}"#
36+
#expect(
37+
String(decoding: try JSONEncoder().encode(test), as: UTF8.self) == #"{"test":{}}"#
3938
)
4039
}
4140
do { // decoding
42-
XCTAssertEqual(
41+
#expect(
4342
try JSONDecoder().decode(
4443
ProductType.self,
45-
from: Data(#"{"executable":{}}"#.utf8)),
46-
exe)
47-
XCTAssertEqual(
44+
from: Data(#"{"executable":{}}"#.utf8)) == exe)
45+
#expect(
4846
try JSONDecoder().decode(
4947
ProductType.self,
50-
from: Data(#"{"library":{"_0":"automatic"}}"#.utf8)),
51-
lib
48+
from: Data(#"{"library":{"_0":"automatic"}}"#.utf8)) == lib
5249
)
53-
XCTAssertEqual(
50+
#expect(
5451
try JSONDecoder().decode(
5552
ProductType.self,
56-
from: Data(#"{"test":{}}"#.utf8)),
57-
test)
53+
from: Data(#"{"test":{}}"#.utf8)) == test)
5854
}
5955
}
6056

61-
func test_Product_save() async throws {
62-
let pkg = Package(id: UUID(), url: "1")
63-
let ver = try Version(id: UUID(), package: pkg)
64-
let prod = try Product(id: UUID(),
65-
version: ver,
66-
type: .library(.automatic),
67-
name: "p1",
68-
targets: ["t1", "t2"])
69-
try await pkg.save(on: app.db)
70-
try await ver.save(on: app.db)
71-
try await prod.save(on: app.db)
72-
do {
73-
let p = try await XCTUnwrapAsync(try await Product.find(prod.id, on: app.db))
74-
XCTAssertEqual(p.$version.id, ver.id)
75-
XCTAssertEqual(p.type, .library(.automatic))
76-
XCTAssertEqual(p.name, "p1")
77-
XCTAssertEqual(p.targets, ["t1", "t2"])
57+
@Test func Product_save() async throws {
58+
try await withApp { app in
59+
let pkg = Package(id: UUID(), url: "1")
60+
let ver = try Version(id: UUID(), package: pkg)
61+
let prod = try Product(id: UUID(),
62+
version: ver,
63+
type: .library(.automatic),
64+
name: "p1",
65+
targets: ["t1", "t2"])
66+
try await pkg.save(on: app.db)
67+
try await ver.save(on: app.db)
68+
try await prod.save(on: app.db)
69+
do {
70+
let p = try #require(try await Product.find(prod.id, on: app.db))
71+
#expect(p.$version.id == ver.id)
72+
#expect(p.type == .library(.automatic))
73+
#expect(p.name == "p1")
74+
#expect(p.targets == ["t1", "t2"])
75+
}
7876
}
7977
}
8078

81-
func test_delete_cascade() async throws {
79+
@Test func delete_cascade() async throws {
8280
// delete version must delete products
83-
let pkg = Package(id: UUID(), url: "1")
84-
let ver = try Version(id: UUID(), package: pkg)
85-
let prod = try Product(id: UUID(), version: ver, type: .library(.automatic), name: "p1")
86-
try await pkg.save(on: app.db)
87-
try await ver.save(on: app.db)
88-
try await prod.save(on: app.db)
89-
let db = app.db
81+
try await withApp { app in
82+
let pkg = Package(id: UUID(), url: "1")
83+
let ver = try Version(id: UUID(), package: pkg)
84+
let prod = try Product(id: UUID(), version: ver, type: .library(.automatic), name: "p1")
85+
try await pkg.save(on: app.db)
86+
try await ver.save(on: app.db)
87+
try await prod.save(on: app.db)
88+
let db = app.db
9089

91-
try await XCTAssertEqualAsync(try await Package.query(on: db).count(), 1)
92-
try await XCTAssertEqualAsync(try await Version.query(on: db).count(), 1)
93-
try await XCTAssertEqualAsync(try await Product.query(on: db).count(), 1)
90+
try await XCTAssertEqualAsync(try await Package.query(on: db).count(), 1)
91+
try await XCTAssertEqualAsync(try await Version.query(on: db).count(), 1)
92+
try await XCTAssertEqualAsync(try await Product.query(on: db).count(), 1)
9493

95-
// MUT
96-
try await ver.delete(on: app.db)
94+
// MUT
95+
try await ver.delete(on: app.db)
9796

98-
// version and product should be deleted
99-
try await XCTAssertEqualAsync(try await Package.query(on: db).count(), 1)
100-
try await XCTAssertEqualAsync(try await Version.query(on: db).count(), 0)
101-
try await XCTAssertEqualAsync(try await Product.query(on: db).count(), 0)
97+
// version and product should be deleted
98+
try await XCTAssertEqualAsync(try await Package.query(on: db).count(), 1)
99+
try await XCTAssertEqualAsync(try await Version.query(on: db).count(), 0)
100+
try await XCTAssertEqualAsync(try await Product.query(on: db).count(), 0)
101+
}
102102
}
103103

104104
}

0 commit comments

Comments
 (0)