Skip to content

Commit

Permalink
[fix] Add RestrictionComments to CustomsInfo Create parameter set (
Browse files Browse the repository at this point in the history
…#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
  • Loading branch information
nwithan8 authored Oct 21, 2024
1 parent 822932a commit ad25818
Show file tree
Hide file tree
Showing 93 changed files with 2,306 additions and 1,841 deletions.
14 changes: 11 additions & 3 deletions EasyPost.Tests/Fixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,9 @@ internal static Dictionary<string, object> BasicPickup

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

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

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

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

Expand Down Expand Up @@ -334,6 +334,13 @@ internal static ParameterSets.CustomsInfo.Create Create(Dictionary<string, objec
}
}

string? restrictionType = fixture.GetOrNull<string>("restriction_type");
string? restrictionComments = fixture.GetOrNull<string>("restriction_comments");
if (restrictionType == "none")
{
restrictionComments ??= "placeholder"; // required if restrictionType is "none", either use the provided value or a fallback placeholder
}

return new ParameterSets.CustomsInfo.Create
{
Id = fixture.GetOrNull<string>("id"),
Expand All @@ -342,7 +349,8 @@ internal static ParameterSets.CustomsInfo.Create Create(Dictionary<string, objec
EelPfc = fixture.GetOrNull<string>("eel_pfc"),
ContentsType = fixture.GetOrNull<string>("contents_type"),
ContentsExplanation = fixture.GetOrNull<string>("contents_explanation"),
RestrictionType = fixture.GetOrNull<string>("restriction_type"),
RestrictionType = restrictionType,
RestrictionComments = restrictionComments,
NonDeliveryOption = fixture.GetOrNull<string>("non_delivery_option"),
CustomsCertify = fixture.GetOrNullBoolean("customs_certify"),
CustomsSigner = fixture.GetOrNull<string>("customs_signer"),
Expand Down
276 changes: 260 additions & 16 deletions EasyPost.Tests/ParametersTests/ParametersTest.cs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using EasyPost.Tests._Utilities.Attributes;
using EasyPost.Utilities.Internal.Attributes;
using Xunit;
using CustomAssertions = EasyPost.Tests._Utilities.Assertions.Assert;

namespace EasyPost.Tests.ServicesTests.WithParameters
{
Expand Down Expand Up @@ -40,6 +41,50 @@ public async Task TestCreate()
}
}

[Fact]
[CrudOperations.Create]
[Testing.Exception]
public async Task TestCreateWithRestrictionAndRestrictionCommentsCombos()
{
UseVCR("create_with_restriction_and_restriction_comments_combos");

Dictionary<string, object> data = Fixtures.BasicCustomsInfo;
Parameters.CustomsInfo.Create parameters = Fixtures.Parameters.CustomsInfo.Create(data);

// User must provide comments if restriction is set to anything other than "none"
parameters.RestrictionType = "other";
parameters.RestrictionComments = null;

Assert.Throws<Exceptions.General.InvalidParameterPairError>(() => parameters.ToDictionary());

parameters.RestrictionType = "other";
parameters.RestrictionComments = "Explanation";

CustomAssertions.DoesNotThrow(() => parameters.ToDictionary());

// User does not necessarily need to provide comments if restriction is set to "none", but can if they want
parameters.RestrictionType = "none";
parameters.RestrictionComments = null;

CustomAssertions.DoesNotThrow(() => parameters.ToDictionary());

parameters.RestrictionType = "none";
parameters.RestrictionComments = "Explanation";

CustomAssertions.DoesNotThrow(() => parameters.ToDictionary());

// User does not need to provide comments if restriction is not set, but can if they want
parameters.RestrictionType = null;
parameters.RestrictionComments = null;

CustomAssertions.DoesNotThrow(() => parameters.ToDictionary());

parameters.RestrictionType = null;
parameters.RestrictionComments = "Explanation";

CustomAssertions.DoesNotThrow(() => parameters.ToDictionary());
}

#endregion

#endregion
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit ad25818

Please sign in to comment.