diff --git a/composer.json b/composer.json index de00c0c..86ed644 100644 --- a/composer.json +++ b/composer.json @@ -32,6 +32,7 @@ "test-code": "vendor/bin/pest", "test-code-ci": "vendor/bin/pest -c . --ci --cache-directory ./tmp", "refactor-check-code": "vendor/bin/rector --dry-run", + "test-coverage": "vendor/bin/pest --configuration=phpunit.xml.dist --coverage-html .build/html", "all-checks": [ "@style-check-code", "@static-code", diff --git a/tests/Feature/Data/one-tag.json b/tests/Feature/Data/one-tag.json new file mode 100644 index 0000000..1c67080 --- /dev/null +++ b/tests/Feature/Data/one-tag.json @@ -0,0 +1,9 @@ +{ + "internal_tag": + { + "name": "some", + "id": 56932, + "object_type": "asset" + } + +} diff --git a/tests/Feature/ManagementApiTest.php b/tests/Feature/ManagementApiTest.php index befa447..33ac430 100644 --- a/tests/Feature/ManagementApiTest.php +++ b/tests/Feature/ManagementApiTest.php @@ -55,5 +55,96 @@ }); +test('Testing create resource, StoryblokData', function (): void { + $responses = [ + \mockResponse("one-tag", 200), + \mockResponse("empty-tags", 404), + ]; + + $client = new MockHttpClient($responses, baseUri: 'https://mapi.storyblok.com'); + $mapiClient = MapiClient::initTest($client); + $managementApi = $mapiClient->managementApi(); + + + // CREATE A TAG + $tag = [ + "name" => "new tag", + "object_type" => "asset" + ]; + $spaceId = "321388"; + $response = $managementApi->post( + "spaces/{$spaceId}/internal_tags", + ["internal_tag" => $tag ] + ); + expect($response->isOk())->toBe(true); + var_dump($response->data()); + $tag = $response->data()->get("internal_tag"); + expect($tag->get("name"))->toBeString(); + expect($tag->getString("name"))->toBeString(); + expect($tag->getString("name"))->toBe("some"); + +}); + +test('Testing delete resource, StoryblokData', function (): void { + $responses = [ + \mockResponse("one-tag", 200), + \mockResponse("empty-tags", 404), + ]; + + $client = new MockHttpClient($responses, baseUri: 'https://mapi.storyblok.com'); + $mapiClient = MapiClient::initTest($client); + $managementApi = $mapiClient->managementApi(); + + + // CREATE A TAG + $tag = [ + "name" => "new tag", + "object_type" => "asset" + ]; + $spaceId = "321388"; + $tagId="56980"; + $response = $managementApi->delete( + "spaces/{$spaceId}/internal_tags/{$tagId}" + ); + expect($response->isOk())->toBe(true); + var_dump($response->data()); + $tag = $response->data()->get("internal_tag"); + expect($tag->get("name"))->toBeString(); + expect($tag->getString("name"))->toBeString(); + expect($tag->getString("name"))->toBe("some"); + +}); + +test('Testing edit resource, StoryblokData', function (): void { + $responses = [ + \mockResponse("one-tag", 200), + \mockResponse("empty-tags", 404), + ]; + + $client = new MockHttpClient($responses, baseUri: 'https://mapi.storyblok.com'); + $mapiClient = MapiClient::initTest($client); + $managementApi = $mapiClient->managementApi(); + + + // CREATE A TAG + $tag = [ + "name" => "some", + "object_type" => "asset" + ]; + $spaceId = "321388"; + $tagId="56980"; + $response = $managementApi->put( + "spaces/{$spaceId}/internal_tags/{$tagId}" + ); + expect($response->isOk())->toBe(true); + var_dump($response->data()); + $tag = $response->data()->get("internal_tag"); + expect($tag->get("name"))->toBeString(); + expect($tag->getString("name"))->toBeString(); + expect($tag->getString("name"))->toBe("some"); + +}); + +