Skip to content

Commit

Permalink
chore: add test for query/mutation errors containing a value prop and…
Browse files Browse the repository at this point in the history
… problems prop

See #1145
  • Loading branch information
nozzlegear committed Jan 24, 2025
1 parent 9b518f3 commit 587c46e
Showing 1 changed file with 74 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Collections.Generic;
using System.Text.Json;
using System.Threading.Tasks;
using FakeItEasy;
Expand Down Expand Up @@ -46,7 +47,6 @@ public async Task WhenQueryOrMutationErrorsAreReturned_ShouldThrowRegardlessOfUs

string[] expectedPath = ["query some-query", "some-expected-path1", "some-expected-path2", "some-expected-path3" ];
var expectedPathString = JsonSerializer.Serialize(expectedPath);
// var expectedPathString = string.Join("\", \"", expectedPath);

var responseJson =
// lang=json
Expand Down Expand Up @@ -101,6 +101,79 @@ public async Task WhenQueryOrMutationErrorsAreReturned_ShouldThrowRegardlessOfUs
});
}

[Theory]
[CombinatorialData]
public async Task WhenQueryOrMutationErrorsAreReturned_AndTheyMatchTheExtensionsHaveAValuePropAndAProblemsProp_ShouldThrowRegardlessOfUserErrorHandling(
GraphRequestUserErrorHandling userErrorHandling)
{
// Setup
const string expectedMessage = "some-expected-message";
const string expectedProblemPath = "some-expected-path";
const string expectedProblemExplanation = "some-expected-explanation";
const string expectedProblemMessage = "some-expected-problem-message";
const string expectedValueKey = "some-expected-value-key";
const string expectedValueValue = "some-expected-value-value";

const string responseJson =
// lang=json
$$"""
{
"{{ErrorsPropertyName}}" : [ {
"message" : "{{expectedMessage}}",
"locations" : [ {
"line" : 7,
"column" : 2
} ],
"extensions" : {
"value": {
"{{expectedValueKey}}": "{{expectedValueValue}}"
},
"problems": [{
"path" : [ "{{expectedProblemPath}}" ],
"explanation" : "{{expectedProblemExplanation}}",
"message" : "{{expectedProblemMessage}}"
}]
}
} ]
}
""";
const string expectedRequestId = "some-expected-request-id";
var response = Utils.MakeRequestResult(responseJson, x => x.RequestId = expectedRequestId);

A.CallTo(_policy)
.WithReturnType<Task<RequestResult<string>>>()
.Returns(response);

// Act
var act = async () => await _sut.PostAsync(new GraphRequest
{
UserErrorHandling = userErrorHandling
});

// Assert
var exn = await act.Should()
.ThrowExactlyAsync<ShopifyGraphErrorsException>()
.WithMessage($"{expectedMessage}");

exn.Which.RequestId.Should().Be(expectedRequestId);
exn.Which.InnerException.Should().BeNull();
exn.Which.GraphErrors.Should().SatisfyRespectively(graphError =>
{
graphError.Message.Should().Be(expectedMessage);
graphError.Path.Should().BeNullOrEmpty();
graphError.Extensions.Should().BeEquivalentTo(new GraphErrorExtensions
{
Value = new Dictionary<string, object>{ {expectedValueKey, expectedValueValue} },
Problems = [new GraphErrorExtensionsProblem
{
Explanation = expectedProblemExplanation,
Message = expectedProblemMessage,
Path = [expectedProblemPath]
}]
});
});
}

[Theory]
[CombinatorialData]
public async Task WhenQueryOrMutationErrorsAreReturned_AndTheArrayIsEmptyWithZeroErrors_ShouldNotThrow(
Expand Down

0 comments on commit 587c46e

Please sign in to comment.