Skip to content

Commit

Permalink
Make CartUpdatedPayload.Note nullable
Browse files Browse the repository at this point in the history
  • Loading branch information
nozzlegear committed Jan 5, 2024
1 parent 9d7be06 commit db6b29a
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 1 deletion.
4 changes: 4 additions & 0 deletions ShopifySharp.Tests/ShopifySharp.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,9 @@
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<DependentUpon>CartUpdatedPayloadTests.cs</DependentUpon>
</Content>
<Content Include="WebhookPayloads\cart_updated_payload_with_null_note.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<DependentUpon>CartUpdatedPayloadTests.cs</DependentUpon>
</Content>
</ItemGroup>
</Project>
18 changes: 18 additions & 0 deletions ShopifySharp.Tests/WebhookPayloads/CartUpdatedPayloadTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public class CartUpdatedPayloadTests
{
private const string JsonFilePath = "./WebhookPayloads/cart_updated_payload.json";
private const string JsonWithPropertiesFilePath = "./WebhookPayloads/cart_updated_payload_with_properties.json";
private const string JsonWithNullNoteFilePath = "./WebhookPayloads/cart_updated_payload_with_null_note.json";

[Fact]
public async Task ShouldDeserializeACartWebhookUpdatedRequest()
Expand All @@ -38,6 +39,23 @@ public async Task ShouldDeserializeACartWebhookUpdatedRequest()
subject.LineItems.Should().NotBeNullOrEmpty();
}

[Fact]
public async Task ShouldDeserializeACartWebhookUpdatedRequest_WithNullNote()
{
// Setup
var json = await ReadJsonFile(JsonWithNullNoteFilePath);

// Act
var act = () => Infrastructure.Serializer.Deserialize<CartUpdatedPayload>(json);

// Test
act.Should().NotThrow();

var subject = act.Should().NotThrow().Subject;

subject.Note.Should().BeNull();
}

[Fact]
public async Task ShouldDeserializeACartWebhookPayload_WithLineItems()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
{
"id": "c1-f880804cdbfc39c683dc9fad79ab940a",
"token": "c1-f880804cdbfc39c683dc9fad79ab940a",
"line_items": [
{
"id": 44901482856738,
"properties": null,
"quantity": 3,
"variant_id": 44901482856738,
"key": "44901482856738:f81223baedf50c10666b0a66c7f612b6",
"discounted_price": "749.95",
"discounts": [],
"gift_card": false,
"grams": 0,
"line_price": "2249.85",
"original_line_price": "2249.85",
"original_price": "749.95",
"price": "749.95",
"product_id": 8213868347682,
"sku": "test-sku",
"taxable": true,
"title": "The Collection Snowboard: Liquid",
"total_discount": "0.00",
"vendor": "Hydrogen Vendor",
"discounted_price_set": {
"shop_money": {
"amount": "749.95",
"currency_code": "USD"
},
"presentment_money": {
"amount": "749.95",
"currency_code": "USD"
}
},
"line_price_set": {
"shop_money": {
"amount": "2249.85",
"currency_code": "USD"
},
"presentment_money": {
"amount": "2249.85",
"currency_code": "USD"
}
},
"original_line_price_set": {
"shop_money": {
"amount": "2249.85",
"currency_code": "USD"
},
"presentment_money": {
"amount": "2249.85",
"currency_code": "USD"
}
},
"price_set": {
"shop_money": {
"amount": "749.95",
"currency_code": "USD"
},
"presentment_money": {
"amount": "749.95",
"currency_code": "USD"
}
},
"total_discount_set": {
"shop_money": {
"amount": "0.0",
"currency_code": "USD"
},
"presentment_money": {
"amount": "0.0",
"currency_code": "USD"
}
}
}
],
"note": null,
"updated_at": "2023-12-11T04:44:14.751Z",
"created_at": "2023-12-11T04:40:09.792Z"
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class CartUpdatedPayload
public ICollection<CartUpdatedLineItem> LineItems { get; set; }

[JsonProperty("note")]
public string Note { get; set; }
public string? Note { get; set; }

[JsonProperty("token")]
public string Token { get; set; }
Expand Down

0 comments on commit db6b29a

Please sign in to comment.