Skip to content

Commit

Permalink
Remove Area
Browse files Browse the repository at this point in the history
  • Loading branch information
Christdej committed Feb 10, 2025
1 parent 3cf832b commit 1e99cac
Show file tree
Hide file tree
Showing 32 changed files with 60 additions and 1,517 deletions.
1 change: 0 additions & 1 deletion backend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,6 @@ The access matrix looks like this:

| | **Read Only** | **User** | **Admin** |
| -------------------------- | ------------- | -------- | --------- |
| Area | Read | Read | CRUD |
| InspectionArea | Read | Read | CRUD |
| Plant | Read | Read | CRUD |
| Installation | Read | Read | CRUD |
Expand Down
166 changes: 0 additions & 166 deletions backend/api.test/Controllers/AreaControllerTests.cs

This file was deleted.

44 changes: 1 addition & 43 deletions backend/api.test/Controllers/MissionSchedulingControllerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ await missionRunThreeResponse.Content.ReadFromJsonAsync<MissionRun>(
Assert.Equal(missionRunOne!.MissionId, activeMissionRun.MissionId);
Assert.Equal(missionRunTwo!.MissionId, activeMissionRun.MissionId);
Assert.Equal(missionRunThree!.MissionId, activeMissionRun.MissionId);
Assert.True(nextMissionRun.Id == missionRunTwo.Id);
Assert.Equal(nextMissionRun.Id, missionRunTwo.Id);
}

[Fact]
Expand Down Expand Up @@ -310,48 +310,6 @@ public async Task CheckThatMissionDoesNotStartIfRobotIsNotInSameInstallationAsMi
Assert.Equal(HttpStatusCode.Conflict, response.StatusCode);
}

[Fact]
public async Task CheckThatMissionFailsIfRobotIsNotInSameInspectionAreaAsMission()
{
// Arrange
var installation = await DatabaseUtilities.NewInstallation();
var plant = await DatabaseUtilities.NewPlant(installation.InstallationCode);

var inspectionAreaOne = await DatabaseUtilities.NewInspectionArea(
installation.InstallationCode,
plant.PlantCode,
"InspectionAreaOne"
);

var inspectionAreaTwo = await DatabaseUtilities.NewInspectionArea(
installation.InstallationCode,
plant.PlantCode,
"InspectionAreaTwo"
);

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

var query = CreateDefaultCustomMissionQuery(
robot.Id,
installation.InstallationCode,
inspectionAreaTwo.Name
);
var content = new StringContent(
JsonSerializer.Serialize(query),
null,
"application/json"
);

// Act
const string CustomMissionsUrl = "/missions/custom";
var missionResponse = await Client.PostAsync(CustomMissionsUrl, content);
Assert.Equal(HttpStatusCode.Conflict, missionResponse.StatusCode);
}

private static CustomMissionQuery CreateDefaultCustomMissionQuery(
string robotId,
string installationCode,
Expand Down
43 changes: 0 additions & 43 deletions backend/api.test/Controllers/RoleAccessTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,48 +76,5 @@ public async Task CheckThatRequestingPlantsWithUnauthorizedUserFails()
Assert.False(samePlantResponse.IsSuccessStatusCode);
Assert.Equal("NotFound", samePlantResponse.StatusCode.ToString());
}

[Fact]
public async Task CheckThatAnAuthorizedUserRoleCanAccessAreaEndpoint()
{
// Arrange
var installation = await DatabaseUtilities.NewInstallation();
var plant = await DatabaseUtilities.NewPlant(installation.InstallationCode);
var inspectionArea = await DatabaseUtilities.NewInspectionArea(
installation.InstallationCode,
plant.PlantCode
);
var area = await DatabaseUtilities.NewArea(
installation.InstallationCode,
plant.PlantCode,
inspectionArea.Name
);

var accessRoleQuery = new CreateAccessRoleQuery
{
InstallationCode = installation.InstallationCode,
RoleName = "User.TestRole",
AccessLevel = RoleAccessLevel.USER,
};
var accessRoleContent = new StringContent(
JsonSerializer.Serialize(accessRoleQuery),
null,
"application/json"
);
_ = await Client.PostAsync("/access-roles", accessRoleContent);

// Act
// Restrict ourselves to RoleAccessLevel.USER
HttpContextAccessor.SetHttpContextRoles(["User.TestRole"]);
var response = await Client.GetAsync($"/areas/{area.Id}");

// Assert
var areaFromResponse = await response.Content.ReadFromJsonAsync<AreaResponse>(
SerializerOptions
);

Assert.True(response.IsSuccessStatusCode);
Assert.Equal(areaFromResponse!.Id, area.Id);
}
}
}
29 changes: 0 additions & 29 deletions backend/api.test/Database/DatabaseUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ public class DatabaseUtilities
{
private readonly AccessRoleService _accessRoleService;
private readonly MissionTaskService _missionTaskService;
private readonly AreaService _areaService;
private readonly InspectionAreaService _inspectionAreaService;
private readonly InstallationService _installationService;
private readonly MissionRunService _missionRunService;
Expand All @@ -28,7 +27,6 @@ public class DatabaseUtilities
private readonly string _testInstallationName = "Installation";
private readonly string _testPlantCode = "PlantCode";
private readonly string _testInspectionAreaName = "InspectionArea";
private readonly string _testAreaName = "Area";

public DatabaseUtilities(FlotillaDbContext context)
{
Expand All @@ -46,13 +44,6 @@ public DatabaseUtilities(FlotillaDbContext context)
_accessRoleService,
new MockSignalRService()
);
_areaService = new AreaService(
context,
_installationService,
_plantService,
_inspectionAreaService,
_accessRoleService
);
_userInfoService = new UserInfoService(
context,
new HttpContextAccessor(),
Expand Down Expand Up @@ -165,26 +156,6 @@ public async Task<InspectionArea> NewInspectionArea(
return await _inspectionAreaService.Create(createInspectionAreaQuery);
}

public async Task<Area> NewArea(
string installationCode,
string plantCode,
string inspectionAreaName,
string areaName = ""
)
{
if (string.IsNullOrEmpty(areaName))
areaName = _testAreaName;
var createAreaQuery = new CreateAreaQuery
{
InstallationCode = installationCode,
PlantCode = plantCode,
InspectionAreaName = inspectionAreaName,
AreaName = areaName,
};

return await _areaService.Create(createAreaQuery);
}

public async Task<Robot> NewRobot(
RobotStatus status,
Installation installation,
Expand Down
Loading

0 comments on commit 1e99cac

Please sign in to comment.