Skip to content

Commit

Permalink
Password controller test coverage (#269)
Browse files Browse the repository at this point in the history
* Added test cases for password controller

* Updated the test cases description

Co-authored-by: Gowsik <gowsik@saeloun.com>
  • Loading branch information
gowsik-ragunath and Gowsik authored Apr 15, 2022
1 parent e682fca commit 43e9fe5
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
Binary file modified .DS_Store
Binary file not shown.
57 changes: 57 additions & 0 deletions spec/requests/users/passwords/update_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# frozen_string_literal: true

require "rails_helper"

RSpec.describe "Users::Passwords#update", type: :request do
let(:company) { create(:company) }
let(:user) { create(:user, current_workspace_id: company.id) }

context "when the password token is valid" do
before do
create(:company_user, company:, user:)
user.add_role :admin, company
send_request :patch, user_password_path, params: {
user: {
email: user.email,
password: "testpassword",
reset_password_token: user.send_reset_password_instructions
}
}
end

it "returns redirect http status" do
expect(response).to have_http_status(:redirect)
end

it "redirects to root_path" do
expect(response).to redirect_to(root_path)
end

it "returns success flash notice" do
expect(flash[:notice])
.to eq("Your password has been changed successfully. You are now signed in.")
end
end

context "when the password token is invalid" do
before do
create(:company_user, company:, user:)
user.add_role :admin, company
send_request :patch, user_password_path, params: {
user: {
email: user.email,
password: "testpassword",
reset_password_token: "invalid_token"
}
}
end

it "returns success response" do
expect(response).to be_successful
end

it "returns error flash message" do
expect(flash[:error]).to eq("Reset password token is invalid")
end
end
end

0 comments on commit 43e9fe5

Please sign in to comment.