mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-11-26 19:53:59 -05:00
test: fix service tests to handle the new aliases
Signed-off-by: Philip Molares <philip.molares@udo.edu>
This commit is contained in:
parent
e9d4a81922
commit
b95a6f56b6
12 changed files with 168 additions and 53 deletions
|
@ -19,6 +19,7 @@ import { HistoryEntry } from '../../../../history/history-entry.entity';
|
||||||
import { HistoryModule } from '../../../../history/history.module';
|
import { HistoryModule } from '../../../../history/history.module';
|
||||||
import { Identity } from '../../../../identity/identity.entity';
|
import { Identity } from '../../../../identity/identity.entity';
|
||||||
import { LoggerModule } from '../../../../logger/logger.module';
|
import { LoggerModule } from '../../../../logger/logger.module';
|
||||||
|
import { Alias } from '../../../../notes/alias.entity';
|
||||||
import { Note } from '../../../../notes/note.entity';
|
import { Note } from '../../../../notes/note.entity';
|
||||||
import { NotesModule } from '../../../../notes/notes.module';
|
import { NotesModule } from '../../../../notes/notes.module';
|
||||||
import { Tag } from '../../../../notes/tag.entity';
|
import { Tag } from '../../../../notes/tag.entity';
|
||||||
|
@ -73,6 +74,8 @@ describe('HistoryController', () => {
|
||||||
.useValue({})
|
.useValue({})
|
||||||
.overrideProvider(getRepositoryToken(Group))
|
.overrideProvider(getRepositoryToken(Group))
|
||||||
.useValue({})
|
.useValue({})
|
||||||
|
.overrideProvider(getRepositoryToken(Alias))
|
||||||
|
.useValue({})
|
||||||
.overrideProvider(getRepositoryToken(Author))
|
.overrideProvider(getRepositoryToken(Author))
|
||||||
.useValue({})
|
.useValue({})
|
||||||
.overrideProvider(getRepositoryToken(Session))
|
.overrideProvider(getRepositoryToken(Session))
|
||||||
|
|
|
@ -18,6 +18,7 @@ import { Identity } from '../../../identity/identity.entity';
|
||||||
import { LoggerModule } from '../../../logger/logger.module';
|
import { LoggerModule } from '../../../logger/logger.module';
|
||||||
import { MediaUpload } from '../../../media/media-upload.entity';
|
import { MediaUpload } from '../../../media/media-upload.entity';
|
||||||
import { MediaModule } from '../../../media/media.module';
|
import { MediaModule } from '../../../media/media.module';
|
||||||
|
import { Alias } from '../../../notes/alias.entity';
|
||||||
import { Note } from '../../../notes/note.entity';
|
import { Note } from '../../../notes/note.entity';
|
||||||
import { Tag } from '../../../notes/tag.entity';
|
import { Tag } from '../../../notes/tag.entity';
|
||||||
import { NoteGroupPermission } from '../../../permissions/note-group-permission.entity';
|
import { NoteGroupPermission } from '../../../permissions/note-group-permission.entity';
|
||||||
|
@ -71,6 +72,8 @@ describe('MeController', () => {
|
||||||
.useValue({})
|
.useValue({})
|
||||||
.overrideProvider(getRepositoryToken(MediaUpload))
|
.overrideProvider(getRepositoryToken(MediaUpload))
|
||||||
.useValue({})
|
.useValue({})
|
||||||
|
.overrideProvider(getRepositoryToken(Alias))
|
||||||
|
.useValue({})
|
||||||
.overrideProvider(getRepositoryToken(Session))
|
.overrideProvider(getRepositoryToken(Session))
|
||||||
.useValue({})
|
.useValue({})
|
||||||
.overrideProvider(getRepositoryToken(Author))
|
.overrideProvider(getRepositoryToken(Author))
|
||||||
|
|
|
@ -19,6 +19,7 @@ import { Identity } from '../../../identity/identity.entity';
|
||||||
import { LoggerModule } from '../../../logger/logger.module';
|
import { LoggerModule } from '../../../logger/logger.module';
|
||||||
import { MediaUpload } from '../../../media/media-upload.entity';
|
import { MediaUpload } from '../../../media/media-upload.entity';
|
||||||
import { MediaModule } from '../../../media/media.module';
|
import { MediaModule } from '../../../media/media.module';
|
||||||
|
import { Alias } from '../../../notes/alias.entity';
|
||||||
import { Note } from '../../../notes/note.entity';
|
import { Note } from '../../../notes/note.entity';
|
||||||
import { NotesModule } from '../../../notes/notes.module';
|
import { NotesModule } from '../../../notes/notes.module';
|
||||||
import { Tag } from '../../../notes/tag.entity';
|
import { Tag } from '../../../notes/tag.entity';
|
||||||
|
@ -76,6 +77,8 @@ describe('MediaController', () => {
|
||||||
.useValue({})
|
.useValue({})
|
||||||
.overrideProvider(getRepositoryToken(Group))
|
.overrideProvider(getRepositoryToken(Group))
|
||||||
.useValue({})
|
.useValue({})
|
||||||
|
.overrideProvider(getRepositoryToken(Alias))
|
||||||
|
.useValue({})
|
||||||
.overrideProvider(getRepositoryToken(Session))
|
.overrideProvider(getRepositoryToken(Session))
|
||||||
.useValue({})
|
.useValue({})
|
||||||
.overrideProvider(getRepositoryToken(Author))
|
.overrideProvider(getRepositoryToken(Author))
|
||||||
|
|
|
@ -23,6 +23,7 @@ import { Identity } from '../../../identity/identity.entity';
|
||||||
import { LoggerModule } from '../../../logger/logger.module';
|
import { LoggerModule } from '../../../logger/logger.module';
|
||||||
import { MediaUpload } from '../../../media/media-upload.entity';
|
import { MediaUpload } from '../../../media/media-upload.entity';
|
||||||
import { MediaModule } from '../../../media/media.module';
|
import { MediaModule } from '../../../media/media.module';
|
||||||
|
import { Alias } from '../../../notes/alias.entity';
|
||||||
import { Note } from '../../../notes/note.entity';
|
import { Note } from '../../../notes/note.entity';
|
||||||
import { NotesService } from '../../../notes/notes.service';
|
import { NotesService } from '../../../notes/notes.service';
|
||||||
import { Tag } from '../../../notes/tag.entity';
|
import { Tag } from '../../../notes/tag.entity';
|
||||||
|
@ -53,6 +54,10 @@ describe('NotesController', () => {
|
||||||
provide: getRepositoryToken(Tag),
|
provide: getRepositoryToken(Tag),
|
||||||
useValue: {},
|
useValue: {},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
provide: getRepositoryToken(Alias),
|
||||||
|
useValue: {},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
provide: getRepositoryToken(User),
|
provide: getRepositoryToken(User),
|
||||||
useValue: {},
|
useValue: {},
|
||||||
|
@ -99,6 +104,8 @@ describe('NotesController', () => {
|
||||||
.useValue({})
|
.useValue({})
|
||||||
.overrideProvider(getRepositoryToken(MediaUpload))
|
.overrideProvider(getRepositoryToken(MediaUpload))
|
||||||
.useValue({})
|
.useValue({})
|
||||||
|
.overrideProvider(getRepositoryToken(Alias))
|
||||||
|
.useValue({})
|
||||||
.overrideProvider(getRepositoryToken(Session))
|
.overrideProvider(getRepositoryToken(Session))
|
||||||
.useValue({})
|
.useValue({})
|
||||||
.overrideProvider(getRepositoryToken(Author))
|
.overrideProvider(getRepositoryToken(Author))
|
||||||
|
|
|
@ -22,6 +22,7 @@ import { Identity } from '../../../identity/identity.entity';
|
||||||
import { LoggerModule } from '../../../logger/logger.module';
|
import { LoggerModule } from '../../../logger/logger.module';
|
||||||
import { MediaUpload } from '../../../media/media-upload.entity';
|
import { MediaUpload } from '../../../media/media-upload.entity';
|
||||||
import { MediaModule } from '../../../media/media.module';
|
import { MediaModule } from '../../../media/media.module';
|
||||||
|
import { Alias } from '../../../notes/alias.entity';
|
||||||
import { Note } from '../../../notes/note.entity';
|
import { Note } from '../../../notes/note.entity';
|
||||||
import { NotesModule } from '../../../notes/notes.module';
|
import { NotesModule } from '../../../notes/notes.module';
|
||||||
import { Tag } from '../../../notes/tag.entity';
|
import { Tag } from '../../../notes/tag.entity';
|
||||||
|
@ -79,6 +80,8 @@ describe('Me Controller', () => {
|
||||||
.useValue({})
|
.useValue({})
|
||||||
.overrideProvider(getRepositoryToken(MediaUpload))
|
.overrideProvider(getRepositoryToken(MediaUpload))
|
||||||
.useValue({})
|
.useValue({})
|
||||||
|
.overrideProvider(getRepositoryToken(Alias))
|
||||||
|
.useValue({})
|
||||||
.overrideProvider(getRepositoryToken(Session))
|
.overrideProvider(getRepositoryToken(Session))
|
||||||
.useValue({})
|
.useValue({})
|
||||||
.overrideProvider(getRepositoryToken(Author))
|
.overrideProvider(getRepositoryToken(Author))
|
||||||
|
|
|
@ -16,6 +16,7 @@ import { Identity } from '../../../identity/identity.entity';
|
||||||
import { LoggerModule } from '../../../logger/logger.module';
|
import { LoggerModule } from '../../../logger/logger.module';
|
||||||
import { MediaUpload } from '../../../media/media-upload.entity';
|
import { MediaUpload } from '../../../media/media-upload.entity';
|
||||||
import { MediaModule } from '../../../media/media.module';
|
import { MediaModule } from '../../../media/media.module';
|
||||||
|
import { Alias } from '../../../notes/alias.entity';
|
||||||
import { Note } from '../../../notes/note.entity';
|
import { Note } from '../../../notes/note.entity';
|
||||||
import { NotesModule } from '../../../notes/notes.module';
|
import { NotesModule } from '../../../notes/notes.module';
|
||||||
import { Tag } from '../../../notes/tag.entity';
|
import { Tag } from '../../../notes/tag.entity';
|
||||||
|
@ -65,6 +66,8 @@ describe('Media Controller', () => {
|
||||||
.useValue({})
|
.useValue({})
|
||||||
.overrideProvider(getRepositoryToken(Group))
|
.overrideProvider(getRepositoryToken(Group))
|
||||||
.useValue({})
|
.useValue({})
|
||||||
|
.overrideProvider(getRepositoryToken(Alias))
|
||||||
|
.useValue({})
|
||||||
.overrideProvider(getRepositoryToken(Session))
|
.overrideProvider(getRepositoryToken(Session))
|
||||||
.useValue({})
|
.useValue({})
|
||||||
.overrideProvider(getRepositoryToken(Author))
|
.overrideProvider(getRepositoryToken(Author))
|
||||||
|
|
|
@ -23,6 +23,7 @@ import { Identity } from '../../../identity/identity.entity';
|
||||||
import { LoggerModule } from '../../../logger/logger.module';
|
import { LoggerModule } from '../../../logger/logger.module';
|
||||||
import { MediaUpload } from '../../../media/media-upload.entity';
|
import { MediaUpload } from '../../../media/media-upload.entity';
|
||||||
import { MediaModule } from '../../../media/media.module';
|
import { MediaModule } from '../../../media/media.module';
|
||||||
|
import { Alias } from '../../../notes/alias.entity';
|
||||||
import { Note } from '../../../notes/note.entity';
|
import { Note } from '../../../notes/note.entity';
|
||||||
import { NotesService } from '../../../notes/notes.service';
|
import { NotesService } from '../../../notes/notes.service';
|
||||||
import { Tag } from '../../../notes/tag.entity';
|
import { Tag } from '../../../notes/tag.entity';
|
||||||
|
@ -53,6 +54,10 @@ describe('Notes Controller', () => {
|
||||||
provide: getRepositoryToken(Tag),
|
provide: getRepositoryToken(Tag),
|
||||||
useValue: {},
|
useValue: {},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
provide: getRepositoryToken(Alias),
|
||||||
|
useValue: {},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
provide: getRepositoryToken(User),
|
provide: getRepositoryToken(User),
|
||||||
useValue: {},
|
useValue: {},
|
||||||
|
@ -101,6 +106,8 @@ describe('Notes Controller', () => {
|
||||||
.useValue({})
|
.useValue({})
|
||||||
.overrideProvider(getRepositoryToken(MediaUpload))
|
.overrideProvider(getRepositoryToken(MediaUpload))
|
||||||
.useValue({})
|
.useValue({})
|
||||||
|
.overrideProvider(getRepositoryToken(Alias))
|
||||||
|
.useValue({})
|
||||||
.overrideProvider(getRepositoryToken(Session))
|
.overrideProvider(getRepositoryToken(Session))
|
||||||
.useValue({})
|
.useValue({})
|
||||||
.overrideProvider(getRepositoryToken(Author))
|
.overrideProvider(getRepositoryToken(Author))
|
||||||
|
|
|
@ -15,6 +15,7 @@ import { NotInDBError } from '../errors/errors';
|
||||||
import { Group } from '../groups/group.entity';
|
import { Group } from '../groups/group.entity';
|
||||||
import { Identity } from '../identity/identity.entity';
|
import { Identity } from '../identity/identity.entity';
|
||||||
import { LoggerModule } from '../logger/logger.module';
|
import { LoggerModule } from '../logger/logger.module';
|
||||||
|
import { Alias } from '../notes/alias.entity';
|
||||||
import { Note } from '../notes/note.entity';
|
import { Note } from '../notes/note.entity';
|
||||||
import { NotesModule } from '../notes/notes.module';
|
import { NotesModule } from '../notes/notes.module';
|
||||||
import { Tag } from '../notes/tag.entity';
|
import { Tag } from '../notes/tag.entity';
|
||||||
|
@ -34,6 +35,7 @@ describe('HistoryService', () => {
|
||||||
let historyRepo: Repository<HistoryEntry>;
|
let historyRepo: Repository<HistoryEntry>;
|
||||||
let connection;
|
let connection;
|
||||||
let noteRepo: Repository<Note>;
|
let noteRepo: Repository<Note>;
|
||||||
|
let aliasRepo: Repository<Alias>;
|
||||||
|
|
||||||
type MockConnection = {
|
type MockConnection = {
|
||||||
transaction: () => void;
|
transaction: () => void;
|
||||||
|
@ -92,12 +94,15 @@ describe('HistoryService', () => {
|
||||||
.useValue({})
|
.useValue({})
|
||||||
.overrideProvider(getRepositoryToken(Author))
|
.overrideProvider(getRepositoryToken(Author))
|
||||||
.useValue({})
|
.useValue({})
|
||||||
|
.overrideProvider(getRepositoryToken(Alias))
|
||||||
|
.useClass(Repository)
|
||||||
.compile();
|
.compile();
|
||||||
|
|
||||||
service = module.get<HistoryService>(HistoryService);
|
service = module.get<HistoryService>(HistoryService);
|
||||||
historyRepo = module.get<Repository<HistoryEntry>>(
|
historyRepo = module.get<Repository<HistoryEntry>>(
|
||||||
getRepositoryToken(HistoryEntry),
|
getRepositoryToken(HistoryEntry),
|
||||||
);
|
);
|
||||||
|
aliasRepo = module.get<Repository<Alias>>(getRepositoryToken(Alias));
|
||||||
connection = module.get<Connection>(Connection);
|
connection = module.get<Connection>(Connection);
|
||||||
noteRepo = module.get<Repository<Note>>(getRepositoryToken(Note));
|
noteRepo = module.get<Repository<Note>>(getRepositoryToken(Note));
|
||||||
});
|
});
|
||||||
|
@ -151,7 +156,8 @@ describe('HistoryService', () => {
|
||||||
Note.create(user, alias),
|
Note.create(user, alias),
|
||||||
user,
|
user,
|
||||||
);
|
);
|
||||||
expect(createHistoryEntry.note.alias).toEqual(alias);
|
expect(createHistoryEntry.note.aliases).toHaveLength(1);
|
||||||
|
expect(createHistoryEntry.note.aliases[0].name).toEqual(alias);
|
||||||
expect(createHistoryEntry.note.owner).toEqual(user);
|
expect(createHistoryEntry.note.owner).toEqual(user);
|
||||||
expect(createHistoryEntry.user).toEqual(user);
|
expect(createHistoryEntry.user).toEqual(user);
|
||||||
expect(createHistoryEntry.pinStatus).toEqual(false);
|
expect(createHistoryEntry.pinStatus).toEqual(false);
|
||||||
|
@ -168,7 +174,8 @@ describe('HistoryService', () => {
|
||||||
Note.create(user, alias),
|
Note.create(user, alias),
|
||||||
user,
|
user,
|
||||||
);
|
);
|
||||||
expect(createHistoryEntry.note.alias).toEqual(alias);
|
expect(createHistoryEntry.note.aliases).toHaveLength(1);
|
||||||
|
expect(createHistoryEntry.note.aliases[0].name).toEqual(alias);
|
||||||
expect(createHistoryEntry.note.owner).toEqual(user);
|
expect(createHistoryEntry.note.owner).toEqual(user);
|
||||||
expect(createHistoryEntry.user).toEqual(user);
|
expect(createHistoryEntry.user).toEqual(user);
|
||||||
expect(createHistoryEntry.pinStatus).toEqual(false);
|
expect(createHistoryEntry.pinStatus).toEqual(false);
|
||||||
|
@ -180,14 +187,27 @@ describe('HistoryService', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('updateHistoryEntry', () => {
|
describe('updateHistoryEntry', () => {
|
||||||
describe('works', () => {
|
|
||||||
it('with an entry', async () => {
|
|
||||||
const user = {} as User;
|
const user = {} as User;
|
||||||
const alias = 'alias';
|
const alias = 'alias';
|
||||||
const note = Note.create(user, alias);
|
const note = Note.create(user, alias);
|
||||||
|
beforeEach(() => {
|
||||||
|
const createQueryBuilder = {
|
||||||
|
leftJoinAndSelect: () => createQueryBuilder,
|
||||||
|
where: () => createQueryBuilder,
|
||||||
|
orWhere: () => createQueryBuilder,
|
||||||
|
setParameter: () => createQueryBuilder,
|
||||||
|
getOne: () => note,
|
||||||
|
};
|
||||||
|
jest
|
||||||
|
.spyOn(noteRepo, 'createQueryBuilder')
|
||||||
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||||
|
// @ts-ignore
|
||||||
|
.mockImplementation(() => createQueryBuilder);
|
||||||
|
});
|
||||||
|
describe('works', () => {
|
||||||
|
it('with an entry', async () => {
|
||||||
const historyEntry = HistoryEntry.create(user, note);
|
const historyEntry = HistoryEntry.create(user, note);
|
||||||
jest.spyOn(historyRepo, 'findOne').mockResolvedValueOnce(historyEntry);
|
jest.spyOn(historyRepo, 'findOne').mockResolvedValueOnce(historyEntry);
|
||||||
jest.spyOn(noteRepo, 'findOne').mockResolvedValueOnce(note);
|
|
||||||
jest
|
jest
|
||||||
.spyOn(historyRepo, 'save')
|
.spyOn(historyRepo, 'save')
|
||||||
.mockImplementation(
|
.mockImplementation(
|
||||||
|
@ -200,18 +220,15 @@ describe('HistoryService', () => {
|
||||||
pinStatus: true,
|
pinStatus: true,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
expect(updatedHistoryEntry.note.alias).toEqual(alias);
|
expect(updatedHistoryEntry.note.aliases).toHaveLength(1);
|
||||||
|
expect(updatedHistoryEntry.note.aliases[0].name).toEqual(alias);
|
||||||
expect(updatedHistoryEntry.note.owner).toEqual(user);
|
expect(updatedHistoryEntry.note.owner).toEqual(user);
|
||||||
expect(updatedHistoryEntry.user).toEqual(user);
|
expect(updatedHistoryEntry.user).toEqual(user);
|
||||||
expect(updatedHistoryEntry.pinStatus).toEqual(true);
|
expect(updatedHistoryEntry.pinStatus).toEqual(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('without an entry', async () => {
|
it('without an entry', async () => {
|
||||||
const user = {} as User;
|
|
||||||
const alias = 'alias';
|
|
||||||
const note = Note.create(user, alias);
|
|
||||||
jest.spyOn(historyRepo, 'findOne').mockResolvedValueOnce(undefined);
|
jest.spyOn(historyRepo, 'findOne').mockResolvedValueOnce(undefined);
|
||||||
jest.spyOn(noteRepo, 'findOne').mockResolvedValueOnce(note);
|
|
||||||
await expect(
|
await expect(
|
||||||
service.updateHistoryEntry(note, user, {
|
service.updateHistoryEntry(note, user, {
|
||||||
pinStatus: true,
|
pinStatus: true,
|
||||||
|
@ -278,7 +295,18 @@ describe('HistoryService', () => {
|
||||||
const note = Note.create(user, alias);
|
const note = Note.create(user, alias);
|
||||||
const historyEntry = HistoryEntry.create(user, note);
|
const historyEntry = HistoryEntry.create(user, note);
|
||||||
jest.spyOn(historyRepo, 'findOne').mockResolvedValueOnce(historyEntry);
|
jest.spyOn(historyRepo, 'findOne').mockResolvedValueOnce(historyEntry);
|
||||||
jest.spyOn(noteRepo, 'findOne').mockResolvedValueOnce(note);
|
const createQueryBuilder = {
|
||||||
|
leftJoinAndSelect: () => createQueryBuilder,
|
||||||
|
where: () => createQueryBuilder,
|
||||||
|
orWhere: () => createQueryBuilder,
|
||||||
|
setParameter: () => createQueryBuilder,
|
||||||
|
getOne: () => note,
|
||||||
|
};
|
||||||
|
jest
|
||||||
|
.spyOn(noteRepo, 'createQueryBuilder')
|
||||||
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||||
|
// @ts-ignore
|
||||||
|
.mockImplementation(() => createQueryBuilder);
|
||||||
jest
|
jest
|
||||||
.spyOn(historyRepo, 'remove')
|
.spyOn(historyRepo, 'remove')
|
||||||
.mockImplementation(
|
.mockImplementation(
|
||||||
|
@ -295,8 +323,19 @@ describe('HistoryService', () => {
|
||||||
const alias = 'alias';
|
const alias = 'alias';
|
||||||
it('without an entry', async () => {
|
it('without an entry', async () => {
|
||||||
const note = Note.create(user, alias);
|
const note = Note.create(user, alias);
|
||||||
|
const createQueryBuilder = {
|
||||||
|
leftJoinAndSelect: () => createQueryBuilder,
|
||||||
|
where: () => createQueryBuilder,
|
||||||
|
orWhere: () => createQueryBuilder,
|
||||||
|
setParameter: () => createQueryBuilder,
|
||||||
|
getOne: () => note,
|
||||||
|
};
|
||||||
|
jest
|
||||||
|
.spyOn(noteRepo, 'createQueryBuilder')
|
||||||
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||||
|
// @ts-ignore
|
||||||
|
.mockImplementation(() => createQueryBuilder);
|
||||||
jest.spyOn(historyRepo, 'findOne').mockResolvedValueOnce(undefined);
|
jest.spyOn(historyRepo, 'findOne').mockResolvedValueOnce(undefined);
|
||||||
jest.spyOn(noteRepo, 'findOne').mockResolvedValueOnce(note);
|
|
||||||
await expect(service.deleteHistoryEntry(note, user)).rejects.toThrow(
|
await expect(service.deleteHistoryEntry(note, user)).rejects.toThrow(
|
||||||
NotInDBError,
|
NotInDBError,
|
||||||
);
|
);
|
||||||
|
@ -320,15 +359,24 @@ describe('HistoryService', () => {
|
||||||
pinStatus: historyEntryImport.pinStatus,
|
pinStatus: historyEntryImport.pinStatus,
|
||||||
updatedAt: historyEntryImport.lastVisited,
|
updatedAt: historyEntryImport.lastVisited,
|
||||||
};
|
};
|
||||||
|
const createQueryBuilder = {
|
||||||
|
innerJoin: () => createQueryBuilder,
|
||||||
|
where: () => createQueryBuilder,
|
||||||
|
orWhere: () => createQueryBuilder,
|
||||||
|
getOne: () => note,
|
||||||
|
};
|
||||||
const mockedManager = {
|
const mockedManager = {
|
||||||
find: jest.fn().mockResolvedValueOnce([historyEntry]),
|
find: jest.fn().mockResolvedValueOnce([historyEntry]),
|
||||||
findOne: jest.fn().mockResolvedValueOnce(note),
|
createQueryBuilder: () => createQueryBuilder,
|
||||||
remove: jest.fn().mockImplementationOnce((entry: HistoryEntry) => {
|
remove: jest.fn().mockImplementationOnce((entry: HistoryEntry) => {
|
||||||
expect(entry.note.alias).toEqual(alias);
|
expect(entry.note.aliases).toHaveLength(1);
|
||||||
|
expect(entry.note.aliases[0].name).toEqual(alias);
|
||||||
expect(entry.pinStatus).toEqual(false);
|
expect(entry.pinStatus).toEqual(false);
|
||||||
}),
|
}),
|
||||||
save: jest.fn().mockImplementationOnce((entry: HistoryEntry) => {
|
save: jest.fn().mockImplementationOnce((entry: HistoryEntry) => {
|
||||||
expect(entry.note.alias).toEqual(newlyCreatedHistoryEntry.note.alias);
|
expect(entry.note.aliases).toEqual(
|
||||||
|
newlyCreatedHistoryEntry.note.aliases,
|
||||||
|
);
|
||||||
expect(entry.pinStatus).toEqual(newlyCreatedHistoryEntry.pinStatus);
|
expect(entry.pinStatus).toEqual(newlyCreatedHistoryEntry.pinStatus);
|
||||||
expect(entry.updatedAt).toEqual(newlyCreatedHistoryEntry.updatedAt);
|
expect(entry.updatedAt).toEqual(newlyCreatedHistoryEntry.updatedAt);
|
||||||
}),
|
}),
|
||||||
|
@ -358,36 +406,23 @@ describe('HistoryService', () => {
|
||||||
});
|
});
|
||||||
const historyEntry = HistoryEntry.create(user, note);
|
const historyEntry = HistoryEntry.create(user, note);
|
||||||
historyEntry.pinStatus = true;
|
historyEntry.pinStatus = true;
|
||||||
jest.spyOn(noteRepo, 'findOne').mockResolvedValueOnce(note);
|
const createQueryBuilder = {
|
||||||
|
leftJoinAndSelect: () => createQueryBuilder,
|
||||||
|
where: () => createQueryBuilder,
|
||||||
|
orWhere: () => createQueryBuilder,
|
||||||
|
getOne: () => note,
|
||||||
|
};
|
||||||
|
jest
|
||||||
|
.spyOn(noteRepo, 'createQueryBuilder')
|
||||||
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||||
|
// @ts-ignore
|
||||||
|
.mockImplementation(() => createQueryBuilder);
|
||||||
const historyEntryDto = service.toHistoryEntryDto(historyEntry);
|
const historyEntryDto = service.toHistoryEntryDto(historyEntry);
|
||||||
expect(historyEntryDto.pinStatus).toEqual(true);
|
expect(historyEntryDto.pinStatus).toEqual(true);
|
||||||
expect(historyEntryDto.identifier).toEqual(alias);
|
expect(historyEntryDto.identifier).toEqual(alias);
|
||||||
expect(historyEntryDto.tags).toEqual(tags);
|
expect(historyEntryDto.tags).toEqual(tags);
|
||||||
expect(historyEntryDto.title).toEqual(title);
|
expect(historyEntryDto.title).toEqual(title);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('with regular note', async () => {
|
|
||||||
const user = {} as User;
|
|
||||||
const title = 'title';
|
|
||||||
const id = 'id';
|
|
||||||
const tags = ['tag1', 'tag2'];
|
|
||||||
const note = Note.create(user);
|
|
||||||
note.title = title;
|
|
||||||
note.id = id;
|
|
||||||
note.tags = tags.map((tag) => {
|
|
||||||
const newTag = new Tag();
|
|
||||||
newTag.name = tag;
|
|
||||||
return newTag;
|
|
||||||
});
|
|
||||||
const historyEntry = HistoryEntry.create(user, note);
|
|
||||||
historyEntry.pinStatus = true;
|
|
||||||
jest.spyOn(noteRepo, 'findOne').mockResolvedValueOnce(note);
|
|
||||||
const historyEntryDto = service.toHistoryEntryDto(historyEntry);
|
|
||||||
expect(historyEntryDto.pinStatus).toEqual(true);
|
|
||||||
expect(historyEntryDto.identifier).toEqual(id);
|
|
||||||
expect(historyEntryDto.tags).toEqual(tags);
|
|
||||||
expect(historyEntryDto.title).toEqual(title);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -17,6 +17,7 @@ import { ClientError, NotInDBError } from '../errors/errors';
|
||||||
import { Group } from '../groups/group.entity';
|
import { Group } from '../groups/group.entity';
|
||||||
import { Identity } from '../identity/identity.entity';
|
import { Identity } from '../identity/identity.entity';
|
||||||
import { LoggerModule } from '../logger/logger.module';
|
import { LoggerModule } from '../logger/logger.module';
|
||||||
|
import { Alias } from '../notes/alias.entity';
|
||||||
import { Note } from '../notes/note.entity';
|
import { Note } from '../notes/note.entity';
|
||||||
import { NotesModule } from '../notes/notes.module';
|
import { NotesModule } from '../notes/notes.module';
|
||||||
import { Tag } from '../notes/tag.entity';
|
import { Tag } from '../notes/tag.entity';
|
||||||
|
@ -83,6 +84,8 @@ describe('MediaService', () => {
|
||||||
.useValue({})
|
.useValue({})
|
||||||
.overrideProvider(getRepositoryToken(Author))
|
.overrideProvider(getRepositoryToken(Author))
|
||||||
.useValue({})
|
.useValue({})
|
||||||
|
.overrideProvider(getRepositoryToken(Alias))
|
||||||
|
.useValue({})
|
||||||
.compile();
|
.compile();
|
||||||
|
|
||||||
service = module.get<MediaService>(MediaService);
|
service = module.get<MediaService>(MediaService);
|
||||||
|
@ -105,7 +108,18 @@ describe('MediaService', () => {
|
||||||
const alias = 'alias';
|
const alias = 'alias';
|
||||||
note = Note.create(user, alias);
|
note = Note.create(user, alias);
|
||||||
jest.spyOn(userRepo, 'findOne').mockResolvedValueOnce(user);
|
jest.spyOn(userRepo, 'findOne').mockResolvedValueOnce(user);
|
||||||
jest.spyOn(noteRepo, 'findOne').mockResolvedValueOnce(note);
|
const createQueryBuilder = {
|
||||||
|
leftJoinAndSelect: () => createQueryBuilder,
|
||||||
|
where: () => createQueryBuilder,
|
||||||
|
orWhere: () => createQueryBuilder,
|
||||||
|
setParameter: () => createQueryBuilder,
|
||||||
|
getOne: () => note,
|
||||||
|
};
|
||||||
|
jest
|
||||||
|
.spyOn(noteRepo, 'createQueryBuilder')
|
||||||
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||||
|
// @ts-ignore
|
||||||
|
.mockImplementation(() => createQueryBuilder);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('works', async () => {
|
it('works', async () => {
|
||||||
|
@ -279,7 +293,7 @@ describe('MediaService', () => {
|
||||||
id: 'testMediaUpload',
|
id: 'testMediaUpload',
|
||||||
backendData: 'testBackendData',
|
backendData: 'testBackendData',
|
||||||
note: {
|
note: {
|
||||||
alias: 'test',
|
aliases: [Alias.create('test', true)],
|
||||||
} as Note,
|
} as Note,
|
||||||
user: {
|
user: {
|
||||||
userName: 'hardcoded',
|
userName: 'hardcoded',
|
||||||
|
|
|
@ -29,6 +29,7 @@ import { RevisionsModule } from '../revisions/revisions.module';
|
||||||
import { Session } from '../users/session.entity';
|
import { Session } from '../users/session.entity';
|
||||||
import { User } from '../users/user.entity';
|
import { User } from '../users/user.entity';
|
||||||
import { UsersModule } from '../users/users.module';
|
import { UsersModule } from '../users/users.module';
|
||||||
|
import { Alias } from './alias.entity';
|
||||||
import {
|
import {
|
||||||
NoteGroupPermissionUpdateDto,
|
NoteGroupPermissionUpdateDto,
|
||||||
NoteUserPermissionUpdateDto,
|
NoteUserPermissionUpdateDto,
|
||||||
|
@ -63,6 +64,10 @@ describe('NotesService', () => {
|
||||||
provide: getRepositoryToken(Tag),
|
provide: getRepositoryToken(Tag),
|
||||||
useClass: Repository,
|
useClass: Repository,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
provide: getRepositoryToken(Alias),
|
||||||
|
useClass: Repository,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
provide: getRepositoryToken(User),
|
provide: getRepositoryToken(User),
|
||||||
useValue: userRepo,
|
useValue: userRepo,
|
||||||
|
@ -83,6 +88,8 @@ describe('NotesService', () => {
|
||||||
.useClass(Repository)
|
.useClass(Repository)
|
||||||
.overrideProvider(getRepositoryToken(Tag))
|
.overrideProvider(getRepositoryToken(Tag))
|
||||||
.useClass(Repository)
|
.useClass(Repository)
|
||||||
|
.overrideProvider(getRepositoryToken(Alias))
|
||||||
|
.useClass(Repository)
|
||||||
.overrideProvider(getRepositoryToken(User))
|
.overrideProvider(getRepositoryToken(User))
|
||||||
.useValue(userRepo)
|
.useValue(userRepo)
|
||||||
.overrideProvider(getRepositoryToken(AuthToken))
|
.overrideProvider(getRepositoryToken(AuthToken))
|
||||||
|
@ -166,7 +173,7 @@ describe('NotesService', () => {
|
||||||
expect(newNote.groupPermissions).toHaveLength(0);
|
expect(newNote.groupPermissions).toHaveLength(0);
|
||||||
expect(newNote.tags).toHaveLength(0);
|
expect(newNote.tags).toHaveLength(0);
|
||||||
expect(newNote.owner).toBeNull();
|
expect(newNote.owner).toBeNull();
|
||||||
expect(newNote.alias).toBeNull();
|
expect(newNote.aliases).toHaveLength(0);
|
||||||
});
|
});
|
||||||
it('without alias, with owner', async () => {
|
it('without alias, with owner', async () => {
|
||||||
const newNote = await service.createNote(content, undefined, user);
|
const newNote = await service.createNote(content, undefined, user);
|
||||||
|
@ -179,7 +186,7 @@ describe('NotesService', () => {
|
||||||
expect(newNote.groupPermissions).toHaveLength(0);
|
expect(newNote.groupPermissions).toHaveLength(0);
|
||||||
expect(newNote.tags).toHaveLength(0);
|
expect(newNote.tags).toHaveLength(0);
|
||||||
expect(newNote.owner).toEqual(user);
|
expect(newNote.owner).toEqual(user);
|
||||||
expect(newNote.alias).toBeNull();
|
expect(newNote.aliases).toHaveLength(0);
|
||||||
});
|
});
|
||||||
it('with alias, without owner', async () => {
|
it('with alias, without owner', async () => {
|
||||||
const newNote = await service.createNote(content, alias);
|
const newNote = await service.createNote(content, alias);
|
||||||
|
@ -191,7 +198,7 @@ describe('NotesService', () => {
|
||||||
expect(newNote.groupPermissions).toHaveLength(0);
|
expect(newNote.groupPermissions).toHaveLength(0);
|
||||||
expect(newNote.tags).toHaveLength(0);
|
expect(newNote.tags).toHaveLength(0);
|
||||||
expect(newNote.owner).toBeNull();
|
expect(newNote.owner).toBeNull();
|
||||||
expect(newNote.alias).toEqual(alias);
|
expect(newNote.aliases).toHaveLength(1);
|
||||||
});
|
});
|
||||||
it('with alias, with owner', async () => {
|
it('with alias, with owner', async () => {
|
||||||
const newNote = await service.createNote(content, alias, user);
|
const newNote = await service.createNote(content, alias, user);
|
||||||
|
@ -204,7 +211,8 @@ describe('NotesService', () => {
|
||||||
expect(newNote.groupPermissions).toHaveLength(0);
|
expect(newNote.groupPermissions).toHaveLength(0);
|
||||||
expect(newNote.tags).toHaveLength(0);
|
expect(newNote.tags).toHaveLength(0);
|
||||||
expect(newNote.owner).toEqual(user);
|
expect(newNote.owner).toEqual(user);
|
||||||
expect(newNote.alias).toEqual(alias);
|
expect(newNote.aliases).toHaveLength(1);
|
||||||
|
expect(newNote.aliases[0].name).toEqual(alias);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe('fails:', () => {
|
describe('fails:', () => {
|
||||||
|
@ -276,19 +284,40 @@ describe('NotesService', () => {
|
||||||
it('works', async () => {
|
it('works', async () => {
|
||||||
const user = User.create('hardcoded', 'Testy') as User;
|
const user = User.create('hardcoded', 'Testy') as User;
|
||||||
const note = Note.create(user);
|
const note = Note.create(user);
|
||||||
jest.spyOn(noteRepo, 'findOne').mockResolvedValueOnce(note);
|
const createQueryBuilder = {
|
||||||
|
leftJoinAndSelect: () => createQueryBuilder,
|
||||||
|
where: () => createQueryBuilder,
|
||||||
|
orWhere: () => createQueryBuilder,
|
||||||
|
setParameter: () => createQueryBuilder,
|
||||||
|
getOne: () => note,
|
||||||
|
};
|
||||||
|
jest
|
||||||
|
.spyOn(noteRepo, 'createQueryBuilder')
|
||||||
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||||
|
// @ts-ignore
|
||||||
|
.mockImplementation(() => createQueryBuilder);
|
||||||
const foundNote = await service.getNoteByIdOrAlias('noteThatExists');
|
const foundNote = await service.getNoteByIdOrAlias('noteThatExists');
|
||||||
expect(foundNote).toEqual(note);
|
expect(foundNote).toEqual(note);
|
||||||
});
|
});
|
||||||
describe('fails:', () => {
|
describe('fails:', () => {
|
||||||
it('no note found', async () => {
|
it('no note found', async () => {
|
||||||
jest.spyOn(noteRepo, 'findOne').mockResolvedValueOnce(undefined);
|
const createQueryBuilder = {
|
||||||
|
leftJoinAndSelect: () => createQueryBuilder,
|
||||||
|
where: () => createQueryBuilder,
|
||||||
|
orWhere: () => createQueryBuilder,
|
||||||
|
setParameter: () => createQueryBuilder,
|
||||||
|
getOne: () => undefined,
|
||||||
|
};
|
||||||
|
jest
|
||||||
|
.spyOn(noteRepo, 'createQueryBuilder')
|
||||||
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||||
|
// @ts-ignore
|
||||||
|
.mockImplementation(() => createQueryBuilder);
|
||||||
await expect(
|
await expect(
|
||||||
service.getNoteByIdOrAlias('noteThatDoesNoteExist'),
|
service.getNoteByIdOrAlias('noteThatDoesNoteExist'),
|
||||||
).rejects.toThrow(NotInDBError);
|
).rejects.toThrow(NotInDBError);
|
||||||
});
|
});
|
||||||
it('id is forbidden', async () => {
|
it('id is forbidden', async () => {
|
||||||
jest.spyOn(noteRepo, 'findOne').mockResolvedValueOnce(undefined);
|
|
||||||
await expect(
|
await expect(
|
||||||
service.getNoteByIdOrAlias(forbiddenNoteId),
|
service.getNoteByIdOrAlias(forbiddenNoteId),
|
||||||
).rejects.toThrow(ForbiddenIdError);
|
).rejects.toThrow(ForbiddenIdError);
|
||||||
|
@ -709,7 +738,7 @@ describe('NotesService', () => {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
.mockImplementation(() => createQueryBuilder);
|
.mockImplementation(() => createQueryBuilder);
|
||||||
note.publicId = 'testId';
|
note.publicId = 'testId';
|
||||||
note.alias = 'testAlias';
|
note.aliases = [Alias.create('testAlias', true)];
|
||||||
note.title = 'testTitle';
|
note.title = 'testTitle';
|
||||||
note.description = 'testDescription';
|
note.description = 'testDescription';
|
||||||
note.owner = user;
|
note.owner = user;
|
||||||
|
@ -737,7 +766,8 @@ describe('NotesService', () => {
|
||||||
note.viewCount = 1337;
|
note.viewCount = 1337;
|
||||||
const metadataDto = await service.toNoteMetadataDto(note);
|
const metadataDto = await service.toNoteMetadataDto(note);
|
||||||
expect(metadataDto.id).toEqual(note.publicId);
|
expect(metadataDto.id).toEqual(note.publicId);
|
||||||
expect(metadataDto.alias).toEqual(note.alias);
|
expect(metadataDto.aliases).toHaveLength(1);
|
||||||
|
expect(metadataDto.aliases[0]).toEqual(note.aliases[0].name);
|
||||||
expect(metadataDto.title).toEqual(note.title);
|
expect(metadataDto.title).toEqual(note.title);
|
||||||
expect(metadataDto.createTime).toEqual(revisions[0].createdAt);
|
expect(metadataDto.createTime).toEqual(revisions[0].createdAt);
|
||||||
expect(metadataDto.description).toEqual(note.description);
|
expect(metadataDto.description).toEqual(note.description);
|
||||||
|
@ -808,7 +838,7 @@ describe('NotesService', () => {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
.mockImplementation(() => createQueryBuilder);
|
.mockImplementation(() => createQueryBuilder);
|
||||||
note.publicId = 'testId';
|
note.publicId = 'testId';
|
||||||
note.alias = 'testAlias';
|
note.aliases = [Alias.create('testAlias', true)];
|
||||||
note.title = 'testTitle';
|
note.title = 'testTitle';
|
||||||
note.description = 'testDescription';
|
note.description = 'testDescription';
|
||||||
note.owner = user;
|
note.owner = user;
|
||||||
|
@ -836,7 +866,8 @@ describe('NotesService', () => {
|
||||||
note.viewCount = 1337;
|
note.viewCount = 1337;
|
||||||
const noteDto = await service.toNoteDto(note);
|
const noteDto = await service.toNoteDto(note);
|
||||||
expect(noteDto.metadata.id).toEqual(note.publicId);
|
expect(noteDto.metadata.id).toEqual(note.publicId);
|
||||||
expect(noteDto.metadata.alias).toEqual(note.alias);
|
expect(noteDto.metadata.aliases).toHaveLength(1);
|
||||||
|
expect(noteDto.metadata.aliases[0]).toEqual(note.aliases[0].name);
|
||||||
expect(noteDto.metadata.title).toEqual(note.title);
|
expect(noteDto.metadata.title).toEqual(note.title);
|
||||||
expect(noteDto.metadata.createTime).toEqual(revisions[0].createdAt);
|
expect(noteDto.metadata.createTime).toEqual(revisions[0].createdAt);
|
||||||
expect(noteDto.metadata.description).toEqual(note.description);
|
expect(noteDto.metadata.description).toEqual(note.description);
|
||||||
|
|
|
@ -13,6 +13,7 @@ import appConfigMock from '../config/mock/app.config.mock';
|
||||||
import { Group } from '../groups/group.entity';
|
import { Group } from '../groups/group.entity';
|
||||||
import { Identity } from '../identity/identity.entity';
|
import { Identity } from '../identity/identity.entity';
|
||||||
import { LoggerModule } from '../logger/logger.module';
|
import { LoggerModule } from '../logger/logger.module';
|
||||||
|
import { Alias } from '../notes/alias.entity';
|
||||||
import { Note } from '../notes/note.entity';
|
import { Note } from '../notes/note.entity';
|
||||||
import { NotesModule } from '../notes/notes.module';
|
import { NotesModule } from '../notes/notes.module';
|
||||||
import { Tag } from '../notes/tag.entity';
|
import { Tag } from '../notes/tag.entity';
|
||||||
|
@ -67,6 +68,8 @@ describe('PermissionsService', () => {
|
||||||
.useValue({})
|
.useValue({})
|
||||||
.overrideProvider(getRepositoryToken(Author))
|
.overrideProvider(getRepositoryToken(Author))
|
||||||
.useValue({})
|
.useValue({})
|
||||||
|
.overrideProvider(getRepositoryToken(Alias))
|
||||||
|
.useValue({})
|
||||||
.compile();
|
.compile();
|
||||||
permissionsService = module.get<PermissionsService>(PermissionsService);
|
permissionsService = module.get<PermissionsService>(PermissionsService);
|
||||||
});
|
});
|
||||||
|
|
|
@ -15,6 +15,7 @@ import { NotInDBError } from '../errors/errors';
|
||||||
import { Group } from '../groups/group.entity';
|
import { Group } from '../groups/group.entity';
|
||||||
import { Identity } from '../identity/identity.entity';
|
import { Identity } from '../identity/identity.entity';
|
||||||
import { LoggerModule } from '../logger/logger.module';
|
import { LoggerModule } from '../logger/logger.module';
|
||||||
|
import { Alias } from '../notes/alias.entity';
|
||||||
import { Note } from '../notes/note.entity';
|
import { Note } from '../notes/note.entity';
|
||||||
import { NotesModule } from '../notes/notes.module';
|
import { NotesModule } from '../notes/notes.module';
|
||||||
import { Tag } from '../notes/tag.entity';
|
import { Tag } from '../notes/tag.entity';
|
||||||
|
@ -68,6 +69,8 @@ describe('RevisionsService', () => {
|
||||||
.useValue({})
|
.useValue({})
|
||||||
.overrideProvider(getRepositoryToken(Group))
|
.overrideProvider(getRepositoryToken(Group))
|
||||||
.useValue({})
|
.useValue({})
|
||||||
|
.overrideProvider(getRepositoryToken(Alias))
|
||||||
|
.useValue({})
|
||||||
.overrideProvider(getRepositoryToken(Session))
|
.overrideProvider(getRepositoryToken(Session))
|
||||||
.useValue({})
|
.useValue({})
|
||||||
.overrideProvider(getRepositoryToken(Author))
|
.overrideProvider(getRepositoryToken(Author))
|
||||||
|
|
Loading…
Reference in a new issue