Skip to content

Commit

Permalink
Remove authorization redundant specs and refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
sauloperez committed Apr 2, 2021
1 parent 4ae09b0 commit 41ed7da
Showing 1 changed file with 40 additions and 35 deletions.
75 changes: 40 additions & 35 deletions spec/lib/decidim/direct_verifications/user_processor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,52 +82,57 @@ module DirectVerifications
end
end

context "when authorizing confirmed users" do
it "has no errors" do
subject.emails = { user.email => user.name }
subject.authorize_users

expect(subject.processed[:authorized].count).to eq(1)
expect(subject.errors[:authorized].count).to eq(0)
end
describe "#authorize_users" do
context "when authorizing confirmed users" do
before do
subject.emails = { user.email => user.name }
end

it "stores user data as authorization metadata" do
subject.emails = { user.email => { name: user.name, type: "consumer" } }
subject.authorize_users
it "has no errors" do
subject.authorize_users

expect(Authorization.last.metadata).to eq("name" => user.name, "type" => "consumer")
expect(subject.processed[:authorized].count).to eq(1)
expect(subject.errors[:authorized].count).to eq(0)
end
end
end

context "when authorizing unconfirmed users" do
it "has no errors" do
subject.emails = ["[email protected]"]
subject.register_users
subject.authorize_users
context "when authorizing confirmed users with metadata" do
before do
subject.emails = { user.email => { name: user.name, type: "consumer" } }
end

expect(subject.processed[:authorized].count).to eq(1)
expect(subject.errors[:authorized].count).to eq(0)
it "stores user data as authorization metadata" do
subject.authorize_users
expect(Authorization.last.metadata).to eq("name" => user.name, "type" => "consumer")
end
end

it "stores user data as authorization metadata" do
subject.emails = { "[email protected]" => { type: "consumer" } }
subject.register_users
subject.authorize_users
context "when authorizing unconfirmed users" do
before do
subject.emails = ["[email protected]"]
subject.register_users
end

expect(Decidim::User.find_by(email: "[email protected]").name).to eq("em")
expect(Authorization.last.metadata).to eq("type" => "consumer")
end
end
it "has no errors" do
subject.authorize_users

context "when authorizing unregistered users" do
before do
subject.emails = ["[email protected]"]
subject.authorize_users
expect(subject.processed[:authorized].count).to eq(1)
expect(subject.errors[:authorized].count).to eq(0)
end
end

it "has errors" do
expect(subject.processed[:authorized].count).to eq(0)
expect(subject.errors[:authorized].count).to eq(1)
context "when authorizing unconfirmed users with metadata" do
before do
subject.emails = { "[email protected]" => { type: "consumer" } }
subject.register_users
end

it "stores user data as authorization metadata" do
subject.authorize_users

expect(Decidim::User.find_by(email: "[email protected]").name).to eq("em")
expect(Authorization.last.metadata).to eq("type" => "consumer")
end
end
end

Expand Down

0 comments on commit 41ed7da

Please sign in to comment.