Skip to content

Commit

Permalink
#526: Exclude untestable code from coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
laingsimon committed Jul 25, 2023
1 parent 2332a3a commit 21bf09b
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ export function DivisionHealth() {
const { season } = useDivisionData();

async function loadHealthCheck() {
/* istanbul ignore next */
if (loading) {
/* istanbul ignore next */
return;
}

Expand All @@ -30,7 +32,9 @@ export function DivisionHealth() {
}

useEffect(() => {
/* istanbul ignore next */
if (loading) {
/* istanbul ignore next */
return;
}

Expand All @@ -40,9 +44,14 @@ export function DivisionHealth() {
// eslint-disable-next-line
[]);

return <div datatype="health">
{loading ? (<Loading />) : null}
{!loading && result ? (<div className="content-background p-3 overflow-auto"><ViewHealthCheck result={result} /></div>) : null}
{!loading && !result ? (<div className="content-background p-3">No health check result</div>) : null}
</div>
try {
return (<div datatype="health">
{loading ? (<Loading/>) : null}
{!loading && result ? (<div className="content-background p-3 overflow-auto"><ViewHealthCheck result={result}/></div>) : null}
{!loading && !result ? (<div className="content-background p-3">No health check result</div>) : null}
</div>);
} catch (e) {
/* istanbul ignore next */
onError(e);
}
}
Original file line number Diff line number Diff line change
@@ -1,30 +1,37 @@
import {isEmpty} from "../../helpers/collections";
import {useApp} from "../../AppContainer";

export function ViewHealthCheck({ result }) {
const { onError } = useApp();
const healthy = result.success && isEmpty(result.errors) && isEmpty(result.warnings);

return (<div datatype="view-health-check">
<h3 className={healthy ? 'text-success' : 'text-warning'}>Status: {healthy ? 'Healthy' : 'Unhealthy'}</h3>
<ol>
{Object.keys(result.checks).map(check => {
const checkResult = result.checks[check];
try {
return (<div datatype="view-health-check">
<h3 className={healthy ? 'text-success' : 'text-warning'}>Status: {healthy ? 'Healthy' : 'Unhealthy'}</h3>
<ol>
{Object.keys(result.checks).map(check => {
const checkResult = result.checks[check];

return (<li key={check}>
<div>
{checkResult.success ? '✔' : '❌'} {check}
</div>
<div>
{checkResult.errors.map((error, index) => (<div key={index} className="text-secondary-50 no-wrap">{error}</div>))}
{checkResult.warnings.map((warning, index) => (<div key={index} className="text-secondary-50 no-wrap">{warning}</div>))}
{checkResult.messages.map((message, index) => (<div key={index} className="text-secondary-50 no-wrap">{message}</div>))}
</div>
</li>)
})}
</ol>
<div>
{result.errors.map((error, index) => (<div key={index} className="text-secondary no-wrap">{error}</div>))}
{result.warnings.map((warning, index) => (<div key={index} className="text-secondary no-wrap">{warning}</div>))}
{result.messages.map((message, index) => (<div key={index} className="text-secondary no-wrap">{message}</div>))}
</div>
</div>);
return (<li key={check}>
<div>
{checkResult.success ? '✔' : '❌'} {check}
</div>
<div>
{checkResult.errors.map((error, index) => (<div key={index} className="text-secondary-50 no-wrap">{error}</div>))}
{checkResult.warnings.map((warning, index) => (<div key={index} className="text-secondary-50 no-wrap">{warning}</div>))}
{checkResult.messages.map((message, index) => (<div key={index} className="text-secondary-50 no-wrap">{message}</div>))}
</div>
</li>)
})}
</ol>
<div>
{result.errors.map((error, index) => (<div key={index} className="text-secondary no-wrap">{error}</div>))}
{result.warnings.map((warning, index) => (<div key={index} className="text-secondary no-wrap">{warning}</div>))}
{result.messages.map((message, index) => (<div key={index} className="text-secondary no-wrap">{message}</div>))}
</div>
</div>);
} catch (e) {
/* istanbul ignore next */
onError(e);
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
using System.Diagnostics.CodeAnalysis;
using CourageScores.Models.Dtos.Health;

namespace CourageScores.Services.Health.Checks;

public class FixturesAfterStartDate : ISeasonHealthCheck
{
[ExcludeFromCodeCoverage]
public string Name => "All fixtures on or after start date";

public Task<HealthCheckResultDto> RunCheck(IReadOnlyCollection<DivisionHealthDto> divisions, HealthCheckContext context, CancellationToken token)
Expand Down
2 changes: 2 additions & 0 deletions CourageScores/Services/Health/Checks/FixturesBeforeEndDate.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
using System.Diagnostics.CodeAnalysis;
using CourageScores.Models.Dtos.Health;

namespace CourageScores.Services.Health.Checks;

public class FixturesBeforeEndDate : ISeasonHealthCheck
{
[ExcludeFromCodeCoverage]
public string Name => "All fixtures on or before end date";

public Task<HealthCheckResultDto> RunCheck(IReadOnlyCollection<DivisionHealthDto> divisions,
Expand Down
2 changes: 2 additions & 0 deletions CourageScores/Services/Health/Checks/TeamsHaveBothLegs.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
using System.Diagnostics.CodeAnalysis;
using CourageScores.Models.Dtos.Division;
using CourageScores.Models.Dtos.Health;

namespace CourageScores.Services.Health.Checks;

public class TeamsHaveBothLegs : ISeasonHealthCheck
{
[ExcludeFromCodeCoverage]
public string Name => "Teams have both legs defined";

public async Task<HealthCheckResultDto> RunCheck(IReadOnlyCollection<DivisionHealthDto> divisions,
Expand Down

0 comments on commit 21bf09b

Please sign in to comment.