22namespace Yabacon \Paystack \Tests \Http ;
33
44use Yabacon \Paystack \Http \Response ;
5+ use Yabacon \Paystack \Exception \ApiException ;
56
67class ResponseTest extends \PHPUnit_Framework_TestCase
78{
@@ -10,4 +11,71 @@ public function testInitialize()
1011 $ r = new Response ();
1112 $ this ->assertNotNull ($ r );
1213 }
14+
15+ public function testWrapUpForApiOkay ()
16+ {
17+ $ r = new Response ();
18+ $ r ->okay = true ;
19+ $ r ->forApi = true ;
20+ $ r ->body = '{"status":"1","data":{"status":"okay"}} ' ;
21+
22+ $ resp = $ r ->wrapUp ();
23+ $ this ->assertEquals ('okay ' , $ resp ->data ->status );
24+ }
25+
26+ public function testWrapUpForApiOkayStatusFalse ()
27+ {
28+ $ r = new Response ();
29+ $ r ->okay = true ;
30+ $ r ->forApi = true ;
31+ $ r ->body = '{"status":"0","message":"I failed on Api","data":{"status":"okay"}} ' ;
32+
33+ $ this ->expectException (ApiException::class);
34+ $ resp = $ r ->wrapUp ();
35+ $ this ->assertEquals ('I failed on Api ' , $ resp ->message );
36+ }
37+
38+ public function testWrapUpForApiOkayBadJSON ()
39+ {
40+ $ r = new Response ();
41+ $ r ->okay = true ;
42+ $ r ->forApi = true ;
43+ $ r ->body = 'API didn \'t give JSON ' ;
44+
45+ $ this ->expectException (ApiException::class);
46+ $ resp = $ r ->wrapUp ();
47+ }
48+
49+ public function testWrapUpForApiNotOkay ()
50+ {
51+ $ r = new Response ();
52+ $ r ->okay = false ;
53+ $ r ->forApi = true ;
54+ $ r ->body = 'I failed before hitting API ' ;
55+
56+ $ this ->expectException (\Exception::class);
57+ $ resp = $ r ->wrapUp ();
58+ }
59+
60+ public function testWrapUpNotForApiOkay ()
61+ {
62+ $ r = new Response ();
63+ $ r ->okay = true ;
64+ $ r ->forApi = false ;
65+ $ r ->body = 'I was not sent to API ' ;
66+
67+ $ resp = $ r ->wrapUp ();
68+ $ this ->assertEquals ('I was not sent to API ' , $ resp );
69+ }
70+
71+ public function testWrapUpNotForApiNotOkay ()
72+ {
73+ $ r = new Response ();
74+ $ r ->okay = false ;
75+ $ r ->forApi = false ;
76+ $ r ->body = 'I was not sent to API but I still failed ' ;
77+
78+ $ resp = $ r ->wrapUp ();
79+ $ this ->assertFalse ($ resp );
80+ }
1381}
0 commit comments