Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions backend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,3 @@ to monitor the backend of our application.

We have one application insight instance for each environment.
The connection strings for the AI instances are stored in the keyvault.

## Custom Mission Loaders

You can create your own mission loader to fetch missions from some external system. The custom mission loader needs to fulfill the [IMissionLoader](api/Services/MissionLoaders/MissionLoaderInterface.cs) interface. If your mission loader is an external API you might need to add it as a downstream API in [Program.cs](api/Program.cs)
55 changes: 19 additions & 36 deletions backend/api.test/Controllers/InspectionAreaControllerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public async Task CheckThatInspectionAreaIsCorrectlyCreatedThroughEndpoint()
}

[Fact]
public async Task CheckThatMissionDefinitionIsCreatedInInspectionAreaWhenSchedulingACustomMissionRun()
public async Task CheckThatMissionDefinitionIsCreatedInInspectionAreaUponCreation()
{
// Arrange
var installation = await DatabaseUtilities.NewInstallation();
Expand All @@ -107,27 +107,24 @@ public async Task CheckThatMissionDefinitionIsCreatedInInspectionAreaWhenSchedul
inspectionArea.Id
);

var inspection = new CustomInspectionQuery
{
InspectionTarget = new Position(),
InspectionType = InspectionType.Image,
};
var tasks = new List<CustomTaskQuery>
var testName = Guid.NewGuid().ToString();

var tasks = new List<TaskQuery>
{
new()
{
Inspection = inspection,
TagId = "test",
RobotPose = new Pose(),
TaskOrder = 0,
TargetPosition = new Position(),
SensorType = SensorType.Image,
AnalysisTypes = [AnalysisType.Fencilla],
Description = "Test description",
},
};
var missionQuery = new CustomMissionQuery
var missionQuery = new CreateMissionQuery
{
RobotId = robot.Id,
CreationTime = DateTime.UtcNow,
InstallationCode = installation.InstallationCode,
Name = "TestMission",
Name = testName,
Tasks = tasks,
};

Expand All @@ -139,31 +136,23 @@ public async Task CheckThatMissionDefinitionIsCreatedInInspectionAreaWhenSchedul

// Act
var missionResponse = await Client.PostAsync(
"/missions/custom",
"/missions/definitions",
missionContent,
TestContext.Current.CancellationToken
);
var userMissionResponse = await missionResponse.Content.ReadFromJsonAsync<MissionRun>(
SerializerOptions,
cancellationToken: TestContext.Current.CancellationToken
);
var inspectionAreaMissionResponse = await Client.GetAsync(
$"/inspectionAreas/{inspectionArea.Id}/mission-definitions",
TestContext.Current.CancellationToken
);

// Assert
var mission = await MissionRunService.ReadById(userMissionResponse!.Id);
var missionDefinitions = await MissionDefinitionService.ReadByInspectionAreaId(
inspectionArea.Id
);

Assert.True(missionResponse.IsSuccessStatusCode);
Assert.NotNull(missionDefinitions.Find((m) => m.Name == testName));
Assert.True(inspectionAreaMissionResponse.IsSuccessStatusCode);
Assert.Single(
missionDefinitions,
m => m.Id.Equals(mission!.MissionId, StringComparison.Ordinal)
);
}

[Fact]
Expand Down Expand Up @@ -214,7 +203,7 @@ public async Task TestUpdatingInspectionAreaPolygon()
}

[Fact]
public async Task ScheduleMissionOutsideInspectionAreaPolygonFails()
public async Task CreateMissionDefinitionOutsideInspectionAreaPolygonFails()
{
// Arrange
var installation = await DatabaseUtilities.NewInstallation();
Expand Down Expand Up @@ -246,25 +235,19 @@ public async Task ScheduleMissionOutsideInspectionAreaPolygonFails()

var robot = await DatabaseUtilities.NewRobot(RobotStatus.Available, installation);

var inspection = new CustomInspectionQuery
{
InspectionTarget = new Position(),
InspectionType = InspectionType.Image,
};
var tasks = new List<CustomTaskQuery>
var tasks = new List<TaskQuery>
{
new()
{
Inspection = inspection,
TagId = "test",
TargetPosition = new Position(),
SensorType = SensorType.Image,
AnalysisTypes = [AnalysisType.Fencilla],
RobotPose = new Pose(11, 11, 11, 0, 0, 0, 1), // Position outside polygon
TaskOrder = 0,
},
};
var missionQuery = new CustomMissionQuery
var missionQuery = new CreateMissionQuery
{
RobotId = robot.Id,
CreationTime = DateTime.UtcNow,
InstallationCode = installation.InstallationCode,
Name = "TestMission",
Tasks = tasks,
Expand All @@ -278,7 +261,7 @@ public async Task ScheduleMissionOutsideInspectionAreaPolygonFails()

// Act
var missionResponse = await Client.PostAsync(
"/missions/custom",
"/missions/definitions",
missionContent,
TestContext.Current.CancellationToken
);
Expand Down
19 changes: 13 additions & 6 deletions backend/api.test/Controllers/MissionDefinitionControllerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ public class MissionDefinitionControllerTests : IAsyncLifetime
public required JsonSerializerOptions SerializerOptions;

public required IMissionDefinitionService MissionDefinitionService;
public required ISourceService SourceService;

public async ValueTask InitializeAsync()
{
Expand All @@ -40,7 +39,6 @@ public async ValueTask InitializeAsync()

MissionDefinitionService =
serviceProvider.GetRequiredService<IMissionDefinitionService>();
SourceService = serviceProvider.GetRequiredService<ISourceService>();
}

public async ValueTask DisposeAsync()
Expand All @@ -60,11 +58,20 @@ public async Task CheckThatListAllMissionDefinitionsEndpointReturnsSuccess()
plant.PlantCode
);

var source = await SourceService.CreateSourceIfDoesNotExist([]);

var task = new TaskDefinition(
new TaskQuery
{
TagId = "test",
TargetPosition = new Position(),
SensorType = SensorType.Image,
AnalysisTypes = [AnalysisType.Fencilla],
RobotPose = new Pose(11, 11, 11, 0, 0, 0, 1),
},
1
);
var missionDefinition = new MissionDefinition
{
Source = source,
Tasks = [task],
InstallationCode = installation.InstallationCode,
Name = "Test Mission Definition",
InspectionArea = inspectionArea,
Expand All @@ -81,7 +88,7 @@ public async Task CheckThatListAllMissionDefinitionsEndpointReturnsSuccess()

// Assert
var missionDefinitions = await response.Content.ReadFromJsonAsync<
List<MissionDefinitionResponse>
IEnumerable<MissionDefinitionResponse>
>(SerializerOptions, cancellationToken: TestContext.Current.CancellationToken);

Assert.Single(missionDefinitions!);
Expand Down
107 changes: 0 additions & 107 deletions backend/api.test/Controllers/MissionLoaderControllerTests.cs

This file was deleted.

Loading
Loading