This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"status": 200, | |
"result": { | |
"postcode": "SW1A 1AA", | |
"quality": 1, | |
"eastings": 529090, | |
"northings": 179645, | |
"country": "England", | |
"nhs_ha": "London", | |
"longitude": -0.141587597876975, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var nock = require('nock'); | |
var request = require('supertest')("http://api.postcodes.io"); | |
var expect = require('chai').expect; | |
//used to read the JSON file | |
var fs = require("fs"); | |
describe("Testing API with a mocked backend", function () { | |
it("responds with json file response", function (done) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var nock = require('nock'); | |
var request = require('supertest')("http://api.postcodes.io"); | |
var expect = require('chai').expect; | |
describe("Testing API with a mocked backend", function () { | |
it("returns a successful mocked response", function (done) { | |
//override the mocha timeout in this test to 60 seconds |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var nock = require('nock'); | |
var request = require('supertest')("http://api.postcodes.io"); | |
var expect = require('chai').expect; | |
describe("Testing API with a mocked backend", function () { | |
it("returns a successful mocked response", function (done) { | |
//specify the url to be intercepted | |
nock("http://api.postcodes.io") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var request = require('supertest')("http://api.postcodes.io"); | |
var expect = require('chai').expect; | |
describe("Bulk post Code lookup", function () { | |
it("returns an array of post codes", function (done) { | |
request | |
.post('/postcodes') | |
.send({ | |
"postcodes": ["SW1A 0AA", "SW1A 0PW", "SW1A 1AA"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var request = require('supertest')("http://api.postcodes.io"); | |
var expect = require('chai').expect; | |
describe("Look up a specific post code", function () { | |
it("locates correct post code when given valid post code", function (done) { | |
request | |
.get('/postcodes/' + "SW1A 1AA") | |
.expect(200) | |
.end(function (err, res) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "supertester", | |
"version": "1.0.0", | |
"description": "example project to demonstrate super test library for integration tests", | |
"main": "index.js", | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1" | |
}, | |
"author": "TobyTheTester", | |
"license": "ISC", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var bodyParser = require('body-parser') | |
var express = require("express"); | |
var app = express(); | |
app.use(bodyParser.json()); | |
app.get('/postcodes', function (req, res) { | |
res.status(200).send({ postcode: 'SW1A 1AA' }) | |
}); |