UNPKG

easyplace

Version:

API to search for ceps, streets, neighborhoods and other places

69 lines (60 loc) 2.87 kB
describe("Testing Place class", () => { it("Should create an instance of Place class", () => { const place = new Place(); expect(place.getCep()).to.be.eql(undefined); expect(place.getCity()).to.be.eql(undefined); expect(place.getState()).to.be.eql(undefined); expect(place.getComplement()).to.be.eql(undefined); expect(place.getNeighborhood()).to.be.eql(undefined); }); it("Should create an instance with valid values", () => { const EXPECTED_CEP = "57055800"; const EXPECTED_STREET = "Rua Professora Eunice Lobao"; const EXPECTED_NEIGHBOURHOOD = "Pinheiro"; const EXPECTED_CITY = "Maceio"; const EXPECTED_STATE = "AL"; const EXPECTED_COMPLEMENT = "number 10"; const place = new Place(EXPECTED_CEP, EXPECTED_STREET, EXPECTED_COMPLEMENT, EXPECTED_NEIGHBOURHOOD, EXPECTED_CITY, EXPECTED_STATE); expect(place.getCep()).to.be.eql(EXPECTED_CEP); expect(place.getCity()).to.be.eql(EXPECTED_CITY); expect(place.getState()).to.be.eql(EXPECTED_STATE); expect(place.getComplement()).to.be.eql(EXPECTED_COMPLEMENT); expect(place.getNeighborhood()).to.be.eql(EXPECTED_NEIGHBOURHOOD); }); }); describe("Testing EasyPlace class", () => { it("Should get a valid address", async () => { const CEP = "57055800"; const EXPECTED_CEP = "57055-800"; const EXPECTED_STREET = "Rua Professora Eunice Lobao"; const EXPECTED_NEIGHBOURHOOD = "Pinheiro"; const EXPECTED_CITY = "Maceió"; const EXPECTED_STATE = "AL"; const EXPECTED_COMPLEMENT = ""; const easyPlace = new EasyPlace(); const address = await easyPlace.getAddressOfCep(CEP); expect(address.getCep()).to.be.eql(EXPECTED_CEP); expect(address.getCity()).to.be.eql(EXPECTED_CITY); expect(address.getState()).to.be.eql(EXPECTED_STATE); expect(address.getComplement()).to.be.eql(EXPECTED_COMPLEMENT); expect(address.getNeighborhood()).to.be.eql(EXPECTED_NEIGHBOURHOOD); }); it("Should make a search using fluent interface", async () => { const places = await new EasyPlace().searchStreetWithName(["eunice"]) .inCity("Maceio") .inState("AL") .inNeighborhood("Pinheiro") .search(); expect(places).to.not.be.eql([]); }); it("Should make a search for an invalid cep", async () => { try { const INVALID_CEP = "00000000"; await new EasyPlace().getAddressOfCep(INVALID_CEP); } catch (e) { expect(e.message).to.be.eql("Invalid CEP value."); } }); });