Skip to content

Commit

Permalink
[chore] Fix casing for SmartRate (#448)
Browse files Browse the repository at this point in the history
- Rename all instances of smartrate to SmartRate/Smart Rate
- Remove obsolete smart rate function on shipment service
  • Loading branch information
nwithan8 committed May 1, 2023
1 parent b8e30f5 commit 0435d34
Show file tree
Hide file tree
Showing 12 changed files with 74 additions and 87 deletions.
8 changes: 4 additions & 4 deletions EasyPost.Tests/CalculationTests/RatesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,23 @@ public void TestGetLowestRateObject()
[Testing.Function]
public void TestGetLowestShipmentSmartRate()
{
List<Smartrate> rates = new()
List<SmartRate> rates = new()
{
new Smartrate
new SmartRate
{
Rate = 100.00,
DeliveryDays = 1,
TimeInTransit = new TimeInTransit { Percentile50 = 1 }
},
new Smartrate
new SmartRate
{
Rate = 1.00,
DeliveryDays = 4,
TimeInTransit = new TimeInTransit { Percentile50 = 4 }
}
};

Smartrate lowestRate = Utilities.Rates.GetLowestSmartRate(rates, 1, SmartrateAccuracy.Percentile50);
SmartRate lowestRate = Utilities.Rates.GetLowestSmartRate(rates, 1, SmartRateAccuracy.Percentile50);
Assert.Equal(100.00, lowestRate.Rate); // Will choose the $100 rate because it is the only rate that meets the delivery days and accuracy requirement
}

Expand Down
6 changes: 3 additions & 3 deletions EasyPost.Tests/ModelsTests/SmartrateAccuracyTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ public SmartRateAccuracyTests() : base("smart_rate_accuracy")
[Testing.Function]
public void TestAll()
{
IEnumerable<SmartrateAccuracy> enums = SmartrateAccuracy.All();
foreach (SmartrateAccuracy? @enum in enums)
IEnumerable<SmartRateAccuracy> enums = SmartRateAccuracy.All();
foreach (SmartRateAccuracy? @enum in enums)
{
Assert.IsType<SmartrateAccuracy>(@enum);
Assert.IsType<SmartRateAccuracy>(@enum);
Assert.IsType<string>(@enum.Value);
}
}
Expand Down
22 changes: 11 additions & 11 deletions EasyPost.Tests/ModelsTests/TimeInTransitTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ public TimeInTransitTests() : base("time_in_transit")
[Testing.Function]
public void TestGetBySmartRateAccuracy()
{
Dictionary<SmartrateAccuracy, int> pairs = new()
Dictionary<SmartRateAccuracy, int> pairs = new()
{
{ SmartrateAccuracy.Percentile50, 1 },
{ SmartrateAccuracy.Percentile75, 2 },
{ SmartrateAccuracy.Percentile85, 3 },
{ SmartrateAccuracy.Percentile90, 4 },
{ SmartrateAccuracy.Percentile95, 5 },
{ SmartrateAccuracy.Percentile97, 6 },
{ SmartrateAccuracy.Percentile99, 7 }
{ SmartRateAccuracy.Percentile50, 1 },
{ SmartRateAccuracy.Percentile75, 2 },
{ SmartRateAccuracy.Percentile85, 3 },
{ SmartRateAccuracy.Percentile90, 4 },
{ SmartRateAccuracy.Percentile95, 5 },
{ SmartRateAccuracy.Percentile97, 6 },
{ SmartRateAccuracy.Percentile99, 7 }
};

TimeInTransit timeInTransit = new()
Expand All @@ -38,11 +38,11 @@ public void TestGetBySmartRateAccuracy()
Percentile99 = 7
};

foreach (KeyValuePair<SmartrateAccuracy, int> pair in pairs)
foreach (KeyValuePair<SmartRateAccuracy, int> pair in pairs)
{
SmartrateAccuracy accuracy = pair.Key;
SmartRateAccuracy accuracy = pair.Key;
int expected = pair.Value;
int? actual = timeInTransit.GetBySmartrateAccuracy(accuracy);
int? actual = timeInTransit.GetBySmartRateAccuracy(accuracy);
Assert.Equal(expected, actual);
}
}
Expand Down
22 changes: 11 additions & 11 deletions EasyPost.Tests/ServicesTests/ShipmentServiceTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -273,9 +273,9 @@ public async Task TestGetSmartRates()

Assert.NotNull(shipment.Rates);

List<Smartrate> smartRates = await Client.Shipment.GetSmartrates(shipment.Id);
Smartrate smartRate = smartRates.First();
// Must compare IDs because one is a Rate object and one is a Smartrate object
List<SmartRate> smartRates = await Client.Shipment.GetSmartRates(shipment.Id);
SmartRate smartRate = smartRates.First();
// Must compare IDs because one is a Rate object and one is a SmartRate object
Assert.Equal(shipment.Rates[0].Id, smartRate.Id);
Assert.NotNull(smartRate.TimeInTransit.Percentile50);
Assert.NotNull(smartRate.TimeInTransit.Percentile75);
Expand Down Expand Up @@ -491,9 +491,9 @@ public async Task TestLowestSmartRateFiltering()
{
// Mock rates since these can change from the API and we want to test the local filtering logic, not the API call
// API call is tested in TestGetSmartRates
List<Smartrate> smartrates = new List<Smartrate>
List<SmartRate> smartRates = new List<SmartRate>
{
new Smartrate
new SmartRate
{
Service = "Priority",
Carrier = "USPS",
Expand All @@ -503,7 +503,7 @@ public async Task TestLowestSmartRateFiltering()
Percentile90 = 3,
},
},
new Smartrate
new SmartRate
{
Service = "First",
Carrier = "USPS",
Expand All @@ -515,16 +515,16 @@ public async Task TestLowestSmartRateFiltering()
},
};

// test lowest Smart Rate with valid filters
Smartrate lowestSmartRate = Utilities.Rates.GetLowestSmartRate(smartrates, 2, SmartrateAccuracy.Percentile90);
// test lowest SmartRate with valid filters
SmartRate lowestSmartRate = Utilities.Rates.GetLowestSmartRate(smartRates, 2, SmartRateAccuracy.Percentile90);
Assert.Equal("First", lowestSmartRate.Service);
Assert.Equal(6.07, lowestSmartRate.Rate);
Assert.Equal("USPS", lowestSmartRate.Carrier);

// test lowest Smart Rate with invalid filters (should error due to strict delivery_days)
await Assert.ThrowsAsync<FilteringError>(() => Task.FromResult(Utilities.Rates.GetLowestSmartRate(smartrates, 0, SmartrateAccuracy.Percentile90)));
// test lowest SmartRate with invalid filters (should error due to strict delivery_days)
await Assert.ThrowsAsync<FilteringError>(() => Task.FromResult(Utilities.Rates.GetLowestSmartRate(smartRates, 0, SmartRateAccuracy.Percentile90)));

// test lowest Smart Rate with invalid filters (should error due to bad delivery_accuracy)
// test lowest SmartRate with invalid filters (should error due to bad delivery_accuracy)
// this test is not needed in the C# CL because it uses enums for the accuracy (can't pass in an incorrect value)
}

Expand Down
4 changes: 2 additions & 2 deletions EasyPost.Tests/UtilitiesTests/SwitchCaseTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public void TestSwitchCaseCaseTypes()
{ "string", () => matchCount += 1 },
{ 100, () => matchCount += 1 },
{ 20.000, () => matchCount += 1 },
{ SmartrateAccuracy.Percentile50, () => matchCount += 1 },
{ SmartRateAccuracy.Percentile50, () => matchCount += 1 },
{ new object(), () => matchCount += 1 },
{ false, () => matchCount += 1 },
{ ReturnsFalse(), () => matchCount += 1 },
Expand All @@ -30,7 +30,7 @@ public void TestSwitchCaseCaseTypes()
{ SwitchCaseScenario.Default, () => matchCount = -1000 }
};

@switch.MatchAll(SmartrateAccuracy.Percentile50);
@switch.MatchAll(SmartRateAccuracy.Percentile50);
Assert.Equal(1, matchCount);

