Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>` (the items plus `meta`), or you can stream every item
Expand Down
6 changes: 6 additions & 0 deletions src/TestingBot.Api/Clients/Requests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ public sealed record ManualTestCreate
/// <summary>The test name (required).</summary>
public required string Name { get; init; }

/// <summary>
/// The <c>browser_id</c> of the browser/device the test ran on (from <c>client.Browsers</c>).
/// The API rejects the request without it ("test[test_environment_id] is missing").
/// </summary>
public int? TestEnvironmentId { get; init; }

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not changing this in this PR. Adding a required member to the public ManualTestCreate record breaks the source of every existing caller, which would need a major version, while this fix is meant to ship as a patch (1.0.1). The property is documented as required by the API in its XML doc and in the README, and the server's 400 message names the field. Making it required in a future major release is reasonable; I've noted that for the maintainer on TB-1008.


/// <summary>Whether the test passed.</summary>
public bool? Success { get; init; }

Expand Down
1 change: 1 addition & 0 deletions src/TestingBot.Api/Clients/TestsClient.Writes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public Task<bool> 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)
Expand Down
21 changes: 21 additions & 0 deletions tests/TestingBot.Api.Tests/Clients/WriteClientsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
Loading