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