Welcome to mirror list, hosted at ThFree Co, Russian Federation.

service_access_token_spec.rb « ai « models « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 12ed24f3bd6a98a80c3432ebd9b36fed635c6dc6 (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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Ai::ServiceAccessToken, type: :model, feature_category: :application_performance do
  describe '.expired', :freeze_time do
    let_it_be(:expired_token) { create(:service_access_token, :code_suggestions, :expired) }
    let_it_be(:active_token) {  create(:service_access_token, :code_suggestions, :active) }

    it 'selects all expired tokens' do
      expect(described_class.expired).to match_array([expired_token])
    end
  end

  # There is currently only one category, please expand this test when a new category is added.
  describe '.for_category' do
    let(:code_suggestions_token) { create(:service_access_token, :code_suggestions) }
    let(:category) { :code_suggestions }

    it 'only selects tokens from the selected category' do
      expect(described_class.for_category(category)).to match_array([code_suggestions_token])
    end
  end

  describe '#token' do
    let(:token_value) { 'Abc' }

    it 'is encrypted' do
      subject.token = token_value

      aggregate_failures do
        expect(subject.encrypted_token_iv).to be_present
        expect(subject.encrypted_token).to be_present
        expect(subject.encrypted_token).not_to eq(token_value)
        expect(subject.token).to eq(token_value)
      end
    end

    describe 'validations' do
      it { is_expected.to validate_presence_of(:token) }
      it { is_expected.to validate_presence_of(:category) }
      it { is_expected.to validate_presence_of(:expires_at) }
    end
  end
end