Skip to content

Commit

Permalink
Tests adjusted, for new feature in jobs
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasdrga committed Jun 26, 2024
1 parent 28681b1 commit c0cc0ae
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
13 changes: 9 additions & 4 deletions spec/jobs/sync_all_topics_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,20 @@
[],
['Projekt', 'Projekt ID', 'Platforma', 'ID draft prípravy', 'ID prípravy', 'ID draft produktu', 'ID produktu'],
['Projekt1', 'ABC1', '', 'ABC1', 'ABC1', 'ABC1', 'ABC1'],
['Projekt2', 'ABC2', 'http://google.com', 'ABC2', 'ABC2', 'ABC2', 'ABC2']
['Projekt2', 'ABC2', '', 'ABC2', 'ABC2', 'ABC2', 'ABC2']
]
end

let(:indices) { { 'Projekt' => 0, 'Projekt ID' => 1, 'Platforma' => 2, 'ID draft prípravy' => 3, 'ID prípravy' => 4, 'ID draft produktu' => 5, 'ID produktu' => 6 } }

before do
allow(Google::Auth::ServiceAccountCredentials).to receive(:make_creds).and_return(instance_double(Google::Auth::ServiceAccountCredentials))
mock_document = instance_double("Google::Apis::DocsV1::Document")
allow(mock_document).to receive(:title).and_return("Dokument RF-priprava-template")
allow(GoogleApiService).to receive(:get_document).and_return(mock_document)
google_sheets_service = instance_double(Google::Apis::SheetsV4::SheetsService)
allow(GoogleApiService).to receive(:get_sheets_service).and_return(google_sheets_service)
allow(google_sheets_service).to receive(:get_spreadsheet_values).with(ENV.fetch('GOOGLE_SHEET_ID'), 'A:Z').and_return(OpenStruct.new(values: response_values))
allow(mock_document).to receive(:body)
end

it 'queues the job' do
Expand All @@ -31,8 +34,9 @@
end

it 'executes perform' do
expect(SyncGoogleDocumentJob).to receive(:perform_now).exactly(4).times

described_class.perform_now
expect(ActiveJob::Base.queue_adapter.enqueued_jobs.size).to eq 4
end

context 'when mandatory columns are missing' do
Expand Down Expand Up @@ -79,8 +83,9 @@
end

it 'enqueues SyncGoogleDocumentJob' do
expect(SyncGoogleDocumentJob).to receive(:perform_now).exactly(3).times

described_class.perform_now
expect(ActiveJob::Base.queue_adapter.enqueued_jobs.map { |j| j[:job] }).to include(SyncGoogleDocumentJob)
end
end
end
1 change: 0 additions & 1 deletion spec/jobs/sync_google_document_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
let(:parsed_hash) { {content: 'Parsed content'} }
let(:page) { create(:page) }
let(:revision) { create(:revision) }
let(:revision) { create(:revision) }

before do
allow(Page).to receive_message_chain(:find_or_create_by!).and_return(page)
Expand Down
7 changes: 4 additions & 3 deletions spec/jobs/sync_one_topic_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
subject(:job) { described_class.perform_later(page_id) }

let(:page_id) { 'ABC1' }
let(:sheets_service) { instance_double('GoogleApiService') }
let(:response_values) do
[
[],
Expand All @@ -22,9 +21,11 @@
let(:indices) { { 'Projekt' => 0, 'Projekt ID' => 1, 'Platforma' => 2, 'ID draft prípravy' => 3, 'ID prípravy' => 4, 'ID draft produktu' => 5, 'ID produktu' => 6 } }

before do
allow(Google::Auth::ServiceAccountCredentials).to receive(:make_creds).and_return(instance_double(Google::Auth::ServiceAccountCredentials))
google_sheets_service = instance_double(Google::Apis::SheetsV4::SheetsService)
allow(GoogleApiService).to receive(:get_sheets_service).and_return(google_sheets_service)
mock_document = instance_double("Google::Apis::DocsV1::Document")
allow(mock_document).to receive(:title).and_return("Dokument RF-priprava-template")
allow(GoogleApiService).to receive(:get_document).and_return(mock_document)
allow(google_sheets_service).to receive(:get_spreadsheet_values).with(ENV.fetch('GOOGLE_SHEET_ID'), 'A:Z').and_return(OpenStruct.new(values: response_values))
end

Expand All @@ -35,8 +36,8 @@
end

it 'executes perform' do
expect(SyncGoogleDocumentJob).to receive(:perform_now)
described_class.perform_now(page_id)
expect(ActiveJob::Base.queue_adapter.enqueued_jobs.map { |j| j[:job] }).to include(SyncGoogleDocumentJob)
end

context 'when performing the job' do
Expand Down

0 comments on commit c0cc0ae

Please sign in to comment.