Skip to content

Commit

Permalink
Update tests to inspection area
Browse files Browse the repository at this point in the history
  • Loading branch information
andchiind committed Dec 12, 2024
1 parent 9b8ba56 commit 05dbed3
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 29 deletions.
13 changes: 6 additions & 7 deletions backend/api.test/Client/AreaTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,19 +144,18 @@ public async Task AreaTest()
}

[Fact]
public async Task MissionIsCreatedInArea()
public async Task MissionIsCreatedInInspectionArea()
{
// Arrange - Initialise area
var installation = await _databaseUtilities.ReadOrNewInstallation();
var plant = await _databaseUtilities.ReadOrNewPlant(installation.InstallationCode);
var deck = await _databaseUtilities.ReadOrNewDeck(installation.InstallationCode, plant.PlantCode);
var area = await _databaseUtilities.ReadOrNewArea(installation.InstallationCode, plant.PlantCode, deck.Name);

// Arrange - Robot
var robot = await _databaseUtilities.NewRobot(RobotStatus.Available, installation);
string robotId = robot.Id;

string testMissionName = "testMissionInAreaTest";
string testMissionName = "testMissionInInspectionAreaTest";

var inspection = new CustomInspectionQuery
{
Expand Down Expand Up @@ -198,12 +197,12 @@ public async Task MissionIsCreatedInArea()
var mission = await missionResponse.Content.ReadFromJsonAsync<MissionRun>(_serializerOptions);
Assert.NotNull(mission);
Assert.NotNull(mission.MissionId);
string areaUrl = "/areas";
var areaMissionsResponse = await _client.GetAsync(areaUrl + $"/{area.Id}/mission-definitions");
string inspectionAreaUrl = "/decks";
var inspectionareaMissionsResponse = await _client.GetAsync(inspectionAreaUrl + $"/{deck.Id}/mission-definitions");

// Assert
Assert.True(areaMissionsResponse.IsSuccessStatusCode);
var missions = await areaMissionsResponse.Content.ReadFromJsonAsync<IList<MissionDefinitionResponse>>(_serializerOptions);
Assert.True(inspectionareaMissionsResponse.IsSuccessStatusCode);
var missions = await inspectionareaMissionsResponse.Content.ReadFromJsonAsync<IList<MissionDefinitionResponse>>(_serializerOptions);
Assert.NotNull(missions);
Assert.Single(missions.Where(m => m.Id.Equals(mission.MissionId, StringComparison.Ordinal)));
}
Expand Down
10 changes: 0 additions & 10 deletions backend/api.test/Client/MissionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,6 @@ public async Task ScheduleOneMissionTest()
{
// Arrange - Area
var installation = await _databaseUtilities.ReadOrNewInstallation();
var plant = await _databaseUtilities.ReadOrNewPlant(installation.InstallationCode);
var deck = await _databaseUtilities.ReadOrNewDeck(installation.InstallationCode, plant.PlantCode);
var area = await _databaseUtilities.ReadOrNewArea(installation.InstallationCode, plant.PlantCode, deck.Name);

// Arrange - Robot
var robot = await _databaseUtilities.NewRobot(RobotStatus.Busy, installation);
Expand All @@ -67,7 +64,6 @@ public async Task ScheduleOneMissionTest()
{
RobotId = robotId,
InstallationCode = installation.InstallationCode,
AreaName = area.Name,
MissionSourceId = missionSourceId,
DesiredStartTime = DateTime.UtcNow
};
Expand All @@ -92,23 +88,18 @@ public async Task Schedule3MissionsTest()
{
// Arrange - Area
var installation = await _databaseUtilities.ReadOrNewInstallation();
var plant = await _databaseUtilities.ReadOrNewPlant(installation.InstallationCode);
var deck = await _databaseUtilities.ReadOrNewDeck(installation.InstallationCode, plant.PlantCode);
var area = await _databaseUtilities.ReadOrNewArea(installation.InstallationCode, plant.PlantCode, deck.Name);

// Arrange - Robot
var robot = await _databaseUtilities.NewRobot(RobotStatus.Busy, installation);
string robotId = robot.Id;


string missionSourceId = "97";

// Act
var query = new ScheduledMissionQuery
{
RobotId = robotId,
InstallationCode = installation.InstallationCode,
AreaName = area.Name,
MissionSourceId = missionSourceId,
DesiredStartTime = DateTime.UtcNow
};
Expand Down Expand Up @@ -471,7 +462,6 @@ public async Task ScheduleDuplicatMissionDefinitions()
{
RobotId = robotId,
InstallationCode = installation.InstallationCode,
AreaName = area.Name,
MissionSourceId = missionSourceId,
DesiredStartTime = DateTime.UtcNow
};
Expand Down
1 change: 0 additions & 1 deletion backend/api.test/Client/RobotTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ public async Task RobotIsNotCreatedWithAreaNotInInstallation()
var wrongInstallation = await _databaseUtilities.NewInstallation("wrongInstallation");
var wrongPlant = await _databaseUtilities.ReadOrNewPlant(wrongInstallation.InstallationCode);
var wrongDeck = await _databaseUtilities.ReadOrNewDeck(wrongInstallation.InstallationCode, wrongPlant.PlantCode);
var wrongArea = await _databaseUtilities.ReadOrNewArea(wrongInstallation.InstallationCode, wrongPlant.PlantCode, wrongDeck.Name);

// Arrange - Create robot
var robotQuery = new CreateRobotQuery
Expand Down
5 changes: 4 additions & 1 deletion backend/api.test/Mocks/StidServiceMock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ public class MockStidService(FlotillaDbContext context) : IStidService
await Task.CompletedTask;
string testAreaName = "StidServiceMockArea";

var area = context.Areas.Include(a => a.Deck).Include(d => d.Plant)
var area = context.Areas
.Include(a => a.Deck).ThenInclude(d => d.Installation)
.Include(a => a.Deck).ThenInclude(d => d.Plant).ThenInclude(p => p.Installation)
.Include(d => d.Plant)
.Include(i => i.Installation).Include(d => d.DefaultLocalizationPose)
.Where(area => area.Name.Contains(testAreaName)).ToList().FirstOrDefault();
if (area != null) { return area; }
Expand Down
1 change: 0 additions & 1 deletion backend/api/Controllers/Models/ScheduledMissionQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ public struct ScheduledMissionQuery
public string MissionSourceId { get; set; }
public DateTime? DesiredStartTime { get; set; }
public string InstallationCode { get; set; }
public string? AreaName { get; set; }
public TimeSpan? InspectionFrequency { get; set; }
}
}
8 changes: 4 additions & 4 deletions backend/api/Services/AreaService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,12 +169,12 @@ private IQueryable<Area> GetAreas(bool readOnly = true)
.Include(area => area.Deck)
.ThenInclude(deck => deck != null ? deck.DefaultLocalizationPose : null)
.Include(area => area.Deck)
.ThenInclude(deck => deck != null ? deck.Plant : null)
.ThenInclude(plant => plant != null ? plant.Installation : null)
.ThenInclude(deck => deck.Plant)
.ThenInclude(plant => plant.Installation)
.Include(area => area.Deck)
.ThenInclude(deck => deck != null ? deck.Installation : null)
.ThenInclude(deck => deck.Installation)
.Include(area => area.Plant)
.ThenInclude(plant => plant != null ? plant.Installation : null)
.ThenInclude(plant => plant.Installation)
.Include(area => area.Installation)
.Where((area) => accessibleInstallationCodes.Result.Contains(area.Installation.InstallationCode.ToUpper()));
return readOnly ? query.AsNoTracking() : query.AsTracking();
Expand Down
4 changes: 2 additions & 2 deletions backend/api/Services/DeckService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public async Task<IEnumerable<Deck>> ReadByInstallation(string installationCode,
{
if (deckName == null) { return null; }
return await GetDecks(readOnly: readOnly).Where(a =>
a.Installation != null && a.Installation.InstallationCode.Equals(installationCode) && a.Name.ToLower().Equals(deckName.ToLower())
a.Installation != null && a.Installation.InstallationCode.ToLower().Equals(installationCode.ToLower()) && a.Name.ToLower().Equals(deckName.ToLower())
).FirstOrDefaultAsync();
}

Expand Down Expand Up @@ -147,7 +147,7 @@ public async Task<Deck> Update(Deck deck)
private IQueryable<Deck> GetDecks(bool readOnly = true)
{
var accessibleInstallationCodes = accessRoleService.GetAllowedInstallationCodes();
var query = context.Decks.Include(p => p.Plant).Include(i => i.Installation).Include(d => d.DefaultLocalizationPose)
var query = context.Decks.Include(p => p.Plant).ThenInclude(p => p.Installation).Include(i => i.Installation).Include(d => d.DefaultLocalizationPose)
.Where((d) => accessibleInstallationCodes.Result.Contains(d.Installation.InstallationCode.ToUpper()));
return readOnly ? query.AsNoTracking() : query.AsTracking();
}
Expand Down
3 changes: 1 addition & 2 deletions backend/api/Services/MissionDefinitionService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,7 @@ private IQueryable<MissionDefinition> GetMissionDefinitionsWithSubModels(bool re
.ThenInclude(deck => deck.Plant)
.ThenInclude(plant => plant.Installation)
.Include(missionDefinition => missionDefinition.InspectionArea)
.Include(missionDefinition => missionDefinition.InspectionArea)
.ThenInclude(area => area != null ? area.Installation : null)
.ThenInclude(area => area.Installation)
.Include(missionDefinition => missionDefinition.Source)
.Include(missionDefinition => missionDefinition.LastSuccessfulRun)
.ThenInclude(missionRun => missionRun != null ? missionRun.Tasks : null)!
Expand Down
1 change: 0 additions & 1 deletion frontend/src/api/ApiCaller.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,6 @@ export class BackendAPICaller {
robotId: desiredRobot[0].id,
missionSourceId: missionSourceId,
installationCode: installationCode,
areaName: '',
}
const result = await BackendAPICaller.POST<unknown, unknown>(path, body).catch(
BackendAPICaller.handleError('POST', path)
Expand Down

0 comments on commit 05dbed3

Please sign in to comment.