Skip to content

Beautiful Open-Source Form Builder

2.3 KB
Raw Blame
<?php

use App\Service\CustomDomainOwnershipService;

describe('Workspace admin-only endpoints', function () {
    it('forbids non-admin users from updating custom domains', function () {
        $owner = $this->actingAsProUser();
        $workspace = $this->createUserWorkspace($owner);

        // Create a non-admin member
        $viewer = $this->createUser();
        $viewer->workspaces()->sync([$workspace->id => ['role' => 'user']], false);
        $this->actingAs($viewer, 'api');

        $this->putJson(route('open.workspaces.save-custom-domains', $workspace), [
            'custom_domains' => ['example.com']
        ])->assertStatus(403);
    });

    it('allows admins to update custom domains', function () {
        $owner = $this->actingAsProUser();
        $workspace = $this->createUserWorkspace($owner);
        $this->mock(CustomDomainOwnershipService::class)
            ->shouldReceive('verify')->with($workspace->id, 'example.com')->once()->andReturnTrue();

        $this->putJson(route('open.workspaces.save-custom-domains', $workspace), [
            'custom_domains' => ['example.com']
        ])->assertSuccessful();
    });

    it('forbids non-admin users from updating email settings', function () {
        $owner = $this->actingAsProUser();
        $workspace = $this->createUserWorkspace($owner);

        $viewer = $this->createUser();
        $viewer->workspaces()->sync([$workspace->id => ['role' => 'user']], false);
        $this->actingAs($viewer, 'api');

        $this->putJson(route('open.workspaces.save-email-settings', $workspace), [
            'host' => 'smtp.example.com',
            'sender_address' => '[email protected]',
            'port' => '587',
            'username' => 'user',
            'password' => 'secret',
        ])->assertStatus(403);
    });

    it('allows admins to update email settings', function () {
        $owner = $this->actingAsProUser();
        $workspace = $this->createUserWorkspace($owner);

        $this->putJson(route('open.workspaces.save-email-settings', $workspace), [
            'host' => 'smtp.example.com',
            'sender_address' => '[email protected]',
            'port' => '587',
            'username' => 'user',
            'password' => 'secret',
        ])->assertSuccessful();
    });
});