Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add health check endpoint #162

Merged
merged 8 commits into from
Oct 10, 2023
Merged
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
2 changes: 2 additions & 0 deletions DfE.FindInformationAcademiesTrusts/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
public static void Main(string[] args)
{
//Create logging mechanism before anything else to catch bootstrap errors
Log.Logger = new LoggerConfiguration()

Check warning on line 20 in DfE.FindInformationAcademiesTrusts/Program.cs

View workflow job for this annotation

GitHub Actions / Build .NET

Make sure that this logger's configuration is safe. (https://rules.sonarsource.com/csharp/RSPEC-4792)

Check warning on line 20 in DfE.FindInformationAcademiesTrusts/Program.cs

View workflow job for this annotation

GitHub Actions / Build .NET

Make sure that this logger's configuration is safe. (https://rules.sonarsource.com/csharp/RSPEC-4792)

Check warning on line 20 in DfE.FindInformationAcademiesTrusts/Program.cs

View workflow job for this annotation

GitHub Actions / Build .NET

Make sure that this logger's configuration is safe. (https://rules.sonarsource.com/csharp/RSPEC-4792)
.WriteTo.Console()
.CreateBootstrapLogger();

Expand All @@ -31,6 +31,7 @@
AddEnvironmentVariablesTo(builder);

builder.Services.AddRazorPages();
builder.Services.AddHealthChecks();
AddAuthenticationServices(builder);

builder.Services.Configure<RouteOptions>(options =>
Expand Down Expand Up @@ -91,6 +92,7 @@

app.MapRazorPages();
app.UseMiddleware<ResponseHeadersMiddleware>();
app.MapHealthChecks("/health").AllowAnonymous();
}

private static HeaderPolicyCollection GetSecurityHeaderPolicies()
Expand Down
14 changes: 14 additions & 0 deletions tests/playwright/deployment-tests/health.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { test } from '@playwright/test'
import { HealthPage } from '../page-object-model/health-page'

test.describe('Health status endpoint', () => {
let healthPage: HealthPage
test.beforeEach(({ page }) => {
healthPage = new HealthPage(page)
})

test('User can navigate to the health endpoint', async () => {
await healthPage.goTo()
await healthPage.expect.toBeHealthy()
})
})
14 changes: 14 additions & 0 deletions tests/playwright/integration-tests/health.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { test } from '@playwright/test'
import { HealthPage } from '../page-object-model/health-page'

test.describe('Health status endpoint', () => {
let healthPage: HealthPage
test.beforeEach(({ page }) => {
healthPage = new HealthPage(page)
})

test('User can navigate to the health endpoint', async () => {
await healthPage.goTo()
await healthPage.expect.toBeHealthy()
})
})
22 changes: 22 additions & 0 deletions tests/playwright/page-object-model/health-page.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { Locator, Page, expect } from '@playwright/test'
export class HealthPage {
readonly expect: HealthPageAssertions
readonly body: Locator

constructor (readonly page: Page) {
this.expect = new HealthPageAssertions(this)
this.body = page.locator('body')
}

async goTo (): Promise<void> {
await this.page.goto('/health')
}
}

class HealthPageAssertions {
constructor (readonly healthPage: HealthPage) { }

async toBeHealthy (): Promise<void> {
await expect(this.healthPage.body).toHaveText('Healthy')
}
}