Skip to content

Commit e497dd2

Browse files
committed
Refactor mission definition tasks
1 parent 6efd6d9 commit e497dd2

75 files changed

Lines changed: 822 additions & 2753 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

backend/api.test/Controllers/InspectionAreaControllerTests.cs

Lines changed: 19 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public async Task CheckThatInspectionAreaIsCorrectlyCreatedThroughEndpoint()
9292
}
9393

9494
[Fact]
95-
public async Task CheckThatMissionDefinitionIsCreatedInInspectionAreaWhenSchedulingACustomMissionRun()
95+
public async Task CheckThatMissionDefinitionIsCreatedInInspectionAreaUponCreation()
9696
{
9797
// Arrange
9898
var installation = await DatabaseUtilities.NewInstallation();
@@ -107,27 +107,25 @@ public async Task CheckThatMissionDefinitionIsCreatedInInspectionAreaWhenSchedul
107107
inspectionArea.Id
108108
);
109109

110-
var inspection = new CustomInspectionQuery
111-
{
112-
InspectionTarget = new Position(),
113-
InspectionType = InspectionType.Image,
114-
};
115-
var tasks = new List<CustomTaskQuery>
110+
var testName = Guid.NewGuid().ToString();
111+
112+
var tasks = new List<TaskQuery>
116113
{
117114
new()
118115
{
119-
Inspection = inspection,
120116
TagId = "test",
121117
RobotPose = new Pose(),
122-
TaskOrder = 0,
118+
TargetPosition = new Position(),
119+
SensorType = SensorType.Image,
120+
AnalysisType = AnalysisType.Fencilla,
121+
Description = "Test description",
123122
},
124123
};
125-
var missionQuery = new CustomMissionQuery
124+
var missionQuery = new MissionQuery
126125
{
127126
RobotId = robot.Id,
128-
CreationTime = DateTime.UtcNow,
129127
InstallationCode = installation.InstallationCode,
130-
Name = "TestMission",
128+
Name = testName,
131129
Tasks = tasks,
132130
};
133131

@@ -139,31 +137,23 @@ public async Task CheckThatMissionDefinitionIsCreatedInInspectionAreaWhenSchedul
139137

140138
// Act
141139
var missionResponse = await Client.PostAsync(
142-
"/missions/custom",
140+
"/missions/definitions",
143141
missionContent,
144142
TestContext.Current.CancellationToken
145143
);
146-
var userMissionResponse = await missionResponse.Content.ReadFromJsonAsync<MissionRun>(
147-
SerializerOptions,
148-
cancellationToken: TestContext.Current.CancellationToken
149-
);
150144
var inspectionAreaMissionResponse = await Client.GetAsync(
151145
$"/inspectionAreas/{inspectionArea.Id}/mission-definitions",
152146
TestContext.Current.CancellationToken
153147
);
154148

155149
// Assert
156-
var mission = await MissionRunService.ReadById(userMissionResponse!.Id);
157150
var missionDefinitions = await MissionDefinitionService.ReadByInspectionAreaId(
158151
inspectionArea.Id
159152
);
160153

161154
Assert.True(missionResponse.IsSuccessStatusCode);
155+
Assert.NotNull(missionDefinitions.Find((m) => m.Name == testName));
162156
Assert.True(inspectionAreaMissionResponse.IsSuccessStatusCode);
163-
Assert.Single(
164-
missionDefinitions,
165-
m => m.Id.Equals(mission!.MissionId, StringComparison.Ordinal)
166-
);
167157
}
168158

169159
[Fact]
@@ -214,7 +204,7 @@ public async Task TestUpdatingInspectionAreaPolygon()
214204
}
215205

216206
[Fact]
217-
public async Task ScheduleMissionOutsideInspectionAreaPolygonFails()
207+
public async Task CreateMissionDefinitionOutsideInspectionAreaPolygonFails()
218208
{
219209
// Arrange
220210
var installation = await DatabaseUtilities.NewInstallation();
@@ -246,25 +236,20 @@ public async Task ScheduleMissionOutsideInspectionAreaPolygonFails()
246236

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

249-
var inspection = new CustomInspectionQuery
250-
{
251-
InspectionTarget = new Position(),
252-
InspectionType = InspectionType.Image,
253-
};
254-
var tasks = new List<CustomTaskQuery>
239+
var tasks = new List<TaskQuery>
255240
{
256241
new()
257242
{
258-
Inspection = inspection,
259243
TagId = "test",
244+
TargetPosition = new Position(),
245+
SensorType = SensorType.Image,
246+
AnalysisType = AnalysisType.Fencilla,
260247
RobotPose = new Pose(11, 11, 11, 0, 0, 0, 1), // Position outside polygon
261-
TaskOrder = 0,
262248
},
263249
};
264-
var missionQuery = new CustomMissionQuery
250+
var missionQuery = new MissionQuery
265251
{
266252
RobotId = robot.Id,
267-
CreationTime = DateTime.UtcNow,
268253
InstallationCode = installation.InstallationCode,
269254
Name = "TestMission",
270255
Tasks = tasks,
@@ -278,7 +263,7 @@ public async Task ScheduleMissionOutsideInspectionAreaPolygonFails()
278263

279264
// Act
280265
var missionResponse = await Client.PostAsync(
281-
"/missions/custom",
266+
"/missions/definitions",
282267
missionContent,
283268
TestContext.Current.CancellationToken
284269
);

backend/api.test/Controllers/MissionDefinitionControllerTests.cs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ public class MissionDefinitionControllerTests : IAsyncLifetime
2222
public required JsonSerializerOptions SerializerOptions;
2323

2424
public required IMissionDefinitionService MissionDefinitionService;
25-
public required ISourceService SourceService;
2625

2726
public async ValueTask InitializeAsync()
2827
{
@@ -40,7 +39,6 @@ public async ValueTask InitializeAsync()
4039

4140
MissionDefinitionService =
4241
serviceProvider.GetRequiredService<IMissionDefinitionService>();
43-
SourceService = serviceProvider.GetRequiredService<ISourceService>();
4442
}
4543

4644
public async ValueTask DisposeAsync()
@@ -60,11 +58,19 @@ public async Task CheckThatListAllMissionDefinitionsEndpointReturnsSuccess()
6058
plant.PlantCode
6159
);
6260

63-
var source = await SourceService.CreateSourceIfDoesNotExist([]);
64-
61+
var task = new MissionTaskDefinition(
62+
new TaskQuery
63+
{
64+
TagId = "test",
65+
TargetPosition = new Position(),
66+
SensorType = SensorType.Image,
67+
AnalysisType = AnalysisType.Fencilla,
68+
RobotPose = new Pose(11, 11, 11, 0, 0, 0, 1),
69+
}
70+
);
6571
var missionDefinition = new MissionDefinition
6672
{
67-
Source = source,
73+
Tasks = [task],
6874
InstallationCode = installation.InstallationCode,
6975
Name = "Test Mission Definition",
7076
InspectionArea = inspectionArea,
@@ -81,7 +87,7 @@ public async Task CheckThatListAllMissionDefinitionsEndpointReturnsSuccess()
8187

8288
// Assert
8389
var missionDefinitions = await response.Content.ReadFromJsonAsync<
84-
List<MissionDefinitionResponse>
90+
IEnumerable<MissionDefinitionResponse>
8591
>(SerializerOptions, cancellationToken: TestContext.Current.CancellationToken);
8692

8793
Assert.Single(missionDefinitions!);

backend/api.test/Controllers/MissionLoaderControllerTests.cs

Lines changed: 0 additions & 107 deletions
This file was deleted.

0 commit comments

Comments
 (0)