Skip to content

Commit

Permalink
Add Patch invalid policy data, Delete_404_IfNotFound and Put_400_IfCh…
Browse files Browse the repository at this point in the history
…annelInvalid tests
  • Loading branch information
griffri committed Feb 22, 2024
1 parent 7ae9921 commit 82d970b
Showing 1 changed file with 104 additions and 0 deletions.
104 changes: 104 additions & 0 deletions src/protagonist/API.Tests/Integration/DeliveryChannelTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,26 @@ public async Task Put_DeliveryChannelPolicy_200()
foundPolicy.PolicyData.Should().Be("[\"audio-mp3-256\"]");
}

[Fact]
public async Task Put_DeliveryChannelPolicy_400_IfChannelInvalid()
{
// Arrange
const int customerId = 88;
const string newDeliveryChannelPolicyJson = @"{
""displayName"": ""Invalid Policy"",
""policyData"": ""[\""audio-mp3-128\""]""
}";

var path = $"customers/{customerId}/deliveryChannelPolicies/foo/put-invalid-channel-policy";

// Act
var content = new StringContent(newDeliveryChannelPolicyJson, Encoding.UTF8, "application/json");
var response = await httpClient.AsCustomer(customerId).PutAsync(path, content);

// Assert
response.StatusCode.Should().Be(HttpStatusCode.BadRequest);
}

[Theory]
[InlineData("")] // No PolicyData specified
[InlineData("[]")] // Empty array
Expand Down Expand Up @@ -308,6 +328,76 @@ public async Task Patch_DeliveryChannelPolicy_201()
foundPolicy.PolicyData.Should().Be("[\"audio-mp3-256\"]");
}

[Theory]
[InlineData("")] // No PolicyData specified
[InlineData("[]")] // Empty array
[InlineData("[\"\"]")] // Array containing an empty value
[InlineData(@"[\""foo\"",\""bar\""]")] // Invalid data
[InlineData(@"[\""100,100\"",\""200,200\""")] // Invalid JSON
public async Task Patch_DeliveryChannelPolicy_400_IfThumbsPolicyDataInvalid(string policyData)
{
// Arrange
const int customerId = 88;

var newDeliveryChannelPolicyJson = $@"{{
""policyData"": ""{policyData}""
}}";
var path = $"customers/{customerId}/deliveryChannelPolicies/thumbs/patch-invalid-thumbs";
var policy = new DLCS.Model.Policies.DeliveryChannelPolicy()
{
Customer = customerId,
Name = "patch-invalid-thumbs",
DisplayName = "Valid Policy (Thumbs Policy Data)",
Channel = "thumbs",
PolicyData = "[\"100,100\"]"
};

await dbContext.DeliveryChannelPolicies.AddAsync(policy);
await dbContext.SaveChangesAsync();

// Act
var content = new StringContent(newDeliveryChannelPolicyJson, Encoding.UTF8, "application/json");
var response = await httpClient.AsCustomer(customerId).PatchAsync(path, content);

// Assert
response.StatusCode.Should().Be(HttpStatusCode.BadRequest);
}

[Theory]
[InlineData("")] // No PolicyData specified
[InlineData("[]")] // Empty array
[InlineData("[\"\"]")] // Array containing an empty value
[InlineData(@"[\""foo\"",\""bar\""]")] // Invalid data
[InlineData(@"[\""transcode-policy\""")] // Invalid JSON
public async Task Patch_DeliveryChannelPolicy_400_IfAvPolicyDataInvalid(string policyData)
{
// Arrange
const int customerId = 88;

var newDeliveryChannelPolicyJson = $@"{{
""policyData"": ""{policyData}""
}}";
var policy = new DLCS.Model.Policies.DeliveryChannelPolicy()
{
Customer = customerId,
Name = "patch-invalid-iiif-av",
DisplayName = "Valid Policy (IIIF-AV Policy Data)",
Channel = "iiif-av",
PolicyData = "[\"100,100\"]"
};
var path = $"customers/{customerId}/deliveryChannelPolicies/iiif-av/patch-invalid-iiif-av";

await dbContext.DeliveryChannelPolicies.AddAsync(policy);
await dbContext.SaveChangesAsync();

// Act
var content = new StringContent(newDeliveryChannelPolicyJson, Encoding.UTF8, "application/json");
var response = await httpClient.AsCustomer(customerId).PatchAsync(path, content);

// Assert
response.StatusCode.Should().Be(HttpStatusCode.BadRequest);
}

[Fact]
public async Task Delete_DeliveryChannelPolicy_204()
{
Expand Down Expand Up @@ -337,6 +427,20 @@ public async Task Delete_DeliveryChannelPolicy_204()
policyExists.Should().BeFalse();
}

[Fact]
public async Task Delete_DeliveryChannelPolicy_404_IfNotFound()
{
// Arrange
const int customerId = 88;
var path = $"customers/{customerId}/deliveryChannelPolicies/thumbs/foo";

// Act
var response = await httpClient.AsCustomer(customerId).DeleteAsync(path);

// Assert
response.StatusCode.Should().Be(HttpStatusCode.NotFound);
}

[Fact]
public async Task Get_DeliveryChannelPolicyCollections_200()
{
Expand Down

0 comments on commit 82d970b

Please sign in to comment.