forked from decidim/decidim
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
64 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# frozen_string_literal: true | ||
|
||
require "spec_helper" | ||
|
||
module Decidim::Admin | ||
describe ShareTokenForm do | ||
let(:organization) { create(:organization) } | ||
let(:current_user) { create(:user, :admin, organization:) } | ||
let(:component) { create(:component, participatory_space: create(:participatory_process, organization:)) } | ||
|
||
let(:form) do | ||
described_class.from_params( | ||
token:, | ||
automatic_token:, | ||
expires_at:, | ||
no_expiration: | ||
).with_context( | ||
current_user:, | ||
current_organization: organization, | ||
component: | ||
) | ||
end | ||
|
||
let(:token) { "ABC123" } | ||
let(:automatic_token) { false } | ||
let(:expires_at) { Time.zone.today + 3.days } | ||
let(:no_expiration) { false } | ||
|
||
context "when automatic_token validation is false" do | ||
let(:automatic_token) { false } | ||
|
||
it "validates presence of token" do | ||
form.token = nil | ||
expect(form).to be_invalid | ||
expect(form.errors[:token]).to include("cannot be blank") | ||
end | ||
end | ||
|
||
context "when token is custom" do | ||
it "returns the token in uppercase" do | ||
form.token = "abc123" | ||
expect(form.token).to eq("ABC123") | ||
end | ||
end | ||
|
||
describe "#token_for" do | ||
it "returns the component from the context" do | ||
expect(form.token_for).to eq(component) | ||
end | ||
end | ||
|
||
describe "#organization" do | ||
it "returns the current organization from the context" do | ||
expect(form.organization).to eq(organization) | ||
end | ||
end | ||
|
||
describe "#user" do | ||
it "returns the current user from the context" do | ||
expect(form.user).to eq(current_user) | ||
end | ||
end | ||
end | ||
end |