Skip to content

Commit

Permalink
Fix endpoint path
Browse files Browse the repository at this point in the history
  • Loading branch information
MiraGeowerkstatt committed Dec 17, 2024
1 parent 55e2b4a commit 51170e3
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 37 deletions.
4 changes: 2 additions & 2 deletions src/api/Controllers/ExportController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ public ExportController(BdmsContext context, ILogger<ExportController> logger)
/// </summary>
/// <param name="ids">The list of IDs for the boreholes to be exported.</param>
/// <returns>A CSV file containing the details of the specified boreholes.</returns>
[HttpGet("export-csv")]
[HttpGet("csv")]
[Authorize(Policy = PolicyNames.Viewer)]
public async Task<IActionResult> DownloadCsvAsync([FromQuery][MaxLength(MaxPageSize)] IEnumerable<int> ids)
public async Task<IActionResult> ExportCsvAsync([FromQuery][MaxLength(MaxPageSize)] IEnumerable<int> ids)
{
List<int> idList = ids.Take(MaxPageSize).ToList();
if (idList.Count < 1) return BadRequest("The list of IDs must not be empty.");
Expand Down
2 changes: 1 addition & 1 deletion src/client/cypress/e2e/helpers/testHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const interceptApiCalls = () => {
cy.intercept("PUT", "/api/v2/layer").as("update-layer");
cy.intercept("/api/v2/location/identify**").as("location");
cy.intercept("/api/v2/borehole/copy*").as("borehole_copy");
cy.intercept("/api/v2/borehole/export-csv**").as("borehole_export_csv");
cy.intercept("/api/v2/export/csv**").as("borehole_export_csv");
cy.intercept("/api/v2/borehole/**").as("borehole_by_id");
cy.intercept("PUT", "/api/v2/borehole").as("update-borehole");

Expand Down
2 changes: 1 addition & 1 deletion src/client/src/api/borehole.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,5 +87,5 @@ export const getAllBoreholes = async (ids: number[] | GridRowSelectionModel, pag

export const exportCSVBorehole = async (boreholeIds: GridRowSelectionModel) => {
const idsQuery = boreholeIds.map(id => `ids=${id}`).join("&");
return await fetchApiV2(`borehole/export-csv?${idsQuery}`, "GET");
return await fetchApiV2(`export/csv?${idsQuery}`, "GET");
};
81 changes: 48 additions & 33 deletions tests/api/Controllers/ExportControllerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class ExportControllerTest
{
private BdmsContext context;
private ExportController controller;
private BoreholeController boreholeController;
private Mock<ILogger<ExportController>> loggerMock;
private static int testBoreholeId = 1000068;

Expand All @@ -27,9 +28,13 @@ public void TestInitialize()
{
var configuration = new ConfigurationBuilder().AddJsonFile("appsettings.Development.json").Build();

context = ContextFactory.CreateContext();
context = ContextFactory.GetTestContext();
loggerMock = new Mock<ILogger<ExportController>>();

var boreholeLockServiceMock = new Mock<IBoreholeLockService>(MockBehavior.Strict);
boreholeLockServiceMock
.Setup(x => x.IsBoreholeLockedAsync(It.IsAny<int?>(), It.IsAny<string?>()))
.ReturnsAsync(false);
boreholeController = new BoreholeController(context, new Mock<ILogger<BoreholeController>>().Object, boreholeLockServiceMock.Object) { ControllerContext = GetControllerContextAdmin() };
controller = new ExportController(context, loggerMock.Object) { ControllerContext = GetControllerContextAdmin() };
}

Expand All @@ -38,7 +43,7 @@ public async Task DownloadCsvWithValidIdsReturnsFileResultWithMax100Boreholes()
{
var ids = Enumerable.Range(testBoreholeId, 120).ToList();

var result = await controller.DownloadCsvAsync(ids) as FileContentResult;
var result = await controller.ExportCsvAsync(ids) as FileContentResult;

Assert.IsNotNull(result);
Assert.AreEqual("text/csv", result.ContentType);
Expand All @@ -64,7 +69,7 @@ public async Task DownloadCsvReturnsTVD()
.Take(3).Select(b => b.Id);

var boreholeIds = await boreholeIdsWithoutGeometry.Concat(boreholeIdsWithGeometry).ToListAsync();
var result = await controller.DownloadCsvAsync(boreholeIds) as FileContentResult;
var result = await controller.ExportCsvAsync(boreholeIds) as FileContentResult;

Assert.IsNotNull(result);
Assert.AreEqual("text/csv", result.ContentType);
Expand Down Expand Up @@ -115,53 +120,63 @@ public async Task DownloadCsvReturnsTVD()
[TestMethod]
public async Task DownloadCsvWithCustomIds()
{
// These codelists are used to make the TestContext aware of the Codelists, so that they can be included in the download controller.
var codelistGeoDIN = new Codelist { Id = 100000010, En = "ID GeODin" };
var codelistKernlager = new Codelist { Id = 100000011, En = "ID Kernlager" };
var codelistTopFels = new Codelist { Id = 100000009, En = "ID TopFels" };

var firstBoreholeId = 1_009_068;
var boreholeWithCustomIds = new Borehole
{
Id = firstBoreholeId,
BoreholeCodelists = new List<BoreholeCodelist>
{
new BoreholeCodelist
{
new BoreholeCodelist
{
BoreholeId = firstBoreholeId,
CodelistId = 100000010,
Value = "ID GeoDIN value",
},
new BoreholeCodelist
{
BoreholeId = firstBoreholeId,
CodelistId = 100000011,
Value = "ID Kernlager value",
},
BoreholeId = firstBoreholeId,
CodelistId = codelistGeoDIN.Id,
Codelist = codelistGeoDIN,
Value = "ID GeoDIN value",
},
new BoreholeCodelist
{
BoreholeId = firstBoreholeId,
CodelistId = codelistKernlager.Id,
Codelist = codelistKernlager,
Value = "ID Kernlager value",
},
},
};

var secondBoreholeId = 1_009_069;
var boreholeWithOtherCustomIds = new Borehole
{
Id = secondBoreholeId,
BoreholeCodelists = new List<BoreholeCodelist>
{
new BoreholeCodelist
{
new BoreholeCodelist
{
BoreholeId = secondBoreholeId,
CodelistId = 100000010,
Value = "ID GeoDIN value",
},
new BoreholeCodelist
{
BoreholeId = secondBoreholeId,
CodelistId = 100000009,
Value = "ID TopFels value",
},
BoreholeId = secondBoreholeId,
CodelistId = codelistGeoDIN.Id,
Codelist = codelistGeoDIN,
Value = "ID GeoDIN value",
},
new BoreholeCodelist
{
BoreholeId = secondBoreholeId,
CodelistId = codelistTopFels.Id,
Codelist = codelistTopFels,
Value = "ID TopFels value",
},
},
};

context.AddRange(boreholeWithCustomIds, boreholeWithOtherCustomIds);
await boreholeController.CreateAsync(boreholeWithCustomIds).ConfigureAwait(false);
await boreholeController.CreateAsync(boreholeWithOtherCustomIds).ConfigureAwait(false);

var ids = new List<int> { firstBoreholeId, secondBoreholeId };

var result = await controller.DownloadCsvAsync(ids) as FileContentResult;
var result = await controller.ExportCsvAsync(ids) as FileContentResult;
Assert.IsNotNull(result);
Assert.AreEqual("text/csv", result.ContentType);
Assert.AreEqual("boreholes_export.csv", result.FileDownloadName);
Expand All @@ -186,7 +201,7 @@ public async Task DownloadCsvWithInvalidIdsReturnsNotFound()
{
var ids = new List<int> { 8, 2, 11, 87 };

var result = await controller.DownloadCsvAsync(ids) as NotFoundObjectResult;
var result = await controller.ExportCsvAsync(ids) as NotFoundObjectResult;

Assert.IsNotNull(result);
Assert.AreEqual("No borehole(s) found for the provided id(s).", result.Value);
Expand All @@ -197,7 +212,7 @@ public async Task DownloadCsvWithPartiallyValidIdsReturnsFileForPartillyValidIds
{
var ids = new List<int> { 9, 8, 0, testBoreholeId };

var result = await controller.DownloadCsvAsync(ids) as FileContentResult;
var result = await controller.ExportCsvAsync(ids) as FileContentResult;

Assert.IsNotNull(result);
Assert.IsNotNull(result);
Expand All @@ -214,7 +229,7 @@ public async Task DownloadCsvEmptyIdsReturnsBadRequest()
{
var ids = new List<int>();

var result = await controller.DownloadCsvAsync(ids) as BadRequestObjectResult;
var result = await controller.ExportCsvAsync(ids) as BadRequestObjectResult;

Assert.IsNotNull(result);
Assert.AreEqual("The list of IDs must not be empty.", result.Value);
Expand Down

0 comments on commit 51170e3

Please sign in to comment.