Skip to content

Commit

Permalink
Test authorization validation
Browse files Browse the repository at this point in the history
  • Loading branch information
sauloperez committed Apr 1, 2021
1 parent 7e842ff commit 03b6018
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions spec/lib/decidim/direct_verifications/authorize_user_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ module DirectVerifications
subject { described_class.new(email, data, session, organization, instrumenter) }

describe "#call" do
let(:data) { user.name }

context "when authorizing confirmed users" do
let(:organization) { build(:organization) }
let(:user) { create(:user, organization: organization) }
Expand Down Expand Up @@ -45,6 +47,43 @@ module DirectVerifications
end
end

context "when the authorization already exists" do
context "when the authorization is not granted" do
let!(:authorization) { create(:authorization, :pending, user: user, name: :direct_verifications) }

it "authorizes the user" do
expect(Verification::ConfirmUserAuthorization).to receive(:call)
subject.call
end
end

context "when the authorization is already granted and expired" do
let!(:authorization) { create(:authorization, :granted, user: user, name: :direct_verifications) }

before do
allow_any_instance_of(Authorization).to receive(:expired?) { true }
end

it "does not authorize the user" do
expect(Verification::ConfirmUserAuthorization).to receive(:call)
subject.call
end
end

context "when the authorization is already granted and not expired" do
let!(:authorization) { create(:authorization, :granted, user: user, name: :direct_verifications) }

before do
allow_any_instance_of(Authorization).to receive(:expired?) { false }
end

it "does not authorize the user" do
expect(Verification::ConfirmUserAuthorization).not_to receive(:call)
subject.call
end
end
end

context "when the user fails to be authorized" do
let(:form) { instance_double(Verification::DirectVerificationsForm, valid?: false) }
let(:data) { user.name }
Expand Down

0 comments on commit 03b6018

Please sign in to comment.