Skip to content

Commit

Permalink
- Address feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
nwithan8 committed Jul 10, 2024
1 parent b4c5a91 commit 696c4af
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,23 +95,12 @@ public async Task TestCreateUps()

Parameters.CarrierAccount.CreateUps parameters = Fixtures.Parameters.CarrierAccounts.CreateUps(data);

try
{
// confirms we can pass in CreateUps parameters to the same Create method because they are children of the generic Create class
CarrierAccount carrierAccount = await Client.CarrierAccount.Create(parameters);
CleanUpAfterTest(carrierAccount.Id);
}

catch (BadRequestError e)
{
// the data we're sending is invalid, we want to check that the API error is because of malformed data and not due to the endpoint
Assert.Equal(400, e.StatusCode); // 400 is fine. We don't want a 404 not found
Assert.NotNull(e.Errors);
Assert.Contains(e.Errors, error => error is { Message: "Invalid Customer Account Nbr" });
// confirms we can pass in CreateUps parameters to the same Create method because they are children of the generic Create class
CarrierAccount carrierAccount = await Client.CarrierAccount.Create(parameters);
CleanUpAfterTest(carrierAccount.Id);

// Check the cassette to make sure the endpoint is correct (it should be ups_oauth_registrations)
// Check the cassette to make sure the "ups_oauth_registrations" key is populated in the request body
}
Assert.IsType<CarrierAccount>(carrierAccount);
Assert.StartsWith("ca_", carrierAccount.Id);
}

[Fact]
Expand Down
15 changes: 5 additions & 10 deletions EasyPost/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,15 +165,12 @@ internal static string DeriveCreateEndpoint(string carrierType)

var @switch = new SwitchCase
{
{ CarrierAccountType.FedEx.Name, () => endpoint = CustomCreateEndpoint },
{ CarrierAccountType.FedExSmartPost.Name, () => endpoint = CustomCreateEndpoint },
{ CarrierAccountType.Ups.Name, () => endpoint = UpsOAuthCreateEndpoint },
{ CarrierAccountType.UpsMailInnovations.Name, () => endpoint = UpsOAuthCreateEndpoint },
{ CarrierAccountType.UpsSurePost.Name, () => endpoint = UpsOAuthCreateEndpoint },
{ new List<string> { CarrierAccountType.FedEx.Name, CarrierAccountType.FedExSmartPost.Name }.Contains(carrierType), () => endpoint = CustomCreateEndpoint },
{ new List<string> { CarrierAccountType.Ups.Name, CarrierAccountType.UpsMailInnovations.Name, CarrierAccountType.UpsSurePost.Name }.Contains(carrierType), () => endpoint = UpsOAuthCreateEndpoint },
{ SwitchCaseScenario.Default, () => endpoint = StandardCreateEndpoint },
};

@switch.MatchFirst(carrierType);
@switch.MatchFirstTrue();

return endpoint;
}
Expand All @@ -184,13 +181,11 @@ internal static string DeriveUpdateEndpoint(string carrierType, string id)

var @switch = new SwitchCase
{
{ CarrierAccountType.Ups.Name, () => endpoint = string.Format(CultureInfo.InvariantCulture, UpsOAuthUpdateEndpoint, id) },
{ CarrierAccountType.UpsMailInnovations.Name, () => endpoint = string.Format(CultureInfo.InvariantCulture, UpsOAuthUpdateEndpoint, id) },
{ CarrierAccountType.UpsSurePost.Name, () => endpoint = string.Format(CultureInfo.InvariantCulture, UpsOAuthUpdateEndpoint, id) },
{ new List<string> { CarrierAccountType.Ups.Name, CarrierAccountType.UpsMailInnovations.Name, CarrierAccountType.UpsSurePost.Name }.Contains(carrierType), () => endpoint = string.Format(CultureInfo.InvariantCulture, UpsOAuthUpdateEndpoint, id) },
{ SwitchCaseScenario.Default, () => endpoint = string.Format(CultureInfo.InvariantCulture, StandardUpdateEndpoint, id) },
};

@switch.MatchFirst(carrierType);
@switch.MatchFirstTrue();

return endpoint;
}
Expand Down

0 comments on commit 696c4af

Please sign in to comment.