Skip to content

Commit

Permalink
Better handle required values in APNs models
Browse files Browse the repository at this point in the history
  • Loading branch information
mburumaxwell committed Oct 2, 2023
1 parent f618864 commit cb858ee
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,7 @@ namespace Tingle.Extensions.PushNotifications.Apple.Models;

/// <summary>
/// Represents the data actually sent to the device.
/// If you need to send more information, inherit from this class.
/// If you need to send more information, inherit from this type.
/// </summary>
public class ApnsMessageData
{
/// <summary>
/// The payload for the push as specified by Apple
/// </summary>
[JsonPropertyName("aps")]
public ApnsMessagePayload Aps { get; set; } = new ApnsMessagePayload { };
}
/// <param name="Aps">The payload for the push as specified by Apple </param>
public record ApnsMessageData([property: JsonPropertyName("aps")] ApnsMessagePayload Aps);
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,5 @@ public sealed class ApnsMessageHeader
/// <summary>
/// The token for the device to send the message to
/// </summary>
public string? DeviceToken { get; set; }
public required string DeviceToken { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace Tingle.Extensions.PushNotifications.Apple.Models;
/// <summary>
/// Represents a payload for a push notification as specified by Apple
/// </summary>
public class ApnsMessagePayload
public record ApnsMessagePayload
{
/// <summary>
/// Set a value when you want the system to display a standard alert or a banner.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public async Task Authentication_IsPopulated()
cache.Set("apns:tokens:cake:cake", "cake-token");
var client = sp.GetRequiredService<ApnsNotifier>();

var rr = await client.SendAsync(new ApnsMessageHeader { DeviceToken = "cake" }, new ApnsMessageData { });
var rr = await client.SendAsync(new ApnsMessageHeader { DeviceToken = "cake" }, new ApnsMessageData(new ApnsMessagePayload { }));
Assert.Equal("bearer cake-token", header);
}

Expand Down Expand Up @@ -112,17 +112,11 @@ public async Task Works()

var header = new ApnsMessageHeader
{
DeviceToken = configuration.GetValue<string>("ApnsTest:DeviceToken"),
DeviceToken = configuration.GetValue<string>("ApnsTest:DeviceToken")!,
Environment = configuration.GetValue<ApnsEnvironment?>("ApnsTest:Environment") ?? ApnsEnvironment.Development,
PushType = ApnsPushType.Background,
};
var data = new ApnsMessageData
{
Aps = new ApnsMessagePayload
{
ContentAvailable = 1
},
};
var data = new ApnsMessageData(new ApnsMessagePayload { ContentAvailable = 1, });

var resp = await client.SendAsync(header, data, default);
resp.EnsureSuccess();
Expand Down

0 comments on commit cb858ee

Please sign in to comment.