Skip to content

Commit

Permalink
Adds Specs for UnlocksController
Browse files Browse the repository at this point in the history
  • Loading branch information
cesartalves committed Oct 18, 2022
1 parent a0d7c46 commit 483a40c
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions spec/controllers/spree/admin/user_unlocks_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# frozen_string_literal: true

RSpec.describe Spree::Admin::UserUnlocksController, type: :controller do
# rubocop:disable RSpec/InstanceVariable
before { @request.env['devise.mapping'] = Devise.mappings[:spree_user] }

describe '#create' do
let(:user) { create(:user, locked_at: Time.current) }

it 'sends unlock instructions to the user' do
# rubocop:disable RSpec/StubbedMock
expect(Spree::UserMailer).to receive(:unlock_instructions).and_return(instance_double(deliver: true))
# rubocop:enable RSpec/StubbedMock

post :create, params: { spree_user: { email: user.email } }

expect(assigns[:spree_user].email).to eq(user.email)
expect(response.code).to eq('302')
end
end

describe '#show' do
let(:user) { create(:user, locked_at: Time.current) }

before {
@raw_token, encrypted_token = Devise.token_generator.generate(user.class, :unlock_token)
user.update(unlock_token: encrypted_token)
}

it 'unlocks a previously locked user' do
get :show, params: { unlock_token: @raw_token }

expect(response.code).to eq '302'
expect(user.reload.locked_at).to be_nil
end
end

# rubocop:enable RSpec/InstanceVariable
end

0 comments on commit 483a40c

Please sign in to comment.