diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 964ab20c8f8..cbf52acce55 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -94,7 +94,7 @@ jobs: SONAR_TOKEN: ${{ secrets.SONARCLOUD_TOKEN }} nest_lint: runs-on: ubuntu-latest - timeout-minutes: 5 + timeout-minutes: 6 steps: - name: checkout uses: actions/checkout@v3 diff --git a/apps/server/src/modules/account/mapper/account-idm-to-dto.mapper.db.spec.ts b/apps/server/src/modules/account/mapper/account-idm-to-dto.mapper.db.spec.ts index 2430afe6081..0774457472a 100644 --- a/apps/server/src/modules/account/mapper/account-idm-to-dto.mapper.db.spec.ts +++ b/apps/server/src/modules/account/mapper/account-idm-to-dto.mapper.db.spec.ts @@ -54,15 +54,27 @@ describe('AccountIdmToDtoMapperDb', () => { }); describe('when date is undefined', () => { - it('should use actual date', () => { + const setup = () => { const testIdmEntity: IdmAccount = { id: 'id', }; + + const dateMock = new Date(); + jest.useFakeTimers(); + jest.setSystemTime(dateMock); + + return { testIdmEntity, dateMock }; + }; + + it('should use actual date', () => { + const { testIdmEntity, dateMock } = setup(); + const ret = mapper.mapToDto(testIdmEntity); - const now = new Date(); - expect(ret.createdAt).toEqual(now); - expect(ret.updatedAt).toEqual(now); + expect(ret.createdAt).toEqual(dateMock); + expect(ret.updatedAt).toEqual(dateMock); + + jest.useRealTimers(); }); }); diff --git a/apps/server/src/modules/files-storage/controller/api-test/files-security.api.spec.ts b/apps/server/src/modules/files-storage/controller/api-test/files-security.api.spec.ts index 5aee0e1fab5..4694b1817ac 100644 --- a/apps/server/src/modules/files-storage/controller/api-test/files-security.api.spec.ts +++ b/apps/server/src/modules/files-storage/controller/api-test/files-security.api.spec.ts @@ -1,3 +1,4 @@ +import { createMock } from '@golevelup/ts-jest'; import { EntityManager } from '@mikro-orm/mongodb'; import { ICurrentUser } from '@modules/authentication'; import { JwtAuthGuard } from '@modules/authentication/guard/jwt-auth.guard'; @@ -13,6 +14,7 @@ import { schoolFactory, userFactory, } from '@shared/testing'; +import NodeClam from 'clamscan'; import { Request } from 'express'; import request from 'supertest'; import { FileRecord, FileRecordParentType } from '../../entity'; @@ -62,6 +64,8 @@ describe(`${baseRouteName} (api)`, () => { return true; }, }) + .overrideProvider(NodeClam) + .useValue(createMock()) .compile(); app = module.createNestApplication(); diff --git a/apps/server/src/modules/files-storage/controller/api-test/files-storage-copy-files.api.spec.ts b/apps/server/src/modules/files-storage/controller/api-test/files-storage-copy-files.api.spec.ts index f8503aa63df..22a7a11fb5b 100644 --- a/apps/server/src/modules/files-storage/controller/api-test/files-storage-copy-files.api.spec.ts +++ b/apps/server/src/modules/files-storage/controller/api-test/files-storage-copy-files.api.spec.ts @@ -17,6 +17,7 @@ import { schoolFactory, userFactory, } from '@shared/testing'; +import NodeClam from 'clamscan'; import { Request } from 'express'; import FileType from 'file-type-cjs/file-type-cjs-index'; import request from 'supertest'; @@ -103,6 +104,8 @@ describe(`${baseRouteName} (api)`, () => { return true; }, }) + .overrideProvider(NodeClam) + .useValue(createMock()) .compile(); app = module.createNestApplication(); diff --git a/apps/server/src/modules/files-storage/controller/api-test/files-storage-delete-files.api.spec.ts b/apps/server/src/modules/files-storage/controller/api-test/files-storage-delete-files.api.spec.ts index 3e297f7bfbc..0557843b8eb 100644 --- a/apps/server/src/modules/files-storage/controller/api-test/files-storage-delete-files.api.spec.ts +++ b/apps/server/src/modules/files-storage/controller/api-test/files-storage-delete-files.api.spec.ts @@ -16,6 +16,7 @@ import { schoolFactory, userFactory, } from '@shared/testing'; +import NodeClam from 'clamscan'; import { Request } from 'express'; import FileType from 'file-type-cjs/file-type-cjs-index'; import request from 'supertest'; @@ -102,6 +103,8 @@ describe(`${baseRouteName} (api)`, () => { return true; }, }) + .overrideProvider(NodeClam) + .useValue(createMock()) .compile(); app = module.createNestApplication(); diff --git a/apps/server/src/modules/files-storage/controller/api-test/files-storage-download-upload.api.spec.ts b/apps/server/src/modules/files-storage/controller/api-test/files-storage-download-upload.api.spec.ts index c58541c1771..e86b778e0ce 100644 --- a/apps/server/src/modules/files-storage/controller/api-test/files-storage-download-upload.api.spec.ts +++ b/apps/server/src/modules/files-storage/controller/api-test/files-storage-download-upload.api.spec.ts @@ -9,6 +9,7 @@ import { EntityId, Permission } from '@shared/domain'; import { AntivirusService } from '@shared/infra/antivirus'; import { S3ClientAdapter } from '@shared/infra/s3-client'; import { cleanupCollections, mapUserToCurrentUser, roleFactory, schoolFactory, userFactory } from '@shared/testing'; +import NodeClam from 'clamscan'; import { Request } from 'express'; import FileType from 'file-type-cjs/file-type-cjs-index'; import request from 'supertest'; @@ -115,6 +116,8 @@ describe('files-storage controller (API)', () => { return true; }, }) + .overrideProvider(NodeClam) + .useValue(createMock()) .compile(); app = module.createNestApplication(); diff --git a/apps/server/src/modules/files-storage/controller/api-test/files-storage-list-files.api.spec.ts b/apps/server/src/modules/files-storage/controller/api-test/files-storage-list-files.api.spec.ts index 10ce2705f72..35410d712c8 100644 --- a/apps/server/src/modules/files-storage/controller/api-test/files-storage-list-files.api.spec.ts +++ b/apps/server/src/modules/files-storage/controller/api-test/files-storage-list-files.api.spec.ts @@ -1,3 +1,4 @@ +import { createMock } from '@golevelup/ts-jest'; import { EntityManager } from '@mikro-orm/mongodb'; import { ICurrentUser } from '@modules/authentication'; import { JwtAuthGuard } from '@modules/authentication/guard/jwt-auth.guard'; @@ -13,6 +14,7 @@ import { schoolFactory, userFactory, } from '@shared/testing'; +import NodeClam from 'clamscan'; import { Request } from 'express'; import request from 'supertest'; import { FileRecordParentType, PreviewStatus } from '../../entity'; @@ -62,6 +64,8 @@ describe(`${baseRouteName} (api)`, () => { return true; }, }) + .overrideProvider(NodeClam) + .useValue(createMock()) .compile(); app = module.createNestApplication(); diff --git a/apps/server/src/modules/files-storage/controller/api-test/files-storage-preview.api.spec.ts b/apps/server/src/modules/files-storage/controller/api-test/files-storage-preview.api.spec.ts index d870b6ee191..e87aa5ddbe6 100644 --- a/apps/server/src/modules/files-storage/controller/api-test/files-storage-preview.api.spec.ts +++ b/apps/server/src/modules/files-storage/controller/api-test/files-storage-preview.api.spec.ts @@ -10,6 +10,7 @@ import { AntivirusService } from '@shared/infra/antivirus'; import { PreviewProducer } from '@shared/infra/preview-generator'; import { S3ClientAdapter } from '@shared/infra/s3-client'; import { cleanupCollections, mapUserToCurrentUser, roleFactory, schoolFactory, userFactory } from '@shared/testing'; +import NodeClam from 'clamscan'; import { Request } from 'express'; import FileType from 'file-type-cjs/file-type-cjs-index'; import request from 'supertest'; @@ -116,6 +117,8 @@ describe('File Controller (API) - preview', () => { return true; }, }) + .overrideProvider(NodeClam) + .useValue(createMock()) .compile(); app = module.createNestApplication(); diff --git a/apps/server/src/modules/files-storage/controller/api-test/files-storage-rename-file.api.spec.ts b/apps/server/src/modules/files-storage/controller/api-test/files-storage-rename-file.api.spec.ts index b75236bbe07..fb1dfa866eb 100644 --- a/apps/server/src/modules/files-storage/controller/api-test/files-storage-rename-file.api.spec.ts +++ b/apps/server/src/modules/files-storage/controller/api-test/files-storage-rename-file.api.spec.ts @@ -1,3 +1,4 @@ +import { createMock } from '@golevelup/ts-jest'; import { EntityManager } from '@mikro-orm/mongodb'; import { ICurrentUser } from '@modules/authentication'; import { JwtAuthGuard } from '@modules/authentication/guard/jwt-auth.guard'; @@ -13,6 +14,7 @@ import { schoolFactory, userFactory, } from '@shared/testing'; +import NodeClam from 'clamscan'; import { Request } from 'express'; import request from 'supertest'; import { FileRecord, FileRecordParentType } from '../../entity'; @@ -62,6 +64,8 @@ describe(`${baseRouteName} (api)`, () => { return true; }, }) + .overrideProvider(NodeClam) + .useValue(createMock()) .compile(); app = module.createNestApplication(); diff --git a/apps/server/src/modules/files-storage/controller/api-test/files-storage-restore-files.api.spec.ts b/apps/server/src/modules/files-storage/controller/api-test/files-storage-restore-files.api.spec.ts index 7442fe9c4e8..496f399d41b 100644 --- a/apps/server/src/modules/files-storage/controller/api-test/files-storage-restore-files.api.spec.ts +++ b/apps/server/src/modules/files-storage/controller/api-test/files-storage-restore-files.api.spec.ts @@ -16,6 +16,7 @@ import { schoolFactory, userFactory, } from '@shared/testing'; +import NodeClam from 'clamscan'; import { Request } from 'express'; import FileType from 'file-type-cjs/file-type-cjs-index'; import request from 'supertest'; @@ -127,6 +128,8 @@ describe(`${baseRouteName} (api)`, () => { return true; }, }) + .overrideProvider(NodeClam) + .useValue(createMock()) .compile(); app = module.createNestApplication(); diff --git a/apps/server/src/modules/legacy-school/service/school-year.service.spec.ts b/apps/server/src/modules/legacy-school/service/school-year.service.spec.ts index 041b80d41d1..4aded660643 100644 --- a/apps/server/src/modules/legacy-school/service/school-year.service.spec.ts +++ b/apps/server/src/modules/legacy-school/service/school-year.service.spec.ts @@ -35,7 +35,6 @@ describe('SchoolYearService', () => { describe('getCurrentSchoolYear', () => { const setup = () => { - jest.setSystemTime(new Date('2022-06-01').getTime()); const schoolYear: SchoolYearEntity = schoolYearFactory.build({ startDate: new Date('2021-09-01'), endDate: new Date('2022-12-31'), @@ -60,7 +59,6 @@ describe('SchoolYearService', () => { describe('findById', () => { const setup = () => { - jest.setSystemTime(new Date('2022-06-01').getTime()); const schoolYear: SchoolYearEntity = schoolYearFactory.build({ startDate: new Date('2021-09-01'), endDate: new Date('2022-12-31'), diff --git a/apps/server/src/modules/task/controller/api-test/task-copy-timeout.api.spec.ts b/apps/server/src/modules/task/controller/api-test/task-copy-timeout.api.spec.ts index 4a810eeb0a8..d5546c435da 100644 --- a/apps/server/src/modules/task/controller/api-test/task-copy-timeout.api.spec.ts +++ b/apps/server/src/modules/task/controller/api-test/task-copy-timeout.api.spec.ts @@ -18,8 +18,10 @@ import { import { Request } from 'express'; import request from 'supertest'; +// config must be set outside before the server module is imported, otherwise the configuration is already set Configuration.set('FEATURE_COPY_SERVICE_ENABLED', true); Configuration.set('INCOMING_REQUEST_TIMEOUT_COPY_API', 1); + // eslint-disable-next-line import/first import { ServerTestModule } from '@modules/server/server.module'; diff --git a/apps/server/src/shared/infra/metrics/prometheus/app.spec.ts b/apps/server/src/shared/infra/metrics/prometheus/app.spec.ts index 9be4558d3f8..8e751298e90 100644 --- a/apps/server/src/shared/infra/metrics/prometheus/app.spec.ts +++ b/apps/server/src/shared/infra/metrics/prometheus/app.spec.ts @@ -6,7 +6,7 @@ describe('createPrometheusMetricsApp', () => { describe('should create an app that should', () => { it('collect all the available metrics and expose them on given route', async () => { const testMetricsRoute = '/prometheus-metrics'; - const exampleDefaultMetricName = 'process_heap_bytes'; + const exampleDefaultMetricName = 'process_cpu_user_seconds_total'; const exampleMetricsRouteMetric = `sc_api_response_time_in_seconds_count{` + `method="GET",` +