Browse code

added appinfo/info.xml appinfo/signature.json CHANGELOG.txt lib/AppInfo/Application.php css/style.css providers/Plivo

DoubleBastionAdmin authored on 05/11/2025 13:35:09
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,163 @@
1
+<?php
2
+
3
+namespace Plivo\Tests\Resources;
4
+
5
+use Plivo\Http\PlivoRequest;
6
+use Plivo\Http\PlivoResponse;
7
+use Plivo\Tests\BaseTestCase;
8
+
9
+
10
+/**
11
+ * Class VerifySessionTest
12
+ * @package Plivo\Tests\Resources
13
+ */
14
+class VerifySessionTest extends BaseTestCase {
15
+
16
+
17
+    public function testVerifySessionCreate()
18
+    {
19
+        $request = new PlivoRequest(
20
+            'POST',
21
+            'Account/MAXXXXXXXXXXXXXXXXXX/Verify/Session/',
22
+            [
23
+                "recipient" => "+919999999999"
24
+            ]);
25
+        $body = file_get_contents(__DIR__ . '/../Mocks/verifySessionCreateResponse.json');
26
+
27
+        $this->mock(new PlivoResponse($request,202, $body));
28
+        $actual = $this->client->verifySessions->create("+919999999999");
29
+        self::assertNotNull($actual);
30
+    }
31
+
32
+    public function testVerifySessionCreateWithRecipientException()
33
+    {
34
+        $this->expectPlivoException('Plivo\Exceptions\PlivoValidationException');
35
+
36
+        $request = new PlivoRequest(
37
+            'POST',
38
+            'Account/MAXXXXXXXXXXXXXXXXXX/Verify/Session/',
39
+            [
40
+                "recipient" => "+919999999999"
41
+            ]);
42
+        $body = file_get_contents(__DIR__ . '/../Mocks/verifySessionCreateResponse.json');
43
+
44
+        $this->mock(new PlivoResponse($request,202, $body));
45
+        $actual = $this->client->verifySessions->create("");
46
+
47
+    }
48
+
49
+    public function testVerifySessionValidateWithSessionUUIDException()
50
+    {
51
+        $this->expectPlivoException('Plivo\Exceptions\PlivoValidationException');
52
+
53
+        $sessionUuid = "5b40a428-bfc7-4daf-9d06-726c558bf3b8";
54
+        $otp = "999999";
55
+        $request = new PlivoRequest(
56
+            'POST',
57
+            'Account/MAXXXXXXXXXXXXXXXXXX/Verify/Session/'.$sessionUuid.'/',
58
+            [
59
+                "otp" => "999999"
60
+            ]);
61
+        $body = file_get_contents(__DIR__ . '/../Mocks/verifySessionValidateResponse.json');
62
+
63
+        $this->mock(new PlivoResponse($request,200, $body));
64
+        $actual = $this->client->verifySessions->validate("", $otp);
65
+
66
+    }
67
+
68
+    public function testVerifySessionValidateWithOTPException()
69
+    {
70
+        $this->expectPlivoException('Plivo\Exceptions\PlivoValidationException');
71
+
72
+        $sessionUuid = "5b40a428-bfc7-4daf-9d06-726c558bf3b8";
73
+        $otp = "999999";
74
+        $request = new PlivoRequest(
75
+            'POST',
76
+            'Account/MAXXXXXXXXXXXXXXXXXX/Verify/Session/'.$sessionUuid.'/',
77
+            [
78
+                "otp" => "999999"
79
+            ]);
80
+        $body = file_get_contents(__DIR__ . '/../Mocks/verifySessionValidateResponse.json');
81
+
82
+        $this->mock(new PlivoResponse($request,200, $body));
83
+        $actual = $this->client->verifySessions->validate($sessionUuid, "");
84
+
85
+    }
86
+
87
+
88
+
89
+    public function testVerifySessionValidate()
90
+    {
91
+        $sessionUuid = "5b40a428-bfc7-4daf-9d06-726c558bf3b8";
92
+        $otp = "999999";
93
+        $request = new PlivoRequest(
94
+            'POST',
95
+            'Account/MAXXXXXXXXXXXXXXXXXX/Verify/Session/'.$sessionUuid.'/',
96
+            [
97
+                "otp" => "999999"
98
+            ]);
99
+        $body = file_get_contents(__DIR__ . '/../Mocks/verifySessionValidateResponse.json');
100
+
101
+        $this->mock(new PlivoResponse($request,200, $body));
102
+
103
+        $actual = $this->client->verifySessions->validate($sessionUuid, $otp);
104
+        self::assertNotNull($actual);
105
+        self::assertEquals($actual->message, "session validated successfully.");
106
+
107
+    }
108
+
109
+    public function testVerifySessionGet()
110
+    {
111
+        $sessionUuid = "4124e518-a8c9-4feb-8cff-d86636ba9234";
112
+        $requesterIP = "172.167.8.2";
113
+        $request = new PlivoRequest(
114
+            'GET',
115
+            'Account/MAXXXXXXXXXXXXXXXXXX/Verify/Session/'.$sessionUuid.'/',
116
+            []);
117
+        $body = file_get_contents(__DIR__ . '/../Mocks/verifySessionGetResponse.json');
118
+
119
+        $this->mock(new PlivoResponse($request,200, $body));
120
+
121
+        $actual = $this->client->verifySessions->get($sessionUuid);
122
+        $this->assertRequest($request);
123
+        self::assertNotNull($actual);
124
+        self::assertEquals($actual->sessionUuid, $sessionUuid);
125
+        self::assertEquals($actual->requesterIP, $requesterIP);
126
+    }
127
+
128
+    public function testVerifySessionGetSessionUUIDException()
129
+    {
130
+        $this->expectPlivoException('Plivo\Exceptions\PlivoValidationException');
131
+
132
+        $sessionUuid = "4124e518-a8c9-4feb-8cff-d86636ba9234";
133
+        $request = new PlivoRequest(
134
+            'GET',
135
+            'Account/MAXXXXXXXXXXXXXXXXXX/Verify/Session/'.$sessionUuid.'/',
136
+            []);
137
+        $body = file_get_contents(__DIR__ . '/../Mocks/verifySessionGetResponse.json');
138
+
139
+        $this->mock(new PlivoResponse($request,200, $body));
140
+        $this->client->verifySessions->get("");
141
+        
142
+    }
143
+
144
+    function testVerifySessionList()
145
+    {
146
+        $requesterIP1 = "110.226.182.196";
147
+        $requesterIP2 = "110.226.182.196";
148
+        $request = new PlivoRequest(
149
+            'Get',
150
+            'Account/MAXXXXXXXXXXXXXXXXXX/Verify/Session/',
151
+            []);
152
+        $body = file_get_contents(__DIR__ . '/../Mocks/verifySessionListResponse.json');
153
+        
154
+        $this->mock(new PlivoResponse($request,200, $body));
155
+        
156
+        $actual = $this->client->verifySessions->list();
157
+        $this->assertRequest($request);
158
+        self::assertNotNull($actual);
159
+        self::assertEquals($actual->resources[0]->requesterIP, $requesterIP1);
160
+        self::assertEquals($actual->resources[3]->requesterIP, $requesterIP2);
161
+    }
162
+
163
+}
0 164
\ No newline at end of file