Wednesday, July 15, 2026 4:59:57 AM
> community_modifiable_by_spec.rb
# frozen_string_literal: true

RSpec.describe ESM::Website::API::Handlers::CommunityModifiableBy do
  describe ".call" do
    let(:discord_user) { build(:discord_user) }
    let(:discord_server) { build(:discord_server, owner: discord_user) }
    let!(:community) { create(:community, discord_server: discord_server) }
    let!(:user) { create(:user, discord_user: discord_user) }

    it "returns true when the user owns the community's guild" do
      expect(described_class.call(id: community.id, user_id: user.id)).to be(true)
    end

    it "returns false for a non-owner user" do
      other_user = create(:user, :with_discord_member, discord_server: discord_server)
      expect(described_class.call(id: community.id, user_id: other_user.id)).to be(false)
    end

    context "when the user is not a member of the community's guild" do
      let(:other_server) { build(:discord_server) }
      let!(:other_community) { create(:community, discord_server: other_server) }

      it "returns false instead of raising" do
        expect(described_class.call(id: other_community.id, user_id: user.id)).to be(false)
      end
    end

    context "when the community is missing" do
      it "returns nil" do
        expect(described_class.call(id: -1, user_id: user.id)).to be_nil
      end
    end

    context "when the user is missing" do
      it "returns nil" do
        expect(described_class.call(id: community.id, user_id: -1)).to be_nil
      end
    end
  end
end
All opinions represented herein are my own
- © 2024 - 2026 itsthedevman
- build 43aa0d7