diff --git a/src/history/history.service.spec.ts b/src/history/history.service.spec.ts index 6cc7d947c..14ca1d82e 100644 --- a/src/history/history.service.spec.ts +++ b/src/history/history.service.spec.ts @@ -143,10 +143,8 @@ describe('HistoryService', () => { describe('works', () => { const user = {} as User; const alias = 'alias'; - const pinStatus = true; - const lastVisited = new Date('2020-12-01 12:23:34'); const historyEntry = HistoryEntry.create(user, Note.create(user, alias)); - it('without an preexisting entry, without pinStatus and without lastVisited', async () => { + it('without an preexisting entry', async () => { jest.spyOn(historyRepo, 'findOne').mockResolvedValueOnce(undefined); jest .spyOn(historyRepo, 'save') @@ -163,65 +161,7 @@ describe('HistoryService', () => { expect(createHistoryEntry.pinStatus).toEqual(false); }); - it('without an preexisting entry, with pinStatus and without lastVisited', async () => { - jest.spyOn(historyRepo, 'findOne').mockResolvedValueOnce(undefined); - jest - .spyOn(historyRepo, 'save') - .mockImplementation( - async (entry: HistoryEntry): Promise => entry, - ); - const createHistoryEntry = await service.createOrUpdateHistoryEntry( - Note.create(user, alias), - user, - pinStatus, - ); - expect(createHistoryEntry.note.alias).toEqual(alias); - expect(createHistoryEntry.note.owner).toEqual(user); - expect(createHistoryEntry.user).toEqual(user); - expect(createHistoryEntry.pinStatus).toEqual(pinStatus); - }); - - it('without an preexisting entry, without pinStatus and with lastVisited', async () => { - jest.spyOn(historyRepo, 'findOne').mockResolvedValueOnce(undefined); - jest - .spyOn(historyRepo, 'save') - .mockImplementation( - async (entry: HistoryEntry): Promise => entry, - ); - const createHistoryEntry = await service.createOrUpdateHistoryEntry( - Note.create(user, alias), - user, - undefined, - lastVisited, - ); - expect(createHistoryEntry.note.alias).toEqual(alias); - expect(createHistoryEntry.note.owner).toEqual(user); - expect(createHistoryEntry.user).toEqual(user); - expect(createHistoryEntry.pinStatus).toEqual(false); - expect(createHistoryEntry.updatedAt).toEqual(lastVisited); - }); - - it('without an preexisting entry, with pinStatus and with lastVisited', async () => { - jest.spyOn(historyRepo, 'findOne').mockResolvedValueOnce(undefined); - jest - .spyOn(historyRepo, 'save') - .mockImplementation( - async (entry: HistoryEntry): Promise => entry, - ); - const createHistoryEntry = await service.createOrUpdateHistoryEntry( - Note.create(user, alias), - user, - pinStatus, - lastVisited, - ); - expect(createHistoryEntry.note.alias).toEqual(alias); - expect(createHistoryEntry.note.owner).toEqual(user); - expect(createHistoryEntry.user).toEqual(user); - expect(createHistoryEntry.pinStatus).toEqual(pinStatus); - expect(createHistoryEntry.updatedAt).toEqual(lastVisited); - }); - - it('with an preexisting entry, without pinStatus and without lastVisited', async () => { + it('with an preexisting entry', async () => { jest.spyOn(historyRepo, 'findOne').mockResolvedValueOnce(historyEntry); jest .spyOn(historyRepo, 'save') @@ -240,67 +180,6 @@ describe('HistoryService', () => { historyEntry.updatedAt.getTime(), ); }); - - it('with an preexisting entry, with pinStatus and without lastVisited', async () => { - jest.spyOn(historyRepo, 'findOne').mockResolvedValueOnce(historyEntry); - jest - .spyOn(historyRepo, 'save') - .mockImplementation( - async (entry: HistoryEntry): Promise => entry, - ); - const createHistoryEntry = await service.createOrUpdateHistoryEntry( - Note.create(user, alias), - user, - pinStatus, - ); - expect(createHistoryEntry.note.alias).toEqual(alias); - expect(createHistoryEntry.note.owner).toEqual(user); - expect(createHistoryEntry.user).toEqual(user); - expect(createHistoryEntry.pinStatus).not.toEqual(pinStatus); - expect(createHistoryEntry.updatedAt.getTime()).toBeGreaterThanOrEqual( - historyEntry.updatedAt.getTime(), - ); - }); - - it('with an preexisting entry, without pinStatus and with lastVisited', async () => { - jest.spyOn(historyRepo, 'findOne').mockResolvedValueOnce(historyEntry); - jest - .spyOn(historyRepo, 'save') - .mockImplementation( - async (entry: HistoryEntry): Promise => entry, - ); - const createHistoryEntry = await service.createOrUpdateHistoryEntry( - Note.create(user, alias), - user, - undefined, - lastVisited, - ); - expect(createHistoryEntry.note.alias).toEqual(alias); - expect(createHistoryEntry.note.owner).toEqual(user); - expect(createHistoryEntry.user).toEqual(user); - expect(createHistoryEntry.pinStatus).toEqual(false); - expect(createHistoryEntry.updatedAt).not.toEqual(lastVisited); - }); - - it('with an preexisting entry, with pinStatus and with lastVisited', async () => { - jest.spyOn(historyRepo, 'findOne').mockResolvedValueOnce(historyEntry); - jest - .spyOn(historyRepo, 'save') - .mockImplementation( - async (entry: HistoryEntry): Promise => entry, - ); - const createHistoryEntry = await service.createOrUpdateHistoryEntry( - Note.create(user, alias), - user, - pinStatus, - lastVisited, - ); - expect(createHistoryEntry.note.alias).toEqual(alias); - expect(createHistoryEntry.note.owner).toEqual(user); - expect(createHistoryEntry.user).toEqual(user); - expect(createHistoryEntry.pinStatus).not.toEqual(pinStatus); - expect(createHistoryEntry.updatedAt).not.toEqual(lastVisited); - }); }); }); diff --git a/src/history/history.service.ts b/src/history/history.service.ts index 276af8190..d2793ac04 100644 --- a/src/history/history.service.ts +++ b/src/history/history.service.ts @@ -80,25 +80,15 @@ export class HistoryService { * Create or update a history entry by the user and note. If the entry is merely updated the updatedAt date is set to the current date. * @param {Note} note - the note that the history entry belongs to * @param {User} user - the user that the history entry belongs to - * @param {boolean} pinStatus - if the pinStatus of the history entry should be set - * @param {Date} lastVisited - the last time the associated note was accessed * @return {HistoryEntry} the requested history entry */ async createOrUpdateHistoryEntry( note: Note, user: User, - pinStatus?: boolean, - lastVisited?: Date, ): Promise { let entry = await this.getEntryByNote(note, user); if (!entry) { entry = HistoryEntry.create(user, note); - if (pinStatus !== undefined) { - entry.pinStatus = pinStatus; - } - if (lastVisited !== undefined) { - entry.updatedAt = lastVisited; - } } else { entry.updatedAt = new Date(); }