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

chore: use new webhook fixtures #583

Merged
merged 4 commits into from
Aug 16, 2024
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 0 additions & 2 deletions EasyPost.Tests/EasyPost.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,5 @@

<ItemGroup>
<Folder Include="cassettes" />
<Folder Include="cassettes\netstandard\smartrate_service_with_parameters\" />
<Folder Include="cassettes\net\smartrate_service_with_parameters\" />
</ItemGroup>
</Project>
14 changes: 9 additions & 5 deletions EasyPost.Tests/Fixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ public static byte[] EventBody
}
}

internal static string WebhookHmacSignature => GetFixtureStructure().WebhookHmacSignature;

internal static string WebhookSecret => GetFixtureStructure().WebhookSecret;

internal static string WebhookUrl => GetFixtureStructure().WebhookUrl;

internal static Dictionary<string, object> BasicCarrierAccount => GetFixtureStructure().CarrierAccounts.Basic;

internal static Dictionary<string, object> BasicCustomsInfo => GetFixtureStructure().CustomsInfos.Basic;
Expand All @@ -56,7 +62,7 @@ internal static Dictionary<string, object> BasicPickup
{
Dictionary<string, object> fixture = GetFixtureStructure().Pickups.Basic;

const string pickupDate = "2024-04-08";
const string pickupDate = "2024-08-21";

fixture!.AddOrUpdate(pickupDate, "min_datetime");
fixture!.AddOrUpdate(pickupDate, "max_datetime");
Expand Down Expand Up @@ -91,9 +97,9 @@ internal static Dictionary<string, object> BasicPickup

internal static string PickupService => GetFixtureStructure().ServiceNames.Usps.PickupService;

internal static string PlannedShipDate => "2024-07-17";
internal static string PlannedShipDate => "2024-08-23";

internal static string DesiredDeliveryDate => "2024-07-17";
internal static string DesiredDeliveryDate => "2024-08-23";

internal static Dictionary<string, object> ReferralCustomer => GetFixtureStructure().Users.Referral;

Expand Down Expand Up @@ -122,8 +128,6 @@ internal static string UspsCarrierAccountId

internal static string UspsService => GetFixtureStructure().ServiceNames.Usps.FirstService;

internal static string WebhookUrl => GetFixtureStructure().WebhookUrl;

private static FixtureStructure GetFixtureStructure()
{
string fixtureData = ReadFixtureData();
Expand Down
6 changes: 6 additions & 0 deletions EasyPost.Tests/FixtureData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ public class FixtureStructure
[JsonProperty("users")]
public Users Users { get; set; }

[JsonProperty("webhook_hmac_signature")]
public string WebhookHmacSignature { get; set; }

[JsonProperty("webhook_secret")]
public string WebhookSecret { get; set; }

[JsonProperty("webhook_url")]
public string WebhookUrl { get; set; }

Expand Down
9 changes: 5 additions & 4 deletions EasyPost.Tests/ServicesTests/WebhookServiceTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,15 @@ public void TestValidateWebHook()
UseVCR("validate_webhook");

byte[] eventData = Fixtures.EventBody;
string webhookHmacSignature = Fixtures.WebhookHmacSignature;
string webhookSecret = Fixtures.WebhookSecret;

// ReSharper disable once StringLiteralTypo
const string webhookSecret = "sécret";
Dictionary<string, object?> headers = new() { { "X-Hmac-Signature", "hmac-sha256-hex=e93977c8ccb20363d51a62b3fe1fc402b7829be1152da9e88cf9e8d07115a46b" } };
Dictionary<string, object?> headers = new() { { "X-Hmac-Signature", webhookHmacSignature } };

Event @event = Client.Webhook.ValidateWebhook(eventData, headers, webhookSecret);

Assert.Equal("batch.created", @event.Description);
Assert.Equal("tracker.updated", @event.Description);
Assert.Equal(614.4, @event.Result["weight"]); // Ensure we convert floats properly
}

[Fact]
Expand Down
19 changes: 10 additions & 9 deletions EasyPost.Tests/cassettes/net/address_service/all.json

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

19 changes: 10 additions & 9 deletions EasyPost.Tests/cassettes/net/address_service/create.json

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

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

Loading
Loading