<file_sep>var expect = require('chai').expect;
var supertest = require('supertest');
var api = supertest('http://localhost:3000');

describe('get main endpoint', function () {

    it('responds with 200', function (done) {

        api.get('/')
            .expect(200)
            .end(function (err, res) {

                if (err) {
                    return done(err);
                }

                done();

            });
    });

});<file_sep>#!/usr/bin/env node

//imports
var express = require('express');
var bodyParser = require('body-parser');
var routes = require('./routes.js');
var mongoose = require('mongoose');

//instantiate express
var app = express();

//config
app.use(bodyParser.json({}));

//use routes to map URLs to handlers
app.use('/', routes);

//catch 404 and forwarding to error handler
app.use(function (req, res, next) {
    var err = new Error('Not Found');
    err.status = 404;
    next(err);
});

var mongoDB = 'mongodb://localhost:27017/test';
mongoose.connect(mongoDB);
var db = mongoose.connection;
mongoose.connection.on('error', console.error.bind(console, 'MongoDB connection error:'));

//set the application port
app.set('port', 3000);

//set the server
var server = app.listen(app.get('port'), function () {
    console.log('Express server listening on port ' + server.address().port);
});<file_sep>var async = require('async');

exports.defaultEndpoint = function (req, res) {


    var amountOfCats = function (callback) {

            var amount = Math.floor((Math.random() * 10) + 1);

            if (amount) {
                callback(null, amount);
            } else {
                callback('Error cat amount failed', null);
            }

    };

    var concatData = function (amount, callback) {

        var dataToReturn = 'Phil has ' + amount.toString() + ' cats!';

        if (dataToReturn) {
            callback(null, dataToReturn);
        } else {
            callback('Data to return failed to process', null);
        }

    };

    async.waterfall([amountOfCats, concatData], function (err, result) {

        if (err) {
            return res.status(500).json({message: err});
        }
        return res.status(200).json({message: result});

    });

};<file_sep>var mongoose = require('mongoose');

var Schema = mongoose.Schema;
var ObjectId = Schema.ObjectId;

var CatSchema = Schema({
    id: ObjectId,
    fluffiness: {
        type: Number,
        required: true
    }
});

exports.Cat = mongoose.model('Cat', CatSchema);<file_sep>var assert = require('chai').assert;
var CatService = require('../services/CatService.js');

describe('amount of cats', function () {

    it('returns value between 1 and 10', function (done) {

        var amountOfCats = CatService.amountOfCats();

        assert(amountOfCats > 0, 'amountOfCats greater than 0');
        assert(amountOfCats <= 10, 'amountOfCats less than 10');

        done();
    });

});

describe('fluffiness', function () {

    it('returns value between 1 and 10', function (done) {

        var fluffiness = CatService.fluffiness();

        assert(fluffiness > 0, 'fluffiness greater than 0');
        assert(fluffiness <= 10, 'fluffiness less than 10');

        done();
    });

});<file_sep>exports.amountOfCats = function () {
    return Math.floor((Math.random() * 10) + 1);
};

exports.fluffiness = function () {
    return Math.floor((Math.random() * 10) + 1);
};