Skip to content

Commit

Permalink
Merge pull request #4 from DFE-Digital/correct-request-spec
Browse files Browse the repository at this point in the history
Correct request spec
  • Loading branch information
duncanjbrown authored May 17, 2022
2 parents 7c19241 + efd7da6 commit 66846b1
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions spec/requests/analytics_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
include DfE::Analytics::Requests

def index
Candidate.create(
model = Class.new(Candidate) do
include DfE::Analytics::Entities
end

model.create(
email_address: 'a@b.com',
first_name: 'Mr',
last_name: 'Knox'
Expand All @@ -23,12 +27,6 @@ def index
})
end

let(:model) do
Class.new(Candidate) do
include DfE::Analytics::Entities
end
end

around do |ex|
Rails.application.routes.draw do
get '/example/path' => 'test#index'
Expand All @@ -43,16 +41,17 @@ def index
end

it 'works end-to-end' do

request_event = { environment: 'test',
event_type: 'web_request',
request_method: 'GET',
request_path: '/example/path' }
request_event_post = stub_analytics_event_submission
request_event_post = stub_analytics_event_submission.with(body: /web_request/)

model_event = { environment: 'test',
event_type: 'create_entity',
entity_table_name: 'candidates' }
model_event_post = stub_analytics_event_submission
model_event_post = stub_analytics_event_submission.with(body: /create_entity/)

perform_enqueued_jobs do
get '/example/path'
Expand All @@ -71,7 +70,7 @@ def index
expect(model_event_post.with do |req|
body = JSON.parse(req.body)
payload = body['rows'].first['json']
expect(payload.except('occurred_at', 'request_uuid')).to match(a_hash_including(request_event.stringify_keys))
expect(payload.except('occurred_at', 'request_uuid')).to match(a_hash_including(model_event.stringify_keys))

expect(payload['request_uuid']).to eq(request_uuid)
end).to have_been_made
Expand All @@ -82,7 +81,7 @@ def index
with_analytics_config(queue: :my_custom_queue) do
expect {
get '/example/path'
}.to have_enqueued_job.on_queue(:my_custom_queue)
}.to have_enqueued_job.twice.on_queue(:my_custom_queue)
end
end
end
Expand All @@ -91,7 +90,7 @@ def index
it 'uses the default queue' do
expect {
get '/example/path'
}.to have_enqueued_job.on_queue(:default)
}.to have_enqueued_job.twice.on_queue(:default)
end
end
end

0 comments on commit 66846b1

Please sign in to comment.