Skip to content

Self-hosted project management for devs and their clients: tickets, time tracking, docs and meetings, with an AI assistant that cites its sources. AGPL-3.0.

1.8 KB
Raw Blame
# frozen_string_literal: true

require 'rails_helper'

RSpec.describe AiSyncStatusPolicy, :ci_guard, type: :policy do
  let(:organisation) { create(:organisation) }
  let(:admin_role) do
    ActsAsTenant.with_tenant(organisation) do
      create(:role, title: 'account_admin', organisation: organisation)
    end
  end
  let(:user_role) do
    ActsAsTenant.with_tenant(organisation) do
      create(:role, title: 'Standard-Benutzer', organisation: organisation, is_default: true)
    end
  end

  let(:admin_user) { create(:user) }
  let(:regular_user) { create(:user) }

  let!(:admin_membership) do
    ActsAsTenant.with_tenant(organisation) do
      create(:membership, user: admin_user, organisation: organisation, role: admin_role, active: true)
    end
  end
  let!(:user_membership) do
    ActsAsTenant.with_tenant(organisation) do
      create(:membership, user: regular_user, organisation: organisation, role: user_role, active: true)
    end
  end

  before { ActsAsTenant.current_tenant = organisation }
  after { ActsAsTenant.current_tenant = nil }

  describe 'show?' do
    context 'when user is account admin' do
      it 'grants access' do
        expect(described_class.new(admin_user, organisation).show?).to be_truthy
      end
    end

    context 'when user is regular user' do
      it 'denies access' do
        expect(described_class.new(regular_user, organisation).show?).to be_falsey
      end
    end
  end

  describe 'reprocess_embeddings?' do
    context 'when user is account admin' do
      it 'grants access' do
        expect(described_class.new(admin_user, organisation).reprocess_embeddings?).to be_truthy
      end
    end

    context 'when user is regular user' do
      it 'denies access' do
        expect(described_class.new(regular_user, organisation).reprocess_embeddings?).to be_falsey
      end
    end
  end
end