Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix] Add RestrictionComments to CustomsInfo Create parameter set #598

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading