Skip to content

feat: luma functions #623

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

Merged
merged 1 commit into from
Jun 18, 2025
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
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# CHANGELOG

## Next Release

- Adds the following functions
- `Shipment.CreateAndBuyLuma`
- `Shipment.BuyLuma`
- `Luma.GetPromise`

## v7.1.0 (2025-05-29)

- Adds `Reference` to Claims
Expand Down
32 changes: 32 additions & 0 deletions EasyPost.Tests/Fixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@ internal static string UspsCarrierAccountId

internal static Billing Billing => GetFixtureStructure().Billing;

internal static string LumaRulesetName => GetFixtureStructure().Luma.RulesetName;

internal static string LumaPlannedShipDate => "2025-06-17";

private static FixtureStructure GetFixtureStructure()
{
string fixtureData = ReadFixtureData();
Expand Down Expand Up @@ -461,6 +465,34 @@ internal static ParameterSets.Insurance.All All(Dictionary<string, object>? fixt
}
}

internal static class Luma
{
internal static ParameterSets.Luma.CreateAndBuy CreateAndBuy(Dictionary<string, object> fixture)
{

return new ParameterSets.Luma.CreateAndBuy
{
ToAddress = Addresses.Create(fixture.GetOrNull<Dictionary<string, object>>("to_address")),
FromAddress = Addresses.Create(fixture.GetOrNull<Dictionary<string, object>>("from_address")),
Parcel = Parcels.Create(fixture.GetOrNull<Dictionary<string, object>>("parcel")),
RulesetName = Fixtures.LumaRulesetName,
PlannedShipDate = Fixtures.LumaPlannedShipDate,
};
}

internal static ParameterSets.Luma.GetPromise GetPromise(Dictionary<string, object> fixture)
{
return new ParameterSets.Luma.GetPromise
{
ToAddress = Addresses.Create(fixture.GetOrNull<Dictionary<string, object>>("to_address")),
FromAddress = Addresses.Create(fixture.GetOrNull<Dictionary<string, object>>("from_address")),
Parcel = Parcels.Create(fixture.GetOrNull<Dictionary<string, object>>("parcel")),
RulesetName = Fixtures.LumaRulesetName,
PlannedShipDate = Fixtures.LumaPlannedShipDate,
};
}
}

internal static Options Options(Dictionary<string, object>? fixture)
{
fixture ??= new Dictionary<string, object>();
Expand Down
13 changes: 13 additions & 0 deletions EasyPost.Tests/FixtureData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ public class FixtureStructure
[JsonProperty("insurances")]
public Insurances Insurances { get; set; }

[JsonProperty("luma")]
public Luma Luma { get; set; }

[JsonProperty("orders")]
public Orders Orders { get; set; }

Expand Down Expand Up @@ -188,6 +191,16 @@ public class Insurances
#endregion
}

public class Luma
{
#region JSON Properties

[JsonProperty("ruleset_name")]
public string RulesetName { get; set; }

#endregion
}

public class Orders
{
#region JSON Properties
Expand Down
31 changes: 31 additions & 0 deletions EasyPost.Tests/ServicesTests/LumaServiceTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using EasyPost.Models.API;
using EasyPost.Tests._Utilities;
using EasyPost.Tests._Utilities.Attributes;
using Xunit;

namespace EasyPost.Tests.ServicesTests
{
public class LumaServiceTests : UnitTest
{
public LumaServiceTests() : base("luma_service")
{
}

[Fact]
[Testing.Function]
public async Task TestGetPromise()
{
UseVCR("get_promise");

Dictionary<string, object> shipmentData = Fixtures.BasicShipment;
shipmentData["ruleset_name"] = Fixtures.LumaRulesetName;
shipmentData["planned_ship_date"] = Fixtures.LumaPlannedShipDate;

LumaInfo response = await Client.Luma.GetPromise(shipmentData);

Assert.NotNull(response.LumaSelectedRate);
}
}
}
35 changes: 35 additions & 0 deletions EasyPost.Tests/ServicesTests/ShipmentServiceTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,41 @@ public async Task TestRecommendShipDateForShipment()
}
}

[Fact]
[Testing.Function]
public async Task TestCreateAndBuyLuma()
{
UseVCR("create_and_buy_luma");

Dictionary<string, object> shipmentData = Fixtures.OneCallBuyShipment;
shipmentData.Remove("service");
shipmentData["ruleset_name"] = Fixtures.LumaRulesetName;
shipmentData["planned_ship_date"] = Fixtures.LumaPlannedShipDate;

Shipment shipment = await Client.Shipment.CreateAndBuyLuma(shipmentData);

Assert.NotNull(shipment.PostageLabel);
}

[Fact]
[Testing.Function]
public async Task TestBuyLuma()
{
UseVCR("buy_luma");

Shipment shipment = await Client.Shipment.Create(Fixtures.BasicShipment);

Dictionary<string, object> parameters = new()
{
{ "ruleset_name", Fixtures.LumaRulesetName },
{ "planned_ship_date", Fixtures.LumaPlannedShipDate }
};

Shipment boughtShipment = await Client.Shipment.BuyLuma(shipment.Id, parameters);

Assert.NotNull(boughtShipment.PostageLabel);
}

#endregion

#endregion
Expand Down
38 changes: 38 additions & 0 deletions EasyPost.Tests/ServicesTests/WithParameters/LumaServiceTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using EasyPost.Models.API;
using EasyPost.Tests._Utilities;
using EasyPost.Tests._Utilities.Attributes;
using Xunit;

namespace EasyPost.Tests.ServicesTests.WithParameters
{
public class LumaServiceTests : UnitTest
{
public LumaServiceTests() : base("luma_service_with_parameters")
{
}

#region Tests

#region Test CRUD Operations

[Fact]
[Testing.Function]
public async Task TestGetPromise()
{
UseVCR("get_promise");

Dictionary<string, object> shipmentData = Fixtures.BasicShipment;
Parameters.Luma.GetPromise parameters = Fixtures.Parameters.Luma.GetPromise(shipmentData);

LumaInfo response = await Client.Luma.GetPromise(parameters);

Assert.NotNull(response.LumaSelectedRate);
}

#endregion

#endregion
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,39 @@ public async Task TestEstimatedDeliveryDates()
}
}

[Fact]
[Testing.Function]
public async Task TestCreateAndBuyLuma()
{
UseVCR("create_and_buy_luma");

Dictionary<string, object> shipmentData = Fixtures.OneCallBuyShipment;
Parameters.Luma.CreateAndBuy parameters = Fixtures.Parameters.Luma.CreateAndBuy(shipmentData);
Shipment shipment = await Client.Shipment.CreateAndBuyLuma(parameters);

Assert.NotNull(shipment.PostageLabel);
}

[Fact]
[Testing.Function]
public async Task TestBuyLuma()
{
UseVCR("buy_luma");

Parameters.Shipment.Create shipmentParameters = Fixtures.Parameters.Shipments.Create(Fixtures.BasicShipment);
Shipment shipment = await Client.Shipment.Create(shipmentParameters);

Parameters.Luma.Buy buyParameters = new()
{
RulesetName = Fixtures.LumaRulesetName,
PlannedShipDate = Fixtures.LumaPlannedShipDate,
};

Shipment boughtShipment = await Client.Shipment.BuyLuma(shipment.Id, buyParameters);

Assert.NotNull(boughtShipment.PostageLabel);
}

#endregion

#endregion
Expand Down
51 changes: 51 additions & 0 deletions EasyPost.Tests/cassettes/net/luma_service/get_promise.json

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

Loading
Loading