Skip to content

Commit 845071d

Browse files
committed
fix lint problems
1 parent ad05915 commit 845071d

3 files changed

Lines changed: 45 additions & 30 deletions

File tree

designer/server/src/routes/admin/form-inspect.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -287,10 +287,12 @@ export default [
287287

288288
const delta = jdp.diff(definitionA, definitionB)
289289
// Strip any <script> tags injected by jsondiffpatch to prevent XSS
290-
const diffHtml = formatDiffHtml(delta, definitionA).replaceAll(
291-
/<script[\s\S]*?<\/script>/g,
292-
''
293-
)
290+
const diffHtml = delta
291+
? (formatDiffHtml(delta, definitionA) ?? '').replaceAll(
292+
/<script[\s\S]*?<\/script>/g,
293+
''
294+
)
295+
: ''
294296

295297
return h.view(
296298
'admin/form-inspect-version-diff-detail',

designer/server/src/routes/admin/form-inspect.test.js

Lines changed: 34 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { StatusCodes } from 'http-status-codes'
22

3+
import { buildDefinition } from '~/src/__stubs__/form-definition.js'
34
import { createServer } from '~/src/createServer.js'
45
import * as forms from '~/src/lib/forms.js'
56
import {
@@ -470,8 +471,8 @@ describe('Form inspect routes', () => {
470471
})
471472

472473
describe('GET /admin/form-inspect/{id}/versions/{versionId} (diff)', () => {
473-
const definitionA = { name: 'My form', pages: [] }
474-
const definitionB = { name: 'My form updated', pages: [] }
474+
const definitionA = buildDefinition({ name: 'My form' })
475+
const definitionB = buildDefinition({ name: 'My form updated' })
475476

476477
test('renders diff detail page for 1..4 format', async () => {
477478
jest
@@ -524,30 +525,37 @@ describe('Form inspect routes', () => {
524525
})
525526

526527
test('objectHash exercises id, path and name branches', async () => {
527-
const defA = {
528-
name: 'My form',
529-
pages: [
530-
{
531-
path: '/page-1',
532-
components: [{ name: 'firstName', type: 'TextField' }]
533-
}
534-
],
535-
conditions: [{ id: 'cond-1', name: 'Is adult' }],
536-
lists: [{ name: 'countries', title: 'Countries', items: [] }],
537-
sections: []
538-
}
539-
const defB = {
540-
name: 'My form',
541-
pages: [
542-
{
543-
path: '/page-1',
544-
components: [{ name: 'lastName', type: 'TextField' }]
545-
}
546-
],
547-
conditions: [{ id: 'cond-2', name: 'Is minor' }],
548-
lists: [{ name: 'regions', title: 'Regions', items: [] }],
549-
sections: []
550-
}
528+
// Cast to FormDefinition — these are intentionally minimal fixtures
529+
// designed to exercise specific objectHash branches (id, path, name),
530+
// not fully valid definitions.
531+
const defA = /** @type {import('@defra/forms-model').FormDefinition} */ (
532+
/** @type {unknown} */ ({
533+
name: 'My form',
534+
pages: [
535+
{
536+
path: '/page-1',
537+
components: [{ name: 'firstName', type: 'TextField' }]
538+
}
539+
],
540+
conditions: [{ id: 'cond-1', name: 'Is adult' }],
541+
lists: [{ name: 'countries', title: 'Countries', items: [] }],
542+
sections: []
543+
})
544+
)
545+
const defB = /** @type {import('@defra/forms-model').FormDefinition} */ (
546+
/** @type {unknown} */ ({
547+
name: 'My form',
548+
pages: [
549+
{
550+
path: '/page-1',
551+
components: [{ name: 'lastName', type: 'TextField' }]
552+
}
553+
],
554+
conditions: [{ id: 'cond-2', name: 'Is minor' }],
555+
lists: [{ name: 'regions', title: 'Regions', items: [] }],
556+
sections: []
557+
})
558+
)
551559

552560
jest
553561
.mocked(forms.getFormDefinitionVersion)

designer/server/src/typings/hapi/index.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,11 @@ declare module '@hapi/yar' {
192192
[sessionNames.validationFailure.deadLetterQueues]: ValidationFailure<{
193193
dlq: string
194194
}>
195+
[sessionNames.validationFailure.formInspect]: ValidationFailure<{
196+
type: string
197+
id: string
198+
slug: string
199+
}>
195200
}
196201

197202
interface YarValues {

0 commit comments

Comments
 (0)