Add various missing imports and provider overrides to fix unit tests.

Signed-off-by: David Mehren <git@herrmehren.de>
This commit is contained in:
David Mehren 2020-09-22 21:59:09 +02:00
parent b06dc5f967
commit 2ce87f3d64
No known key found for this signature in database
GPG key ID: 185982BA4C42B7C3
4 changed files with 96 additions and 7 deletions

View file

@ -4,6 +4,8 @@ import { HistoryModule } from '../../../history/history.module';
import { AuthorColor } from '../../../notes/author-color.entity';
import { Note } from '../../../notes/note.entity';
import { NotesModule } from '../../../notes/notes.module';
import { Authorship } from '../../../revisions/authorship.entity';
import { Revision } from '../../../revisions/revision.entity';
import { AuthToken } from '../../../users/auth-token.entity';
import { Identity } from '../../../users/identity.entity';
import { User } from '../../../users/user.entity';
@ -28,6 +30,10 @@ describe('Me Controller', () => {
.useValue({})
.overrideProvider(getRepositoryToken(AuthorColor))
.useValue({})
.overrideProvider(getRepositoryToken(Authorship))
.useValue({})
.overrideProvider(getRepositoryToken(Revision))
.useValue({})
.compile();
controller = module.get<MeController>(MeController);

View file

@ -1,10 +1,15 @@
import { Test, TestingModule } from '@nestjs/testing';
import { getRepositoryToken } from '@nestjs/typeorm';
import { AuthorColor } from '../../../notes/author-color.entity';
import { Note } from '../../../notes/note.entity';
import { NotesService } from '../../../notes/notes.service';
import { Authorship } from '../../../revisions/authorship.entity';
import { Revision } from '../../../revisions/revision.entity';
import { RevisionsModule } from '../../../revisions/revisions.module';
import { AuthToken } from '../../../users/auth-token.entity';
import { Identity } from '../../../users/identity.entity';
import { User } from '../../../users/user.entity';
import { UsersModule } from '../../../users/users.module';
import { NotesController } from './notes.controller';
describe('Notes Controller', () => {
@ -13,8 +18,14 @@ describe('Notes Controller', () => {
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
controllers: [NotesController],
providers: [NotesService],
imports: [RevisionsModule],
providers: [
NotesService,
{
provide: getRepositoryToken(Note),
useValue: {},
},
],
imports: [RevisionsModule, UsersModule],
})
.overrideProvider(getRepositoryToken(Note))
.useValue({})
@ -22,6 +33,16 @@ describe('Notes Controller', () => {
.useValue({})
.overrideProvider(getRepositoryToken(Authorship))
.useValue({})
.overrideProvider(getRepositoryToken(AuthorColor))
.useValue({})
.overrideProvider(getRepositoryToken(User))
.useValue({})
.overrideProvider(getRepositoryToken(AuthToken))
.useValue({})
.overrideProvider(getRepositoryToken(Identity))
.useValue({})
.overrideProvider(getRepositoryToken(Note))
.useValue({})
.compile();
controller = module.get<NotesController>(NotesController);

View file

@ -1,4 +1,14 @@
import { Test, TestingModule } from '@nestjs/testing';
import { getRepositoryToken } from '@nestjs/typeorm';
import { Authorship } from '../revisions/authorship.entity';
import { Revision } from '../revisions/revision.entity';
import { RevisionsModule } from '../revisions/revisions.module';
import { AuthToken } from '../users/auth-token.entity';
import { Identity } from '../users/identity.entity';
import { User } from '../users/user.entity';
import { UsersModule } from '../users/users.module';
import { AuthorColor } from './author-color.entity';
import { Note } from './note.entity';
import { NotesService } from './notes.service';
describe('NotesService', () => {
@ -6,9 +16,30 @@ describe('NotesService', () => {
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [NotesService],
}).compile();
providers: [
NotesService,
{
provide: getRepositoryToken(Note),
useValue: {},
},
],
imports: [UsersModule, RevisionsModule],
})
.overrideProvider(getRepositoryToken(User))
.useValue({})
.overrideProvider(getRepositoryToken(AuthToken))
.useValue({})
.overrideProvider(getRepositoryToken(Identity))
.useValue({})
.overrideProvider(getRepositoryToken(Authorship))
.useValue({})
.overrideProvider(getRepositoryToken(AuthorColor))
.useValue({})
.overrideProvider(getRepositoryToken(Revision))
.useValue({})
.overrideProvider(getRepositoryToken(Note))
.useValue({})
.compile();
service = module.get<NotesService>(NotesService);
});

View file

@ -1,4 +1,13 @@
import { Test, TestingModule } from '@nestjs/testing';
import { getRepositoryToken } from '@nestjs/typeorm';
import { AuthorColor } from '../notes/author-color.entity';
import { Note } from '../notes/note.entity';
import { NotesModule } from '../notes/notes.module';
import { AuthToken } from '../users/auth-token.entity';
import { Identity } from '../users/identity.entity';
import { User } from '../users/user.entity';
import { Authorship } from './authorship.entity';
import { Revision } from './revision.entity';
import { RevisionsService } from './revisions.service';
describe('RevisionsService', () => {
@ -6,8 +15,30 @@ describe('RevisionsService', () => {
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [RevisionsService],
}).compile();
providers: [
RevisionsService,
{
provide: getRepositoryToken(Revision),
useValue: {},
},
],
imports: [NotesModule],
})
.overrideProvider(getRepositoryToken(Authorship))
.useValue({})
.overrideProvider(getRepositoryToken(AuthorColor))
.useValue({})
.overrideProvider(getRepositoryToken(User))
.useValue({})
.overrideProvider(getRepositoryToken(AuthToken))
.useValue({})
.overrideProvider(getRepositoryToken(Identity))
.useValue({})
.overrideProvider(getRepositoryToken(Note))
.useValue({})
.overrideProvider(getRepositoryToken(Revision))
.useValue({})
.compile();
service = module.get<RevisionsService>(RevisionsService);
});