From 74d15d31b99318f31530cff9dedaf9a1d3c5dcdd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anders=20Chirico=20Indreb=C3=B8?= Date: Thu, 21 Dec 2023 13:28:40 +0100 Subject: [PATCH] Fix installations setup in missiontests --- backend/api.test/Client/MissionTests.cs | 47 ++++++++++++++++++++----- 1 file changed, 38 insertions(+), 9 deletions(-) diff --git a/backend/api.test/Client/MissionTests.cs b/backend/api.test/Client/MissionTests.cs index f9c775399..02fad2fd8 100644 --- a/backend/api.test/Client/MissionTests.cs +++ b/backend/api.test/Client/MissionTests.cs @@ -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>(_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 @@ -191,6 +201,29 @@ private async Task PostToDb(string postUrl, StringContent content) return (installation, plant, deck, area); } + private async Task 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(installationUrl, installationContent); + + return installation; + } + [Fact] public async Task ScheduleOneEchoMissionTest() { @@ -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>(_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 @@ -669,7 +698,7 @@ public async Task MissionDoesNotStartIfRobotIsNotInSameInstallationAsMission() Enabled = true, Host = "localhost", Port = 3000, - CurrentInstallationCode = installationCode, + CurrentInstallationCode = otherInstallation.InstallationCode, CurrentAreaName = null, VideoStreams = new List() }; @@ -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), @@ -740,7 +769,7 @@ public async Task MissionFailsIfRobotIsNotInSameDeckAsMission() Host = "localhost", Port = 3000, CurrentInstallationCode = installation.InstallationCode, - CurrentAreaName = areaName, + CurrentAreaName = null, VideoStreams = new List() };