Skip to content

Commit

Permalink
fix(sms): fix content type for sms sending apis
Browse files Browse the repository at this point in the history
  • Loading branch information
sudkumar committed Sep 29, 2020
1 parent 8b46208 commit 95b099b
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 12 deletions.
7 changes: 7 additions & 0 deletions src/Contracts/Options.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,11 @@ public function message($message = '');
* @return $this;
*/
public function mergeWith($options = null);

/**
* Set the sender
* @param string|null sender id
* @return $this
*/
public function from($sender_id = null);
}
5 changes: 3 additions & 2 deletions src/Support/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,10 @@ public function handle()
$method = strtolower($this->method);
try {
$resp = $client->{$method}($this->url, [
"form_params" => $payload,
\GuzzleHttp\RequestOptions::JSON => $payload,
"headers" => [
'authkey' => $payload['authkey']
'authkey' => $payload['authkey'],
'content-type' => 'application/json'
]
]);
return new Response($resp);
Expand Down
11 changes: 11 additions & 0 deletions src/Support/Service.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,17 @@ public function to($mobile = null)
return $this;
}

/**
* Set the sender
* @param int|null $sender_id
* @return $this
*/
public function from($sender_id = null)
{
$this->getOptions()->from($sender_id);
return $this;
}

/**
* Set the content of message
* @param string|null $message
Expand Down
11 changes: 4 additions & 7 deletions tests/OTP/OTPServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ public function test_otp_send()
$phone_number = 919999999999;
$response = (new Client($this->config, $this->createMockHttpClient()))
->otp()
->from("SMSIND")
->to($phone_number)
->send();

$this->assertInstanceOf(CraftsysResponse::class, $response);
// make sure there was exacly on request
$this->assertCount(1, $this->container);
Expand All @@ -60,8 +60,7 @@ public function test_otp_send()
// check the method
$this->assertEquals("POST", $transaction['request']->getMethod());
// check the request data
$data = [];
parse_str($transaction['request']->getBody()->getContents(), $data);
$data = (array) json_decode($transaction['request']->getBody()->getContents());
$this->assertArrayHasKey('mobile', $data);
$this->assertEquals($phone_number, $data['mobile']);
$this->assertArrayHasKey('authkey', $data);
Expand All @@ -85,8 +84,7 @@ public function test_verify_otp()
// check the method
$this->assertEquals("POST", $transaction['request']->getMethod());
// check the request data
$data = [];
parse_str($transaction['request']->getBody()->getContents(), $data);
$data = (array) json_decode($transaction['request']->getBody()->getContents());
$this->assertArrayHasKey('mobile', $data);
$this->assertEquals($phone_number, $data['mobile']);
$this->assertArrayHasKey('authkey', $data);
Expand All @@ -111,8 +109,7 @@ public function test_otp_resend()
// check the method
$this->assertEquals("POST", $transaction['request']->getMethod());
// check the request data
$data = [];
parse_str($transaction['request']->getBody()->getContents(), $data);
$data = (array) json_decode($transaction['request']->getBody()->getContents());
$this->assertArrayHasKey('mobile', $data);
$this->assertEquals($phone_number, $data['mobile']);
$this->assertArrayHasKey('authkey', $data);
Expand Down
6 changes: 3 additions & 3 deletions tests/SMS/SMSServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
class SMSServiceTest extends TestCase
{
protected $config = [
"key" => "123123123123"
"key" => "12345678901234567890"
];

protected $container = [];
Expand Down Expand Up @@ -43,14 +43,14 @@ protected function createMockHttpClient(): HttpClient
public function test_sms_send()
{
$phone_number = 919999999999;
$message = "My message";
$response = (new Client($this->config, $this->createMockHttpClient()))
->sms()
->message($message)
->from("SENDER_ID")
->flow("flow_id_here")
->to($phone_number)
->send();


$this->assertInstanceOf(CraftsysResponse::class, $response);
// make sure there was exacly on request
$this->assertCount(1, $this->container);
Expand Down

0 comments on commit 95b099b

Please sign in to comment.