Skip to content

Commit

Permalink
move tests from using error code to ErrorTypeUri
Browse files Browse the repository at this point in the history
  • Loading branch information
JackLewis-digirati committed Sep 18, 2024
1 parent 14b65a4 commit 733b424
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ public async Task DeleteCollection_FailsToDeleteCollection_WhenAttemptingToDelet

// Assert
response.StatusCode.Should().Be(HttpStatusCode.BadRequest);
errorResponse!.Code.Should().Be(1);
errorResponse!.ErrorTypeUri.Should().Be("http://localhost/errors/DeleteCollectionType/CannotDeleteRootCollection");
errorResponse.Detail.Should().Be("Cannot delete a root collection");
}

Expand All @@ -553,7 +553,7 @@ public async Task DeleteCollection_FailsToDeleteCollection_WhenAttemptingToDelet

// Assert
response.StatusCode.Should().Be(HttpStatusCode.BadRequest);
errorResponse!.Code.Should().Be(1);
errorResponse!.ErrorTypeUri.Should().Be("http://localhost/errors/DeleteCollectionType/CannotDeleteRootCollection");
errorResponse.Detail.Should().Be("Cannot delete a root collection");
}

Expand All @@ -571,7 +571,7 @@ public async Task DeleteCollection_FailsToDeleteCollection_WhenAttemptingToDelet

// Assert
response.StatusCode.Should().Be(HttpStatusCode.BadRequest);
errorResponse!.Code.Should().Be(2);
errorResponse!.ErrorTypeUri.Should().Be("http://localhost/errors/DeleteCollectionType/CollectionNotEmpty");
errorResponse.Detail.Should().Be("Cannot delete a collection with child items");
}
}
7 changes: 2 additions & 5 deletions src/IIIFPresentation/API/Infrastructure/ControllerBaseX.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,25 +115,22 @@ public static ObjectResult ValidationFailed(this ControllerBase controller, Vali
/// <param name="instance">The value for <see cref="Error.Instance" />.</param>
/// <param name="title">The value for <see cref="Error.Title" />.</param>
/// <param name="type">The value for <see cref="Error.Type" />.</param>
/// <param name="errorCode">The value for <see cref="Error.Code" />.</param>
/// <returns>The created <see cref="ObjectResult"/> for the response.</returns>
public static ObjectResult PresentationProblem(
this ControllerBase controller,
string? detail = null,
string? instance = null,
int? statusCode = null,
string? title = null,
string? type = null,
int? errorCode = null)
string? type = null)
{
var error = new Error
{
Detail = detail,
Instance = instance ?? controller.Request.GetDisplayUrl(),
Status = statusCode ?? 500,
Title = title,
ErrorTypeUri = type,
Code = errorCode
ErrorTypeUri = type
};

return new ObjectResult(error)
Expand Down
2 changes: 0 additions & 2 deletions src/IIIFPresentation/Models/API/General/Error.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,4 @@ public class Error : JsonLdBase
public string? ErrorTypeUri { get; set; }

public int Status { get; set; }

public int? Code { get; set; }
}

0 comments on commit 733b424

Please sign in to comment.