Friday, September 20, 2024 3:58:05 AM
> settings

Customize


Authenticate

> decline_spec.rb
# frozen_string_literal: true

describe ESM::Command::Request::Decline, category: "command" do
  include_context "command"
  include_examples "validate_command"

  describe "#execute" do
    let!(:user_2) { ESM::Test.user }

    let!(:request) do
      create(
        :request,
        requestor_user_id: user.id,
        requestee_user_id: user_2.id,
        requested_from_channel_id: ESM::Test.channel(in: community).id,
        command_name: "id"
      )
    end

    context "when the request is for this user" do
      it "declines the request" do
        execute!(user: user_2, channel_type: :dm, arguments: {uuid: request.uuid_short})

        embed = ESM::Test.messages.first.content
        expect(embed).not_to be(nil)
        expect(ESM::Request.all.size).to eq(0)
      end
    end

    context "when the request is for a different user" do
      it "raises an exception" do
        # The uuid is valid, but the user is not the who the request is for
        execution_args = {user: user, channel_type: :dm, arguments: {uuid: request.uuid_short}}

        expect { execute!(**execution_args) }.to raise_error(ESM::Exception::CheckFailure, /unable to find a request/i)
      end
    end
  end
end
All opinions represented herein are my own
- © 2024 itsthedevman
- build 340fbb8