mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-12-28 15:20:46 +00:00
HistoryService: Remove extra parameters from createOrUpdateHistoryEntry
As the function is now only called with a user and a note and the previous extra parameters are now added into the transactional setHistory method, this is no longer necessary. Signed-off-by: Philip Molares <philip.molares@udo.edu>
This commit is contained in:
parent
6b6aef284c
commit
7c648e7056
2 changed files with 2 additions and 133 deletions
|
@ -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<HistoryEntry> => 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<HistoryEntry> => 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<HistoryEntry> => 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<HistoryEntry> => 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<HistoryEntry> => 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<HistoryEntry> => 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);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -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<HistoryEntry> {
|
||||
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();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue