Skip to content

Commit

Permalink
Merge pull request #29 from salesforce/add-test-for-async-jobs
Browse files Browse the repository at this point in the history
Job tests
  • Loading branch information
vswamidass-sfdc authored May 7, 2024
2 parents e9e3ceb + 9a0c791 commit b277b75
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
8 changes: 8 additions & 0 deletions spec/controllers/documents_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@
end
end

context 'when the document saves successfully' do
it 'enqueues an EmbedDocumentJob' do
expect {
post :create, params: { document: valid_attributes }
}.to have_enqueued_job(EmbedDocumentJob).on_queue('default')
end
end

context 'with a new external ID' do
it 'creates a new Document with the given external ID' do
expect do
Expand Down
8 changes: 8 additions & 0 deletions spec/controllers/questions_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@
end
end

context 'when the question saves successfully' do
it 'enqueues an GenerateAnswerJob' do
expect {
post :create, params: { question: valid_attributes }
}.to have_enqueued_job(GenerateAnswerJob).on_queue('default')
end
end

context 'with invalid params' do
it 'fails to create' do
post :create, params: { question: invalid_attributes }
Expand Down
4 changes: 4 additions & 0 deletions spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@
RSpec.configure do |config|
config.include AuthHelpers, type: :controller

config.before(:each) do
ActiveJob::Base.queue_adapter = :test
end

# Include FactoryBot syntax to simplify calls to factories
config.include FactoryBot::Syntax::Methods

Expand Down

0 comments on commit b277b75

Please sign in to comment.