Skip to content

Commit 1e59c1e

Browse files
committed
Full coverage test for Workflow
1 parent f1fb9ab commit 1e59c1e

File tree

3 files changed

+111
-1
lines changed

3 files changed

+111
-1
lines changed

src/Endpoints/WorkflowApi.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ public function delete(string|int $workflowId): StoryblokResponseInterface
5858
return $this->makeRequest(
5959
"DELETE",
6060
'/v1/spaces/' . $this->spaceId . '/workflows/' . $workflowId,
61+
dataClass: WorkflowData::class
6162
);
6263
}
6364

tests/Feature/Data/one-workflow.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"workflow": {
3+
"id": 15268,
4+
"content_types": [
5+
"author"
6+
],
7+
"is_default": false,
8+
"name": "author workflow"
9+
}
10+
}

tests/Feature/WorkflowTest.php

Lines changed: 100 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
declare(strict_types=1);
44

55

6+
use Storyblok\ManagementApi\Data\WorkflowData;
7+
use Storyblok\ManagementApi\Endpoints\WorkflowApi;
68
use Storyblok\ManagementApi\ManagementApiClient;
79
use Symfony\Component\HttpClient\MockHttpClient;
810

@@ -15,7 +17,7 @@
1517

1618
$client = new MockHttpClient($responses);
1719
$mapiClient = ManagementApiClient::initTest($client);
18-
$workflowApi = $mapiClient->workflowApi("222");
20+
$workflowApi = new WorkflowApi($mapiClient, "222");
1921

2022
$storyblokResponse = $workflowApi->list(
2123
$contentType = "article"
@@ -29,6 +31,103 @@
2931
$string = $storyblokResponse->getLastCalledUrl();
3032
expect($string)->toMatch('/.*content_type=article%2Ccategory.*$/');
3133

34+
});
35+
36+
test('Testing one workflow', function (): void {
37+
$responses = [
38+
\mockResponse("one-workflow", 200),
39+
\mockResponse("list-workflows", 200),
40+
//\mockResponse("empty-asset", 404),
41+
];
42+
43+
$client = new MockHttpClient($responses);
44+
$mapiClient = ManagementApiClient::initTest($client);
45+
$workflowApi = new WorkflowApi($mapiClient, "222");
46+
47+
$storyblokResponse = $workflowApi->get( "15268"
48+
);
49+
$string = $storyblokResponse->getLastCalledUrl();
50+
expect($string)->toMatch('/.*workflow.*$/');
51+
$data = $storyblokResponse->data();
52+
expect($data->getString("id"))->toBe("15268");
53+
expect($data->id())->toBe("15268");
54+
expect($data->name())->toBe("author workflow");
55+
expect($data->isDefault())->toBeFalse();
56+
expect($data->contentTypes())->toBe(["author"]);
57+
58+
});
59+
60+
test('Testing deleting workflow', function (): void {
61+
$responses = [
62+
\mockResponse("one-workflow", 200),
63+
\mockResponse("list-workflows", 200),
64+
//\mockResponse("empty-asset", 404),
65+
];
66+
67+
$client = new MockHttpClient($responses);
68+
$mapiClient = ManagementApiClient::initTest($client);
69+
$workflowApi = new WorkflowApi($mapiClient, "222");
70+
71+
$storyblokResponse = $workflowApi->delete( "15268"
72+
);
73+
$string = $storyblokResponse->getLastCalledUrl();
74+
expect($string)->toMatch('/.*workflow.*$/');
75+
$data = $storyblokResponse->data();
76+
expect($data->getString("id"))->toBe("15268");
77+
expect($data->id())->toBe("15268");
78+
expect($data->name())->toBe("author workflow");
79+
expect($data->isDefault())->toBeFalse();
80+
expect($data->contentTypes())->toBe(["author"]);
81+
82+
});
83+
84+
test('Testing creating workflow', function (): void {
85+
$responses = [
86+
\mockResponse("one-workflow", 200),
87+
\mockResponse("list-workflows", 200),
88+
//\mockResponse("empty-asset", 404),
89+
];
90+
91+
$client = new MockHttpClient($responses);
92+
$mapiClient = ManagementApiClient::initTest($client);
93+
$workflowApi = new WorkflowApi($mapiClient, "222");
94+
95+
96+
$workflowData = new WorkflowData();
97+
$workflowData->setName("Name");
98+
99+
$storyblokResponse = $workflowApi->create($workflowData);
100+
$string = $storyblokResponse->getLastCalledUrl();
101+
expect($string)->toMatch('/.*workflow.*$/');
102+
expect($storyblokResponse->isOk())->toBeTrue();
32103

104+
});
105+
106+
107+
test('Testing updating workflow', function (): void {
108+
$responses = [
109+
\mockResponse("one-workflow", 200),
110+
\mockResponse("one-workflow", 200),
111+
//\mockResponse("empty-asset", 404),
112+
];
113+
114+
$client = new MockHttpClient($responses);
115+
$mapiClient = ManagementApiClient::initTest($client);
116+
$workflowApi = new WorkflowApi($mapiClient, "222");
117+
118+
$storyblokResponse = $workflowApi->get( "15268");
119+
$workflowData = $storyblokResponse->data();
120+
$workflowData->setName("Name");
121+
122+
$storyblokResponse = $workflowApi->update( "15268", $workflowData);
123+
124+
$string = $storyblokResponse->getLastCalledUrl();
125+
expect($string)->toMatch('/.*workflow.*$/');
126+
$data = $storyblokResponse->data();
127+
expect($data->getString("id"))->toBe("15268");
128+
expect($data->id())->toBe("15268");
129+
expect($data->name())->toBe("author workflow");
130+
expect($data->isDefault())->toBeFalse();
131+
expect($data->contentTypes())->toBe(["author"]);
33132

34133
});

0 commit comments

Comments
 (0)