-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #739 from dlcs/feature/api_deliverychannelpolicies
Add endpoints for managing API delivery channel policies
- Loading branch information
Showing
23 changed files
with
1,854 additions
and
3 deletions.
There are no files selected for viewing
119 changes: 119 additions & 0 deletions
119
...API.Tests/Features/DeliveryChannels/Validation/DeliveryChannelPolicyDataValidatorTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
using API.Features.DeliveryChannels.Validation; | ||
|
||
namespace API.Tests.Features.DeliveryChannelPolicies.Validation; | ||
|
||
public class DeliveryChannelPolicyDataValidatorTests | ||
{ | ||
private readonly DeliveryChannelPolicyDataValidator sut; | ||
|
||
public DeliveryChannelPolicyDataValidatorTests() | ||
{ | ||
sut = new DeliveryChannelPolicyDataValidator(); | ||
} | ||
|
||
[Theory] | ||
[InlineData("[\"400,400\",\"200,200\",\"100,100\"]")] | ||
[InlineData("[\"!400,400\",\"!200,200\",\"!100,100\"]")] | ||
[InlineData("[\"400,\",\"200,\",\"100,\"]")] | ||
[InlineData("[\"!400,\",\"!200,\",\"!100,\"]")] | ||
[InlineData("[\"400,400\"]")] | ||
public void PolicyDataValidator_ReturnsTrue_ForValidThumbSizes(string policyData) | ||
{ | ||
// Arrange And Act | ||
var result = sut.Validate(policyData, "thumbs"); | ||
|
||
// Assert | ||
result.Should().BeTrue(); | ||
} | ||
|
||
[Fact] | ||
public void PolicyDataValidator_ReturnsFalse_ForBadThumbSizes() | ||
{ | ||
// Arrange | ||
var policyData = "[\"400,400\",\"foo,bar\",\"100,100\"]"; | ||
|
||
// Act | ||
var result = sut.Validate(policyData, "thumbs"); | ||
|
||
// Assert | ||
result.Should().BeFalse(); | ||
} | ||
|
||
[Fact] | ||
public void PolicyDataValidator_ReturnsFalse_ForInvalidThumbSizesJson() | ||
{ | ||
// Arrange | ||
var policyData = "[\"400,400\","; | ||
|
||
// Act | ||
var result = sut.Validate(policyData, "thumbs"); | ||
|
||
// Assert | ||
result.Should().BeFalse(); | ||
} | ||
|
||
[Theory] | ||
[InlineData("")] | ||
[InlineData("[]")] | ||
[InlineData("[\"\"]")] | ||
public void PolicyDataValidator_ReturnsFalse_ForEmptyThumbSizes(string policyData) | ||
{ | ||
// Arrange and Act | ||
var result = sut.Validate(policyData, "thumbs"); | ||
|
||
// Assert | ||
result.Should().BeFalse(); | ||
} | ||
|
||
[Fact] | ||
public void PolicyDataValidator_ReturnsTrue_ForValidAvPolicy() | ||
{ | ||
// Arrange | ||
var policyData = "[\"media-format-quality\"]"; // For now, any single string values are accepted - this will need | ||
// to be rewritten once the API requires policies that exist | ||
|
||
// Act | ||
var result = sut.Validate(policyData, "iiif-av"); | ||
|
||
// Assert | ||
result.Should().BeTrue(); | ||
} | ||
|
||
[Theory] | ||
[InlineData("[\"\"]")] | ||
[InlineData("[\"policy-1\",\"\"]")] | ||
public void PolicyDataValidator_ReturnsFalse_ForBadAvPolicy(string policyData) | ||
{ | ||
// Arrange and Act | ||
var result = sut.Validate(policyData, "iiif-av"); | ||
|
||
// Assert | ||
result.Should().BeFalse(); | ||
} | ||
|
||
[Theory] | ||
[InlineData("")] | ||
[InlineData("[]")] | ||
[InlineData("[\"\"]")] | ||
public void PolicyDataValidator_ReturnsFalse_ForEmptyAvPolicy(string policyData) | ||
{ | ||
// Arrange and Act | ||
var result = sut.Validate(policyData, "iiif-av"); | ||
|
||
// Assert | ||
result.Should().BeFalse(); | ||
} | ||
|
||
[Fact] | ||
public void PolicyDataValidator_ReturnsFalse_ForInvalidAvPolicyJson() | ||
{ | ||
// Arrange | ||
var policyData = "[\"policy-1\","; | ||
|
||
// Act | ||
var result = sut.Validate(policyData, "iiif-av"); | ||
|
||
// Assert | ||
result.Should().BeFalse(); | ||
} | ||
} |
93 changes: 93 additions & 0 deletions
93
...PI.Tests/Features/DeliveryChannels/Validation/HydraDeliveryChannelPolicyValidatorTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
using System; | ||
using API.Features.DeliveryChannels.Validation; | ||
using DLCS.HydraModel; | ||
using FluentValidation.TestHelper; | ||
|
||
namespace API.Tests.Features.DeliveryChannelPolicies.Validation; | ||
|
||
public class HydraDeliveryChannelPolicyValidatorTests | ||
{ | ||
private readonly HydraDeliveryChannelPolicyValidator sut; | ||
|
||
public HydraDeliveryChannelPolicyValidatorTests() | ||
{ | ||
sut = new HydraDeliveryChannelPolicyValidator(new DeliveryChannelPolicyDataValidator()); | ||
} | ||
|
||
[Fact] | ||
public void NewDeliveryChannelPolicy_CannotHave_AssetId() | ||
{ | ||
var policy = new DeliveryChannelPolicy() | ||
{ | ||
Id = "foo", | ||
}; | ||
var result = sut.TestValidate(policy); | ||
result.ShouldHaveValidationErrorFor(p => p.Id); | ||
} | ||
|
||
[Fact] | ||
public void NewDeliveryChannelPolicy_CannotHave_CustomerId() | ||
{ | ||
var policy = new DeliveryChannelPolicy() | ||
{ | ||
CustomerId = 1, | ||
}; | ||
var result = sut.TestValidate(policy); | ||
result.ShouldHaveValidationErrorFor(p => p.CustomerId); | ||
} | ||
|
||
[Fact] | ||
public void NewDeliveryChannelPolicy_CannotHave_PolicyCreated() | ||
{ | ||
var policy = new DeliveryChannelPolicy() | ||
{ | ||
Created = DateTime.UtcNow | ||
}; | ||
var result = sut.TestValidate(policy); | ||
result.ShouldHaveValidationErrorFor(p => p.Created); | ||
} | ||
|
||
[Fact] | ||
public void NewDeliveryChannelPolicy_CannotHave_PolicyModified() | ||
{ | ||
var policy = new DeliveryChannelPolicy() | ||
{ | ||
Modified = DateTime.UtcNow | ||
}; | ||
var result = sut.TestValidate(policy); | ||
result.ShouldHaveValidationErrorFor(p => p.Modified); | ||
} | ||
|
||
[Fact] | ||
public void NewDeliveryChannelPolicy_Requires_Name_OnPost() | ||
{ | ||
var policy = new DeliveryChannelPolicy() | ||
{ | ||
Name = null | ||
}; | ||
var result = sut.TestValidate(policy, p => p.IncludeRuleSets("default", "post")); | ||
result.ShouldHaveValidationErrorFor(p => p.Name); | ||
} | ||
|
||
[Fact] | ||
public void NewDeliveryChannelPolicy_Requires_PolicyData_OnPost() | ||
{ | ||
var policy = new DeliveryChannelPolicy() | ||
{ | ||
PolicyData = null, | ||
}; | ||
var result = sut.TestValidate(policy, p => p.IncludeRuleSets("default", "post")); | ||
result.ShouldHaveValidationErrorFor(p => p.PolicyData); | ||
} | ||
|
||
[Fact] | ||
public void NewDeliveryChannelPolicy_Requires_PolicyData_OnPut() | ||
{ | ||
var policy = new DeliveryChannelPolicy() | ||
{ | ||
PolicyData = null, | ||
}; | ||
var result = sut.TestValidate(policy, p => p.IncludeRuleSets("default", "put")); | ||
result.ShouldHaveValidationErrorFor(p => p.PolicyData); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.