Skip to content

Commit

Permalink
clean up importing document paths + move tests
Browse files Browse the repository at this point in the history
  • Loading branch information
velimd committed Oct 11, 2024
1 parent 005f86a commit df801f5
Show file tree
Hide file tree
Showing 10 changed files with 90 additions and 71 deletions.
4 changes: 2 additions & 2 deletions src/main/features/claim-documents/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as express from 'express'
import * as path from 'path'

import { Paths } from 'claim/paths'
import { Paths } from 'claim-documents/paths'

import { AuthorizationMiddleware } from 'idam/authorizationMiddleware'
import { RouterFinder } from 'shared/router/routerFinder'
Expand All @@ -25,7 +25,7 @@ function claimIssueRequestHandler (): express.RequestHandler {
export class Feature {
enableFor (app: express.Express) {
if (app.settings.nunjucksEnv && app.settings.nunjucksEnv.globals) {
app.settings.nunjucksEnv.globals.ClaimPaths = Paths
app.settings.nunjucksEnv.globals.ClaimDocumentsPaths = Paths
}

app.all('/claim/*', claimIssueRequestHandler())
Expand Down
4 changes: 2 additions & 2 deletions src/main/features/claim/views/macro/claim-confirmation.njk
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<h1 class="bold-large">{{ claim.claimNumber }}</h1>
</div>
<p class="receipt-download-container">
{{ internalLink(t('Download your claim form'), ClaimPaths.receiptReceiver.evaluateUri({ externalId: claim.externalId})) }}
{{ internalLink(t('Download your claim form'), ClaimDocumentsPaths.receiptReceiver.evaluateUri({ externalId: claim.externalId})) }}
</p>
</div>
<h2 class="heading-medium">{{ t('What happens next') }}</h2>
Expand All @@ -24,4 +24,4 @@

<h2 class="heading-medium">{{ t('If the defendant pays you') }}</h2>
<p>{{ t('You need to sign in to your account to tell us you’ve been paid.') }}</p>
{% endmacro %}
{% endmacro %}
4 changes: 2 additions & 2 deletions src/main/features/dashboard/views/claimant.njk
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
{% endif %}
{% endset %}
<p>
{{ internalLink(document.documentDisplayName + pdfText, ClaimPaths.documentPage.evaluateUri({ externalId: claim.externalId, documentURI: document.uri })) }}
{{ internalLink(document.documentDisplayName + pdfText, ClaimDocumentsPaths.documentPage.evaluateUri({ externalId: claim.externalId, documentURI: document.uri })) }}
<br>
<span style="color:grey; font-size: 15px">
Created: {{ document.createdDatetime.format('LL') }}
Expand All @@ -55,7 +55,7 @@
{% elseif(claim) %}
<p>
{% if claim.state !== 'HWF_APPLICATION_PENDING' and claim.state !== 'AWAITING_RESPONSE_HWF' %}
{{ internalLink('Download claim (PDF)', ClaimPaths.documentPage.evaluateUri({ externalId: claim.externalId, documentURI: 'claim-receipt' })) }}
{{ internalLink('Download claim (PDF)', ClaimDocumentsPaths.documentPage.evaluateUri({ externalId: claim.externalId, documentURI: 'claim-receipt' })) }}
{% else %}
{{ internalLink(t('Download claim (PDF)'), ClaimPaths.draftReceiptReceiver.evaluateUri({ externalId: claim.externalId})) }}
{% endif %}
Expand Down
4 changes: 2 additions & 2 deletions src/main/features/dashboard/views/defendant.njk
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
{% endif %}
{% endset %}
<p>
{{ internalLink(document.documentDisplayName + pdfText, ClaimPaths.documentPage.evaluateUri({ externalId: claim.externalId, documentURI: document.uri })) }}
{{ internalLink(document.documentDisplayName + pdfText, ClaimDocumentsPaths.documentPage.evaluateUri({ externalId: claim.externalId, documentURI: document.uri })) }}
<br>
<span style="color:grey; font-size: 15px">
Created: {{ document.createdDatetime.format('LL') }}
Expand All @@ -43,7 +43,7 @@
{% endfor %}
{% elseif(claim) %}
<p>
{{ internalLink('Download claim (PDF)', ClaimPaths.documentPage.evaluateUri({ externalId: claim.externalId, documentURI: 'claim-receipt' })) }}
{{ internalLink('Download claim (PDF)', ClaimDocumentsPaths.documentPage.evaluateUri({ externalId: claim.externalId, documentURI: 'claim-receipt' })) }}
<br>
<span style="color:grey; font-size: 15px">
Created: {{ claim.createdAt.format('LL') }}
Expand Down
4 changes: 2 additions & 2 deletions src/main/features/response/routes/claim-details.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as express from 'express'
import { Paths } from 'response/paths'
import { Paths as ClaimPaths } from 'claim/paths'
import { Paths as ClaimDocumentsPaths } from 'claim-documents/paths'
import { Claim } from 'claims/models/claim'
import { getInterestDetails } from 'shared/interestUtils'
import { ErrorHandling } from 'shared/errorHandling'
Expand All @@ -27,7 +27,7 @@ export default express.Router()
res.render(Paths.claimDetailsPage.associatedView, {
interestData: interestData,
numOfDayInYear: numOfDaysInYear,
pdfUrl: isCurrentUserLinkedToClaim(res.locals.user, res.locals.claim) ? ClaimPaths.sealedClaimPdfReceiver : ClaimPaths.receiptReceiver
pdfUrl: isCurrentUserLinkedToClaim(res.locals.user, res.locals.claim) ? ClaimDocumentsPaths.sealedClaimPdfReceiver : ClaimDocumentsPaths.receiptReceiver
})
})
)
7 changes: 4 additions & 3 deletions src/test/a11y/a11y.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { expect } from 'chai'
import { RoutablePath } from 'shared/router/routablePath'
import { Paths as EligibilityPaths } from 'eligibility/paths'
import { ErrorPaths as ClaimIssueErrorPaths, Paths as ClaimIssuePaths } from 'claim/paths'
import { Paths as ClaimDocumentsPaths } from 'claim-documents/paths'
import { ErrorPaths as DefendantFirstContactErrorPaths, Paths as DefendantFirstContactPaths } from 'first-contact/paths'
import { FullAdmissionPaths, Paths, Paths as DefendantResponsePaths, StatementOfMeansPaths } from 'response/paths'
import { Paths as ClaimantResponsePaths } from 'claimant-response/paths'
Expand Down Expand Up @@ -132,12 +133,12 @@ function ensureNoAccessibilityAlerts (issueType: string, issues: Issue[]): void

