diff --git a/README.md b/README.md index dee8100..fcaabe2 100644 --- a/README.md +++ b/README.md @@ -68,6 +68,20 @@ await client.Tests.UpdateAsync(test.SessionId!, new TestUpdate }); ``` +### Recording an external result + +`POST /v1/tests` needs the `BrowserId` of the browser/device the test ran on: + +```csharp +var browsers = await client.Browsers.ListAsync(); +await client.Tests.CreateAsync(new ManualTestCreate +{ + Name = "external result", + TestEnvironmentId = browsers[0].BrowserId, + Success = true, +}); +``` + ## Pagination List endpoints return a `TestingBotPage` (the items plus `meta`), or you can stream every item diff --git a/src/TestingBot.Api/Clients/Requests.cs b/src/TestingBot.Api/Clients/Requests.cs index 682a1f5..94ba26d 100644 --- a/src/TestingBot.Api/Clients/Requests.cs +++ b/src/TestingBot.Api/Clients/Requests.cs @@ -33,6 +33,12 @@ public sealed record ManualTestCreate /// The test name (required). public required string Name { get; init; } + /// + /// The browser_id of the browser/device the test ran on (from client.Browsers). + /// The API rejects the request without it ("test[test_environment_id] is missing"). + /// + public int? TestEnvironmentId { get; init; } + /// Whether the test passed. public bool? Success { get; init; } diff --git a/src/TestingBot.Api/Clients/TestsClient.Writes.cs b/src/TestingBot.Api/Clients/TestsClient.Writes.cs index 611f825..91bd3b8 100644 --- a/src/TestingBot.Api/Clients/TestsClient.Writes.cs +++ b/src/TestingBot.Api/Clients/TestsClient.Writes.cs @@ -71,6 +71,7 @@ public Task CreateAsync(ManualTestCreate test, CancellationToken cancellat ArgumentNullException.ThrowIfNull(test); var form = new FormContentBuilder() .Add("test", "name", test.Name) + .Add("test", "test_environment_id", test.TestEnvironmentId) .Add("test", "success", test.Success) .Add("test", "status_message", test.StatusMessage) .Add("test", "extra", test.Extra) diff --git a/tests/TestingBot.Api.Tests/Clients/WriteClientsTests.cs b/tests/TestingBot.Api.Tests/Clients/WriteClientsTests.cs index d33e58a..2110601 100644 --- a/tests/TestingBot.Api.Tests/Clients/WriteClientsTests.cs +++ b/tests/TestingBot.Api.Tests/Clients/WriteClientsTests.cs @@ -31,6 +31,27 @@ public async Task Tests_Update_sends_rails_form_and_success_as_one() mock.VerifyNoOutstandingExpectation(); } + [Fact] + public async Task Tests_Create_sends_test_environment_id() + { + var (connection, mock) = TestConnectionFactory.Create(); + mock.Expect(HttpMethod.Post, BaseUrl + "tests") + .WithFormData("test[name]", "external result") + .WithFormData("test[test_environment_id]", "32166") + .WithFormData("test[success]", "1") + .Respond("application/json", "{\"success\":true}"); + + var ok = await new TestsClient(connection).CreateAsync(new ManualTestCreate + { + Name = "external result", + TestEnvironmentId = 32166, + Success = true, + }); + + ok.Should().BeTrue(); + mock.VerifyNoOutstandingExpectation(); + } + [Fact] public async Task Tests_Stop_and_Delete() {