Skip to content

Commit

Permalink
VIH-9653 Updated self test to return OK true/false rather than 200/404 (
Browse files Browse the repository at this point in the history
#2287)

* Updated self test to return OK(true/false) rather than 200/404

* Fixed test expected response type
  • Loading branch information
will-craig authored Nov 5, 2024
1 parent 63cb1a1 commit cf388d1
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,18 @@ public void Setup()
}

[Test]
public async Task should_return_ok_when_user_has_completed_a_test_call_today()
public async Task should_return_ok_true_when_user_has_completed_a_test_call_today()
{
await _testCallCache.AddTestCompletedForTodayAsync(_username);
var result = await _controller.CheckUserCompletedATestTodayAsync();
result.Should().BeOfType<OkResult>();
result.Should().BeOfType<OkObjectResult>().Which.Value.Should().Be(true);
}

[Test]
public async Task should_return_not_found_when_user_has_not_completed_a_test_call_today()
public async Task should_return_ok_false_when_user_has_not_completed_a_test_call_today()
{
var result = await _controller.CheckUserCompletedATestTodayAsync();
result.Should().BeOfType<NotFoundResult>();
result.Should().BeOfType<OkObjectResult>().Which.Value.Should().Be(false);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import {
import { ConferenceLite } from '../models/conference-lite';
import { SessionStorage } from '../session-storage';
import { IVideoWebApiService } from './video-web-service.interface';
import { catchError, map } from 'rxjs/operators';

import { Store } from '@ngrx/store';
import { ConferenceState } from 'src/app/waiting-space/store/reducers/conference.reducer';
Expand Down Expand Up @@ -95,10 +94,7 @@ export class VideoWebService implements IVideoWebApiService {
}

checkUserHasCompletedSelfTest(): Observable<boolean> {
return this.apiClient.checkUserCompletedATestToday().pipe(
map(() => true),
catchError(() => [false])
);
return this.apiClient.checkUserCompletedATestToday();
}

getSelfTestToken(participantId: string): Promise<TokenResponse> {
Expand Down
29 changes: 13 additions & 16 deletions VideoWeb/VideoWeb/ClientApp/src/app/services/clients/api-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6276,14 +6276,16 @@ export class ApiClient extends ApiClientBase {
* Check if a user has completed a test call at least once today
* @return OK
*/
checkUserCompletedATestToday(): Observable<void> {
checkUserCompletedATestToday(): Observable<boolean> {
let url_ = this.baseUrl + '/selftest/today';
url_ = url_.replace(/[?&]$/, '');

let options_: any = {
observe: 'response',
responseType: 'blob',
headers: new HttpHeaders({})
headers: new HttpHeaders({
Accept: 'application/json'
})
};

return _observableFrom(this.transformOptions(options_))
Expand All @@ -6303,14 +6305,14 @@ export class ApiClient extends ApiClientBase {
try {
return this.processCheckUserCompletedATestToday(response_ as any);
} catch (e) {
return _observableThrow(e) as any as Observable<void>;
return _observableThrow(e) as any as Observable<boolean>;
}
} else return _observableThrow(response_) as any as Observable<void>;
} else return _observableThrow(response_) as any as Observable<boolean>;
})
);
}

protected processCheckUserCompletedATestToday(response: HttpResponseBase): Observable<void> {
protected processCheckUserCompletedATestToday(response: HttpResponseBase): Observable<boolean> {
const status = response.status;
const responseBlob =
response instanceof HttpResponse
Expand Down Expand Up @@ -6338,16 +6340,11 @@ export class ApiClient extends ApiClientBase {
} else if (status === 200) {
return blobToText(responseBlob).pipe(
_observableMergeMap(_responseText => {
return _observableOf<void>(null as any);
})
);
} else if (status === 404) {
return blobToText(responseBlob).pipe(
_observableMergeMap(_responseText => {
let result404: any = null;
let resultData404 = _responseText === '' ? null : JSON.parse(_responseText, this.jsonParseReviver);
result404 = ProblemDetails.fromJS(resultData404);
return throwException('Not Found', status, _responseText, _headers, result404);
let result200: any = null;
let resultData200 = _responseText === '' ? null : JSON.parse(_responseText, this.jsonParseReviver);
result200 = resultData200 !== undefined ? resultData200 : <any>null;

return _observableOf(result200);
})
);
} else if (status === 401) {
Expand All @@ -6363,7 +6360,7 @@ export class ApiClient extends ApiClientBase {
})
);
}
return _observableOf<void>(null as any);
return _observableOf<boolean>(null as any);
}

/**
Expand Down
11 changes: 4 additions & 7 deletions VideoWeb/VideoWeb/Controllers/SelfTestController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,10 @@ public async Task<ActionResult<SelfTestPexipResponse>> GetPexipConfig()
/// <returns>OK if a test has been completed at least once, else not found</returns>
[HttpGet("today")]
[SwaggerOperation(OperationId = "CheckUserCompletedATestToday")]
[ProducesResponseType((int)HttpStatusCode.OK)]
[ProducesResponseType((int)HttpStatusCode.NotFound)]
public async Task<IActionResult> CheckUserCompletedATestTodayAsync()
{
var hasUserCompletedATestToday = await testCallCache.HasUserCompletedATestToday(User.Identity.Name);
return hasUserCompletedATestToday ? Ok() : NotFound();
}
[ProducesResponseType(typeof(bool), (int)HttpStatusCode.OK)]
public async Task<IActionResult> CheckUserCompletedATestTodayAsync()
=> Ok(await testCallCache.HasUserCompletedATestToday(User.Identity?.Name));


[ServiceFilter(typeof(CheckParticipantCanAccessConferenceAttribute))]
[HttpGet]
Expand Down

0 comments on commit cf388d1

Please sign in to comment.