mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-11-25 11:16:31 -05:00
refactor: adapt for typeorm 0.3
Signed-off-by: David Mehren <git@herrmehren.de>
This commit is contained in:
parent
43d3f14322
commit
06c39ea759
5 changed files with 89 additions and 76 deletions
|
@ -5,8 +5,8 @@
|
|||
*/
|
||||
import { ConfigModule } from '@nestjs/config';
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { getConnectionToken, getRepositoryToken } from '@nestjs/typeorm';
|
||||
import { Connection, Repository } from 'typeorm';
|
||||
import { getDataSourceToken, getRepositoryToken } from '@nestjs/typeorm';
|
||||
import { DataSource, Repository } from 'typeorm';
|
||||
|
||||
import { AuthToken } from '../auth/auth-token.entity';
|
||||
import { Author } from '../authors/author.entity';
|
||||
|
@ -34,7 +34,7 @@ import { HistoryService } from './history.service';
|
|||
describe('HistoryService', () => {
|
||||
let service: HistoryService;
|
||||
let historyRepo: Repository<HistoryEntry>;
|
||||
let connection;
|
||||
let dataSource: DataSource;
|
||||
let noteRepo: Repository<Note>;
|
||||
|
||||
type MockConnection = {
|
||||
|
@ -52,7 +52,7 @@ describe('HistoryService', () => {
|
|||
providers: [
|
||||
HistoryService,
|
||||
{
|
||||
provide: getConnectionToken(),
|
||||
provide: getDataSourceToken(),
|
||||
useFactory: mockConnection,
|
||||
},
|
||||
{
|
||||
|
@ -106,7 +106,7 @@ describe('HistoryService', () => {
|
|||
historyRepo = module.get<Repository<HistoryEntry>>(
|
||||
getRepositoryToken(HistoryEntry),
|
||||
);
|
||||
connection = module.get<Connection>(Connection);
|
||||
dataSource = module.get<DataSource>(DataSource);
|
||||
noteRepo = module.get<Repository<Note>>(getRepositoryToken(Note));
|
||||
});
|
||||
|
||||
|
@ -467,8 +467,10 @@ describe('HistoryService', () => {
|
|||
expect(entry.updatedAt).toEqual(newlyCreatedHistoryEntry.updatedAt);
|
||||
}),
|
||||
};
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
|
||||
connection.transaction.mockImplementation((cb) => {
|
||||
dataSource.transaction.mockImplementation((cb) => {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
|
||||
cb(mockedManager);
|
||||
});
|
||||
|
|
|
@ -59,6 +59,7 @@ export class HistoryService {
|
|||
.where('entry.note = :note', { note: note.id })
|
||||
.andWhere('entry.user = :user', { user: user.id })
|
||||
.leftJoinAndSelect('entry.note', 'note')
|
||||
.leftJoinAndSelect('entry.user', 'user')
|
||||
.getOne();
|
||||
if (!entry) {
|
||||
throw new NotInDBError(
|
||||
|
|
|
@ -49,7 +49,7 @@ export class IdentityService {
|
|||
},
|
||||
relations: ['user'],
|
||||
});
|
||||
if (identity === undefined) {
|
||||
if (identity === null) {
|
||||
throw new NotInDBError(`Identity for user id '${userId}' not found`);
|
||||
}
|
||||
return identity;
|
||||
|
|
|
@ -91,14 +91,18 @@ describe('NotesService', () => {
|
|||
note.owner = Promise.resolve(user);
|
||||
note.userPermissions = Promise.resolve([
|
||||
{
|
||||
noteId: note.id,
|
||||
note: note,
|
||||
userId: user.id,
|
||||
user: user,
|
||||
canEdit: true,
|
||||
},
|
||||
]);
|
||||
note.groupPermissions = Promise.resolve([
|
||||
{
|
||||
noteId: note.id,
|
||||
note: note,
|
||||
groupId: group.id,
|
||||
group: group,
|
||||
canEdit: true,
|
||||
},
|
||||
|
|
14
src/seed.ts
14
src/seed.ts
|
@ -51,7 +51,9 @@ const dataSource = new DataSource({
|
|||
dropSchema: true,
|
||||
});
|
||||
|
||||
dataSource.initialize().then(async () => {
|
||||
dataSource
|
||||
.initialize()
|
||||
.then(async () => {
|
||||
const password = 'test_password';
|
||||
const users = [];
|
||||
users.push(User.create('hardcoded', 'Test User 1'));
|
||||
|
@ -63,12 +65,16 @@ dataSource.initialize().then(async () => {
|
|||
notes.push(Note.create(null, 'test3') as Note);
|
||||
|
||||
for (let i = 0; i < 3; i++) {
|
||||
const author = await dataSource.manager.save(dataSource.manager.create(Author, Author.create(1))) as Author;
|
||||
const user = await dataSource.manager.save(dataSource.manager.create(User, users[i])) as User;
|
||||
const author = (await dataSource.manager.save(
|
||||
dataSource.manager.create(Author, Author.create(1)),
|
||||
)) as Author;
|
||||
const user = (await dataSource.manager.save(
|
||||
dataSource.manager.create(User, users[i]),
|
||||
)) as User;
|
||||
const identity = Identity.create(user, ProviderType.LOCAL, false);
|
||||
identity.passwordHash = await hashPassword(password);
|
||||
dataSource.manager.create(Identity, identity);
|
||||
author.user = (dataSource.manager.save(user) as Promise<User>);
|
||||
author.user = dataSource.manager.save(user);
|
||||
const revision = Revision.create(
|
||||
'This is a test note',
|
||||
'This is a test note',
|
||||
|
|
Loading…
Reference in a new issue