-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TRG-128: Make /api/pages.json endpoint return relative links when the…
… sites is configured to use relative links.
- Loading branch information
Showing
3 changed files
with
23 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
<%= GovukTechDocs::Pages.new(sitemap, config).to_json %> | ||
<%= GovukTechDocs::Pages.new(sitemap, config, current_page).to_json %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,33 @@ | ||
RSpec.describe GovukTechDocs::Pages do | ||
describe "#to_json" do | ||
it "returns the pages as JSON" do | ||
it "returns the pages as JSON when using absolute links" do | ||
current_page = double(path: "/api/pages.json") | ||
sitemap = double(resources: [ | ||
double(url: "/a.html", data: double(title: "A thing", owner_slack: "#2ndline", last_reviewed_on: Date.yesterday, review_in: "0 days")), | ||
double(url: "/b.html", data: double(title: "B thing", owner_slack: "#2ndline", last_reviewed_on: Date.yesterday, review_in: "2 days")), | ||
]) | ||
|
||
json = described_class.new(sitemap, tech_docs: {}).to_json | ||
json = described_class.new(sitemap, {}, current_page).to_json | ||
|
||
expect(JSON.parse(json)).to eql([ | ||
{ "title" => "A thing", "url" => "/a.html", "review_by" => Date.yesterday.to_s, "owner_slack" => "#2ndline" }, | ||
{ "title" => "B thing", "url" => "/b.html", "review_by" => Date.tomorrow.to_s, "owner_slack" => "#2ndline" }, | ||
]) | ||
end | ||
|
||
it "returns the pages as JSON when using relative links" do | ||
current_page = double(path: "/api/pages.json") | ||
sitemap = double(resources: [ | ||
double(url: "/a.html", path: "/a.html", data: double(title: "A thing", owner_slack: "#2ndline", last_reviewed_on: Date.yesterday, review_in: "0 days")), | ||
double(url: "/b/c.html", path: "/b/c.html", data: double(title: "B thing", owner_slack: "#2ndline", last_reviewed_on: Date.yesterday, review_in: "2 days")), | ||
]) | ||
|
||
json = described_class.new(sitemap, {:relative_links => true}, current_page).to_json | ||
|
||
expect(JSON.parse(json)).to eql([ | ||
{ "title" => "A thing", "url" => "../a.html", "review_by" => Date.yesterday.to_s, "owner_slack" => "#2ndline" }, | ||
{ "title" => "B thing", "url" => "../b/c.html", "review_by" => Date.tomorrow.to_s, "owner_slack" => "#2ndline" }, | ||
]) | ||
end | ||
end | ||
end |