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

VIH-9653 Updated self test to return OK true/false rather than 200/404 #2287

Merged
merged 3 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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<OkResult>().Which.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<OkResult>().Which.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
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
Loading