diff --git a/src/Endpoints/Accounts/Rulesets.php b/src/Endpoints/Accounts/Rulesets.php index 6964661..788230f 100644 --- a/src/Endpoints/Accounts/Rulesets.php +++ b/src/Endpoints/Accounts/Rulesets.php @@ -35,7 +35,7 @@ public function get(string $accountId): ResponseInterface public function create(string $accountId, array|Ruleset $values): ResponseInterface { if (is_array($values)) { - $this->requiredParams(['name', 'kind', 'phase', 'rules'], $values); + $this->requiredParams(['name', 'kind', 'phase'], $values); } else { $values = $values->toArray(); } diff --git a/src/Endpoints/Zones/Rulesets.php b/src/Endpoints/Zones/Rulesets.php index 972067a..b48cf17 100644 --- a/src/Endpoints/Zones/Rulesets.php +++ b/src/Endpoints/Zones/Rulesets.php @@ -35,7 +35,7 @@ public function get(string $zoneId): ResponseInterface public function create(string $zoneId, array|Ruleset $values): ResponseInterface { if (is_array($values)) { - $this->requiredParams(['name', 'kind', 'phase', 'rules'], $values); + $this->requiredParams(['name', 'kind', 'phase'], $values); } else { $values = $values->toArray(); } diff --git a/test/Tests/Endpoints/Accounts/RulesetsTest.php b/test/Tests/Endpoints/Accounts/RulesetsTest.php index db573f9..2d13a77 100644 --- a/test/Tests/Endpoints/Accounts/RulesetsTest.php +++ b/test/Tests/Endpoints/Accounts/RulesetsTest.php @@ -46,6 +46,41 @@ public function shouldCreateWithArray() $this->assertSame('/client/v4/accounts/account_id/rulesets', $this->lastRequest()->getUri()->getPath()); } + #[Test] + public function shouldCreateWithEmptyRulesArray() + { + $client = $this->mockClient([ + new Response(200, [], json_encode(['success' => true, 'result' => ['id' => 'ruleset_id']])), + ]); + + $response = $client->accounts()->rulesets()->create('account_id', [ + 'name' => 'my ruleset', + 'kind' => 'root', + 'phase' => 'http_request_firewall_custom', + 'rules' => [], + ]); + + $this->assertTrue($response->successful()); + $this->assertSame('POST', $this->lastRequest()->getMethod()); + } + + #[Test] + public function shouldCreateWithoutRulesKey() + { + $client = $this->mockClient([ + new Response(200, [], json_encode(['success' => true, 'result' => ['id' => 'ruleset_id']])), + ]); + + $response = $client->accounts()->rulesets()->create('account_id', [ + 'name' => 'my ruleset', + 'kind' => 'root', + 'phase' => 'http_request_firewall_custom', + ]); + + $this->assertTrue($response->successful()); + $this->assertSame('POST', $this->lastRequest()->getMethod()); + } + #[Test] public function shouldCreateWithRulesetObject() { diff --git a/test/Tests/Endpoints/Zones/RulesetsTest.php b/test/Tests/Endpoints/Zones/RulesetsTest.php index 2dc31a1..a4333f7 100644 --- a/test/Tests/Endpoints/Zones/RulesetsTest.php +++ b/test/Tests/Endpoints/Zones/RulesetsTest.php @@ -46,6 +46,41 @@ public function shouldCreateWithArray() $this->assertSame('/client/v4/zones/zone_id/rulesets', $this->lastRequest()->getUri()->getPath()); } + #[Test] + public function shouldCreateWithEmptyRulesArray() + { + $client = $this->mockClient([ + new Response(200, [], json_encode(['success' => true, 'result' => ['id' => 'ruleset_id']])), + ]); + + $response = $client->zones()->rulesets()->create('zone_id', [ + 'name' => 'my ruleset', + 'kind' => 'zone', + 'phase' => 'http_request_firewall_custom', + 'rules' => [], + ]); + + $this->assertTrue($response->successful()); + $this->assertSame('POST', $this->lastRequest()->getMethod()); + } + + #[Test] + public function shouldCreateWithoutRulesKey() + { + $client = $this->mockClient([ + new Response(200, [], json_encode(['success' => true, 'result' => ['id' => 'ruleset_id']])), + ]); + + $response = $client->zones()->rulesets()->create('zone_id', [ + 'name' => 'my ruleset', + 'kind' => 'zone', + 'phase' => 'http_request_firewall_custom', + ]); + + $this->assertTrue($response->successful()); + $this->assertSame('POST', $this->lastRequest()->getMethod()); + } + #[Test] public function shouldCreateWithRulesetObject() {