Browse Source

Update Postcode service related spec

CLDC-1468-add-postcode-to-sales-property-info-journey
Mo Seedat 2 years ago
parent
commit
2957ee3d19
  1. 6
      app/services/postcode_service.rb
  2. 8
      spec/request_helper.rb
  3. 22
      spec/services/postcode_service_spec.rb

6
app/services/postcode_service.rb

@ -22,9 +22,9 @@ class PostcodeService
OpenStruct.new({ OpenStruct.new({
location_code: postcode_lookup.codes["admin_district"], location_code: postcode_lookup.codes["admin_district"],
location_admin_district: postcode_lookup&.admin_district, location_admin_district: postcode_lookup&.admin_district,
incode: postcode_lookup.incode, incode: postcode_lookup&.incode,
outcode: postcode_lookup.outcode, outcode: postcode_lookup&.outcode,
result?: postcode_lookup.outcode.present?, result?: postcode_lookup&.outcode&.present?,
}) })
end end
end end

8
spec/request_helper.rb

@ -7,13 +7,13 @@ module RequestHelper
.to_return(status: 200, body: "{\"status\":404,\"error\":\"Postcode not found\"}", headers: {}) .to_return(status: 200, body: "{\"status\":404,\"error\":\"Postcode not found\"}", headers: {})
WebMock.stub_request(:get, "https://api.postcodes.io/postcodes/AA11AA") WebMock.stub_request(:get, "https://api.postcodes.io/postcodes/AA11AA")
.to_return(status: 200, body: "{\"status\":200,\"result\":{\"postcode\":\"AA1 1AA\",\"admin_district\":\"Westminster\",\"codes\":{\"admin_district\":\"E09000033\"}}}", headers: {}) .to_return(status: 200, body: "{\"status\":200,\"result\":{\"postcode\":\"AA1 1AA\", \"outcode\": \"AA1\", \"incode\": \"1AA\", \"admin_district\":\"Westminster\",\"codes\":{\"admin_district\":\"E09000033\"}}}", headers: {})
WebMock.stub_request(:get, "https://api.postcodes.io/postcodes/AA12AA") WebMock.stub_request(:get, "https://api.postcodes.io/postcodes/AA12AA")
.to_return(status: 200, body: "{\"status\":200,\"result\":{\"postcode\":\"AA1 2AA\",\"admin_district\":\"Westminster\",\"codes\":{\"admin_district\":\"E09000033\"}}}", headers: {}) .to_return(status: 200, body: "{\"status\":200,\"result\":{\"postcode\":\"AA1 2AA\", \"outcode\": \"AA1\", \"incode\": \"2AA\", \"admin_district\":\"Westminster\",\"codes\":{\"admin_district\":\"E09000033\"}}}", headers: {})
WebMock.stub_request(:get, "https://api.postcodes.io/postcodes/NW1L5DP") WebMock.stub_request(:get, "https://api.postcodes.io/postcodes/NW1L5DP")
.to_return(status: 200, body: "{\"status\":200,\"result\":{\"postcode\":\"NW1L 5DP\",\"admin_district\":\"Westminster\",\"codes\":{\"admin_district\":\"E09000033\"}}}", headers: {}) .to_return(status: 200, body: "{\"status\":200,\"result\":{\"postcode\":\"NW1L 5DP\", \"outcode\": \"NW1L\", \"incode\": \"5DP\", \"admin_district\":\"Westminster\",\"codes\":{\"admin_district\":\"E09000033\"}}}", headers: {})
WebMock.stub_request(:get, "https://api.postcodes.io/postcodes/ZZ11ZZ") WebMock.stub_request(:get, "https://api.postcodes.io/postcodes/ZZ11ZZ")
.to_return(status: 200, body: "{\"status\":200,\"result\":{\"postcode\":\"ZZ1 1ZZ\",\"admin_district\":\"Westminster\",\"codes\":{\"admin_district\":\"E09000033\"}}}", headers: {}) .to_return(status: 200, body: "{\"status\":200,\"result\":{\"postcode\":\"ZZ1 1ZZ\", \"outcode\": \"ZZ1\", \"incode\": \"1ZZ\", \"admin_district\":\"Westminster\",\"codes\":{\"admin_district\":\"E09000033\"}}}", headers: {})
WebMock.stub_request(:post, /api.notifications.service.gov.uk\/v2\/notifications\/email/) WebMock.stub_request(:post, /api.notifications.service.gov.uk\/v2\/notifications\/email/)
.to_return(status: 200, body: "", headers: {}) .to_return(status: 200, body: "", headers: {})

22
spec/services/postcode_service_spec.rb

@ -6,4 +6,26 @@ describe PostcodeService do
it "returns clean postcode" do it "returns clean postcode" do
expect(described_class.clean(postcode)).to eq "SR81LS" expect(described_class.clean(postcode)).to eq "SR81LS"
end end
describe "#lookup" do
context "with valid postcode" do
subject(:result) { described_class.new.lookup("AA11AA") }
it "returns hash" do
expect(result[:location_code]).to eq("E09000033")
expect(result[:location_admin_district]).to eq("Westminster")
expect(result[:outcode]).to eq("AA1")
expect(result[:incode]).to eq("1AA")
expect(result[:result?]).to be true
end
it "returns object" do
expect(result.location_code).to eq("E09000033")
expect(result.location_admin_district).to eq("Westminster")
expect(result.outcode).to eq("AA1")
expect(result.incode).to eq("1AA")
expect(result.result?).to be true
end
end
end
end end

Loading…
Cancel
Save