-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapi_steps.rb
More file actions
62 lines (52 loc) · 2.18 KB
/
api_steps.rb
File metadata and controls
62 lines (52 loc) · 2.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
When("I access the search API endpoint without any parameters") do
visit "/api/blocks/search"
@body = JSON.parse(page.source)
end
Then("the response is a list containing {int} block(s)") do |count|
expect(@body["results"].count).to eq(count.to_i)
end
Given(/^there are the following published content blocks:$/) do |table|
table.hashes.each_with_index do |hash, index|
hash["lead_organisation_id"] = Organisation.all.find { |org| org.name == hash["organisation"] }.id
hash["document"] = create(:document, block_type: hash["block_type"])
hash["created_at"] = index.days.ago
create(:edition, :published, **hash.except("block_type", "organisation"))
end
end
And(/^(one|another) block has the following attributes:$/) do |_, table|
expect(@body["results"]).to include(hash_including(table.hashes.first))
end
When("query the search API endpoint for block type {string}") do |block_type|
visit "/api/blocks/search?block_type=#{block_type}"
@body = JSON.parse(page.source)
end
When("I query the search API endpoint for the organisation {string}") do |organisation_name|
organisation = Organisation.all.find { |org| org.name == organisation_name }
visit "/api/blocks/search?lead_organisation_id=#{organisation.id}"
@body = JSON.parse(page.source)
end
When("I query the search API endpoint for the keyword {string}") do |keyword|
visit "/api/blocks/search?keyword=#{keyword}"
@body = JSON.parse(page.source)
end
Given(/^the API has been configured to return one result per page$/) do
stub_const("ContentBlock::Query::DEFAULT_PAGE_SIZE", 1)
end
When(/^I query the search API endpoint for the (first|second|third) page of results$/) do |ordinal|
page_number = { "first" => 1, "second" => 2, "third" => 3 }[ordinal]
visit "/api/blocks/search?page=#{page_number}"
@body = JSON.parse(page.source)
end
And(/^the pagination response has the following attributes:$/) do |table|
table.hashes.each do |hash|
expect(@body[hash["key"]].to_s).to eq(hash["value"])
end
end
And(/^the pagination response has the following links:$/) do |table|
table.hashes.each do |hash|
expect(@body["links"]).to include({
"rel" => hash["rel"],
"href" => hash["href"],
})
end
end