// If there is no match, the default case should be executed
Expand Down
6 changes: 3 additions & 3 deletions EasyPost/Calculation/Rates.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ public static class Rates
/// <summary>
/// Get the lowest smartRate from a list of rates.
///
/// Deprecated. Use <see cref="EasyPost.Utilities.Rates.GetLowestSmartRate(IEnumerable{EasyPost.Models.API.Smartrate}, int, EasyPost.Models.API.SmartrateAccuracy)"/> instead.
/// Deprecated. Use <see cref="EasyPost.Utilities.Rates.GetLowestSmartRate(IEnumerable{EasyPost.Models.API.SmartRate}, int, EasyPost.Models.API.SmartRateAccuracy)"/> instead.
/// </summary>
/// <param name="smartrates">List of smartRates to parse.</param>
/// <param name="smartRates">List of smartRates to parse.</param>
/// <param name="deliveryDays">Delivery days to include in the filter.</param>
/// <param name="deliveryAccuracy">Delivery accuracy to include in the filter.</param>
/// <returns>Lowest rate matching the filter.</returns>
[Obsolete("This method is deprecated. Please use EasyPost.Utilities.Rates.GetLowestSmartRate() instead. This method will be removed in a future version.", false)]
public static EasyPost.Models.API.Smartrate GetLowestShipmentSmartrate(IEnumerable<EasyPost.Models.API.Smartrate> smartrates, int deliveryDays, EasyPost.Models.API.SmartrateAccuracy deliveryAccuracy) => Utilities.Rates.GetLowestSmartRate(smartrates, deliveryDays, deliveryAccuracy);
public static EasyPost.Models.API.SmartRate GetLowestShipmentSmartRate(IEnumerable<EasyPost.Models.API.SmartRate> smartRates, int deliveryDays, EasyPost.Models.API.SmartRateAccuracy deliveryAccuracy) => Utilities.Rates.GetLowestSmartRate(smartRates, deliveryDays, deliveryAccuracy);
}
#pragma warning restore CA1724 // Naming conflicts with Parameters.Beta.Rates
}
2 changes: 1 addition & 1 deletion EasyPost/Models/API/Beta/CarrierMetadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,6 @@ private CarrierMetadataType(int id, string name)
{
}

public static IEnumerable<SmartrateAccuracy> All() => GetAll<SmartrateAccuracy>();
public static IEnumerable<SmartRateAccuracy> All() => GetAll<SmartRateAccuracy>();
}
}
4 changes: 2 additions & 2 deletions EasyPost/Models/API/Smartrate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace EasyPost.Models.API
{
public class Smartrate : EasyPostObject
public class SmartRate : EasyPostObject
{
#region JSON Properties

Expand Down Expand Up @@ -43,7 +43,7 @@ public class Smartrate : EasyPostObject

#endregion

internal Smartrate()
internal SmartRate()
{
}
}
Expand Down
20 changes: 10 additions & 10 deletions EasyPost/Models/API/SmartrateAccuracy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@

namespace EasyPost.Models.API
{
public class SmartrateAccuracy : ValueEnum
public class SmartRateAccuracy : ValueEnum
{
public static readonly SmartrateAccuracy Percentile50 = new(1, "percentile_50");
public static readonly SmartrateAccuracy Percentile75 = new(2, "percentile_75");
public static readonly SmartrateAccuracy Percentile85 = new(3, "percentile_85");
public static readonly SmartrateAccuracy Percentile90 = new(4, "percentile_90");
public static readonly SmartrateAccuracy Percentile95 = new(5, "percentile_95");
public static readonly SmartrateAccuracy Percentile97 = new(6, "percentile_97");
public static readonly SmartrateAccuracy Percentile99 = new(7, "percentile_99");
public static readonly SmartRateAccuracy Percentile50 = new(1, "percentile_50");
public static readonly SmartRateAccuracy Percentile75 = new(2, "percentile_75");
public static readonly SmartRateAccuracy Percentile85 = new(3, "percentile_85");
public static readonly SmartRateAccuracy Percentile90 = new(4, "percentile_90");
public static readonly SmartRateAccuracy Percentile95 = new(5, "percentile_95");
public static readonly SmartRateAccuracy Percentile97 = new(6, "percentile_97");
public static readonly SmartRateAccuracy Percentile99 = new(7, "percentile_99");

private SmartrateAccuracy(int id, string name)
private SmartRateAccuracy(int id, string name)
: base(id, name)
{
}

public static IEnumerable<SmartrateAccuracy> All() => GetAll<SmartrateAccuracy>();
public static IEnumerable<SmartRateAccuracy> All() => GetAll<SmartRateAccuracy>();
}
}
20 changes: 10 additions & 10 deletions EasyPost/Models/API/TimeInTransit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,45 +29,45 @@ internal TimeInTransit()
}

