import { PropertyQuestionsService, PropertyQuestion, isEligibilityStatus, isQuestion } from './PropertyQuestionsService'; import { UserDataState } from '../state/UserDataState'; import { expect } from 'chai'; describe('Property questions service', () => { let userDataState: UserDataState; let service: PropertyQuestionsService; beforeEach(() => { userDataState = {} as UserDataState; service = new PropertyQuestionsService(userDataState); }); it('should return the meters question for dual fuel', () => { userDataState.fuel = 'Dual'; expect(service.getFirstUnansweredQuestion()).to.have.property('id', 'MetersDiffFloor'); }); it('should return the storage heaters question for electricity', () => { userDataState.fuel = 'Electricity'; expect(service.getFirstUnansweredQuestion()).to.have.property('id', 'StorageHeaters'); }); it('should return the first unanswered question', () => { userDataState.fuel = 'Dual'; userDataState.metersDiffFloor = 'No'; expect(service.getFirstUnansweredQuestion()).to.have.property('id', 'GasBrownBox'); }); it('should set the answer and get the next question', () => { userDataState.fuel = 'Dual'; const firstQuestion = service.getFirstUnansweredQuestion() as PropertyQuestion; const nextQuestion = service.setAnswer(firstQuestion, "Yes"); expect(nextQuestion).to.have.property('id', 'InFlat'); }); it('should set the answer and get the eligibility status', () => { userDataState.fuel = 'Electricity'; const firstQuestion = service.getFirstUnansweredQuestion() as PropertyQuestion; expect(service.setAnswer(firstQuestion, 'Yes')).to.equal('PropertyNotEligible'); }); it('should return status if all the questions have been answered', () => { userDataState.fuel = 'Electricity'; userDataState.storageHeaters = 'Yes'; expect(service.getEligibilityStatus()).to.equal('PropertyNotEligible'); }); it('should return status undefined if the questions have not all been answered', () => { userDataState.fuel = 'Dual'; expect(service.getEligibilityStatus()).to.be.undefined; }); it('should check if a tree node is a question', () => { userDataState.fuel = 'Dual'; expect(isQuestion(service.getFirstUnansweredQuestion())).to.be.true; }); it('should check if a tree node is an eligibility status', () => { userDataState.fuel = 'Electricity'; userDataState.storageHeaters = 'Yes'; expect(isQuestion(service.getFirstUnansweredQuestion())).to.be.false; }); });