Skip to content

Commit 3995919

Browse files
committed
Added tests for login functionality
1 parent a84e584 commit 3995919

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

Tests/HabitTrackerAppServerTests/HabitTrackerAppServerLoginTests.swift

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,28 @@ struct HabitTrackerAppServerLoginTests {
8383
}
8484
}
8585
}
86+
87+
@Test("Test User Login Fail - Wrong username and wrong password")
88+
func testUserLoginFailureWrongUsernameAndWrongPassword() async throws {
89+
try await withApp(configure: configure) { app in
90+
// Create user in this app instance
91+
try await createUser(in: app)
92+
93+
// Now test login with the same app instance
94+
let loginCredentials = User(username: "wronguser", password: "wrongpassword")
95+
try await app.testing().test(.POST, "/api/login") { req in
96+
try req.content.encode(loginCredentials)
97+
} afterResponse: { res in
98+
#expect(res.status == .badRequest)
99+
// Check that we get a meaningful error response (not empty)
100+
#expect(!res.body.string.isEmpty)
101+
#expect(res.body.string.contains("User not found"))
102+
103+
}
104+
}
105+
}
106+
107+
86108
}
87109

88110

0 commit comments

Comments
 (0)