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

Fix/verification/start sms empty options #84

Merged
merged 5 commits into from
Oct 22, 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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions src/Sinch/Verification/SinchVerification.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,18 +158,23 @@ public async Task<StartSmsVerificationResponse> StartSms(StartSmsVerificationReq
};
}

SmsOptions? options = null;
if (request.CodeType != null || request.Expiry != null || request.Template != null)
{
options = new SmsOptions()
{
CodeType = request.CodeType,
Expiry = request.Expiry,
Template = request.Template
};
}
var result = await Start(new StartVerificationRequest
{
Custom = request.Custom,
Identity = request.Identity,
Method = request.Method,
Reference = request.Reference,
SmsOptions = new SmsOptions()
{
CodeType = request.CodeType,
Expiry = request.Expiry,
Template = request.Template
}
SmsOptions = options
}, cancellationToken, headers: headers);
return result as StartSmsVerificationResponse ??
throw new InvalidOperationException($"{nameof(StartSmsVerificationResponse)} result is null.");
Expand Down
37 changes: 32 additions & 5 deletions tests/Sinch.Tests/e2e/Verification/VerificationStartTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,7 @@ public async Task StartSmsVerification()
Custom = "456",
Reference = "123",
Method = VerificationMethodEx.Sms,
Identity = new Identity
{
Endpoint = "+49000000",
Type = IdentityType.Number
}
Identity = Identity.Number("+49000000")
};

var response = await VerificationClient.Verification.StartSms(new StartSmsVerificationRequest
Expand Down Expand Up @@ -118,6 +114,37 @@ public async Task StartSmsVerification()
});
}

[Fact]
public async Task StartSmsVerificationNoOptions()
{
var response = await VerificationClient.Verification.StartSms(new StartSmsVerificationRequest
{
Custom = "456",
Reference = "123",
Identity = Identity.Number("+49000000"),
AcceptLanguage = "en-US"
});
response.Should().BeEquivalentTo(new StartSmsVerificationResponse
{
Id = "123",
Method = VerificationMethodEx.Sms,
Sms = new SmsInfo
{
Template = "{{CODE}} - to access all secrets",
InterceptionTimeout = 32
},
Links = new List<Links>
{
new()
{
Method = "put",
Href = "href",
Rel = "status"
}
}
});
}

[Fact]
public async Task StartFlashCallVerification()
{
Expand Down
Loading