<commit_before>time = require 'time'
should = require('chai').Should()
helpers = require './helpers'

Alarm = require "#{helpers.prefix}server/models/alarm"

TESTPORT = 8889
TESTMAIL = '<EMAIL>'
TESTPASS = 'password'

describe 'Alarm manager handles alarms', ->

    before helpers.createUser TESTMAIL, TESTPASS
    before helpers.setup TESTPORT
    before ->
        @client = helpers.getClient TESTPORT, @
        @dataClient = helpers.getClient 9101, @

    before helpers.wait 2000
    before ->
        @counter = 0
        # console.log @app
        @noConflictHN = @app.alarmManager.handleNotification
        @app.alarmManager.handleNotification = =>
            @counter = @counter + 1
    after ->
        @app.alarmManager.handleNotification = @noConflictHN
    after helpers.takeDown


    it "When I create 3 Alarms", (done) ->

        now = new time.Date()
        oneDay = 24*60*60*1000

        alarm1 = new Alarm
            action: 'DISPLAY'
            trigg: new time.Date(now.getTime() + 2000)
            description: 'alarm1'

        alarm2 = new Alarm
            action: 'EMAIL'
            trigg: new time.Date(now.getTime() + 2500 - oneDay)
            rrule: 'FREQ=DAILY'
            description: 'alarm2'

        alarm3 = new Alarm
            action: 'BOTH'
            trigg: new time.Date(now.getTime() + 3000)
            description: 'alarm3'

        alarm1.save (err) ->
            return done err if err
            alarm2.save (err) ->
                return done err if err
                alarm3.save done


    it "Then I wait 10s", (done) ->
        @timeout 14000
        setTimeout done, 12000

    it "And handleNotification has been called 3 times", ->
        @counter.should.equal 3
<commit_msg>increase timeout for alarm tests<commit_after>time = require 'time'
should = require('chai').Should()
helpers = require './helpers'

Alarm = require "#{helpers.prefix}server/models/alarm"

TESTPORT = 8889
TESTMAIL = '<EMAIL>'
TESTPASS = 'password'

describe 'Alarm manager handles alarms', ->

    before helpers.createUser TESTMAIL, TESTPASS
    before helpers.setup TESTPORT
    before ->
        @client = helpers.getClient TESTPORT, @
        @dataClient = helpers.getClient 9101, @

    before helpers.wait 2000
    before ->
        @counter = 0
        # console.log @app
        @noConflictHN = @app.alarmManager.handleNotification
        @app.alarmManager.handleNotification = =>
            @counter = @counter + 1
    after ->
        @app.alarmManager.handleNotification = @noConflictHN
    after helpers.takeDown


    it "When I create 3 Alarms", (done) ->

        now = new time.Date()
        oneDay = 24*60*60*1000

        alarm1 = new Alarm
            action: 'DISPLAY'
            trigg: new time.Date(now.getTime() + 2000)
            description: 'alarm1'

        alarm2 = new Alarm
            action: 'EMAIL'
            trigg: new time.Date(now.getTime() + 2500 - oneDay)
            rrule: 'FREQ=DAILY'
            description: 'alarm2'

        alarm3 = new Alarm
            action: 'BOTH'
            trigg: new time.Date(now.getTime() + 3000)
            description: 'alarm3'

        alarm1.save (err) ->
            return done err if err
            alarm2.save (err) ->
                return done err if err
                alarm3.save done


    it "Then I wait 20s", (done) ->
        @timeout 22000
        setTimeout done, 20 * 1000

    it "And handleNotification has been called 3 times", ->
        @counter.should.equal 3

{'fraction_non_alphanumeric': 0.10321296559567814, 'fraction_numerical': 0.034404321865226045, 'mean_word_length': 1.9687763713080169, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 25, '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': '2454167', 'n_tokens_mistral': 1146, 'n_tokens_neox': 1034, 'n_words': 285}