Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct request spec #4

Merged
merged 1 commit into from
May 17, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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