|
1 | 1 | RSpec.describe GovukTechDocs::Pages do |
2 | 2 | describe "#to_json" do |
3 | | - it "returns the pages as JSON" do |
| 3 | + it "returns the pages as JSON when using absolute links" do |
| 4 | + current_page = double(path: "/api/pages.json") |
4 | 5 | sitemap = double(resources: [ |
5 | 6 | double(url: "/a.html", data: double(title: "A thing", owner_slack: "#2ndline", last_reviewed_on: Date.yesterday, review_in: "0 days")), |
6 | 7 | double(url: "/b.html", data: double(title: "B thing", owner_slack: "#2ndline", last_reviewed_on: Date.yesterday, review_in: "2 days")), |
7 | 8 | ]) |
8 | 9 |
|
9 | | - json = described_class.new(sitemap, tech_docs: {}).to_json |
| 10 | + json = described_class.new(sitemap, {}, current_page).to_json |
10 | 11 |
|
11 | 12 | expect(JSON.parse(json)).to eql([ |
12 | 13 | { "title" => "A thing", "url" => "/a.html", "review_by" => Date.yesterday.to_s, "owner_slack" => "#2ndline" }, |
13 | 14 | { "title" => "B thing", "url" => "/b.html", "review_by" => Date.tomorrow.to_s, "owner_slack" => "#2ndline" }, |
14 | 15 | ]) |
15 | 16 | end |
| 17 | + |
| 18 | + it "returns the pages as JSON when using relative links" do |
| 19 | + current_page = double(path: "/api/pages.json") |
| 20 | + sitemap = double(resources: [ |
| 21 | + double(url: "/a.html", path: "/a.html", data: double(title: "A thing", owner_slack: "#2ndline", last_reviewed_on: Date.yesterday, review_in: "0 days")), |
| 22 | + 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")), |
| 23 | + ]) |
| 24 | + |
| 25 | + json = described_class.new(sitemap, { relative_links: true }, current_page).to_json |
| 26 | + |
| 27 | + expect(JSON.parse(json)).to eql([ |
| 28 | + { "title" => "A thing", "url" => "../a.html", "review_by" => Date.yesterday.to_s, "owner_slack" => "#2ndline" }, |
| 29 | + { "title" => "B thing", "url" => "../b/c.html", "review_by" => Date.tomorrow.to_s, "owner_slack" => "#2ndline" }, |
| 30 | + ]) |
| 31 | + end |
16 | 32 | end |
17 | 33 | end |
0 commit comments