Skip to content

Commit

Permalink
Merge branch 'release/2.0.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
RicLeP committed Mar 24, 2023
2 parents f119cb2 + 1b9813d commit 8192851
Show file tree
Hide file tree
Showing 10 changed files with 382 additions and 384 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
},
"require-dev": {
"orchestra/testbench": "^7.0|^8.0",
"pestphp/pest": "^1.22",
"pestphp/pest-plugin-laravel": "^1.4"
"pestphp/pest": "^2.0",
"pestphp/pest-plugin-laravel": "^2"
}
}
37 changes: 15 additions & 22 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,25 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="vendor/autoload.php"
backupGlobals="false"
backupStaticAttributes="false"
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="vendor/autoload.php"
colors="true"
verbose="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false">
<testsuites>
<testsuite name="Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<logging>
<junit outputFile="build/report.junit.xml"/>
</logging>
<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">./src</directory>
</include>
</coverage>
>
<testsuites>
<testsuite name="Test Suite">
<directory suffix="Test.php">./tests</directory>
</testsuite>
</testsuites>
<coverage>
<include>
<directory suffix=".php">./app</directory>
<directory suffix=".php">./src</directory>
</include>
</coverage>
</phpunit>
173 changes: 173 additions & 0 deletions tests/Feature/ComponentsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
<?php

use Riclep\StoryblokCli\Endpoints\ComponentGroups;
use Riclep\StoryblokCli\Endpoints\Components;

test('can get components for space', function () {
$components = Components::make('dummy-token');
$components->mockable([
mockResponse('components'),
]);

$componentsData = $components->all();

expect($componentsData->getComponents())->not()->toBeNull();
expect($componentsData->getComponents())->toHaveCount(5);
expect($componentsData->getComponents()[0]['name'])->toEqual('page');
});

test('can get component by ID', function () {
$components = Components::make('dummy-token');
$components->mockable([
mockResponse('components/2559045'),
]);

$componentData = $components->byId(2559045);

expect($componentData->getComponent()['name'])->toEqual('hero');
});

test('can create a component', function () {
$components = Components::make('dummy-token');
$components->mockable([
mockResponse('components/2559045'),
]);

$componentData = $components->create([
'component' => [
'name' => 'hero',
'display_name' => 'Hero',
'schema' => [
'title' => [
'type' => 'text',
'pos' => 0,
],
'image' => [
'type' => 'image',
'pos' => 1,
],
],
'is_root' => false,
'is_nestable' => true,
],
]);

expect($componentData->getComponent()['name'])->toEqual('hero');
});

test('can update a component', function () {
$components = Components::make('dummy-token');
$components->mockable([
mockResponse('components/2559045'),
]);

$componentData = $components->update(2559045, [
'component' => [
'name' => 'hero',
'display_name' => 'Hero',
'schema' => [
'title' => [
'type' => 'text',
'pos' => 0,
],
'image' => [
'type' => 'image',
'pos' => 1,
],
],
'is_root' => false,
'is_nestable' => true,
],
]);

expect($componentData->getComponent()['name'])->toEqual('hero');
});

test('can delete a component', function () {
$components = Components::make('dummy-token');
$components->mockable([
mockResponse('components/2559045'),
]);

$componentData = $components->delete(2559045);

expect($componentData->getComponent()['name'])->toEqual('hero');
});

test('can get component groups', function () {
$components = Components::make('dummy-token');
$components->mockable([
mockResponse('components'),
]);

$componentsData = $components->all();

expect($componentsData->getComponentGroups())->not()->toBeNull();
expect($componentsData->getComponentGroups())->toHaveCount(2);
expect($componentsData->getComponentGroups()[0]['name'])->toEqual('Body blocks');
});

test('can get all component groups for space', function () {
$componentGroups = ComponentGroups::make('dummy-token');
$componentGroups->mockable([
mockResponse('component_groups'),
]);

$componentGroupsData = $componentGroups->all();

expect($componentGroupsData->getComponentGroups())->not()->toBeNull();
expect($componentGroupsData->getComponentGroups())->toHaveCount(2);
expect($componentGroupsData->getComponentGroups()[0]['name'])->toEqual('Body blocks');
});

test('can get component group by ID', function () {
$componentGroups = ComponentGroups::make('dummy-token');
$componentGroups->mockable([
mockResponse('component_groups/58878'),
]);

$componentGroupsData = $componentGroups->byId(58878);

expect($componentGroupsData->getComponentGroup()['name'])->toEqual('Body blocks');
});

test('can create a component group', function () {
$componentGroups = ComponentGroups::make('dummy-token');
$componentGroups->mockable([
mockResponse('component_groups/58878'),
]);

$componentGroupData = $componentGroups->create([
'component_group' => [
'name' => 'Body blocks',
],
]);

expect($componentGroupData->getComponentGroup()['name'])->toEqual('Body blocks');
});

test('can update a component group', function () {
$componentGroups = ComponentGroups::make('dummy-token');
$componentGroups->mockable([
mockResponse('component_groups/58878'),
]);

$componentGroupData = $componentGroups->update(58878, [
'component_group' => [
'name' => 'Body blocks',
],
]);

expect($componentGroupData->getComponentGroup()['name'])->toEqual('Body blocks');
});

test('can delete a component group', function () {
$componentGroups = ComponentGroups::make('dummy-token');
$componentGroups->mockable([
mockResponse('component_groups/58878'),
]);

$componentGroupData = $componentGroups->delete(58878);

expect($componentGroupData->getComponentGroup()['name'])->toEqual('Body blocks');
});
5 changes: 5 additions & 0 deletions tests/Feature/ExampleTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

test('example', function () {
expect(true)->toBeTrue();
});
55 changes: 55 additions & 0 deletions tests/Feature/SpacesTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

use Riclep\StoryblokCli\Endpoints\Spaces;
use Riclep\StoryblokCli\Endpoints\Stories;

test('returns empty collection when data does not exist', function () {
$spaces = Spaces::make('dummy-token');
$spaces->mockable([
mockResponse('spaces/196985'),
]);

$spaceData = $spaces->byId(196985)->getCollectionFromResponse('not-here');

expect($spaceData)->not()->toBeNull();
expect($spaceData)->toHaveCount(0);
expect($spaceData)->toBeCollection();
});

test('can get spaces', function () {
$spaces = Spaces::make('dummy-token');
$spaces->mockable([
mockResponse('spaces'),
]);

$spacesData = $spaces->all();
expect($spacesData->getSpaces())->not()->toBeNull();
expect($spacesData->getSpaces())->toHaveCount(2);

$spaceValues = $spacesData->getSpaces();
expect($spaceValues[0]['name'])->toEqual('Example Space 1');
expect($spaceValues[1]['name'])->toEqual('Example Space 2');
});

test('can get a space by id', function () {
$spaces = Spaces::make('dummy-token');
$spaces->mockable([
mockResponse('spaces/196985'),
]);

$spaceData = $spaces->byId(196985);

$spaceValue = $spaceData->getSpace();
expect($spaceValue['name'])->toEqual('CLI space');
});

test('can set space id', function () {
$story = Stories::make('dummy-token');
$story->mockable([
mockResponse('stories/259645264'),
]);

$storyData = $story->spaceId(12345)->byId(259645264);

expect($storyData->getStory()['name'])->toEqual('Home');
});
Loading

0 comments on commit 8192851

Please sign in to comment.