|
72 | 72 | end
|
73 | 73 | end
|
74 | 74 | end
|
| 75 | + |
| 76 | + describe "local authority slugs" do |
| 77 | + context "when the slug is not found" |
| 78 | + before { stub_local_links_manager_does_not_have_an_authority("foo") } |
| 79 | + |
| 80 | + it "returns a 404 if the slug is not found" do |
| 81 | + get "/api/local-authority/foo" |
| 82 | + |
| 83 | + expect(response).to have_http_status(:not_found) |
| 84 | + end |
| 85 | + |
| 86 | + context "when the slug points to a unitary authority" do |
| 87 | + before { stub_local_links_manager_has_a_local_authority("westminster") } |
| 88 | + |
| 89 | + it "returns the authority with no parent and tier set to unitary" do |
| 90 | + get "/api/local-authority/westminster" |
| 91 | + |
| 92 | + expect(response).to have_http_status(:ok) |
| 93 | + expect(response.parsed_body).to eq({ |
| 94 | + "local_authority" => { |
| 95 | + "name" => "Westminster", |
| 96 | + "homepage_url" => "http://westminster.example.com", |
| 97 | + "tier" => "unitary", |
| 98 | + "slug" => "westminster", |
| 99 | + }, |
| 100 | + }) |
| 101 | + end |
| 102 | + end |
| 103 | + |
| 104 | + context "when the slug points to a district authority" do |
| 105 | + before { stub_local_links_manager_has_a_district_and_county_local_authority("aylesbury", "buckinghamshire") } |
| 106 | + |
| 107 | + it "returns the authority with the parent and tier set to district" do |
| 108 | + get "/api/local-authority/aylesbury" |
| 109 | + |
| 110 | + expect(response).to have_http_status(:ok) |
| 111 | + expect(response.parsed_body).to eq({ |
| 112 | + "local_authority" => { |
| 113 | + "name" => "Aylesbury", |
| 114 | + "homepage_url" => "http://aylesbury.example.com", |
| 115 | + "tier" => "district", |
| 116 | + "slug" => "aylesbury", |
| 117 | + "parent" => { |
| 118 | + "name" => "Buckinghamshire", |
| 119 | + "homepage_url" => "http://buckinghamshire.example.com", |
| 120 | + "tier" => "county", |
| 121 | + "slug" => "buckinghamshire", |
| 122 | + }, |
| 123 | + }, |
| 124 | + }) |
| 125 | + end |
| 126 | + end |
| 127 | + end |
75 | 128 | end
|
0 commit comments