/// <summary>
/// Get the value of a specific percentile by its corresponding SmartrateAccuracy enum.
/// Get the value of a specific percentile by its corresponding SmartRateAccuracy enum.
/// </summary>
/// <param name="accuracy">SmartrateAccuracy enum to find associated value for.</param>
/// <param name="accuracy">SmartRateAccuracy enum to find associated value for.</param>
/// <returns>Corresponding percentile int value.</returns>
public int? GetBySmartrateAccuracy(SmartrateAccuracy accuracy)
public int? GetBySmartRateAccuracy(SmartRateAccuracy accuracy)
{
if (accuracy.Equals(SmartrateAccuracy.Percentile50))
if (accuracy.Equals(SmartRateAccuracy.Percentile50))
{
return Percentile50;
}

if (accuracy.Equals(SmartrateAccuracy.Percentile75))
if (accuracy.Equals(SmartRateAccuracy.Percentile75))
{
return Percentile75;
}

if (accuracy.Equals(SmartrateAccuracy.Percentile85))
if (accuracy.Equals(SmartRateAccuracy.Percentile85))
{
return Percentile85;
}

if (accuracy.Equals(SmartrateAccuracy.Percentile90))
if (accuracy.Equals(SmartRateAccuracy.Percentile90))
{
return Percentile90;
}

if (accuracy.Equals(SmartrateAccuracy.Percentile95))
if (accuracy.Equals(SmartRateAccuracy.Percentile95))
{
return Percentile95;
}

if (accuracy.Equals(SmartrateAccuracy.Percentile97))
if (accuracy.Equals(SmartRateAccuracy.Percentile97))
{
return Percentile97;
}

// ReSharper disable once ConvertIfStatementToReturnStatement
#pragma warning disable IDE0046
if (accuracy.Equals(SmartrateAccuracy.Percentile99))
if (accuracy.Equals(SmartRateAccuracy.Percentile99))
#pragma warning restore IDE0046
{
return Percentile99;
Expand Down
19 changes: 3 additions & 16 deletions EasyPost/Services/ShipmentService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using EasyPost._base;
Expand Down Expand Up @@ -121,11 +120,11 @@ public async Task<ShipmentCollection> All(BetaFeatures.Parameters.Shipments.All
/// <summary>
/// Get the SmartRates for this shipment.
/// </summary>
/// <returns>A list of EasyPost.Smartrate instances.</returns>
/// <returns>A list of EasyPost.SmartRate instances.</returns>
[CrudOperations.Read]
public async Task<List<Smartrate>> GetSmartrates(string id)
public async Task<List<SmartRate>> GetSmartRates(string id)
{
return await Request<List<Smartrate>>(Method.Get, $"shipments/{id}/smartrate", null, "result");
return await Request<List<SmartRate>>(Method.Get, $"shipments/{id}/smartrate", null, "result");
}

/// <summary>
Expand Down Expand Up @@ -275,17 +274,5 @@ public async Task<Shipment> RegenerateRates(string id, BetaFeatures.Parameters.S
}

#endregion

/// <summary>
/// Get the lowest Smart Rate from a list of Smart Rates.
///
/// Deprecated. Use <see cref="EasyPost.Utilities.Rates.GetLowestSmartRate(IEnumerable{EasyPost.Models.API.Smartrate}, int, EasyPost.Models.API.SmartrateAccuracy)"/> instead.
/// </summary>
/// <param name="smartrates">List of smartrates to filter.</param>
/// <param name="deliveryDays">Delivery days restriction to use when filtering.</param>
/// <param name="deliveryAccuracy">Delivery days accuracy restriction to use when filtering.</param>
/// <returns>Lowest EasyPost.Smartrate object instance.</returns>
[Obsolete("This method is deprecated. Please use EasyPost.Utilities.Rates.GetLowestSmartRate() instead. This method will be removed in a future version.", false)]
public static Smartrate GetLowestSmartrate(IEnumerable<Smartrate> smartrates, int deliveryDays, SmartrateAccuracy deliveryAccuracy) => Utilities.Rates.GetLowestSmartRate(smartrates, deliveryDays, deliveryAccuracy);
}
}
Loading

0 comments on commit 0435d34

Please sign in to comment.