Skip to content

Commit 1b8bad4

Browse files
authored
Merge pull request #623 from EasyPost/luma
feat: luma functions
2 parents 54f9398 + 4a640ce commit 1b8bad4

File tree

26 files changed

+1019
-103
lines changed

26 files changed

+1019
-103
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# CHANGELOG
22

3+
## Next Release
4+
5+
- Adds the following functions
6+
- `Shipment.CreateAndBuyLuma`
7+
- `Shipment.BuyLuma`
8+
- `Luma.GetPromise`
9+
310
## v7.1.0 (2025-05-29)
411

512
- Adds `Reference` to Claims

EasyPost.Tests/Fixture.cs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,10 @@ internal static string UspsCarrierAccountId
130130

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

133+
internal static string LumaRulesetName => GetFixtureStructure().Luma.RulesetName;
134+
135+
internal static string LumaPlannedShipDate => "2025-06-17";
136+
133137
private static FixtureStructure GetFixtureStructure()
134138
{
135139
string fixtureData = ReadFixtureData();
@@ -461,6 +465,34 @@ internal static ParameterSets.Insurance.All All(Dictionary<string, object>? fixt
461465
}
462466
}
463467

468+
internal static class Luma
469+
{
470+
internal static ParameterSets.Luma.CreateAndBuy CreateAndBuy(Dictionary<string, object> fixture)
471+
{
472+
473+
return new ParameterSets.Luma.CreateAndBuy
474+
{
475+
ToAddress = Addresses.Create(fixture.GetOrNull<Dictionary<string, object>>("to_address")),
476+
FromAddress = Addresses.Create(fixture.GetOrNull<Dictionary<string, object>>("from_address")),
477+
Parcel = Parcels.Create(fixture.GetOrNull<Dictionary<string, object>>("parcel")),
478+
RulesetName = Fixtures.LumaRulesetName,
479+
PlannedShipDate = Fixtures.LumaPlannedShipDate,
480+
};
481+
}
482+
483+
internal static ParameterSets.Luma.GetPromise GetPromise(Dictionary<string, object> fixture)
484+
{
485+
return new ParameterSets.Luma.GetPromise
486+
{
487+
ToAddress = Addresses.Create(fixture.GetOrNull<Dictionary<string, object>>("to_address")),
488+
FromAddress = Addresses.Create(fixture.GetOrNull<Dictionary<string, object>>("from_address")),
489+
Parcel = Parcels.Create(fixture.GetOrNull<Dictionary<string, object>>("parcel")),
490+
RulesetName = Fixtures.LumaRulesetName,
491+
PlannedShipDate = Fixtures.LumaPlannedShipDate,
492+
};
493+
}
494+
}
495+
464496
internal static Options Options(Dictionary<string, object>? fixture)
465497
{
466498
fixture ??= new Dictionary<string, object>();

EasyPost.Tests/FixtureData.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ public class FixtureStructure
4040
[JsonProperty("insurances")]
4141
public Insurances Insurances { get; set; }
4242

43+
[JsonProperty("luma")]
44+
public Luma Luma { get; set; }
45+
4346
[JsonProperty("orders")]
4447
public Orders Orders { get; set; }
4548

@@ -188,6 +191,16 @@ public class Insurances
188191
#endregion
189192
}
190193

194+
public class Luma
195+
{
196+
#region JSON Properties
197+
198+
[JsonProperty("ruleset_name")]
199+
public string RulesetName { get; set; }
200+
201+
#endregion
202+
}
203+
191204
public class Orders
192205
{
193206
#region JSON Properties
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using System.Collections.Generic;
2+
using System.Threading.Tasks;
3+
using EasyPost.Models.API;
4+
using EasyPost.Tests._Utilities;
5+
using EasyPost.Tests._Utilities.Attributes;
6+
using Xunit;
7+
8+
namespace EasyPost.Tests.ServicesTests
9+
{
10+
public class LumaServiceTests : UnitTest
11+
{
12+
public LumaServiceTests() : base("luma_service")
13+
{
14+
}
15+
16+
[Fact]
17+
[Testing.Function]
18+
public async Task TestGetPromise()
19+
{
20+
UseVCR("get_promise");
21+
22+
Dictionary<string, object> shipmentData = Fixtures.BasicShipment;
23+
shipmentData["ruleset_name"] = Fixtures.LumaRulesetName;
24+
shipmentData["planned_ship_date"] = Fixtures.LumaPlannedShipDate;
25+
26+
LumaInfo response = await Client.Luma.GetPromise(shipmentData);
27+
28+
Assert.NotNull(response.LumaSelectedRate);
29+
}
30+
}
31+
}

EasyPost.Tests/ServicesTests/ShipmentServiceTest.cs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,41 @@ public async Task TestRecommendShipDateForShipment()
565565
}
566566
}
567567

