Sha256: 2bd604dcccff38cd809c30d6f5e83ca274837bbc5bb7fabee42daaa09095252a
Contents?: true
Size: 1.88 KB
Versions: 2
Compression:
Stored size: 1.88 KB
Contents
# frozen_string_literal: true require 'spec_helper' require 'spree/testing_support/factories/user_factory' RSpec.describe SolidusJwt::DeviseStrategies::RefreshToken do let(:request) { instance_double('ActionController::Request') } let(:strategy) { described_class.new(nil, :spree_user) } let(:params) do { refresh_token: token.token, grant_type: 'refresh_token' } end let(:headers) { {} } let(:user) { FactoryBot.create(:user, password: password) } let(:password) { 'secret' } let(:token) { user.auth_tokens.create! } before do allow(request).to receive(:headers).and_return(:headers) allow(strategy).to receive(:request).and_return(request) allow(strategy).to receive(:params).and_return(params) end describe '#valid?' do subject { strategy.valid? } it { is_expected.to be true } context 'when refresh_token is missing' do before { params.delete(:refresh_token) } it { is_expected.to be false } end context 'when grant_type is not refresh_token' do before { params[:grant_type] = 'invalid' } it { is_expected.to be false } end end describe '#authenticate!' do subject { strategy.authenticate! } it { is_expected.to be :success } context 'when token is not honorable' do before do allow_any_instance_of(SolidusJwt::Token).to receive(:honor?).and_return false # rubocop:disable RSpec/AnyInstance end it { is_expected.to be :failure } end context 'when user is not valid for authentication' do before do allow_any_instance_of(Spree::User).to receive(:valid_for_authentication?).and_return(false) # rubocop:disable RSpec/AnyInstance end it { is_expected.to be :failure } end context 'when token is used more than once' do before { strategy.authenticate! } it { is_expected.to be :failure } end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
solidus_jwt-1.2.1 | spec/lib/solidus_jwt/devise_strategies/refresh_token_spec.rb |
solidus_jwt-1.2.0 | spec/lib/solidus_jwt/devise_strategies/refresh_token_spec.rb |