-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove authorization redundant specs and refactor
- Loading branch information
1 parent
4ae09b0
commit 41ed7da
Showing
1 changed file
with
40 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
||
|