test: fix e2e tests to handle the new aliases

Signed-off-by: Philip Molares <philip.molares@udo.edu>
This commit is contained in:
Philip Molares 2021-06-06 17:55:41 +02:00 committed by David Mehren
parent 90b64c73b3
commit 56eaddff8c
No known key found for this signature in database
GPG key ID: 185982BA4C42B7C3
6 changed files with 465 additions and 24 deletions

View file

@ -77,7 +77,7 @@ describe('History', () => {
const userService = moduleRef.get(UsersService);
user = await userService.createUser('hardcoded', 'Testy');
const notesService = moduleRef.get(NotesService);
note = await notesService.createNote(content, null, user);
note = await notesService.createNote(content, 'note', user);
note2 = await notesService.createNote(content, 'note2', user);
});
@ -109,7 +109,9 @@ describe('History', () => {
const pinStatus = true;
const lastVisited = new Date('2020-12-01 12:23:34');
const postEntryDto = new HistoryEntryImportDto();
postEntryDto.note = note2.alias;
postEntryDto.note = note2.aliases.filter(
(alias) => alias.primary,
)[0].name;
postEntryDto.pinStatus = pinStatus;
postEntryDto.lastVisited = lastVisited;
await request(app.getHttpServer())
@ -119,7 +121,7 @@ describe('History', () => {
.expect(201);
const userEntries = await historyService.getEntriesByUser(user);
expect(userEntries.length).toEqual(1);
expect(userEntries[0].note.alias).toEqual(note2.alias);
expect(userEntries[0].note.aliases).toEqual(note2.aliases);
expect(userEntries[0].user.userName).toEqual(user.userName);
expect(userEntries[0].pinStatus).toEqual(pinStatus);
expect(userEntries[0].updatedAt).toEqual(lastVisited);
@ -136,7 +138,9 @@ describe('History', () => {
pinStatus = !previousHistory[0].pinStatus;
lastVisited = new Date('2020-12-01 23:34:45');
postEntryDto = new HistoryEntryImportDto();
postEntryDto.note = note2.alias;
postEntryDto.note = note2.aliases.filter(
(alias) => alias.primary,
)[0].name;
postEntryDto.pinStatus = pinStatus;
postEntryDto.lastVisited = lastVisited;
});
@ -165,7 +169,7 @@ describe('History', () => {
afterEach(async () => {
const historyEntries = await historyService.getEntriesByUser(user);
expect(historyEntries).toHaveLength(1);
expect(historyEntries[0].note.alias).toEqual(prevEntry.note.alias);
expect(historyEntries[0].note.aliases).toEqual(prevEntry.note.aliases);
expect(historyEntries[0].user.userName).toEqual(
prevEntry.user.userName,
);
@ -184,8 +188,9 @@ describe('History', () => {
it('PUT /me/history/:note', async () => {
const entry = await historyService.updateHistoryEntryTimestamp(note2, user);
expect(entry.pinStatus).toBeFalsy();
const alias = entry.note.aliases.filter((alias) => alias.primary)[0].name;
await request(app.getHttpServer())
.put(`/me/history/${entry.note.alias || 'undefined'}`)
.put(`/me/history/${alias || 'undefined'}`)
.send({ pinStatus: true })
.expect(200);
const userEntries = await historyService.getEntriesByUser(user);
@ -196,10 +201,11 @@ describe('History', () => {
it('DELETE /me/history/:note', async () => {
const entry = await historyService.updateHistoryEntryTimestamp(note2, user);
const alias = entry.note.aliases.filter((alias) => alias.primary)[0].name;
const entry2 = await historyService.updateHistoryEntryTimestamp(note, user);
const entryDto = historyService.toHistoryEntryDto(entry2);
await request(app.getHttpServer())
.delete(`/me/history/${entry.note.alias || 'undefined'}`)
.delete(`/me/history/${alias || 'undefined'}`)
.expect(200);
const userEntries = await historyService.getEntriesByUser(user);
expect(userEntries.length).toEqual(1);