-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
complete CheckTokenExpiration interactor
- Loading branch information
Showing
3 changed files
with
96 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
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,43 @@ | ||
RSpec.describe CheckTokenExpiration do | ||
describe ".call" do | ||
context "when successful" do | ||
let(:user) do | ||
create(:confirmed_user, reset_sent_at: 1.hour.ago) | ||
end | ||
|
||
subject { described_class.call(sent_at: user.reset_sent_at) } | ||
|
||
it "is a success" do | ||
is_expected.to be_a_success | ||
end | ||
end | ||
|
||
context "when sent_at not provided" do | ||
subject { described_class.call(sent_at: nil) } | ||
|
||
it "is a failure" do | ||
is_expected.to be_a_failure | ||
end | ||
|
||
it "adds an error to errors" do | ||
expect(subject.errors).to eq("invalid token") | ||
end | ||
end | ||
|
||
context "when the token was sent more than a day ago" do | ||
let(:user) do | ||
create(:confirmed_user, reset_sent_at: (1.day + 1.hour).ago) | ||
end | ||
|
||
subject { described_class.call(sent_at: user.reset_sent_at) } | ||
|
||
it "is a failure" do | ||
is_expected.to be_a_failure | ||
end | ||
|
||
it "adds an error to errors" do | ||
expect(subject.errors).to eq("token expired") | ||
end | ||
end | ||
end | ||
end |
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,37 @@ | ||
RSpec.describe CreatePasswordResetToken do | ||
describe ".call" do | ||
let(:user) { create(:confirmed_user) } | ||
|
||
context "when successful" do | ||
subject { described_class.call(user: user) } | ||
|
||
it "is a success" do | ||
is_expected.to be_a_success | ||
end | ||
|
||
it "sets the reset digest" do | ||
expect { subject }.to change(subject.user.reset_digest) | ||
end | ||
end | ||
|
||
context "when input is invalid" do | ||
it "fails" do | ||
is_expected.to be_a_failure | ||
end | ||
|
||
it "adds an error to errors" do | ||
expect(subject.errors).to eq("invalid input") | ||
end | ||
end | ||
|
||
context "when output is invalid" do | ||
it "fails" do | ||
is_expected.to be_a_failure | ||
end | ||
|
||
it "adds an error to errors" do | ||
expect(subject.errors).to eq("internal server error") | ||
end | ||
end | ||
end | ||
end |