diff --git a/API/Testing/test/TestFetchPOILists.js b/API/Testing/test/TestFetchPOILists.js new file mode 100644 index 0000000..7c6c639 --- /dev/null +++ b/API/Testing/test/TestFetchPOILists.js @@ -0,0 +1,55 @@ +var supertest = require("supertest"); +var should = require("should"); +var assert = require("assert"); + +var server = supertest.agent("http://api.openchargemap.io"); +//var server = supertest.agent("http://localhost:8080"); + +// Begin Tests + +describe("Fetch POI List via API V0", function () { + it("Return a list of 5 US based POIs", function (done) { + testFetchPOIList("/?output=json&countrycode=US&maxresults=" + 5, 5, 2) + .expect(200, done); // complete test (HTTP Status 200 OK) + }); +}); + +describe("Fetch POI List via API V1", function () { + it("Return a list of 5 US based POIs", function (done) { + testFetchPOIList("/v1/?output=json&countrycode=US&maxresults=" + 5, 5, 2) + .expect(200, done); + }); +}); + +describe("Fetch POI List via API V2", function () { + it("Return a list of 5 GB based POIs", function (done) { + testFetchPOIList("/v2/poi/?output=json&countrycode=GB&maxresults=" + 5, 5, 1) + .expect(200, done); + }); +}); + +describe("Fetch POI List via API V3", function () { + it("Return a list of 5 US based POIs", function (done) { + testFetchPOIList("/v3/poi/?output=json&countrycode=US&maxresults=" + 5, 5, 2) + .expect(200, done); + }); +}); + +/////////////////// Test Helpers /////////////////////////// +function testFetchPOIList(apiParams, expectedNumPOIs, expectedCountryID) { + + return (server + .get(apiParams) + .expect("Content-type", /json/) + + .expect(function (res) { + + assert(res.body.length == expectedNumPOIs, "Did not get the required number of POIs."); + assert(res.body[0].AddressInfo != null, "POI should have an AddressInfo."); + + if (expectedCountryID != null) { + assert(res.body[0].AddressInfo.CountryID == expectedCountryID, "POI does not match expected country."); + } + })); + +} \ No newline at end of file diff --git a/API/Testing/test/test.js b/API/Testing/test/test.js new file mode 100644 index 0000000..5031be0 --- /dev/null +++ b/API/Testing/test/test.js @@ -0,0 +1,10 @@ +var assert = require('chai').assert; + +describe('Array', function() { + describe('#indexOf()', function () { + it('should return -1 when the value is not present', function () { + assert.equal(-1, [1,2,3].indexOf(5)); + assert.equal(-1, [1,2,3].indexOf(0)); + }); + }); +}); \ No newline at end of file