Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BC-5597 - Fix unstable tests #4497

Merged
merged 13 commits into from
Oct 25, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { createMock } from '@golevelup/ts-jest';
import { Configuration } from '@hpi-schul-cloud/commons/lib';
import { IConfig } from '@hpi-schul-cloud/commons/lib/interfaces/IConfig';
import { EntityManager } from '@mikro-orm/mongodb';
import { ICurrentUser } from '@modules/authentication';
import { JwtAuthGuard } from '@modules/authentication/guard/jwt-auth.guard';
import { ExecutionContext, INestApplication } from '@nestjs/common';
import { Test, TestingModule } from '@nestjs/testing';
import { ICurrentUser } from '@modules/authentication';
import {
cleanupCollections,
courseFactory,
Expand All @@ -12,12 +14,14 @@ import {
taskFactory,
userFactory,
} from '@shared/testing';
import { JwtAuthGuard } from '@modules/authentication/guard/jwt-auth.guard';
import { FilesStorageClientAdapterService } from '@src/modules/files-storage-client';
bischofmax marked this conversation as resolved.
Show resolved Hide resolved
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';

Expand All @@ -42,6 +46,8 @@ describe('Task copy (API)', () => {
return true;
},
})
.overrideProvider(FilesStorageClientAdapterService)
.useValue(createMock<FilesStorageClientAdapterService>())
.compile();

app = moduleFixture.createNestApplication();
Expand Down
Loading