From c0cc0ae0d4d0ef3225d6af5be4860e3d65de98c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Drga?= Date: Thu, 27 Jun 2024 00:27:55 +0200 Subject: [PATCH] Tests adjusted, for new feature in jobs --- spec/jobs/sync_all_topics_job_spec.rb | 13 +++++++++---- spec/jobs/sync_google_document_job_spec.rb | 1 - spec/jobs/sync_one_topic_job_spec.rb | 7 ++++--- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/spec/jobs/sync_all_topics_job_spec.rb b/spec/jobs/sync_all_topics_job_spec.rb index 3ca5bec..9f6d4a9 100644 --- a/spec/jobs/sync_all_topics_job_spec.rb +++ b/spec/jobs/sync_all_topics_job_spec.rb @@ -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 @@ -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 @@ -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 diff --git a/spec/jobs/sync_google_document_job_spec.rb b/spec/jobs/sync_google_document_job_spec.rb index cdf9773..4ed140a 100644 --- a/spec/jobs/sync_google_document_job_spec.rb +++ b/spec/jobs/sync_google_document_job_spec.rb @@ -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) diff --git a/spec/jobs/sync_one_topic_job_spec.rb b/spec/jobs/sync_one_topic_job_spec.rb index 434b2d2..f83135d 100644 --- a/spec/jobs/sync_one_topic_job_spec.rb +++ b/spec/jobs/sync_one_topic_job_spec.rb @@ -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 [ [], @@ -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 @@ -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