Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .vite/fixtures/cdp-uploader.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const callbackReceiverFixture = {
const cdpUploaderStackFixture = {
// Depends on callbackReceiver to ensure correct initialisation order
cdpUploaderStack: [
async ({ callbackReceiver }, use) => {
async ({ callbackReceiver: _ }, use) => {
// Disable vitest-fetch-mock so we can make real HTTP requests to containers
// The global fetch is mocked by default in .vite/setup-files.js
if (globalThis.fetchMock) {
Expand Down
1 change: 0 additions & 1 deletion .vite/fixtures/server-with-db.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ export const it = dbTest.extend({
server: [
async ({ db }, use) => {
// db parameter triggers MongoDB setup (unused directly)
// eslint-disable-next-line no-unused-vars
const _dbUri = db
const { createServer } = await import('#server/server.js')
const server = await createServer()
Expand Down
12 changes: 12 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,17 @@ export default [
rules: {
'n/no-unpublished-import': 'off'
}
},
{
rules: {
'no-unused-vars': [
'error',
{
argsIgnorePattern: '^_',
caughtErrorsIgnorePattern: '^_',
varsIgnorePattern: '^_'
}
]
}
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export async function createOrganisationCollection(
try {
await db.collection(collectionName).drop()
console.log('Dropped existing organisation collection')
} catch (error) {
} catch (_error) {
console.log('Organisation collection does not exist, creating new')
}

Expand Down Expand Up @@ -149,7 +149,7 @@ export async function createRegistrationCollection(
try {
await db.collection(collectionName).drop()
console.log('Dropped existing registration collection')
} catch (error) {
} catch (_error) {
console.log('Registration collection does not exist, creating new')
}

Expand Down Expand Up @@ -355,7 +355,7 @@ export async function createAccreditationCollection(
try {
await db.collection(collectionName).drop()
console.log('Dropped existing accreditation collection')
} catch (error) {
} catch (_error) {
console.log('Accreditation collection does not exist, creating new')
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export async function createOrganisationCollection(
try {
await db.collection(collectionName).drop()
console.log('Dropped existing collection')
} catch (error) {
} catch (_error) {
console.log('Collection does not exist, creating new')
}

Expand Down
5 changes: 5 additions & 0 deletions sonar-project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,8 @@ sonar.test.inclusions=src/**/*.test.js,src/**/*.contract.js

sonar.javascript.lcov.reportPaths=./coverage/lcov.info
sonar.coverage.exclusions=src/index.js,src/common/helpers/secure-context.js,src/domain/organisations/model.js

# Disable S1481 - we use _ prefix for intentionally unused variables (enforced by ESLint)
sonar.issue.ignore.multicriteria=e1
sonar.issue.ignore.multicriteria.e1.ruleKey=javascript:S1481
sonar.issue.ignore.multicriteria.e1.resourceKey=**/*
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ describe('createSeedData', () => {
}
)

it('creates seed data when there are no documents already in epr-organisations collection', async (collectionName) => {
it('creates seed data when there are no documents already in epr-organisations collection', async () => {
const { mockDb } = createMockDb({
countDocuments: async () => 0
})
Expand Down
2 changes: 1 addition & 1 deletion src/common/helpers/s3/s3-client.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ describe('createS3Client', () => {
beforeEach(() => {
s3Client = { config: { region } }

vi.mocked(S3Client).mockImplementation(function (config) {
vi.mocked(S3Client).mockImplementation(function () {
return s3Client
})
})
Expand Down
18 changes: 9 additions & 9 deletions src/forms-submission-data/migrate-forms-data.test.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { beforeEach, describe, expect, it, vi } from 'vitest'
import { migrateFormsData } from './migrate-forms-data.js'
import { logger } from '#common/helpers/logging/logger.js'
import { createFormSubmissionsRepository } from '#repositories/form-submissions/inmemory.js'
import { createInMemoryOrganisationsRepository } from '#repositories/organisations/inmemory.js'
import { readdirSync, readFileSync } from 'fs'
import { join } from 'path'
import {
LOGGING_EVENT_ACTIONS,
LOGGING_EVENT_CATEGORIES
} from '#common/enums/index.js'
import { MATERIAL } from '#domain/organisations/model.js'
import reprocessorGlassAccreditation from '#data/fixtures/ea/accreditation/reprocessor-glass.json'
import { logger } from '#common/helpers/logging/logger.js'
import exporterAccreditation from '#data/fixtures/ea/accreditation/exporter.json'
import reprocessorGlassAccreditation from '#data/fixtures/ea/accreditation/reprocessor-glass.json'
import { MATERIAL } from '#domain/organisations/model.js'
import { createFormSubmissionsRepository } from '#repositories/form-submissions/inmemory.js'
import { createInMemoryOrganisationsRepository } from '#repositories/organisations/inmemory.js'
import { readdirSync, readFileSync } from 'fs'
import { join } from 'path'
import { beforeEach, describe, expect, it, vi } from 'vitest'
import { migrateFormsData } from './migrate-forms-data.js'

vi.mock('#common/helpers/logging/logger.js', () => ({
logger: {
Expand Down
6 changes: 3 additions & 3 deletions src/repositories/organisations/contract/insert.contract.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, beforeEach, expect } from 'vitest'
import { beforeEach, describe, expect } from 'vitest'
import { buildOrganisation } from './test-data.js'

export const testInsertBehaviour = (it) => {
Expand All @@ -24,14 +24,14 @@ export const testInsertBehaviour = (it) => {
...orgWithoutStatusHistory,
formSubmissionTime: new Date(orgData.formSubmissionTime),
registrations: orgData.registrations.map((reg) => {
const { statusHistory, ...regWithoutStatusHistory } = reg
const { statusHistory: _, ...regWithoutStatusHistory } = reg
return {
...regWithoutStatusHistory,
formSubmissionTime: new Date(reg.formSubmissionTime)
}
}),
accreditations: orgData.accreditations.map((acc) => {
const { statusHistory, ...accWithoutStatusHistory } = acc
const { statusHistory: _, ...accWithoutStatusHistory } = acc
return {
...accWithoutStatusHistory,
formSubmissionTime: new Date(acc.formSubmissionTime)
Expand Down
4 changes: 2 additions & 2 deletions src/repositories/organisations/contract/update.contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ export const testUpdateBehaviour = (it) => {
)
expect(addedReg).toBeDefined()

const { statusHistory, ...expectedReg } = {
const { statusHistory: _, ...expectedReg } = {
...newRegistration,
formSubmissionTime: new Date(newRegistration.formSubmissionTime)
}
Expand Down Expand Up @@ -184,7 +184,7 @@ export const testUpdateBehaviour = (it) => {
)
expect(addedAcc).toBeDefined()

const { statusHistory, ...expectedAcc } = {
const { statusHistory: _, ...expectedAcc } = {
...newAccreditation,
formSubmissionTime: new Date(newAccreditation.formSubmissionTime)
}
Expand Down
13 changes: 10 additions & 3 deletions src/repositories/organisations/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export const mergeItemsWithUpdates = (existingItems, itemUpdates) => {
}))

return [...processedExisting, ...newItems].map((item) => {
const { status, ...remainingFields } = item
const { status: _, ...remainingFields } = item
return remainingFields
})
}
Expand Down Expand Up @@ -93,7 +93,7 @@ const normalizeItem = (item) => {
if (!item) {
return item
}
const { status, statusHistory, ...rest } = item
const { status: _, statusHistory: _s, ...rest } = item
return rest
}

Expand All @@ -102,7 +102,14 @@ export const normalizeForComparison = (org) => {
return org
}

const { version, schemaVersion, status, statusHistory, users, ...rest } = org
const {
schemaVersion: _sv,
status: _s,
statusHistory: _sh,
users: _u,
version: _v,
...rest
} = org

const normalized = {
...rest,
Expand Down
20 changes: 10 additions & 10 deletions src/repositories/organisations/inmemory.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import {
validateId,
validateOrganisationInsert,
validateOrganisationUpdate
} from './schema/index.js'
import Boom from '@hapi/boom'
import {
SCHEMA_VERSION,
collateUsersOnApproval,
createInitialStatusHistory,
getCurrentStatus,
statusHistoryWithChanges,
hasChanges,
mergeSubcollection,
hasChanges
statusHistoryWithChanges
} from './helpers.js'
import Boom from '@hapi/boom'
import {
validateId,
validateOrganisationInsert,
validateOrganisationUpdate
} from './schema/index.js'

// Aggressive retry settings for in-memory testing (setImmediate() is microseconds)
const MAX_CONSISTENCY_RETRIES = 5
Expand Down Expand Up @@ -104,7 +104,7 @@ const performUpdate =
)
}

const { status, ...merged } = { ...existing, ...validatedUpdates }
const { status: _, ...merged } = { ...existing, ...validatedUpdates }

const registrations = mergeSubcollection(
existing.registrations,
Expand Down Expand Up @@ -146,7 +146,7 @@ const performUpsert =
(storage, staleCache, pendingSyncRef, insertFn, updateFn) =>
async (organisation) => {
const validated = validateOrganisationInsert(organisation)
const { id, version, schemaVersion, ...updateData } = validated
const { id, version: _v, schemaVersion: _s, ...updateData } = validated

const existing = storage.find((o) => o.id === id)

Expand Down
6 changes: 3 additions & 3 deletions src/repositories/organisations/mongodb.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ const performUpdate = (db) => async (id, version, updates) => {
throw Boom.notFound(`Organisation with id ${validatedId} not found`)
}

const { status, ...merged } = { ...existing, ...validatedUpdates }
const { status: _, ...merged } = { ...existing, ...validatedUpdates }

const registrations = mergeSubcollection(
existing.registrations,
Expand Down Expand Up @@ -131,7 +131,7 @@ const performUpdate = (db) => async (id, version, updates) => {

const performUpsert = (db) => async (organisation) => {
const validated = validateOrganisationInsert(organisation)
const { id, version, schemaVersion, ...updateData } = validated
const { id, version: _v, schemaVersion: _s, ...updateData } = validated

const existing = await db
.collection(COLLECTION_NAME)
Expand Down Expand Up @@ -173,7 +173,7 @@ const performFindById =
let validatedId
try {
validatedId = validateId(id)
} catch (error) {
} catch (_error) {
throw Boom.notFound(`Organisation with id ${id} not found`)
}

Expand Down
4 changes: 2 additions & 2 deletions src/repositories/summary-logs/contract/test-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const buildFile = (overrides = {}) => ({
})

export const buildPendingFile = (overrides = {}) => {
const { uri, status, ...rest } = overrides
const { uri: _u, status: _s, ...rest } = overrides
return {
id: generateFileId(),
name: 'test.xlsx',
Expand All @@ -21,7 +21,7 @@ export const buildPendingFile = (overrides = {}) => {
}

export const buildRejectedFile = (overrides = {}) => {
const { uri, status, ...rest } = overrides
const { uri: _u, status: _s, ...rest } = overrides
return {
id: generateFileId(),
name: 'test.xlsx',
Expand Down
2 changes: 1 addition & 1 deletion src/repositories/waste-records/mongodb.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const SCHEMA_VERSION = 1
* @returns {import('./port.js').WasteRecord} Domain waste record
*/
const mapDocumentToDomain = (doc) => {
const { _id, schemaVersion, ...domainFields } = doc
const { _id, schemaVersion: _s, ...domainFields } = doc
return structuredClone(domainFields)
}

Expand Down
12 changes: 6 additions & 6 deletions src/repositories/waste-records/validation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,28 +80,28 @@ describe('validation', () => {
})

it('rejects record missing organisationId', () => {
const { organisationId, ...invalid } = validRecord
const { organisationId: _, ...invalid } = validRecord
expect(() => validateWasteRecord(invalid)).toThrow(
/organisationId is required/
)
})

it('rejects record missing registrationId', () => {
const { registrationId, ...invalid } = validRecord
const { registrationId: _, ...invalid } = validRecord
expect(() => validateWasteRecord(invalid)).toThrow(
/registrationId is required/
)
})

it('rejects record missing rowId', () => {
const { rowId, ...invalid } = validRecord
const { rowId: _, ...invalid } = validRecord
expect(() => validateWasteRecord(invalid)).toThrow(
/Invalid waste record:.*rowId.*is required/
)
})

it('rejects record missing type', () => {
const { type, ...invalid } = validRecord
const { type: _, ...invalid } = validRecord
expect(() => validateWasteRecord(invalid)).toThrow(
/Invalid waste record:.*type.*is required/
)
Expand All @@ -115,14 +115,14 @@ describe('validation', () => {
})

it('rejects record missing data', () => {
const { data, ...invalid } = validRecord
const { data: _, ...invalid } = validRecord
expect(() => validateWasteRecord(invalid)).toThrow(
/Invalid waste record:.*data.*is required/
)
})

it('rejects record missing versions', () => {
const { versions, ...invalid } = validRecord
const { versions: _, ...invalid } = validRecord
expect(() => validateWasteRecord(invalid)).toThrow(
/Invalid waste record:.*versions.*is required/
)
Expand Down
3 changes: 1 addition & 2 deletions src/routes/v1/dev/organisations/patch-by-id.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { mergeSubcollection } from '#repositories/organisations/helpers.js'
import Boom from '@hapi/boom'
import { StatusCodes } from 'http-status-codes'
import Joi from 'joi'
import mergeWith from 'lodash.mergewith'

import { mergeSubcollection } from '#repositories/organisations/helpers.js'

/** @import {Organisation} from '#domain/organisations/model.js' */
/** @import {OrganisationsRepository} from '#repositories/organisations/port.js' */

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ describe(`${summaryLogsSubmitPath} route`, () => {

server = await createTestServer({
repositories: {
summaryLogsRepository: (logger) => summaryLogsRepository
summaryLogsRepository: (_logger) => summaryLogsRepository
},
workers: {
summaryLogsWorker
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import {
UPLOAD_STATUS
} from '#domain/summary-logs/status.js'
import { createInMemoryFeatureFlags } from '#feature-flags/feature-flags.inmemory.js'
import { createTestServer } from '#test/create-test-server.js'
import { createInMemorySummaryLogsRepository } from '#repositories/summary-logs/inmemory.js'
import { setupAuthContext } from '#vite/helpers/setup-auth-mocking.js'
import { createTestServer } from '#test/create-test-server.js'
import { entraIdMockAuthTokens } from '#vite/helpers/create-entra-id-test-tokens.js'
import { setupAuthContext } from '#vite/helpers/setup-auth-mocking.js'

import { summaryLogsUploadCompletedPath } from './post.js'

Expand Down Expand Up @@ -113,7 +113,7 @@ describe(`${summaryLogsUploadCompletedPath} route`, () => {

server = await createTestServer({
repositories: {
summaryLogsRepository: (logger) => summaryLogsRepository
summaryLogsRepository: (_logger) => summaryLogsRepository
},
workers: {
summaryLogsWorker
Expand Down
Loading
Loading