Skip to content

Commit

Permalink
fix: add missing ClientRef property on SmsResponseMesage
Browse files Browse the repository at this point in the history
  • Loading branch information
Tr00d committed May 7, 2024
1 parent 1252147 commit 3051a53
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 75 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"remaining-balance": "3.14159265",
"message-price": "0.03330000",
"network": "12345",
"account-ref": "customer1234"
"account-ref": "customer1234",
"client-ref": "my-personal-reference"
}
]
}
74 changes: 16 additions & 58 deletions Vonage.Test/MessagingTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Collections.Generic;
using System.Net;
using System.Threading.Tasks;
using FluentAssertions;
using Newtonsoft.Json;
using Vonage.Cryptography;
using Vonage.Messaging;
Expand Down Expand Up @@ -28,7 +29,7 @@ public async Task NullMessagesResponse()
Assert.NotNull(exception);
Assert.Equal("Encountered an Empty SMS response", exception.Message);
}

[Fact]
public async Task SendSmsAsyncBadResponse()
{
Expand All @@ -47,7 +48,7 @@ await client.SmsClient.SendAnSmsAsync(new SendSmsRequest
exception.Message);
Assert.Equal(SmsStatusCode.InvalidCredentials, exception.Response.Messages[0].StatusCode);
}

[Theory]
[InlineData(false)]
[InlineData(true)]
Expand Down Expand Up @@ -90,8 +91,9 @@ public async Task SendSmsAsyncWithAllPropertiesSet(bool passCreds)
Assert.Equal("3.14159265", response.Messages[0].RemainingBalance);
Assert.Equal("12345", response.Messages[0].Network);
Assert.Equal("customer1234", response.Messages[0].AccountRef);
response.Messages[0].ClientRef.Should().Be("my-personal-reference");
}

[Fact]
public async Task SendSmsTypicalUsage()
{
Expand Down Expand Up @@ -125,7 +127,7 @@ public async Task SendSmsTypicalUsage()
Assert.Equal("12345", response.Messages[0].Network);
Assert.Equal("customer1234", response.Messages[0].AccountRef);
}

[Fact]
public async Task SendSmsTypicalUsageSimplifiedAsync()
{
Expand All @@ -145,7 +147,7 @@ public async Task SendSmsTypicalUsageSimplifiedAsync()
Assert.Equal("12345", response.Messages[0].Network);
Assert.Equal("customer1234", response.Messages[0].AccountRef);
}

[Fact]
public async Task SendSmsUnicode()
{
Expand Down Expand Up @@ -179,51 +181,7 @@ public async Task SendSmsUnicode()
Assert.Equal("12345", response.Messages[0].Network);
Assert.Equal("customer1234", response.Messages[0].AccountRef);
}

[Theory]
[InlineData(false)]
[InlineData(true)]
public async Task SendSmsWithAllPropertiesSet(bool passCreds)
{
var expectedResponse = this.GetResponseJson();
var expectedUri = $"{this.RestUrl}/sms/json";
var expectedRequestContent = $"from=AcmeInc&to=447700900000&text={WebUtility.UrlEncode("Hello World!")}" +
$"&ttl=900000&status-report-req=true&callback={WebUtility.UrlEncode("https://example.com/sms-dlr")}&message-class=0" +
"&type=text&body=638265253311&udh=06050415811581&protocol-id=127" +
$"&client-ref=my-personal-reference&account-ref=customer1234&entity-id=testEntity&content-id=testcontent&api_key={this.ApiKey}&api_secret={this.ApiSecret}&";
var request = new SendSmsRequest
{
AccountRef = "customer1234",
Body = "638265253311",
Callback = "https://example.com/sms-dlr",
ClientRef = "my-personal-reference",
From = "AcmeInc",
To = "447700900000",
MessageClass = 0,
ProtocolId = 127,
StatusReportReq = true,
Text = "Hello World!",
Ttl = 900000,
Type = SmsType.Text,
Udh = "06050415811581",
ContentId = "testcontent",
EntityId = "testEntity",
};
var creds = Credentials.FromApiKeyAndSecret(this.ApiKey, this.ApiSecret);
this.Setup(expectedUri, expectedResponse, expectedRequestContent);
var client = this.BuildVonageClient(creds);
var response = passCreds
? await client.SmsClient.SendAnSmsAsync(request, creds)
: await client.SmsClient.SendAnSmsAsync(request);
Assert.Equal("1", response.MessageCount);
Assert.Equal("447700900000", response.Messages[0].To);
Assert.Equal("0A0000000123ABCD1", response.Messages[0].MessageId);
Assert.Equal("0", response.Messages[0].Status);
Assert.Equal("3.14159265", response.Messages[0].RemainingBalance);
Assert.Equal("12345", response.Messages[0].Network);
Assert.Equal("customer1234", response.Messages[0].AccountRef);
}


