auth updates

This commit is contained in:
Aaron Po
2026-01-31 11:34:55 -05:00
parent 1af3d6f987
commit 77bb1f6733
14 changed files with 118 additions and 192 deletions

View File

@@ -0,0 +1,11 @@
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
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

View File

@@ -1,10 +1,10 @@
Feature: NotFound API
As a client of the API
I want consistent 404 responses
So that consumers can handle missing routes
Feature: NotFound Responses
As a client of the API
I want consistent 404 responses
So that consumers can gracefully handle missing routes
Scenario: GET error 404 returns NotFound message
Given the API is running
When I GET "/error/404"
Then the response status code should be 404
And the response JSON should have "message" equal "Route not found."
Scenario: GET request to an invalid route returns 404
Given the API is running
When I send an HTTP request "GET" to "/invalid-route"
Then the response has HTTP status 404
And the response JSON should have "message" equal "Route not found."

View File

@@ -8,14 +8,14 @@ namespace API.Specs.Steps;
[Binding]
public class ApiSteps
{
private readonly TestApiFactory _factory;
private readonly TestApiFactory _factory = new();
private HttpClient? _client;
private HttpResponseMessage? _response;
public ApiSteps()
{
_factory = new TestApiFactory();
}
private (string username, string password) testUser;
private
[Given("the API is running")]
public void GivenTheApiIsRunning()
@@ -23,15 +23,6 @@ public class ApiSteps
_client = _factory.CreateClient();
}
// No user service assumptions needed for 404 tests
[When("I GET {string}")]
public async Task WhenIGet(string path)
{
_client.Should().NotBeNull("API client must be initialized");
_response = await _client!.GetAsync(path);
}
[Then("the response status code should be {int}")]
public void ThenStatusCodeShouldBe(int expected)
{
@@ -48,4 +39,45 @@ public class ApiSteps
dict!.TryGetValue(field, out var value).Should().BeTrue();
(value?.ToString()).Should().Be(expected);
}
}
[When("I send an HTTP request {string} to {string} with body:")]
public async Task WhenISendAnHttpRequestToWithBody(string method, string url, string jsonBody)
{
_client.Should().NotBeNull();
var requestMessage = new HttpRequestMessage(new HttpMethod(method), url)
{
// Convert the string body into JSON content
Content = new StringContent(jsonBody, System.Text.Encoding.UTF8, "application/json")
};
_response = await _client!.SendAsync(requestMessage);
}
[When("I send an HTTP request {string} to {string}")]
public async Task WhenISendAnHttpRequestTo(string method, string url)
{
var requestMessage = new HttpRequestMessage(new HttpMethod(method), url);
_response = await _client!.SendAsync(requestMessage);
}
[Then("the response has HTTP status {int}")]
public void ThenTheResponseHasHttpStatus(int expectedCode)
{
_response.Should().NotBeNull("No response was received from the API");
((int)_response!.StatusCode).Should().Be(expectedCode);
}
[Given("I have an existing account")]
public void GivenIHaveAnExistingAccount()
{
testUser = ("test.user", "password");
}
[Given("I submit a login request with a valid username and password")]
public void GivenISubmitALoginRequestWithAValidUsernameAndPassword()
{
WhenISendAnHttpRequestToWithBody("POST", "/api/v1/account/login");
}
}