Skip to content

Commit ad25818

Browse files
authored
[fix] Add RestrictionComments to CustomsInfo Create parameter set (#598)
- Add value-based inter-dependency checks for Parameters, in addition to existing presence-based checks - Add unit tests to confirm inter-dependency Parameter checks - Add `RestrictionComments` parameter to `CustomsInfo` create parameter set - Mark `RestrictionComments` presence as dependent on `RestrictionType` value - Add unit test to confirm `RestrictionComments` validation based on `RestrictionType` - Update test fixtures accordingly
1 parent 822932a commit ad25818

File tree

93 files changed

+2306
-1841
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+2306
-1841
lines changed

EasyPost.Tests/Fixture.cs

+11-3
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,9 @@ internal static Dictionary<string, object> BasicPickup
9797

9898
internal static string PickupService => GetFixtureStructure().ServiceNames.Usps.PickupService;
9999

100-
internal static string PlannedShipDate => "2024-08-23";
100+
internal static string PlannedShipDate => "2024-10-23";
101101

102-
internal static string DesiredDeliveryDate => "2024-08-23";
102+
internal static string DesiredDeliveryDate => "2024-10-23";
103103

104104
internal static Dictionary<string, object> ReferralCustomer => GetFixtureStructure().Users.Referral;
105105

@@ -334,6 +334,13 @@ internal static ParameterSets.CustomsInfo.Create Create(Dictionary<string, objec
334334
}
335335
}
336336

337+
string? restrictionType = fixture.GetOrNull<string>("restriction_type");
338+
string? restrictionComments = fixture.GetOrNull<string>("restriction_comments");
339+
if (restrictionType == "none")
340+
{
341+
restrictionComments ??= "placeholder"; // required if restrictionType is "none", either use the provided value or a fallback placeholder
342+
}
343+
337344
return new ParameterSets.CustomsInfo.Create
338345
{
339346
Id = fixture.GetOrNull<string>("id"),
@@ -342,7 +349,8 @@ internal static ParameterSets.CustomsInfo.Create Create(Dictionary<string, objec
342349
EelPfc = fixture.GetOrNull<string>("eel_pfc"),
343350
ContentsType = fixture.GetOrNull<string>("contents_type"),
344351
ContentsExplanation = fixture.GetOrNull<string>("contents_explanation"),
345-
RestrictionType = fixture.GetOrNull<string>("restriction_type"),
352+
RestrictionType = restrictionType,
353+
RestrictionComments = restrictionComments,
346354
NonDeliveryOption = fixture.GetOrNull<string>("non_delivery_option"),
347355
CustomsCertify = fixture.GetOrNullBoolean("customs_certify"),
348356
CustomsSigner = fixture.GetOrNull<string>("customs_signer"),

EasyPost.Tests/ParametersTests/ParametersTest.cs

+260-16
Large diffs are not rendered by default.

EasyPost.Tests/ServicesTests/WithParameters/CustomsInfoServiceTest.cs

+45
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using EasyPost.Tests._Utilities.Attributes;
66
using EasyPost.Utilities.Internal.Attributes;
77
using Xunit;
8+
using CustomAssertions = EasyPost.Tests._Utilities.Assertions.Assert;
89

910
namespace EasyPost.Tests.ServicesTests.WithParameters
1011
{
@@ -40,6 +41,50 @@ public async Task TestCreate()
4041
}
4142
}
4243

44+
[Fact]
45+
[CrudOperations.Create]
46+
[Testing.Exception]
47+
public async Task TestCreateWithRestrictionAndRestrictionCommentsCombos()
48+
{
49+
UseVCR("create_with_restriction_and_restriction_comments_combos");
50+
51+
Dictionary<string, object> data = Fixtures.BasicCustomsInfo;
52+
Parameters.CustomsInfo.Create parameters = Fixtures.Parameters.CustomsInfo.Create(data);
53+
54+
// User must provide comments if restriction is set to anything other than "none"
55+
parameters.RestrictionType = "other";
56+
parameters.RestrictionComments = null;
57+
58+
Assert.Throws<Exceptions.General.InvalidParameterPairError>(() => parameters.ToDictionary());
59+
60+
parameters.RestrictionType = "other";
61+
parameters.RestrictionComments = "Explanation";
62+
63+
CustomAssertions.DoesNotThrow(() => parameters.ToDictionary());
64+
65+
// User does not necessarily need to provide comments if restriction is set to "none", but can if they want
66+
parameters.RestrictionType = "none";
67+
parameters.RestrictionComments = null;
68+
69+
CustomAssertions.DoesNotThrow(() => parameters.ToDictionary());
70+
71+
parameters.RestrictionType = "none";
72+
parameters.RestrictionComments = "Explanation";
73+
74+
CustomAssertions.DoesNotThrow(() => parameters.ToDictionary());
75+
76+
// User does not need to provide comments if restriction is not set, but can if they want
77+
parameters.RestrictionType = null;
78+
parameters.RestrictionComments = null;
79+
80+
CustomAssertions.DoesNotThrow(() => parameters.ToDictionary());
81+
82+
parameters.RestrictionType = null;
83+
parameters.RestrictionComments = "Explanation";
84+
85+
CustomAssertions.DoesNotThrow(() => parameters.ToDictionary());
86+
}
87+
4388
#endregion
4489

4590
#endregion

EasyPost.Tests/cassettes/net/claim_service_with_parameters/all.json

+9-9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)