Sha256: 3c674588b2f13e3b97a93e46c81cd81c791e8912dd9e5954a8190dab8b4c6fe8

Contents?: true

Size: 1 KB

Versions: 1

Compression:

Stored size: 1 KB

Contents

# frozen_string_literal: true

require 'spec_helper'

RSpec.describe SolidusJwt::Token, type: :model do
  subject { instance }

  let(:instance) { FactoryBot.create(:token) }

  it { is_expected.to be_valid }
  it { is_expected.to be_active }
  it { is_expected.not_to be_expired }

  context 'when token is nil' do
    let(:instance) { FactoryBot.build(:token, token: nil) }

    it 'generates one automatically' do
      aggregate_failures do
        expect(instance.token).to be_nil
        instance.save
        expect(instance.token).to be_present
      end
    end
  end

  describe '.honor?' do
    subject { described_class.honor?(token) }

    let(:token) { instance.token }

    it { is_expected.to be true }

    context 'when token is inactive' do
      let(:instance) { FactoryBot.create(:token, :inactive) }

      it { is_expected.to be false }
    end

    context 'when token is expired' do
      let(:instance) { FactoryBot.create(:token, :expired) }

      it { is_expected.to be false }
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
solidus_jwt-1.2.2 spec/models/solidus_jwt/token_spec.rb