568+
[Fact]
569+
[Testing.Function]
570+
public async Task TestCreateAndBuyLuma()
571+
{
572+
UseVCR("create_and_buy_luma");
573+
574+
Dictionary<string, object> shipmentData = Fixtures.OneCallBuyShipment;
575+
shipmentData.Remove("service");
576+
shipmentData["ruleset_name"] = Fixtures.LumaRulesetName;
577+
shipmentData["planned_ship_date"] = Fixtures.LumaPlannedShipDate;
578+
579+
Shipment shipment = await Client.Shipment.CreateAndBuyLuma(shipmentData);
580+
581+
Assert.NotNull(shipment.PostageLabel);
582+
}
583+
584+
[Fact]
585+
[Testing.Function]
586+
public async Task TestBuyLuma()
587+
{
588+
UseVCR("buy_luma");
589+
590+
Shipment shipment = await Client.Shipment.Create(Fixtures.BasicShipment);
591+
592+
Dictionary<string, object> parameters = new()
593+
{
594+
{ "ruleset_name", Fixtures.LumaRulesetName },
595+
{ "planned_ship_date", Fixtures.LumaPlannedShipDate }
596+
};
597+
598+
Shipment boughtShipment = await Client.Shipment.BuyLuma(shipment.Id, parameters);
599+
600+
Assert.NotNull(boughtShipment.PostageLabel);
601+
}
602+
568603
#endregion
569604

570605
#endregion
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
using System.Collections.Generic;
2+
using System.Threading.Tasks;
3+
using EasyPost.Models.API;
4+
using EasyPost.Tests._Utilities;
5+
using EasyPost.Tests._Utilities.Attributes;
6+
using Xunit;
7+
8+
namespace EasyPost.Tests.ServicesTests.WithParameters
9+
{
10+
public class LumaServiceTests : UnitTest
11+
{
12+
public LumaServiceTests() : base("luma_service_with_parameters")
13+
{
14+
}
15+
16+
#region Tests
17+
18+
#region Test CRUD Operations
19+
20+
[Fact]
21+
[Testing.Function]
22+
public async Task TestGetPromise()
23+
{
24+
UseVCR("get_promise");
25+
26+
Dictionary<string, object> shipmentData = Fixtures.BasicShipment;
27+
Parameters.Luma.GetPromise parameters = Fixtures.Parameters.Luma.GetPromise(shipmentData);
28+
29+
LumaInfo response = await Client.Luma.GetPromise(parameters);
30+
31+
Assert.NotNull(response.LumaSelectedRate);
32+
}
33+
34+
#endregion
35+
36+
#endregion
37+
}
38+
}

EasyPost.Tests/ServicesTests/WithParameters/ShipmentServiceTest.cs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,39 @@ public async Task TestEstimatedDeliveryDates()
326326
}
327327
}
328328

329+
[Fact]
330+
[Testing.Function]
331+
public async Task TestCreateAndBuyLuma()
332+
{
333+
UseVCR("create_and_buy_luma");
334+
335+
Dictionary<string, object> shipmentData = Fixtures.OneCallBuyShipment;
336+
Parameters.Luma.CreateAndBuy parameters = Fixtures.Parameters.Luma.CreateAndBuy(shipmentData);
337+
Shipment shipment = await Client.Shipment.CreateAndBuyLuma(parameters);
338+
339+
Assert.NotNull(shipment.PostageLabel);
340+
}
341+
342+
[Fact]
343+
[Testing.Function]
344+
public async Task TestBuyLuma()
345+
{
346+
UseVCR("buy_luma");
347+
348+
Parameters.Shipment.Create shipmentParameters = Fixtures.Parameters.Shipments.Create(Fixtures.BasicShipment);
349+
Shipment shipment = await Client.Shipment.Create(shipmentParameters);
350+
351+
Parameters.Luma.Buy buyParameters = new()
352+
{
353+
RulesetName = Fixtures.LumaRulesetName,
354+
PlannedShipDate = Fixtures.LumaPlannedShipDate,
355+
};
356+
357+
Shipment boughtShipment = await Client.Shipment.BuyLuma(shipment.Id, buyParameters);
358+
359+
Assert.NotNull(boughtShipment.PostageLabel);
360+
}
361+
329362
#endregion
330363

331364
#endregion

EasyPost.Tests/cassettes/net/luma_service/get_promise.json

Lines changed: 51 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)