Skip to content

Commit

Permalink
Fix/verification/start sms empty options (#84)
Browse files Browse the repository at this point in the history
* chore: don't pass sms options object if no field is set
  • Loading branch information
Dovchik authored Oct 22, 2024
1 parent 49d53ac commit e8646c7
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 11 deletions.
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

0 comments on commit e8646c7

Please sign in to comment.