mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-17 08:34:54 -04:00
PrivateHistoryE2E: Extend POST /me/history
Test the correct behaviour in error cases Signed-off-by: Philip Molares <philip.molares@udo.edu>
This commit is contained in:
parent
258a38f8c0
commit
8186c96806
1 changed files with 75 additions and 20 deletions
|
@ -5,7 +5,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { INestApplication } from '@nestjs/common';
|
import { INestApplication } from '@nestjs/common';
|
||||||
import { ConfigModule } from '@nestjs/config';
|
import { ConfigModule, ConfigService } from '@nestjs/config';
|
||||||
import { Test } from '@nestjs/testing';
|
import { Test } from '@nestjs/testing';
|
||||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||||
import request from 'supertest';
|
import request from 'supertest';
|
||||||
|
@ -27,6 +27,7 @@ import { PrivateApiModule } from '../../src/api/private/private-api.module';
|
||||||
import { HistoryService } from '../../src/history/history.service';
|
import { HistoryService } from '../../src/history/history.service';
|
||||||
import { Note } from '../../src/notes/note.entity';
|
import { Note } from '../../src/notes/note.entity';
|
||||||
import { HistoryEntryImportDto } from '../../src/history/history-entry-import.dto';
|
import { HistoryEntryImportDto } from '../../src/history/history-entry-import.dto';
|
||||||
|
import { HistoryEntry } from '../../src/history/history-entry.entity';
|
||||||
|
|
||||||
describe('History', () => {
|
describe('History', () => {
|
||||||
let app: INestApplication;
|
let app: INestApplication;
|
||||||
|
@ -34,6 +35,7 @@ describe('History', () => {
|
||||||
let user: User;
|
let user: User;
|
||||||
let note: Note;
|
let note: Note;
|
||||||
let note2: Note;
|
let note2: Note;
|
||||||
|
let forbiddenNoteId: string;
|
||||||
let content: string;
|
let content: string;
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
|
@ -66,6 +68,8 @@ describe('History', () => {
|
||||||
],
|
],
|
||||||
}).compile();
|
}).compile();
|
||||||
|
|
||||||
|
const config = moduleRef.get<ConfigService>(ConfigService);
|
||||||
|
forbiddenNoteId = config.get('appConfig').forbiddenNoteIds[0];
|
||||||
app = moduleRef.createNestApplication();
|
app = moduleRef.createNestApplication();
|
||||||
await app.init();
|
await app.init();
|
||||||
content = 'This is a test note.';
|
content = 'This is a test note.';
|
||||||
|
@ -99,8 +103,9 @@ describe('History', () => {
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('POST /me/history', async () => {
|
describe('POST /me/history', () => {
|
||||||
expect((await historyService.getEntriesByUser(user)).length).toEqual(1);
|
it('works', async () => {
|
||||||
|
expect(await historyService.getEntriesByUser(user)).toHaveLength(1);
|
||||||
const pinStatus = true;
|
const pinStatus = true;
|
||||||
const lastVisited = new Date('2020-12-01 12:23:34');
|
const lastVisited = new Date('2020-12-01 12:23:34');
|
||||||
const postEntryDto = new HistoryEntryImportDto();
|
const postEntryDto = new HistoryEntryImportDto();
|
||||||
|
@ -119,6 +124,56 @@ describe('History', () => {
|
||||||
expect(userEntries[0].pinStatus).toEqual(pinStatus);
|
expect(userEntries[0].pinStatus).toEqual(pinStatus);
|
||||||
expect(userEntries[0].updatedAt).toEqual(lastVisited);
|
expect(userEntries[0].updatedAt).toEqual(lastVisited);
|
||||||
});
|
});
|
||||||
|
describe('fails', () => {
|
||||||
|
let pinStatus: boolean;
|
||||||
|
let lastVisited: Date;
|
||||||
|
let postEntryDto: HistoryEntryImportDto;
|
||||||
|
let prevEntry: HistoryEntry;
|
||||||
|
beforeAll(async () => {
|
||||||
|
const previousHistory = await historyService.getEntriesByUser(user);
|
||||||
|
expect(previousHistory).toHaveLength(1);
|
||||||
|
prevEntry = previousHistory[0];
|
||||||
|
pinStatus = !previousHistory[0].pinStatus;
|
||||||
|
lastVisited = new Date('2020-12-01 23:34:45');
|
||||||
|
postEntryDto = new HistoryEntryImportDto();
|
||||||
|
postEntryDto.note = note2.alias;
|
||||||
|
postEntryDto.pinStatus = pinStatus;
|
||||||
|
postEntryDto.lastVisited = lastVisited;
|
||||||
|
});
|
||||||
|
it('with forbiddenId', async () => {
|
||||||
|
const brokenEntryDto = new HistoryEntryImportDto();
|
||||||
|
brokenEntryDto.note = forbiddenNoteId;
|
||||||
|
brokenEntryDto.pinStatus = pinStatus;
|
||||||
|
brokenEntryDto.lastVisited = lastVisited;
|
||||||
|
await request(app.getHttpServer())
|
||||||
|
.post('/me/history')
|
||||||
|
.set('Content-Type', 'application/json')
|
||||||
|
.send(JSON.stringify({ history: [brokenEntryDto] }))
|
||||||
|
.expect(400);
|
||||||
|
});
|
||||||
|
it('with non-existing note', async () => {
|
||||||
|
const brokenEntryDto = new HistoryEntryImportDto();
|
||||||
|
brokenEntryDto.note = 'i_dont_exist';
|
||||||
|
brokenEntryDto.pinStatus = pinStatus;
|
||||||
|
brokenEntryDto.lastVisited = lastVisited;
|
||||||
|
await request(app.getHttpServer())
|
||||||
|
.post('/me/history')
|
||||||
|
.set('Content-Type', 'application/json')
|
||||||
|
.send(JSON.stringify({ history: [brokenEntryDto] }))
|
||||||
|
.expect(400);
|
||||||
|
});
|
||||||
|
afterEach(async () => {
|
||||||
|
const historyEntries = await historyService.getEntriesByUser(user);
|
||||||
|
expect(historyEntries).toHaveLength(1);
|
||||||
|
expect(historyEntries[0].note.alias).toEqual(prevEntry.note.alias);
|
||||||
|
expect(historyEntries[0].user.userName).toEqual(
|
||||||
|
prevEntry.user.userName,
|
||||||
|
);
|
||||||
|
expect(historyEntries[0].pinStatus).toEqual(prevEntry.pinStatus);
|
||||||
|
expect(historyEntries[0].updatedAt).toEqual(prevEntry.updatedAt);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it('DELETE /me/history', async () => {
|
it('DELETE /me/history', async () => {
|
||||||
expect((await historyService.getEntriesByUser(user)).length).toEqual(1);
|
expect((await historyService.getEntriesByUser(user)).length).toEqual(1);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue