opnform/tests/Feature/WorkspaceTest.php

37 lines
1.0 KiB
PHP
Raw Normal View History

2022-09-20 19:59:52 +00:00
<?php
it('can create and delete Workspace', function () {
$user = $this->actingAsUser();
2024-02-23 10:54:12 +00:00
for ($i = 1; $i <= 3; $i++) {
2022-09-20 19:59:52 +00:00
$this->postJson(route('open.workspaces.create'), [
2024-02-23 10:54:12 +00:00
'name' => 'Workspace Test - '.$i,
'icon' => '🧪',
])
2022-09-20 19:59:52 +00:00
->assertSuccessful()
->assertJson([
'type' => 'success',
2024-02-23 10:54:12 +00:00
'message' => 'Workspace created.',
2022-09-20 19:59:52 +00:00
]);
}
expect($user->workspaces()->count())->toBe(3);
2024-02-23 10:54:12 +00:00
$i = 0;
foreach ($user->workspaces as $workspace) {
2022-09-20 19:59:52 +00:00
$i++;
2024-02-23 10:54:12 +00:00
if ($i !== 3) {
2022-09-20 19:59:52 +00:00
$this->deleteJson(route('open.workspaces.delete', $workspace->id))
->assertSuccessful()
->assertJson([
'type' => 'success',
2024-02-23 10:54:12 +00:00
'message' => 'Workspace deleted.',
2022-09-20 19:59:52 +00:00
]);
2024-02-23 10:54:12 +00:00
} else {
2022-09-20 19:59:52 +00:00
// Last workspace can not delete
$this->deleteJson(route('open.workspaces.delete', $workspace->id))
->assertStatus(403);
}
}
});