<commit_before>should = require('should')
async = require('async')
Client = require('request-json').JsonClient
instantiateApp = require('../server')
app = instantiateApp()

client = new Client "http://localhost:8888/"

helpers = null
describe "Alarms management", ->

    before ->
        app.listen 8888
        helpers = require("./helpers")(app.compound)

    after ->
        app.compound.server.close()

    describe "GET alarms/", ->

        before (done) ->
            initDb = (callback) ->
                async.series [
                    helpers.createAlarm "DISPLAY", "Something to remind", "20130410T1500Z"
                    helpers.createAlarm "EMAIL", "Something else to remind", "20130412T1630Z"
                ], ->
                    callback()
            helpers.cleanDb ->
                initDb done

        it "should return all the alarms in database", (done) ->
            client.get "alarms/", (error, response, body) ->

                should.not.exist error
                should.exist response
                should.exist body

                response.statusCode.should.equal 200
                body.length.should.equal 2
                done()

    describe "POST alarms/", ->

        before (done) ->
            helpers.cleanDb done
            @alarm =
                action: 'DISPLAY'
                trigg: '20130410T1500Z'
                description: 'Something to remind'

        it "should return the alarm json object", (done) ->

            client.post "alarms/", @alarm, (error, response, body) =>

                should.not.exist error
                should.exist response
                response.statusCode.should.equal 201
                should.exist body
                should.exist body.action
                should.exist body.trigg
                should.exist body.description

                body.action.should.equal @alarm.action
                body.trigg.should.equal @alarm.trigg
                body.description.should.equal @alarm.description

                done()

        it "should have persisted the alarm into database", (done) ->
            helpers.getAllAlarms (err, alarms) =>

                should.not.exist err
                should.exist alarms
                alarms.length.should.equal 1
                should.exist alarms[0].action
                should.exist alarms[0].trigg
                should.exist alarms[0].description
                alarms[0].action.should.equal @alarm.action
                alarms[0].trigg.should.equal @alarm.trigg
                alarms[0].description.should.equal @alarm.description
                done()

    describe "PUT alarms/:id", ->
        it "should return the alarm with the updated value"
        it "should have persisted the alarm into database"

    describe "DELETE alarms/:id", ->
        it "should return the deleted alarm"
        it "should have removed the alarm from the database"<commit_msg>Improved tests<commit_after>should = require('should')
async = require('async')
Client = require('request-json').JsonClient
instantiateApp = require('../server')
app = instantiateApp()

client = new Client "http://localhost:8888/"

helpers = null
describe "Alarms management", ->

    before ->
        app.listen 8888
        helpers = require("./helpers")(app.compound)

    after ->
        app.compound.server.close()

    describe "GET alarms/", ->

        before (done) ->
            initDb = (callback) ->
                async.series [
                    helpers.createAlarm "DISPLAY", "Something to remind", "20130410T1500Z"
                    helpers.createAlarm "EMAIL", "Something else to remind", "20130412T1630Z"
                ], ->
                    callback()
            helpers.cleanDb ->
                initDb done

        it "should return all the alarms in database", (done) ->
            client.get "alarms/", (error, response, body) ->

                should.not.exist error
                should.exist response
                should.exist body

                response.should.have.property 'statusCode'
                response.statusCode.should.equal 200
                body.length.should.equal 2
                done()

    describe "POST alarms/", ->

        before (done) =>
            helpers.cleanDb done
            @alarm =
                action: 'DISPLAY'
                trigg: '20130410T1500Z'
                description: 'Something to remind'

        it "should return the alarm json object", (done) =>

            client.post "alarms/", @alarm, (error, response, body) =>

                should.not.exist error
                should.exist response
                response.should.have.status 201
                should.exist body
                body.should.have.property 'action', @alarm.action
                body.should.have.property 'trigg', @alarm.trigg
                body.should.have.property 'description', @alarm.description

                done()

        it "should have persisted the alarm into database", (done) =>
            helpers.getAllAlarms (err, alarms) =>

                should.not.exist err
                should.exist alarms
                alarms.length.should.equal 1
                should.exist alarms[0]

                alarms[0].should.have.property 'action', @alarm.action
                alarms[0].should.have.property 'trigg', @alarm.trigg
                alarms[0].should.have.property 'description', @alarm.description

                done()

    describe "PUT alarms/:id", ->
        it "should return the alarm with the updated value"
        it "should have persisted the alarm into database"

    describe "DELETE alarms/:id", ->
        it "should return the deleted alarm"
        it "should have removed the alarm from the database"
{'fraction_non_alphanumeric': 0.10044874007594062, 'fraction_numerical': 0.019675526406627546, 'mean_word_length': 1.6245471014492754, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1513968', 'n_tokens_mistral': 1620, 'n_tokens_neox': 1421, 'n_words': 390}