summaryrefslogtreecommitdiff
path: root/spec/models/token_with_iv_spec.rb
blob: 8dbccc192173077a586006d71331313fb2460fd6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe TokenWithIv do
  describe 'validations' do
    it { is_expected.to validate_presence_of :hashed_token }
    it { is_expected.to validate_presence_of :iv }
    it { is_expected.to validate_presence_of :hashed_plaintext_token }
  end

  describe '.find_by_hashed_token' do
    it 'only includes matching record' do
      matching_record = create(:token_with_iv, hashed_token: ::Digest::SHA256.digest('hashed-token'))
      create(:token_with_iv)

      expect(described_class.find_by_hashed_token('hashed-token')).to eq(matching_record)
    end
  end

  describe '.find_by_plaintext_token' do
    it 'only includes matching record' do
      matching_record = create(:token_with_iv, hashed_plaintext_token: ::Digest::SHA256.digest('hashed-token'))
      create(:token_with_iv)

      expect(described_class.find_by_plaintext_token('hashed-token')).to eq(matching_record)
    end
  end
end