| 
 | 1 | +'use strict'  | 
 | 2 | + | 
 | 3 | +// Test framework dependencies  | 
 | 4 | +const Lab = require('@hapi/lab')  | 
 | 5 | +const Code = require('@hapi/code')  | 
 | 6 | + | 
 | 7 | +const { describe, it, beforeEach } = (exports.lab = Lab.script())  | 
 | 8 | +const { expect } = Code  | 
 | 9 | + | 
 | 10 | +// Test helpers  | 
 | 11 | +const RecipientsFixture = require('../../../fixtures/recipients.fixtures.js')  | 
 | 12 | + | 
 | 13 | +// Thing under test  | 
 | 14 | +const CreateEventPresenter = require('../../../../app/presenters/notifications/setup/create-event.presenter.js')  | 
 | 15 | + | 
 | 16 | +describe('Notifications Setup - Event presenter', () => {  | 
 | 17 | +  let session  | 
 | 18 | +  let recipients  | 
 | 19 | + | 
 | 20 | +  beforeEach(async () => {  | 
 | 21 | +    recipients = RecipientsFixture.recipients()  | 
 | 22 | + | 
 | 23 | +    session = {  | 
 | 24 | +      returnsPeriod: 'quarterFour',  | 
 | 25 | +      removeLicences: [],  | 
 | 26 | +      journey: 'invitations',  | 
 | 27 | +      referenceCode: 'RINV-123',  | 
 | 28 | +      recipients: [...Object.values(recipients)],  | 
 | 29 | +      determinedReturnsPeriod: {  | 
 | 30 | +        dueDate: new Date(`2025-07-28`),  | 
 | 31 | +        endDate: new Date(`2025-06-30`),  | 
 | 32 | +        startDate: new Date(`2025-04-01`),  | 
 | 33 | +        summer: 'true'  | 
 | 34 | +      }  | 
 | 35 | +    }  | 
 | 36 | +  })  | 
 | 37 | + | 
 | 38 | +  it('correctly presents the data', () => {  | 
 | 39 | +    const result = CreateEventPresenter.go(session)  | 
 | 40 | + | 
 | 41 | +    expect(result).to.equal({  | 
 | 42 | +      licences: [  | 
 | 43 | +        recipients.primaryUser.licence_refs,  | 
 | 44 | +        recipients.returnsAgent.licence_refs,  | 
 | 45 | +        recipients.licenceHolder.licence_refs,  | 
 | 46 | +        recipients.returnsTo.licence_refs,  | 
 | 47 | +        ...recipients.licenceHolderWithMultipleLicences.licence_refs.split(',')  | 
 | 48 | +      ],  | 
 | 49 | +      metadata: {  | 
 | 50 | +        name: 'Returns: invitation',  | 
 | 51 | +        options: {  | 
 | 52 | +          excludeLicences: []  | 
 | 53 | +        },  | 
 | 54 | +        recipients: 5,  | 
 | 55 | +        returnCycle: {  | 
 | 56 | +          dueDate: session.determinedReturnsPeriod.dueDate,  | 
 | 57 | +          endDate: session.determinedReturnsPeriod.endDate,  | 
 | 58 | +          isSummer: 'true',  | 
 | 59 | +          startDate: session.determinedReturnsPeriod.startDate  | 
 | 60 | +        }  | 
 | 61 | +      },  | 
 | 62 | +      referenceCode: 'RINV-123',  | 
 | 63 | +      status: 'started',  | 
 | 64 | +      subtype: 'returnInvitation'  | 
 | 65 | +    })  | 
 | 66 | +  })  | 
 | 67 | + | 
 | 68 | +  describe('the "licences" property', () => {  | 
 | 69 | +    it('correctly return an array of all licence from all recipients', () => {  | 
 | 70 | +      const result = CreateEventPresenter.go(session)  | 
 | 71 | + | 
 | 72 | +      expect(result.licences).to.equal([  | 
 | 73 | +        recipients.primaryUser.licence_refs,  | 
 | 74 | +        recipients.returnsAgent.licence_refs,  | 
 | 75 | +        recipients.licenceHolder.licence_refs,  | 
 | 76 | +        recipients.returnsTo.licence_refs,  | 
 | 77 | +        ...recipients.licenceHolderWithMultipleLicences.licence_refs.split(',')  | 
 | 78 | +      ])  | 
 | 79 | +    })  | 
 | 80 | +  })  | 
 | 81 | + | 
 | 82 | +  describe('the "metadata" property', () => {  | 
 | 83 | +    describe('the "options.excludeLicences" property', () => {  | 
 | 84 | +      describe('when there licences excluded from the recipients list', () => {  | 
 | 85 | +        beforeEach(() => {  | 
 | 86 | +          session.removeLicences = ['123', '456']  | 
 | 87 | +        })  | 
 | 88 | + | 
 | 89 | +        it('correctly returns the exclude licences', () => {  | 
 | 90 | +          const result = CreateEventPresenter.go(session)  | 
 | 91 | + | 
 | 92 | +          expect(result.metadata.options.excludeLicences).to.equal(['123', '456'])  | 
 | 93 | +        })  | 
 | 94 | +      })  | 
 | 95 | + | 
 | 96 | +      describe('when there are no licences excluded from the recipients list', () => {  | 
 | 97 | +        beforeEach(() => {  | 
 | 98 | +          session.removeLicences = []  | 
 | 99 | +        })  | 
 | 100 | + | 
 | 101 | +        it('correctly returns the exclude licences', () => {  | 
 | 102 | +          const result = CreateEventPresenter.go(session)  | 
 | 103 | + | 
 | 104 | +          expect(result.metadata.options.excludeLicences).to.equal([])  | 
 | 105 | +        })  | 
 | 106 | +      })  | 
 | 107 | +    })  | 
 | 108 | + | 
 | 109 | +    describe('the "recipients" property', () => {  | 
 | 110 | +      beforeEach(() => {  | 
 | 111 | +        session.recipients = [...Object.values(recipients)]  | 
 | 112 | +      })  | 
 | 113 | + | 
 | 114 | +      it('correctly returns the length of recipients', () => {  | 
 | 115 | +        const result = CreateEventPresenter.go(session)  | 
 | 116 | + | 
 | 117 | +        expect(result.metadata.recipients).to.equal(5)  | 
 | 118 | +      })  | 
 | 119 | +    })  | 
 | 120 | + | 
 | 121 | +    describe('the "returnCycle" property', () => {  | 
 | 122 | +      beforeEach(() => {  | 
 | 123 | +        session.determinedReturnsPeriod = {  | 
 | 124 | +          dueDate: new Date(`2025-07-28`),  | 
 | 125 | +          endDate: new Date(`2025-06-30`),  | 
 | 126 | +          startDate: new Date(`2025-04-01`),  | 
 | 127 | +          summer: 'true'  | 
 | 128 | +        }  | 
 | 129 | +      })  | 
 | 130 | + | 
 | 131 | +      it('correctly returns the return cycle', () => {  | 
 | 132 | +        const result = CreateEventPresenter.go(session)  | 
 | 133 | + | 
 | 134 | +        expect(result.metadata.returnCycle).to.equal({  | 
 | 135 | +          dueDate: session.determinedReturnsPeriod.dueDate,  | 
 | 136 | +          endDate: session.determinedReturnsPeriod.endDate,  | 
 | 137 | +          isSummer: 'true',  | 
 | 138 | +          startDate: session.determinedReturnsPeriod.startDate  | 
 | 139 | +        })  | 
 | 140 | +      })  | 
 | 141 | +    })  | 
 | 142 | +  })  | 
 | 143 | + | 
 | 144 | +  describe('when the journey is for "invitations"', () => {  | 
 | 145 | +    beforeEach(() => {  | 
 | 146 | +      session.journey = 'invitations'  | 
 | 147 | +    })  | 
 | 148 | + | 
 | 149 | +    it('correctly sets the "metadata.name"', () => {  | 
 | 150 | +      const result = CreateEventPresenter.go(session)  | 
 | 151 | + | 
 | 152 | +      expect(result.metadata.name).to.equal('Returns: invitation')  | 
 | 153 | +    })  | 
 | 154 | + | 
 | 155 | +    it('correctly sets the "subtype"', () => {  | 
 | 156 | +      const result = CreateEventPresenter.go(session)  | 
 | 157 | + | 
 | 158 | +      expect(result.subtype).to.equal('returnInvitation')  | 
 | 159 | +    })  | 
 | 160 | +  })  | 
 | 161 | + | 
 | 162 | +  describe('when the journey is for "reminders"', () => {  | 
 | 163 | +    beforeEach(() => {  | 
 | 164 | +      session.journey = 'reminders'  | 
 | 165 | +    })  | 
 | 166 | + | 
 | 167 | +    it('correctly sets the "metadata.name"', () => {  | 
 | 168 | +      const result = CreateEventPresenter.go(session)  | 
 | 169 | + | 
 | 170 | +      expect(result.metadata.name).to.equal('Returns: reminder')  | 
 | 171 | +    })  | 
 | 172 | + | 
 | 173 | +    it('correctly sets the "subtype"', () => {  | 
 | 174 | +      const result = CreateEventPresenter.go(session)  | 
 | 175 | + | 
 | 176 | +      expect(result.subtype).to.equal('returnReminder')  | 
 | 177 | +    })  | 
 | 178 | +  })  | 
 | 179 | + | 
 | 180 | +  describe('when the journey is not recognised', () => {  | 
 | 181 | +    beforeEach(() => {  | 
 | 182 | +      session.journey = ''  | 
 | 183 | +    })  | 
 | 184 | + | 
 | 185 | +    it('correctly sets the "metadata.name"', () => {  | 
 | 186 | +      const result = CreateEventPresenter.go(session)  | 
 | 187 | + | 
 | 188 | +      expect(result.metadata.name).to.equal('')  | 
 | 189 | +    })  | 
 | 190 | + | 
 | 191 | +    it('correctly sets the "subtype"', () => {  | 
 | 192 | +      const result = CreateEventPresenter.go(session)  | 
 | 193 | + | 
 | 194 | +      expect(result.subtype).to.equal('')  | 
 | 195 | +    })  | 
 | 196 | +  })  | 
 | 197 | +})  | 
0 commit comments