summaryrefslogtreecommitdiff
path: root/spec/finders/projects/export_job_finder_spec.rb
blob: 1cc39e35e4dd0fb88f49732c2b4224744703b291 (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
46
47
48
49
50
51
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Projects::ExportJobFinder do
  let(:project) { create(:project) }
  let(:project_export_job1) { create(:project_export_job, project: project) }
  let(:project_export_job2) { create(:project_export_job, project: project) }

  describe '#execute' do
    subject { described_class.new(project, params).execute }

    context 'when queried for a project' do
      let(:params) { {} }

      it 'scopes to the project' do
        expect(subject).to contain_exactly(
          project_export_job1, project_export_job2
        )
      end
    end

    context 'when queried by job id' do
      let(:params) { { jid: project_export_job1.jid } }

      it 'filters records' do
        expect(subject).to contain_exactly(project_export_job1)
      end
    end

    context 'when queried by status' do
      let(:params) { { status: :started } }

      before do
        project_export_job2.start!
      end

      it 'filters records' do
        expect(subject).to contain_exactly(project_export_job2)
      end
    end

    context 'when queried by invalid status' do
      let(:params) { { status: '1234ad' } }

      it 'raises exception' do
        expect { subject }.to raise_error(described_class::InvalidExportJobStatusError, 'Invalid export job status')
      end
    end
  end
end