{"size": 1975, "ext": "js", "max_stars_repo_path": "lib/__tests__/_use_case_scenarios_/case-3.test.js", "max_stars_repo_name": "gianDiazM/aircall-pager-test", "max_stars_repo_stars_event_min_datetime": "2021-09-17T11:58:01.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-17T11:58:01.000Z", "max_issues_repo_path": "lib/__tests__/_use_case_scenarios_/case-3.test.js", "max_issues_repo_name": "gianDiazM/aircall-pager-test", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "lib/__tests__/_use_case_scenarios_/case-3.test.js", "max_forks_repo_name": "gianDiazM/aircall-pager-test", "max_forks_repo_forks_event_min_datetime": "2021-11-24T06:47:26.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-24T06:47:26.000Z"}
{"max_stars_count": 1, "max_issues_count": null, "max_forks_count": 1, "avg_line_length": 35.9090909091, "max_line_length": 83, "alphanum_fraction": 0.6962025316}
const MockPagerDataSource = require('./__mocks__/mockPagerDataSource')
const MockEPDataSource = require('./__mocks__/mockEPDataSource')
const mockPagerDataSource = new MockPagerDataSource()
const mockEPDataSource = new MockEPDataSource()

jest.mock('../../services/sms')
jest.mock('../../services/timer')
jest.mock('../../../lib/dataSources/pager/PagerProvidersFactory', ()=>{
    return {
        getDataSourceProvider: ()=> mockPagerDataSource
    }
})
jest.mock('../../../lib/dataSources/escalationPolicy/EPProvidersFactory', ()=>{
    return {
        getDataSourceProvider: ()=> mockEPDataSource
    }
})
const pager = require("../../../lib/services/pager");
const sms = require('../../services/sms')
const epService = require('../../services/escalationPolicy')

/**
 Given a Monitored Service in an Unhealthy State
 when the Pager receives the Acknowledgement
 and later receives the Acknowledgement Timeout,
 then the Pager doesn't notify any Target
 and doesn't set an acknowledgement delay.
 */


describe(' Given a Monitored Service in an Unhealthy State\n' +
    ' when the Pager receives the Acknowledgement\n' +
    ' and later receives the Acknowledgement Timeout,', ()=>{
    const monitoredServiceId = 1
    const rightMessage= {monitoredServiceId, message: 'any-1'}
    beforeEach(()=>{
        // set Unhealthy State to service 1
        pager.processAlert(rightMessage)

        // pager receives the Acknowledgement ()
        pager.handleAcknowledged(monitoredServiceId)
        // reset mock
        sms.sendSMS.mockClear()
    })

    it('then the Pager doesn\'t notify any Target\n' +
        ' and doesn\'t set an acknowledgement delay.', ()=>{
        const escalationPolicy = epService.getPolicyByServiceId(monitoredServiceId)
        // When timeOut expires this notifyNextAvailableTargets is called
        pager.handleAcknowledgedTimeout(escalationPolicy)
        // Service is no called
        expect(sms.sendSMS).toBeCalledTimes(0)
    })
})
