Skip to content

Commit

Permalink
add simple sandbox page test to prove out 500 error checking
Browse files Browse the repository at this point in the history
  • Loading branch information
hahn-kev committed Oct 25, 2023
1 parent cfbc2fb commit d67645d
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 23 deletions.
11 changes: 7 additions & 4 deletions backend/LexBoxApi/Controllers/TestingController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

namespace LexBoxApi.Controllers;

#if DEBUG
[ApiController]
[Route("/api/[controller]")]
public class TestingController : ControllerBase
Expand All @@ -32,8 +31,7 @@ public TestingController(LexAuthService lexAuthService,
_redmineDbContext = redmineDbContext;
}



#if DEBUG
[AllowAnonymous]
[HttpGet("makeJwt")]
[ProducesResponseType(StatusCodes.Status200OK)]
Expand Down Expand Up @@ -98,11 +96,16 @@ public record TestingControllerProject(Guid Id, string Name, string Code, List<T

public record TestingControllerProjectUser(string? Username, string Role, string Email, Guid Id);

#endif
[HttpGet("throwsException")]
[AllowAnonymous]
public ActionResult ThrowsException()
{
throw new ExceptionWithCode("This is a test exception", "test-error");
}

[HttpGet("test500NoException")]
[AllowAnonymous]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public ActionResult Test500NoError() => StatusCode(500);
}
#endif
1 change: 1 addition & 0 deletions backend/LexBoxApi/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@
context.Response.Headers.Add("lexbox-version", AppVersionService.Version);
await next();
});
app.UseStatusCodePages();
if (!app.Environment.IsDevelopment())
app.UseExceptionHandler();
app.UseHealthChecks("/api/healthz");
Expand Down
10 changes: 10 additions & 0 deletions backend/Testing/Browser/Page/SandboxPage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using Microsoft.Playwright;

namespace Testing.Browser.Page;

public class SandboxPage : BasePage<SandboxPage>
{
public SandboxPage(IPage page) : base(page, "/sandbox", page.Locator(":text('Sandbox')"))
{
}
}
22 changes: 22 additions & 0 deletions backend/Testing/Browser/SandboxPageTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using Shouldly;
using Testing.Browser.Base;
using Testing.Browser.Page;

namespace Testing.Browser;

public class SandboxPageTests : PageTest
{
[Fact]
public async Task Goto500Works()
{
await new SandboxPage(Page).Goto();
var request = await Page.RunAndWaitForRequestFinishedAsync(async () =>
{
await Page.GetByText("goto 500 page").ClickAsync();
});
var response = await request.ResponseAsync();
response.ShouldNotBeNull();
response.Ok.ShouldBeFalse();
response.Status.ShouldBe(500);
}
}
19 changes: 0 additions & 19 deletions frontend/src/routes/(authenticated)/sandbox/+page.svelte

This file was deleted.

20 changes: 20 additions & 0 deletions frontend/src/routes/(unauthenticated)/sandbox/+page.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<script lang="ts">
import TusUpload from '$lib/components/TusUpload.svelte';
function uploadFinished(): void {
alert('upload done!');
}
</script>
<div class="grid gap-2">
<h2>Sandbox</h2>
<div class="card w-96 bg-base-200 shadow-lg">
<a rel="external" class="btn" href="/api/testing/test500NoException">Goto 500 page</a>
</div>
<div class="card w-96 bg-base-200 shadow-lg">
<div class="card-body">
<TusUpload endpoint="/api/tus-test" accept="image/*" on:uploadComplete={uploadFinished}/>
</div>
</div>
</div>

0 comments on commit d67645d

Please sign in to comment.