const excludedPaths: Paths[] = [
ClaimIssuePaths.finishPaymentController,
ClaimIssuePaths.documentPage,
ClaimDocumentsPaths.documentPage,
ClaimIssuePaths.startPaymentReceiver,
ClaimIssuePaths.finishPaymentReceiver,
ClaimIssuePaths.initiatePaymentController,
ClaimIssuePaths.receiptReceiver,
ClaimIssuePaths.sealedClaimPdfReceiver,
ClaimDocumentsPaths.receiptReceiver,
ClaimDocumentsPaths.sealedClaimPdfReceiver,
ClaimIssuePaths.draftReceiptReceiver,
DefendantResponsePaths.receiptReceiver,
DefendantResponsePaths.scannedResponseForm,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ import { expect } from 'chai'
import * as request from 'supertest'
import * as config from 'config'

import { attachDefaultHooks } from 'test/routes/hooks'
import 'test/routes/expectations'
import { checkAuthorizationGuards } from 'test/features/offer/routes/checks/authorization-check'
import { attachDefaultHooks } from '../../../routes/hooks'
import '../../../routes/expectations'
import { checkAuthorizationGuards } from '../../offer/routes/checks/authorization-check'

import { app } from 'main/app'
import { app } from '../../../../main/app'

import * as idamServiceMock from 'test/http-mocks/idam'
import * as claimStoreServiceMock from 'test/http-mocks/claim-store'
import { Paths } from 'claim/paths'
import * as idamServiceMock from '../../../http-mocks/idam'
import * as claimStoreServiceMock from '../../../http-mocks/claim-store'
import { Paths } from 'claim-documents/paths'

const cookieName: string = config.get<string>('session.cookieName')

Expand Down
61 changes: 61 additions & 0 deletions src/test/features/claim-documents/routes/receipt.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { expect } from 'chai'
import * as request from 'supertest'
import * as config from 'config'

import { attachDefaultHooks } from '../../../routes/hooks'
import '../../../routes/expectations'
import { checkAuthorizationGuards } from '../../claim/routes/checks/authorization-check'

import { Paths as ClaimDocumentsPaths } from 'claim-documents/paths'

import { app } from '../../../../main/app'

import * as idamServiceMock from '../../../http-mocks/idam'
import * as claimStoreServiceMock from '../../../http-mocks/claim-store'

const cookieName: string = config.get<string>('session.cookieName')

const externalId = '400f4c57-9684-49c0-adb4-4cf46579d6dc'

describe('Claim issue: receipt', () => {
attachDefaultHooks(app)

describe('on GET', () => {
checkAuthorizationGuards(app, 'get', ClaimDocumentsPaths.receiptReceiver.evaluateUri({ externalId: externalId }))

describe('for authorized user', () => {
beforeEach(() => {
idamServiceMock.resolveRetrieveUserFor('1', 'citizen')
})

it('should return 500 and render error page when cannot retrieve claim by external id', async () => {
claimStoreServiceMock.rejectRetrieveClaimByExternalId('HTTP error')

await request(app)
.get(ClaimDocumentsPaths.receiptReceiver.evaluateUri({ externalId: externalId }))
.set('Cookie', `${cookieName}=ABC`)
.expect(res => expect(res).to.be.serverError.withText('Error'))
})

it('should return 500 and render error page when cannot generate PDF', async () => {
claimStoreServiceMock.resolveRetrieveClaimByExternalId()
claimStoreServiceMock.rejectRetrieveDocument('HTTP error')

await request(app)
.get(ClaimDocumentsPaths.receiptReceiver.evaluateUri({ externalId: externalId }))
.set('Cookie', `${cookieName}=ABC`)
.expect(res => expect(res).to.be.serverError.withText('Error'))
})

it('should return receipt when everything is fine', async () => {
claimStoreServiceMock.resolveRetrieveClaimByExternalId()
claimStoreServiceMock.resolveRetrieveDocument()

await request(app)
.get(ClaimDocumentsPaths.receiptReceiver.evaluateUri({ externalId: externalId }))
.set('Cookie', `${cookieName}=ABC`)
.expect(res => expect(res).to.be.successful)
})
})
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,27 @@ import { expect } from 'chai'
import * as request from 'supertest'
import * as config from 'config'

import { attachDefaultHooks } from 'test/routes/hooks'
import 'test/routes/expectations'
import { checkAuthorizationGuards } from 'test/features/claim/routes/checks/authorization-check'
import { attachDefaultHooks } from '../../../routes/hooks'
import '../../../routes/expectations'
import { checkAuthorizationGuards } from '../../claim/routes/checks/authorization-check'

import { Paths as ClaimPaths } from 'claim/paths'
import { Paths as ClaimDocumentsPaths } from 'claim-documents/paths'

import { app } from 'main/app'
import { app } from '../../../../main/app'

import * as idamServiceMock from 'test/http-mocks/idam'
import * as idamServiceMock from '../../../http-mocks/idam'
import {
resolveRetrieveClaimByExternalId,
rejectRetrieveClaimByExternalId,
rejectRetrieveDocument,
resolveRetrieveDocument,
sampleClaimObj
} from 'test/http-mocks/claim-store'
} from '../../../http-mocks/claim-store'
import { RoutablePath } from 'shared/router/routablePath'

const cookieName: string = config.get<string>('session.cookieName')
const externalId = '400f4c57-9684-49c0-adb4-4cf46579d6dc'
const path: RoutablePath = ClaimPaths.sealedClaimPdfReceiver
const path: RoutablePath = ClaimDocumentsPaths.sealedClaimPdfReceiver

describe('Sealed Claim: pdf', () => {
attachDefaultHooks(app)
Expand Down
43 changes: 0 additions & 43 deletions src/test/features/claim/routes/receipt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,49 +17,6 @@ const cookieName: string = config.get<string>('session.cookieName')

const externalId = '400f4c57-9684-49c0-adb4-4cf46579d6dc'

describe('Claim issue: receipt', () => {
attachDefaultHooks(app)

describe('on GET', () => {
checkAuthorizationGuards(app, 'get', ClaimPaths.receiptReceiver.evaluateUri({ externalId: externalId }))

describe('for authorized user', () => {
beforeEach(() => {
idamServiceMock.resolveRetrieveUserFor('1', 'citizen')
})

it('should return 500 and render error page when cannot retrieve claim by external id', async () => {
claimStoreServiceMock.rejectRetrieveClaimByExternalId('HTTP error')

await request(app)
.get(ClaimPaths.receiptReceiver.evaluateUri({ externalId: externalId }))
.set('Cookie', `${cookieName}=ABC`)
.expect(res => expect(res).to.be.serverError.withText('Error'))
})

it('should return 500 and render error page when cannot generate PDF', async () => {
claimStoreServiceMock.resolveRetrieveClaimByExternalId()
claimStoreServiceMock.rejectRetrieveDocument('HTTP error')

await request(app)
.get(ClaimPaths.receiptReceiver.evaluateUri({ externalId: externalId }))
.set('Cookie', `${cookieName}=ABC`)
.expect(res => expect(res).to.be.serverError.withText('Error'))
})

it('should return receipt when everything is fine', async () => {
claimStoreServiceMock.resolveRetrieveClaimByExternalId()
claimStoreServiceMock.resolveRetrieveDocument()

await request(app)
.get(ClaimPaths.receiptReceiver.evaluateUri({ externalId: externalId }))
.set('Cookie', `${cookieName}=ABC`)
.expect(res => expect(res).to.be.successful)
})
})
})
})

describe('Claim issue: HWF Draft receipt', () => {
attachDefaultHooks(app)

Expand Down

0 comments on commit df801f5

Please sign in to comment.