mirror of
https://github.com/aaronpo97/the-biergarten-app.git
synced 2026-02-16 10:42:08 +00:00
add tests for login behaviour
This commit is contained in:
@@ -1,23 +0,0 @@
|
||||
{
|
||||
"$schema": "https://json.schemastore.org/launchsettings.json",
|
||||
"profiles": {
|
||||
"http": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": false,
|
||||
"applicationUrl": "http://localhost:5069",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
},
|
||||
"https": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": false,
|
||||
"applicationUrl": "https://localhost:7002;http://localhost:5069",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,12 @@
|
||||
Feature: User Login
|
||||
As a registered user
|
||||
I want to log in to my account
|
||||
So that I receive an authentication token to access authenticated routes
|
||||
As a registered user
|
||||
I want to log in to my account
|
||||
So that I receive an authentication token to access authenticated routes
|
||||
|
||||
Scenario: Successful login with valid credentials
|
||||
Given the API is running
|
||||
And I have an existing account
|
||||
And I submit a login request with a valid username and password
|
||||
Then the system successfully authenticates the user
|
||||
And returns a valid access token
|
||||
And the response has HTTP status 200
|
||||
And I submit a login request with a valid username and password
|
||||
Then the response has HTTP status 200
|
||||
And the response JSON should have "message" equal "Logged in successfully."
|
||||
And the response JSON should have a valid access token.
|
||||
@@ -14,15 +14,13 @@ public class ApiSteps
|
||||
|
||||
private (string username, string password) testUser;
|
||||
|
||||
|
||||
private
|
||||
|
||||
[Given("the API is running")]
|
||||
public void GivenTheApiIsRunning()
|
||||
{
|
||||
_client = _factory.CreateClient();
|
||||
}
|
||||
|
||||
|
||||
[Then("the response status code should be {int}")]
|
||||
public void ThenStatusCodeShouldBe(int expected)
|
||||
{
|
||||
@@ -62,7 +60,7 @@ public class ApiSteps
|
||||
}
|
||||
|
||||
[Then("the response has HTTP status {int}")]
|
||||
public void ThenTheResponseHasHttpStatus(int expectedCode)
|
||||
public void ThenTheResponseHasHttpStatusInt(int expectedCode)
|
||||
{
|
||||
_response.Should().NotBeNull("No response was received from the API");
|
||||
|
||||
@@ -76,8 +74,26 @@ public class ApiSteps
|
||||
}
|
||||
|
||||
[Given("I submit a login request with a valid username and password")]
|
||||
public void GivenISubmitALoginRequestWithAValidUsernameAndPassword()
|
||||
public async Task GivenISubmitALoginRequestWithAValidUsernameAndPassword()
|
||||
{
|
||||
WhenISendAnHttpRequestToWithBody("POST", "/api/v1/account/login");
|
||||
await WhenISendAnHttpRequestToWithBody("POST", "/api/v1/account/login", $@"
|
||||
{{
|
||||
""username"": ""{testUser.username}"",
|
||||
""password"": ""{testUser.password}""
|
||||
}}");
|
||||
}
|
||||
|
||||
[Then("the response JSON should have a valid access token.")]
|
||||
public async Task ThenTheResponseJsonShouldHaveAValidAccessToken()
|
||||
{
|
||||
var dict = await _response!.Content.ReadFromJsonAsync<Dictionary<string, object>>();
|
||||
dict.Should().NotBeNull();
|
||||
|
||||
dict!.TryGetValue("AccessToken", out var value).Should().BeTrue();
|
||||
|
||||
var messageStr = value!.ToString();
|
||||
|
||||
Console.WriteLine(messageStr);
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user