Skip to content

Commit adc134d

Browse files
committed
test(ZohoCliq): enhance client retry logic tests
- Increase mock response array size from 2 to 10 to allow more retry attempts - Add multiple test cases to verify client behavior with different retry scenarios and HTTP status codes - Confirm that client correctly handles retries on 401 and 400 errors before succeeding or failing - Ensure UserMessage instances include emailId for accurate testing - Improve clarity and coverage of retry logic in ZohoCliq client tests Signed-off-by: guanguans <[email protected]>
1 parent 4eedaec commit adc134d

File tree

1 file changed

+37
-4
lines changed

1 file changed

+37
-4
lines changed

tests/ZohoCliq/ClientTest.php

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
cache: new NullCache,
4141
client: (new \Guanguans\Notify\Foundation\Client)->mock(array_pad(
4242
[],
43-
2,
43+
6,
4444
response(
4545
<<<'JSON'
4646
{
@@ -165,14 +165,47 @@
165165

166166
it('can retry send user message', function (): void {
167167
/** @var \Guanguans\Notify\Foundation\Response $response */
168+
$message = UserMessage::make($this->message)->emailId(fake()->email());
168169
$response = $this
169170
->client
170171
->mock([
171-
response('{"code":"oauthtoken_invalid","message":"Invalid OAuth token passed."}', 401),
172+
response('retries0', 401),
173+
response('retries1', 401),
174+
response('retries2', 401),
172175
response(status: 204),
173-
])
174-
->send(UserMessage::make($this->message)->emailId(fake()->email()));
176+
])->send($message);
177+
expect($response)
178+
->body()->toBe('retries1')
179+
->status()->toBe(401);
180+
181+
$response = $this
182+
->client
183+
->mock([
184+
response('retries0', 400),
185+
response('retries1', 401),
186+
response(status: 204),
187+
])->send($message);
188+
expect($response)
189+
->body()->toBe('retries0')
190+
->status()->toBe(400);
191+
192+
$response = $this
193+
->client
194+
->mock([
195+
response('retries0', 200),
196+
response('retries1', 401),
197+
response(status: 204),
198+
])->send($message);
199+
expect($response)
200+
->body()->toBe('retries0')
201+
->status()->toBe(200);
175202

203+
$response = $this
204+
->client
205+
->mock([
206+
response('retries0', 401),
207+
response(status: 204),
208+
])->send($message);
176209
expect($response)
177210
->body()->toBeEmpty()
178211
->status()->toBe(204);

0 commit comments

Comments
 (0)