Skip to content

Commit

Permalink
testfix/VIH-5552 : Fixes for Conferences for today changes (#250)
Browse files Browse the repository at this point in the history
Co-authored-by: Nicholas Poxon <[email protected]>
  • Loading branch information
npoxon and Nicholas Poxon authored Mar 29, 2020
1 parent 29c8fec commit 7e6bcee
Show file tree
Hide file tree
Showing 17 changed files with 434 additions and 191 deletions.
4 changes: 2 additions & 2 deletions .githooks/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ LC_ALL=C

local_branch="$(git rev-parse --abbrev-ref HEAD)"

valid_branch_regex="^(feature\/VIH-[0-9]{4})[a-zA-Z0-9._-]+$"
valid_branch_regex="^((feature|testfix|bugfix)\/VIH-[0-9]{4})[a-zA-Z0-9._-]+$"

message="There is something wrong with your branch name. Branch names in this project must start with feature/VIH-XXXX-anyNameOfBranch. Your commit will be rejected. You should rename your branch to a valid name and try again."
message="There is something wrong with your branch name. Branch names in this project must start with feature, testfix or bugfix, i.e. feature/VIH-XXXX-anyNameOfBranch. Your commit will be rejected. You should rename your branch to a valid name and try again."

if [[ ! $local_branch =~ $valid_branch_regex ]]
then
Expand Down
4 changes: 2 additions & 2 deletions .githooks/prepare-commit-msg
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ BRANCH_NAME=$(git rev-parse --abbrev-ref HEAD)
TRIMMED=$(echo $BRANCH_NAME | sed -e 's/.*\/*\(VIH-[0-9]\{4\}\).*/\1/')
# get the current commit message
currentmsg=$(cat "$COMMIT_MSG_FILE")
message="Commit message must start with the prefix 'feature/VIH-XXXX : ' folowing by 8 or more characters. Your commit will be rejected. You should rename your commit to a valid name and try again."
valid_mesg_regex="^(feature\/VIH-[0-9]{4} : )([:_, a-zA-Z0-9.-]{8,})+$"
message="Commit message must start with the prefix 'feature', 'testfix' or 'bugfix' i.e. feature/VIH-XXXX : ' followed by 8 or more characters. Your commit will be rejected. You should rename your commit to a valid name and try again."
valid_mesg_regex="^((feature|testfix|bugfix)\/VIH-[0-9]{4} : )([:_, a-zA-Z0-9.-]{8,})+$"

feature="feature/"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@

<ItemGroup>
<PackageReference Include="Faker.NETCore" Version="1.0.2" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="3.1.2" />
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="3.1.2" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="3.1.2" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="3.1.2" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="3.1.2" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="3.1.2" />
<PackageReference Include="Microsoft.Extensions.Options" Version="3.1.2" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="3.1.3" />
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="3.1.3" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="3.1.3" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="3.1.3" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="3.1.3" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="3.1.3" />
<PackageReference Include="Microsoft.Extensions.Options" Version="3.1.3" />
<PackageReference Include="NBuilder" Version="6.1.0" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="nunit" Version="3.12.0" />
Expand All @@ -31,10 +31,10 @@
<PackageReference Include="Selenium.WebDriver.ChromeDriver" Version="80.0.3987.10600" />
<PackageReference Include="Selenium.WebDriver.IEDriver" Version="3.150.1" />
<PackageReference Include="Selenium.WebDriver.MicrosoftDriver" Version="17.17134.0" />
<PackageReference Include="SpecFlow" Version="3.1.86" />
<PackageReference Include="SpecFlow.NUnit" Version="3.1.86" />
<PackageReference Include="SpecFlow.Tools.MsBuild.Generation" Version="3.1.86" />
<PackageReference Include="VH.AcceptanceTests.Common" Version="1.0.82" />
<PackageReference Include="SpecFlow" Version="3.1.89" />
<PackageReference Include="SpecFlow.NUnit" Version="3.1.89" />
<PackageReference Include="SpecFlow.Tools.MsBuild.Generation" Version="3.1.89" />
<PackageReference Include="VH.AcceptanceTests.Common" Version="1.0.114" />
</ItemGroup>

<ItemGroup>
Expand All @@ -60,6 +60,10 @@
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<TargetPath>appsettings.aat.json</TargetPath>
</ContentWithTargetPath>
<ContentWithTargetPath Include="Configuration\Environments\appsettings.demo.json" Condition="Exists('Configuration\Environments\appsettings.demo.json')">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<TargetPath>appsettings.demo.json</TargetPath>
</ContentWithTargetPath>
<ContentWithTargetPath Include="Configuration\Environments\appsettings.dev.json" Condition="Exists('Configuration\Environments\appsettings.dev.json')">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<TargetPath>appsettings.dev.json</TargetPath>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ internal class HearingRequestBuilder
private readonly List<UserAccount> _individuals;
private readonly List<UserAccount> _representatives;
private readonly List<ParticipantRequest> _participants;
private readonly UserManager _userManager;
private List<UserAccount> _userAccounts;

public HearingRequestBuilder()
Expand All @@ -26,7 +25,6 @@ public HearingRequestBuilder()
_individuals = new List<UserAccount>();
_representatives = new List<UserAccount>();
_participants = new List<ParticipantRequest>();
_userManager = new UserManager();
_userAccounts = new List<UserAccount>();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ public class DefaultDataManager
{
public DefaultData SerialiseTestData(string path = "Data/TestData/DefaultData.xml")
{
var serialiser = new XmlSerialiser();
var xmlInputData = File.ReadAllText(path);
return serialiser.Deserialize<DefaultData>(xmlInputData);
return XmlSerialiser.Deserialize<DefaultData>(xmlInputData);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public sealed class ConfigHooks

public ConfigHooks(TestContext context)
{
_configRoot = new ConfigurationManager("f99a3fe8-cf72-486a-b90f-b65c27da84ee").BuildConfig(GetTargetEnvironment());
_configRoot = ConfigurationManager.BuildConfig("f99a3fe8-cf72-486a-b90f-b65c27da84ee", GetTargetEnvironment());
context.AdminWebConfig = new AdminWebConfig();
context.UserAccounts = new List<UserAccount>();
context.Tokens = new AdminWebTokens();
Expand Down Expand Up @@ -73,11 +73,11 @@ private static void RegisterDefaultData(TestContext context)
{
context.Test = new Test
{
HearingParticipants = new List<UserAccount>(),
AddParticipant = new AddParticipant(),
CommonData = LoadXmlFile.SerialiseCommonData(),
HearingDetails = new HearingDetails(),
HearingParticipants = new List<UserAccount>(),
HearingSchedule = new HearingSchedule(),
AddParticipant = new AddParticipant(),
CommonData = new LoadXmlFile().SerialiseCommonData(),
TestData = new DefaultDataManager().SerialiseTestData()
};
context.Test.AddParticipant = context.Test.TestData.AddParticipant;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Linq;
using System.Net;
using AcceptanceTests.Common.Api.Helpers;
using AcceptanceTests.Common.Api.Requests;
using AcceptanceTests.Common.Configuration.Users;
using AdminWebsite.AcceptanceTests.Data;
Expand Down
73 changes: 58 additions & 15 deletions AdminWebsite/AdminWebsite.AcceptanceTests/Hooks/DriverHooks.cs
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
using System.Collections.Generic;
using AcceptanceTests.Common.Configuration.Users;
using AcceptanceTests.Common.Driver;
using AcceptanceTests.Common.Driver.Browser;
using AcceptanceTests.Common.Driver.Helpers;
using AcceptanceTests.Common.PageObject.Pages;
using AdminWebsite.AcceptanceTests.Helpers;
using BoDi;
using FluentAssertions;
using TechTalk.SpecFlow;

namespace AdminWebsite.AcceptanceTests.Hooks
{
[Binding]
public sealed class DriverHooks
{
private readonly DriverManager _driverManager;
private Dictionary<string, UserBrowser> _browsers;
private readonly IObjectContainer _objectContainer;

public DriverHooks(IObjectContainer objectContainer)
{
_objectContainer = objectContainer;
_driverManager = new DriverManager();
}

[BeforeScenario(Order = (int)HooksSequence.InitialiseBrowserHooks)]
Expand All @@ -30,26 +32,67 @@ public void InitialiseBrowserContainer()
[BeforeScenario(Order = (int)HooksSequence.ConfigureDriverHooks)]
public void ConfigureDriver(TestContext context, ScenarioContext scenarioContext)
{
context.AdminWebConfig.TestConfig.TargetBrowser = _driverManager.GetTargetBrowser(NUnit.Framework.TestContext.Parameters["TargetBrowser"]);
context.AdminWebConfig.TestConfig.TargetDevice = _driverManager.GetTargetDevice(NUnit.Framework.TestContext.Parameters["TargetDevice"]);
_driverManager.KillAnyLocalDriverProcesses(context.AdminWebConfig.TestConfig.TargetBrowser, context.AdminWebConfig.SauceLabsConfiguration.RunningOnSauceLabs());
context.Driver = new DriverSetup(context.AdminWebConfig.SauceLabsConfiguration, scenarioContext.ScenarioInfo, context.AdminWebConfig.TestConfig.TargetBrowser);
context.AdminWebConfig.TestConfig.TargetBrowser = DriverManager.GetTargetBrowser(NUnit.Framework.TestContext.Parameters["TargetBrowser"]);
context.AdminWebConfig.TestConfig.TargetDevice = DriverManager.GetTargetDevice(NUnit.Framework.TestContext.Parameters["TargetDevice"]);
DriverManager.KillAnyLocalDriverProcesses();
context.Driver = new DriverSetup(context.AdminWebConfig.SauceLabsConfiguration, scenarioContext.ScenarioInfo, context.AdminWebConfig.TestConfig.TargetDevice, context.AdminWebConfig.TestConfig.TargetBrowser);
}

[AfterScenario]
public void AfterScenario(TestContext context, ScenarioContext scenarioContext)
[AfterScenario(Order = (int)HooksSequence.SignOutHooks)]
public void SignOutIfPossible(TestContext context)
{
_driverManager.RunningOnSauceLabs(context.AdminWebConfig.SauceLabsConfiguration.RunningOnSauceLabs());
if (_browsers != null)
if (context.CurrentUser == null) return;
if (_browsers?[context.CurrentUser.Key].Driver == null) return;
if (SignOutLinkIsPresent(context.CurrentUser.Key))
SignOut(context.CurrentUser.Key);
}

public bool SignOutLinkIsPresent(string key)
{
try
{
_driverManager.LogTestResult(_browsers.Count > 0 ? _browsers[context.CurrentUser.Key].Driver : context.Driver.GetDriver(""), scenarioContext.TestError == null);
_browsers[key].Driver.FindElement(CommonPages.SignOutLink, 2);
return true;
}
else
catch
{
return false;
}
}

private void SignOut(string key)
{
_browsers[key].ClickLink(CommonPages.SignOutLink, 2);
_browsers[key].Retry(() => _browsers[key].Driver.Title.Trim().Should().Be(LoginPage.SignInTitle), 2);
}

[AfterScenario(Order = (int)HooksSequence.LogResultHooks)]
public void LogResult(TestContext context, ScenarioContext scenarioContext)
{
if (_browsers == null) return;
if (_browsers.Count.Equals(0))
{
_driverManager.LogTestResult(context.Driver.GetDriver(""), scenarioContext.TestError == null);
context.CurrentUser = UserManager.GetDefaultParticipantUser(context.UserAccounts);
var browser = new UserBrowser(context.CurrentUser)
.SetBaseUrl(context.AdminWebConfig.VhServices.AdminWebUrl)
.SetTargetBrowser(context.AdminWebConfig.TestConfig.TargetBrowser)
.SetDriver(context.Driver);
_browsers.Add(context.CurrentUser.Key, browser);
}
_driverManager.TearDownBrowsers(_browsers);
_driverManager.KillAnyLocalDriverProcesses(context.AdminWebConfig.TestConfig.TargetBrowser, context.AdminWebConfig.SauceLabsConfiguration.RunningOnSauceLabs());

DriverManager.LogTestResult(
context.AdminWebConfig.SauceLabsConfiguration.RunningOnSauceLabs(),
_browsers[context.CurrentUser.Key].Driver,
scenarioContext.TestError == null);
}

[AfterScenario(Order = (int)HooksSequence.TearDownBrowserHooks)]
public void TearDownBrowser()
{
if (_browsers != null)
DriverManager.TearDownBrowsers(_browsers);

DriverManager.KillAnyLocalDriverProcesses();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ private void CheckApiHealth(TestContext context)

private static void CheckBookingsApiHealth(string apiUrl, string bearerToken)
{
new HealthcheckManager(apiUrl, bearerToken).CheckHealthOfBookingsApi();
HealthcheckManager.CheckHealthOfBookingsApi(apiUrl, bearerToken);
}
private static void CheckUserApiHealth(string apiUrl, string bearerToken)
{
new HealthcheckManager(apiUrl, bearerToken).CheckHealthOfUserApi();
HealthcheckManager.CheckHealthOfUserApi(apiUrl, bearerToken);
}
private static void CheckVideoApiHealth(string apiUrl, string bearerToken)
{
new HealthcheckManager(apiUrl, bearerToken).CheckHealthOfVideoApi();
HealthcheckManager.CheckHealthOfVideoApi(apiUrl, bearerToken);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ internal enum HooksSequence
InitialiseBrowserHooks = 4,
ConfigureDriverHooks = 5,
RemoveDataHooks = 6,
DataHooks = 7
DataHooks = 7,
SignOutHooks = 8,
LogResultHooks = 9,
TearDownBrowserHooks = 10
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Net;
using System.Threading;
using AcceptanceTests.Common.Api.Hearings;
using AcceptanceTests.Common.Api.Helpers;
using AcceptanceTests.Common.Api.Requests;
using AcceptanceTests.Common.Api.Users;
using AcceptanceTests.Common.Configuration.Users;
Expand Down Expand Up @@ -80,14 +81,12 @@ private static void DeleteTheHearing(BookingsApiManager bookingsApi, Guid hearin

private void ClearClosedConferencesForClerk(BookingsApiManager bookingsApi, VideoApiManager videoApi)
{
var response = videoApi.GetConferencesForToday();
var todaysConferences = RequestHelper.DeserialiseSnakeCaseJsonToResponse<List<ConferenceSummaryResponse>>(response.Content);
var response = videoApi.GetConferencesForTodayJudge(_clerkUsername);
var todaysConferences = RequestHelper.DeserialiseSnakeCaseJsonToResponse<List<ConferenceForJudgeResponse>>(response.Content);
if (todaysConferences == null) return;

foreach (var conference in todaysConferences)
{
if (!ClerkUserIsAParticipantInTheConference(conference.Participants, _clerkUsername)) continue;

var hearingId = GetTheHearingIdFromTheConference(videoApi, conference.Id);

if (HearingHasNotBeenDeletedAlready(bookingsApi, hearingId) && !hearingId.Equals(Guid.Empty))
Expand All @@ -97,10 +96,6 @@ private void ClearClosedConferencesForClerk(BookingsApiManager bookingsApi, Vide
DeleteTheConference(videoApi, conference.Id);
}
}
private static bool ClerkUserIsAParticipantInTheConference(IEnumerable<ParticipantSummaryResponse> participants, string username)
{
return participants.Any(x => x.Username.ToLower().Equals(username.ToLower()));
}

private static Guid GetTheHearingIdFromTheConference(VideoApiManager videoApi, Guid conferenceId)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using AcceptanceTests.Common.Api.Requests;
using AcceptanceTests.Common.Api.Helpers;
using AcceptanceTests.Common.Configuration.Users;
using AcceptanceTests.Common.Driver.Browser;
using AcceptanceTests.Common.Driver.Helpers;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using System.Linq;
using System.Net;
using AcceptanceTests.Common.Api.Hearings;
using AcceptanceTests.Common.Api.Requests;
using AcceptanceTests.Common.Api.Helpers;
using AcceptanceTests.Common.Driver.Browser;
using AcceptanceTests.Common.Driver.Helpers;
using AcceptanceTests.Common.Test.Steps;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Linq;
using System.Threading;
using AcceptanceTests.Common.Api.Hearings;
using AcceptanceTests.Common.Api.Helpers;
using AcceptanceTests.Common.Api.Requests;
using AcceptanceTests.Common.Api.Users;
using AcceptanceTests.Common.Configuration.Users;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace AdminWebsite.UnitTests.Security
public class TokenProviderTests
{
private readonly TokenProvider _provider;
private Mock<IOptions<SecuritySettings>> _securitySettings;
private readonly Mock<IOptions<SecuritySettings>> _securitySettings;

public TokenProviderTests()
{
Expand Down
Loading

0 comments on commit 7e6bcee

Please sign in to comment.