Skip to content

Commit 587c46e

Browse files
committed
chore: add test for query/mutation errors containing a value prop and problems prop
See #1145
1 parent 9b518f3 commit 587c46e

File tree

1 file changed

+74
-1
lines changed

1 file changed

+74
-1
lines changed

ShopifySharp.Tests/Services/Graph/GraphService.ErrorHandlingTests.cs

Lines changed: 74 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System.Collections.Generic;
12
using System.Text.Json;
23
using System.Threading.Tasks;
34
using FakeItEasy;
@@ -46,7 +47,6 @@ public async Task WhenQueryOrMutationErrorsAreReturned_ShouldThrowRegardlessOfUs
4647

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

5151
var responseJson =
5252
// lang=json
@@ -101,6 +101,79 @@ public async Task WhenQueryOrMutationErrorsAreReturned_ShouldThrowRegardlessOfUs
101101
});
102102
}
103103

104+
[Theory]
105+
[CombinatorialData]
106+
public async Task WhenQueryOrMutationErrorsAreReturned_AndTheyMatchTheExtensionsHaveAValuePropAndAProblemsProp_ShouldThrowRegardlessOfUserErrorHandling(
107+
GraphRequestUserErrorHandling userErrorHandling)
108+
{
109+
// Setup
110+
const string expectedMessage = "some-expected-message";
111+
const string expectedProblemPath = "some-expected-path";
112+
const string expectedProblemExplanation = "some-expected-explanation";
113+
const string expectedProblemMessage = "some-expected-problem-message";
114+
const string expectedValueKey = "some-expected-value-key";
115+
const string expectedValueValue = "some-expected-value-value";
116+
117+
const string responseJson =
118+
// lang=json
119+
$$"""
120+
{
121+
"{{ErrorsPropertyName}}" : [ {
122+
"message" : "{{expectedMessage}}",
123+
"locations" : [ {
124+
"line" : 7,
125+
"column" : 2
126+
} ],
127+
"extensions" : {
128+
"value": {
129+
"{{expectedValueKey}}": "{{expectedValueValue}}"
130+
},
131+
"problems": [{
132+
"path" : [ "{{expectedProblemPath}}" ],
133+
"explanation" : "{{expectedProblemExplanation}}",
134+
"message" : "{{expectedProblemMessage}}"
135+
}]
136+
}
137+
} ]
138+
}
139+
""";
140+
const string expectedRequestId = "some-expected-request-id";
141+
var response = Utils.MakeRequestResult(responseJson, x => x.RequestId = expectedRequestId);
142+
143+
A.CallTo(_policy)
144+
.WithReturnType<Task<RequestResult<string>>>()
145+
.Returns(response);
146+
147+
// Act
148+
var act = async () => await _sut.PostAsync(new GraphRequest
149+
{
150+
UserErrorHandling = userErrorHandling
151+
});
152+
153+
// Assert
154+
var exn = await act.Should()
155+
.ThrowExactlyAsync<ShopifyGraphErrorsException>()
156+
.WithMessage($"{expectedMessage}");
157+
158+
exn.Which.RequestId.Should().Be(expectedRequestId);
159+
exn.Which.InnerException.Should().BeNull();
160+
exn.Which.GraphErrors.Should().SatisfyRespectively(graphError =>
161+
{
162+
graphError.Message.Should().Be(expectedMessage);
163+
graphError.Path.Should().BeNullOrEmpty();
164+
graphError.Extensions.Should().BeEquivalentTo(new GraphErrorExtensions
165+
{
166+
Value = new Dictionary<string, object>{ {expectedValueKey, expectedValueValue} },
167+
Problems = [new GraphErrorExtensionsProblem
168+
{
169+
Explanation = expectedProblemExplanation,
170+
Message = expectedProblemMessage,
171+
Path = [expectedProblemPath]
172+
}]
173+
});
174+
});
175+
}
176+
104177
[Theory]
105178
[CombinatorialData]
106179
public async Task WhenQueryOrMutationErrorsAreReturned_AndTheArrayIsEmptyWithZeroErrors_ShouldNotThrow(

0 commit comments

Comments
 (0)