Skip to content

Commit

Permalink
Add mocha based API tests
Browse files Browse the repository at this point in the history
  • Loading branch information
webprofusion-chrisc committed Jun 20, 2016
1 parent a18e9d8 commit 31ad606
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
55 changes: 55 additions & 0 deletions API/Testing/test/TestFetchPOILists.js
Original file line number Diff line number Diff line change
@@ -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.");
}
}));

}
10 changes: 10 additions & 0 deletions API/Testing/test/test.js
Original file line number Diff line number Diff line change
@@ -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));
});
});
});

0 comments on commit 31ad606

Please sign in to comment.