public async Task <TestCallResult> GetTestCallScoreAsync(Guid participantId) { HttpResponseMessage responseMessage; using (var httpClient = new HttpClient()) { var requestUri = $"{_kinlySelfTestScoreEndpointUrl}/{participantId}"; var request = new HttpRequestMessage { RequestUri = new Uri(requestUri), Method = HttpMethod.Get, }; request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", _customJwtTokenProvider.GenerateToken(participantId.ToString(), 2)); responseMessage = await httpClient.SendAsync(request); } if (responseMessage.StatusCode == HttpStatusCode.NotFound) { throw new NotFoundException($"Could not find Self Test for ParticipantId: {participantId}"); } responseMessage.EnsureSuccessStatusCode(); var content = await responseMessage.Content.ReadAsStringAsync(); var testCall = ApiRequestHelper.DeserialiseSnakeCaseJsonToResponse <KinlyVideoTestCall>(content); return(new TestCallResult(testCall.Passed, testCall.Score)); }
public void Should_get_token_when_requested_with_correct_participant_id() { var responseMessage = SendGetRequestWithBearerTokenAsync($"/participants/{Guid.NewGuid()}/token").Result; var content = responseMessage.Content.ReadAsStringAsync().Result; var tokenResponse = ApiRequestHelper.DeserialiseSnakeCaseJsonToResponse <TokenResponse>(content); responseMessage.StatusCode.Should().Be(HttpStatusCode.OK); tokenResponse.Should().NotBeNull(); tokenResponse.Token.Should().NotBeEmpty(); }
public async Task Should_retrieve_the_client_config_settings() { var response = await SendGetRequestAsync("api/config"); response.StatusCode.Should().Be(HttpStatusCode.OK); var responseBody = await response.Content.ReadAsStringAsync(); var settings = ApiRequestHelper.DeserialiseSnakeCaseJsonToResponse <ClientConfiguration>(responseBody); settings.Should().NotBeNull(); }
public async Task should_be_redirected_to_microsoft_login_if_not_authenticated() { var response = await SendGetRequestAsync("https://localhost:5600/api/config"); response.StatusCode.Should().Be(HttpStatusCode.OK); var responseBody = await response.Content.ReadAsStringAsync(); var settings = ApiRequestHelper.DeserialiseSnakeCaseJsonToResponse <ClientConfiguration>(responseBody); settings.VideoAppUrl.Should().Contain("localhost"); settings.BaseVideoUrl.Should().NotBeNullOrEmpty(); }
public void ThenAllTheAnswersShouldBeMatch() { var reponses = _scenarioContext.Get <IEnumerable <SuitabilityResponse> >("Responses"); foreach (var expectedResponse in reponses) { var displayedAnswer = GetMethods.GetText(By.CssSelector($"#{expectedResponse.QuestionKey} strong"), _browserContext); if (expectedResponse.Answer == AnswerType.NotSure) { displayedAnswer.Should().Be("I'm not sure"); } else { displayedAnswer.Should().Be(expectedResponse.Answer.ToString()); } if (!string.IsNullOrEmpty(expectedResponse.Details?.Trim())) { var displayedNotes = GetMethods.GetText(By.CssSelector($"#{expectedResponse.QuestionKey}_Notes span"), _browserContext); displayedNotes.Should().Be(expectedResponse.Details.ToString()); } } //Verify the expected data by comparing them against database var request = _testContext.Get($"persons/username/{_testContext.TestUserSecrets.Representative}/suitability-answers"); var response = _testContext.Client().Execute(request); var model = ApiRequestHelper.DeserialiseSnakeCaseJsonToResponse <List <PersonSuitabilityAnswerResponse> >(response.Content); var answers = model.First(h => h.Hearing_id.ToString() == _testContext.HearingId).Answers; foreach (var expectedResponse in reponses) { var answer = answers.Single(a => a.Key == expectedResponse.QuestionKey); switch (expectedResponse.Answer) { case AnswerType.Yes: answer.Answer.Should().Be(answer.Key == RepresentativeQuestionKeys.AboutYourComputer ? "Yes" : "true"); break; case AnswerType.No: answer.Answer.Should().Be(answer.Key == RepresentativeQuestionKeys.AboutYourComputer ? "Yes" : "false"); break; case AnswerType.NotSure: answer.Answer.Should().Be("Not sure"); break; } if (!string.IsNullOrEmpty(expectedResponse.Details?.Trim())) { answer.Extended_answer.Should().Be(expectedResponse.Details.Trim().ToString()); } } }
public async Task Should_retrieve_the_client_config_settings() { var getResponse = await SendGetRequestAsync(_configSettingsEndpoints.GetConfigSettings); var resonpseString = await getResponse.Content.ReadAsStringAsync(); getResponse.StatusCode.Should().Be(HttpStatusCode.OK, resonpseString); var clientSettingsResponseModel = ApiRequestHelper.DeserialiseSnakeCaseJsonToResponse <ClientSettingsResponse>(resonpseString); clientSettingsResponseModel.Should().NotBeNull(); clientSettingsResponseModel.ClientId.Should().NotBeNull(); clientSettingsResponseModel.TenantId.Should().NotBeNull(); clientSettingsResponseModel.RedirectUri.Should().NotBeNull(); clientSettingsResponseModel.TestUsernameStem.Should().NotBeNullOrEmpty(); clientSettingsResponseModel.TestUsernameStem.Length.Should().Be(26); }
public void CreateNewHearingRequest(TestContext testContext) { var requestBody = CreateHearingRequest.BuildRequest(testContext.TestUserSecrets.Individual, testContext.TestUserSecrets.Representative); testContext.Request = testContext.Post("/hearings", requestBody); testContext.Response = testContext.Client().Execute(testContext.Request); testContext.Response.StatusCode.Should().Be(HttpStatusCode.Created); var model = ApiRequestHelper.DeserialiseSnakeCaseJsonToResponse <HearingDetailsResponse>(testContext.Response.Content); testContext.HearingId = model.Id.ToString(); var individual = model.Participants.Single(p => p.Username.Equals(testContext.TestUserSecrets.Individual)); testContext.IndividualParticipantId = individual.Id.ToString(); var representative = model.Participants.Single(p => p.Username.Equals(testContext.TestUserSecrets.Representative)); testContext.RepresentativeParticipantId = representative.Id.ToString(); }