Files
opnform-host-nginx/tests/Feature/WorkspaceUserTest.php
Favour Olayinka 90ff91b1e9 Team functionality (#459)
* add api enpoints for adding, removing, updating user to workspace and leaving workspace

* feat: updates client site workspace settings

* refactor and add domain setting ui in modal

* move workspace user functionality to its own component

* adds tests

* fix linting

* updates select input to FlatSelectInput

* moves workspace user role edit to seperated component

* move user adding to its own component

* adds check to usure users exist before checking is admin

* fix loading users

* feat: invite user to team functionality

* fix token coulmn

* fix self host mode changes

* tests for  user invite

* Refactor back-end

* Rename variables

* Improve some styling elements + refactor workspace settings

* More styling

* More UI polishing

* More UI fixes

* PHP linting

* Implemented most of the logic for team-functionnality

* Fix user avatar URL

* WIP remove users on cancellation

* Finished pricing for team functionality

* Fix tests

* Fix linting

* Added pricing_enabled helper

* Fix pricing_enabled shortcut

* Debug CI

* Disable pricing when testing

---------

Co-authored-by: LL-Etiane <lukongleinyuyetiane@gmail.com>
Co-authored-by: Lukong Etiane <83535251+LL-Etiane@users.noreply.github.com>
Co-authored-by: Julien Nahum <julien@nahum.net>
2024-07-04 17:21:36 +02:00

91 lines
2.8 KiB
PHP

<?php
use App\Models\User;
use App\Models\Workspace;
use Illuminate\Support\Facades\Mail;
use App\Mail\UserInvitationEmail;
beforeEach(function () {
$this->user = $this->actingAsProUser();
$this->workspace = Workspace::factory()->create();
$this->workspace->users()->attach($this->user, ['role' => 'admin']);
});
it('can list users in a workspace', function () {
$this->getJson(route('open.workspaces.users.index', ['workspaceId' => $this->workspace->id]))
->assertSuccessful()
->assertJsonCount(1);
});
it('can add a user to a workspace', function () {
$newUser = User::factory()->create(['email' => 'newuser@example.com']);
$this->postJson(route('open.workspaces.users.add', ['workspaceId' => $this->workspace->id]), [
'email' => $newUser->email,
'role' => 'user',
])
->assertSuccessful()
->assertJson([
'message' => 'User has been successfully added to workspace.'
]);
expect($this->workspace->users()->count())->toBe(2);
});
it('can send an invitation email to a non-existing user', function () {
Mail::fake();
$this->postJson(route('open.workspaces.users.add', ['workspaceId' => $this->workspace->id]), [
'email' => 'nonexisting@example.com',
'role' => 'user',
])
->assertSuccessful()
->assertJson([
'message' => 'Registration invitation email sent to user.'
]);
Mail::assertQueued(UserInvitationEmail::class);
});
it('can update user role in a workspace', function () {
$existingUser = User::factory()->create();
$this->workspace->users()->attach($existingUser, ['role' => 'user']);
$this->putJson(route('open.workspaces.users.update-role', [
'workspaceId' => $this->workspace->id,
'userId' => $existingUser->id
]), [
'role' => 'admin',
])
->assertSuccessful()
->assertJson([
'message' => 'User role changed successfully.'
]);
});
it('can remove a user from a workspace', function () {
$existingUser = User::factory()->create();
$this->workspace->users()->attach($existingUser);
$this->deleteJson(route('open.workspaces.users.remove', [
'workspaceId' => $this->workspace->id,
'userId' => $existingUser->id
]))
->assertSuccessful()
->assertJson([
'message' => 'User removed from workspace successfully.'
]);
expect($this->workspace->users()->count())->toBe(1);
});
it('can leave a workspace', function () {
$this->postJson(route('open.workspaces.leave', ['workspaceId' => $this->workspace->id]))
->assertSuccessful()
->assertJson([
'message' => 'You have left the workspace successfully.'
]);
expect($this->workspace->users()->count())->toBe(0);
});