Skip to content

Commit

Permalink
Fix installations setup in missiontests
Browse files Browse the repository at this point in the history
  • Loading branch information
andchiind committed Dec 21, 2023
1 parent f550a18 commit 74d15d3
Showing 1 changed file with 38 additions and 9 deletions.
47 changes: 38 additions & 9 deletions backend/api.test/Client/MissionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,16 @@ private async Task VerifyNonDuplicateAreaDbNames(string installationCode, string
Assert.False(installationResponses.Where((i) => i.InstallationCode == installationCode).Any(), $"Duplicate installation name detected: {installationCode}");
}

private async Task VerifyNonDuplicateInstallationDbName(string installationCode)
{
string installationUrl = "/installations";
var installationResponse = await _client.GetAsync(installationUrl);
Assert.True(installationResponse.IsSuccessStatusCode);
var installationResponses = await installationResponse.Content.ReadFromJsonAsync<List<Installation>>(_serializerOptions);
Assert.True(installationResponses != null);
Assert.False(installationResponses.Where((i) => i.InstallationCode == installationCode).Any(), $"Duplicate installation name detected: {installationCode}");
}

private static (StringContent installationContent, StringContent plantContent, StringContent deckContent, StringContent areaContent) ArrangeAreaPostQueries(string installationCode, string plantCode, string deckName, string areaName)
{
var testPose = new Pose
Expand Down Expand Up @@ -191,6 +201,29 @@ private async Task<T> PostToDb<T>(string postUrl, StringContent content)
return (installation, plant, deck, area);
}

private async Task<Installation> PostInstallationInformationToDb(string installationCode)
{
await VerifyNonDuplicateInstallationDbName(installationCode);

string installationUrl = "/installations";

var installationQuery = new CreateInstallationQuery
{
InstallationCode = installationCode,
Name = installationCode
};

var installationContent = new StringContent(
JsonSerializer.Serialize(installationQuery),
null,
"application/json"
);

var installation = await PostToDb<Installation>(installationUrl, installationContent);

return installation;
}

[Fact]
public async Task ScheduleOneEchoMissionTest()
{
Expand Down Expand Up @@ -651,12 +684,8 @@ public async Task MissionDoesNotStartIfRobotIsNotInSameInstallationAsMission()
string testMissionName = "testMissionDoesNotStartIfRobotIsNotInSameInstallationAsMission";

// Arrange - Get different installation
string installationUrl = "/installations";
var installationResponse = await _client.GetAsync(installationUrl);
Assert.True(installationResponse.IsSuccessStatusCode);
var installations = await installationResponse.Content.ReadFromJsonAsync<List<Installation>>(_serializerOptions);
Assert.True(installations != null);
var missionInstallation = installations[0];
string otherInstallationCode = "installationMissionDoesNotStartIfRobotIsNotInSameInstallationAsMission_Other";
var otherInstallation = await PostInstallationInformationToDb(otherInstallationCode);

// Arrange - Create robot
var robotQuery = new CreateRobotQuery
Expand All @@ -669,7 +698,7 @@ public async Task MissionDoesNotStartIfRobotIsNotInSameInstallationAsMission()
Enabled = true,
Host = "localhost",
Port = 3000,
CurrentInstallationCode = installationCode,
CurrentInstallationCode = otherInstallation.InstallationCode,
CurrentAreaName = null,
VideoStreams = new List<CreateVideoStreamQuery>()
};
Expand All @@ -682,7 +711,7 @@ public async Task MissionDoesNotStartIfRobotIsNotInSameInstallationAsMission()
var query = new CustomMissionQuery
{
RobotId = robotId,
InstallationCode = missionInstallation.InstallationCode,
InstallationCode = installation.InstallationCode,
AreaName = areaName,
DesiredStartTime = DateTime.SpecifyKind(new DateTime(3050, 1, 1), DateTimeKind.Utc),
InspectionFrequency = new TimeSpan(14, 0, 0, 0),
Expand Down Expand Up @@ -740,7 +769,7 @@ public async Task MissionFailsIfRobotIsNotInSameDeckAsMission()
Host = "localhost",
Port = 3000,
CurrentInstallationCode = installation.InstallationCode,
CurrentAreaName = areaName,
CurrentAreaName = null,
VideoStreams = new List<CreateVideoStreamQuery>()
};

Expand Down

0 comments on commit 74d15d3

Please sign in to comment.