@@ -72,4 +72,54 @@ public function testGetListRaisesServerExceptions()
7272
7373 $ this ->client ->whitelist ->getList ('johndoe ' );
7474 }
75+
76+ public function testCreate ()
77+ {
78+ $ entryData = [
79+ 'ip ' => '1.2.3.4 ' ,
80+ 'type ' => 'waf ' ,
81+ 'description ' => 'Office IP ' ,
82+ ];
83+ $ createdEntry = array_merge ($ entryData , [
84+ 'id ' => 1234 ,
85+ 'created ' => '2026-07-15T12:00:00Z ' ,
86+ 'app ' => 'johndoe ' ,
87+ ]);
88+ $ this ->responses ->append (
89+ new Response (200 , [], json_encode ($ createdEntry )),
90+ );
91+
92+ $ result = $ this ->client ->whitelist ->create ('johndoe ' , $ entryData );
93+
94+ $ request = $ this ->responses ->getLastRequest ();
95+ $ this ->assertEquals ('POST ' , $ request ->getMethod ());
96+ $ this ->assertEquals ('/v2/whitelist/johndoe/ ' , $ request ->getUri ());
97+ $ this ->assertJson ((string )$ request ->getBody ());
98+ $ this ->assertEquals ($ entryData , json_decode ((string )$ request ->getBody (), true ));
99+ $ this ->assertEquals ($ createdEntry , $ result );
100+ }
101+
102+ public function testCreateRaisesClientExceptions ()
103+ {
104+ $ badRequestResponse = new Response (400 , [], json_encode ([
105+ 'non_field_errors ' => ['Your request was invalid. ' ]
106+ ]));
107+ $ this ->responses ->append ($ badRequestResponse );
108+
109+ $ this ->expectExceptionObject (new HypernodeApiClientException ($ badRequestResponse ));
110+
111+ $ this ->client ->whitelist ->create ('johndoe ' , ['ip ' => '1.2.3.4 ' ]);
112+ }
113+
114+ public function testCreateRaisesServerExceptions ()
115+ {
116+ $ badRequestResponse = new Response (500 , [], json_encode ([
117+ 'non_field_errors ' => ['Something went wrong processing your request. ' ]
118+ ]));
119+ $ this ->responses ->append ($ badRequestResponse );
120+
121+ $ this ->expectExceptionObject (new HypernodeApiServerException ($ badRequestResponse ));
122+
123+ $ this ->client ->whitelist ->create ('johndoe ' , ['ip ' => '1.2.3.4 ' ]);
124+ }
75125}
0 commit comments