1- @ testable import App
1+ import Foundation
22import Hummingbird
33import HummingbirdAuthTesting
44import HummingbirdTesting
5- import XCTest
5+ import Testing
6+
7+ @testable import App
68
79struct TestArguments : AppArguments {
810 var migrate : Bool = true
911 var inMemoryDatabase : Bool = true
1012}
1113
12- final class AppTests : XCTestCase {
14+ struct AppTests {
1315 func createUser< Return> (
1416 name: String ,
1517 password: String ,
@@ -32,7 +34,7 @@ final class AppTests: XCTestCase {
3234 client: some TestClientProtocol ,
3335 _ callback: @escaping ( TestResponse ) throws -> Return
3436 ) async throws -> Return {
35- return try await client. execute (
37+ try await client. execute (
3638 uri: " /user/login " ,
3739 method: . post,
3840 auth: . basic( username: name, password: password)
@@ -46,7 +48,7 @@ final class AppTests: XCTestCase {
4648 client: some TestClientProtocol ,
4749 _ callback: @escaping ( TestResponse ) throws -> Return
4850 ) async throws -> Return {
49- return try await client. execute (
51+ try await client. execute (
5052 uri: " /user " ,
5153 method: . get,
5254 headers: cookie. map { [ . cookie: $0] } ?? [ : ]
@@ -55,48 +57,47 @@ final class AppTests: XCTestCase {
5557 }
5658 }
5759
58- func testCreateUser( ) async throws {
60+ @ Test func testCreateUser( ) async throws {
5961 let app = try await buildApplication ( TestArguments ( ) , configuration: . init( ) )
6062 try await app. test ( . live) { client in
6163 try await self . createUser ( name: " adam " , password: " test " , client: client) { response in
62- XCTAssertEqual ( response. status, . ok)
64+ #expect ( response. status == . ok)
6365 }
6466 try await self . createUser ( name: " adam " , password: " test " , client: client) { response in
65- XCTAssertEqual ( response. status, . conflict)
67+ #expect ( response. status == . conflict)
6668 }
6769 }
6870 }
6971
70- func testLogin( ) async throws {
72+ @ Test func testLogin( ) async throws {
7173 let app = try await buildApplication ( TestArguments ( ) , configuration: . init( ) )
7274 try await app. test ( . live) { client in
7375 try await self . createUser ( name: " adam " , password: " testLogin " , client: client) { response in
74- XCTAssertEqual ( response. status, . ok)
76+ #expect ( response. status == . ok)
7577 }
7678 try await self . login ( name: " adam " , password: " testLogin " , client: client) { response in
77- XCTAssertEqual ( response. status, . ok)
79+ #expect ( response. status == . ok)
7880 }
7981 }
8082 }
8183
82- func testSession( ) async throws {
84+ @ Test func testSession( ) async throws {
8385 let app = try await buildApplication ( TestArguments ( ) , configuration: . init( ) )
8486 try await app. test ( . live) { client in
8587 try await self . createUser ( name: " john " , password: " testSession " , client: client) { response in
86- XCTAssertEqual ( response. status, . ok)
88+ #expect ( response. status == . ok)
8789 }
8890 let cookie = try await self . login ( name: " john " , password: " testSession " , client: client) { response in
89- XCTAssertEqual ( response. status, . ok)
90- return try XCTUnwrap ( response. headers [ . setCookie] )
91+ #expect ( response. status == . ok)
92+ return try #require ( response. headers [ . setCookie] )
9193 }
9294 try await self . getCurrent ( cookie: cookie, client: client) { response in
93- XCTAssertEqual ( response. status, . ok)
94- let body = try XCTUnwrap ( response. body)
95- let user = try JSONDecoder ( ) . decode ( UserResponse . self, from: body)
96- XCTAssertEqual ( user. name, " john " )
95+ #expect( response. status == . ok)
96+ let user = try JSONDecoder ( ) . decode ( UserResponse . self, from: response. body)
97+ #expect( user. name == " john " )
9798 }
9899 try await self . getCurrent ( cookie: nil , client: client) { response in
99- XCTAssertEqual ( response. status, . unauthorized)
100+ #expect ( response. status == . unauthorized)
100101 }
101102 }
102103 }
0 commit comments