Skip to content

Commit

Permalink
Adding tests for creating, delete and editing resources
Browse files Browse the repository at this point in the history
  • Loading branch information
roberto-butti committed Jan 22, 2025
1 parent 1932642 commit b54c91d
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 0 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
9 changes: 9 additions & 0 deletions tests/Feature/Data/one-tag.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"internal_tag":
{
"name": "some",
"id": 56932,
"object_type": "asset"
}

}
91 changes: 91 additions & 0 deletions tests/Feature/ManagementApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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");

});




0 comments on commit b54c91d

Please sign in to comment.