Skip to content

Commit

Permalink
fix(otp-resend): otp resend requires content type to be form data (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
sudkumar authored Mar 23, 2021
1 parent bdfb048 commit bbffa00
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
3 changes: 3 additions & 0 deletions src/OTP/ResendRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@

use Craftsys\Msg91\Support\Request;
use Craftsys\Msg91\URLs;
use GuzzleHttp\RequestOptions;

class ResendRequest extends Request
{
protected $url = URLs::OTP_RESEND_URL;

protected $content_type = RequestOptions::FORM_PARAMS;
}
12 changes: 7 additions & 5 deletions tests/OTP/OTPServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class OTPServiceTest extends TestCase
"key" => "12345678901234567890"
];

protected $phone_number = 919999999999;

protected $container = [];

protected function setUp(): void
Expand Down Expand Up @@ -46,7 +48,7 @@ protected function createMockHttpClient(

public function test_otp_send()
{
$phone_number = 919999999999;
$phone_number = $this->phone_number;
$response = (new Client($this->config, $this->createMockHttpClient()))
->otp()
->from("SMSIND")
Expand All @@ -70,7 +72,7 @@ public function test_otp_send()

public function test_verify_otp()
{
$phone_number = 919999999999;
$phone_number = $this->phone_number;
$otp = 1234;
$response = (new Client($this->config, $this->createMockHttpClient()))
->otp($otp)
Expand All @@ -95,7 +97,7 @@ public function test_verify_otp()

public function test_otp_resend()
{
$phone_number = 919999999999;
$phone_number = $this->phone_number;
$response = (new Client($this->config, $this->createMockHttpClient()))
->otp()
->to($phone_number)
Expand All @@ -109,7 +111,7 @@ public function test_otp_resend()
// check the method
$this->assertEquals("POST", $transaction['request']->getMethod());
// check the request data
$data = (array) json_decode($transaction['request']->getBody()->getContents());
parse_str($transaction['request']->getBody()->getContents(), $data);
$this->assertArrayHasKey('mobile', $data);
$this->assertEquals($phone_number, $data['mobile']);
$this->assertArrayHasKey('authkey', $data);
Expand All @@ -120,7 +122,7 @@ public function test_otp_resend()

public function test_api_key_required()
{
$phone_number = 919999999999;
$phone_number = $this->phone_number;
$this->expectException(ValidationException::class);
(new Client([], $this->createMockHttpClient()))
->otp()
Expand Down

0 comments on commit bbffa00

Please sign in to comment.