[Fact]
public void TestDlrStruct()
{
Expand Down Expand Up @@ -259,7 +217,7 @@ public void TestDlrStruct()
Assert.Equal("1A20E4E2069B609FDA6CECA9DE18D5CAFE99720DDB628BD6BE8B19942A336E1C", dlr.Sig);
Assert.Equal("steve", dlr.ClientRef);
}

[Fact]
public void TestDlrStructCamelCaseIgnore()
{
Expand Down Expand Up @@ -296,7 +254,7 @@ public void TestDlrStructCamelCaseIgnore()
Assert.Equal("1A20E4E2069B609FDA6CECA9DE18D5CAFE99720DDB628BD6BE8B19942A336E1C", dlr.Sig);
Assert.Equal("steve", dlr.ClientRef);
}

[Fact]
public void TestDlrStructNoStatus()
{
Expand Down Expand Up @@ -331,7 +289,7 @@ public void TestDlrStructNoStatus()
Assert.Equal("1A20E4E2069B609FDA6CECA9DE18D5CAFE99720DDB628BD6BE8B19942A336E1C", dlr.Sig);
Assert.Equal("steve", dlr.ClientRef);
}

[Fact]
public void TestInboundSmsStruct()
{
Expand Down Expand Up @@ -371,7 +329,7 @@ public void TestInboundSmsStruct()
Assert.Equal("abc123", inboundSms.Data);
Assert.Equal("abc123", inboundSms.Udh);
}

[Fact]
public void TestValidateSignatureMd5()
{
Expand All @@ -397,7 +355,7 @@ public void TestValidateSignatureMd5()
SmsSignatureGenerator.Method.md5);
Assert.True(inboundSmsShell.ValidateSignature(TestSigningSecret, SmsSignatureGenerator.Method.md5));
}

[Fact]
public void TestValidateSignatureMd5Hash()
{
Expand All @@ -423,7 +381,7 @@ public void TestValidateSignatureMd5Hash()
SmsSignatureGenerator.Method.md5hash);
Assert.True(inboundSmsShell.ValidateSignature(TestSigningSecret, SmsSignatureGenerator.Method.md5hash));
}

[Fact]
public void TestValidateSignatureSha1()
{
Expand All @@ -449,7 +407,7 @@ public void TestValidateSignatureSha1()
SmsSignatureGenerator.Method.sha1);
Assert.True(inboundSmsShell.ValidateSignature(TestSigningSecret, SmsSignatureGenerator.Method.sha1));
}

[Fact]
public void TestValidateSignatureSha256()
{
Expand All @@ -475,7 +433,7 @@ public void TestValidateSignatureSha256()
SmsSignatureGenerator.Method.sha256);
Assert.True(inboundSmsShell.ValidateSignature(TestSigningSecret, SmsSignatureGenerator.Method.sha256));
}

[Fact]
public void TestValidateSignatureSha512()
{
Expand Down
39 changes: 23 additions & 16 deletions Vonage/Messaging/SmsResponseMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,51 +5,58 @@ namespace Vonage.Messaging;
public class SmsResponseMessage
{
/// <summary>
/// If a client-ref was included when sending the SMS, this field will be included and hold the value that was sent.
/// An optional string used to identify separate accounts using the SMS endpoint for billing purposes. To use this
/// feature, please email support
/// </summary>
[JsonProperty("account-ref")]
public string AccountRef { get; set; }


/// <summary>
/// If a client-ref was included when sending the SMS, this field will be included and hold the value that was sent.
/// </summary>
[JsonProperty("client-ref")]
public string ClientRef { get; set; }

/// <summary>
/// The status of the message. See Troubleshooting Failed SMS.
/// The status of the message. See Troubleshooting Failed SMS.
/// </summary>
[JsonProperty("error-text")]
public string ErrorText { get; set; }

/// <summary>
/// The ID of the message
/// The ID of the message
/// </summary>
[JsonProperty("message-id")]
public string MessageId { get; set; }

/// <summary>
/// The cost of the message
/// The cost of the message
/// </summary>
[JsonProperty("message-price")]
public string MessagePrice { get; set; }

/// <summary>
/// The ID of the network of the recipient
/// The ID of the network of the recipient
/// </summary>
[JsonProperty("network")]
public string Network { get; set; }

/// <summary>
/// Your remaining balance
/// Your remaining balance
/// </summary>
[JsonProperty("remaining-balance")]
public string RemainingBalance { get; set; }

/// <summary>
/// The status of the message. See: https://developer.nexmo.com/messaging/sms/guides/troubleshooting-sms
/// The status of the message. See: https://developer.nexmo.com/messaging/sms/guides/troubleshooting-sms
/// </summary>
[JsonProperty("status")]
public string Status { get; set; }

[JsonIgnore] public SmsStatusCode StatusCode => (SmsStatusCode) int.Parse(this.Status);

/// <summary>
/// The number the message was sent to. Numbers are specified in E.164 format.
/// The number the message was sent to. Numbers are specified in E.164 format.
/// </summary>
[JsonProperty("to")]
public string To { get; set; }
Expand Down

0 comments on commit 3051a53

Please sign in to comment.