Skip to content

Commit

Permalink
chore: extend handler tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hoeppner-dataport committed Nov 16, 2023
1 parent f3e6174 commit 50c6888
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,27 +32,39 @@ describe(BoardUrlHandler.name, () => {
});

describe('getMetaData', () => {
it('should call courseService with the correct id', async () => {
const id = 'af322312feae';
const url = `https://localhost/rooms/${id}/board`;
describe('when url fits', () => {
it('should call courseService with the correct id', async () => {
const id = 'af322312feae';
const url = `https://localhost/rooms/${id}/board`;

await boardUrlHandler.getMetaData(url);
await boardUrlHandler.getMetaData(url);

expect(columnBoardService.findById).toHaveBeenCalledWith(id);
expect(columnBoardService.findById).toHaveBeenCalledWith(id);
});

it('should take the title from the board name', async () => {
const id = 'af322312feae';
const url = `https://localhost/rooms/${id}/board`;
const boardName = 'My Board';
columnBoardService.findById.mockResolvedValue({
title: boardName,
context: { type: 'course', id: 'a-board-id' },
} as ColumnBoard);

const result = await boardUrlHandler.getMetaData(url);

expect(result).toEqual(expect.objectContaining({ title: boardName, type: 'board' }));
});
});

it('should take the title from the board name', async () => {
const id = 'af322312feae';
const url = `https://localhost/rooms/${id}/board`;
const boardName = 'My Board';
columnBoardService.findById.mockResolvedValue({
title: boardName,
context: { type: 'course', id: 'a-board-id' },
} as ColumnBoard);
describe('when url does not fit', () => {
it('should return undefined', async () => {
const url = `https://localhost/invalid/ef2345abe4e3b`;

const result = await boardUrlHandler.getMetaData(url);
const result = await boardUrlHandler.getMetaData(url);

expect(result).toEqual(expect.objectContaining({ title: boardName, type: 'board' }));
expect(result).toBeUndefined();
});
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,36 @@ describe(CourseUrlHandler.name, () => {
});

describe('getMetaData', () => {
it('should call courseService with the correct id', async () => {
const id = 'af322312feae';
const url = `https://localhost/rooms/${id}`;
describe('when url fits', () => {
it('should call courseService with the correct id', async () => {
const id = 'af322312feae';
const url = `https://localhost/rooms/${id}`;

await courseUrlHandler.getMetaData(url);
await courseUrlHandler.getMetaData(url);

expect(courseService.findById).toHaveBeenCalledWith(id);
expect(courseService.findById).toHaveBeenCalledWith(id);
});

it('should take the title from the course name', async () => {
const id = 'af322312feae';
const url = `https://localhost/rooms/${id}`;
const courseName = 'My Course';
courseService.findById.mockResolvedValue({ name: courseName } as Course);

const result = await courseUrlHandler.getMetaData(url);

expect(result).toEqual(expect.objectContaining({ title: courseName, type: 'course' }));
});
});

it('should take the title from the course name', async () => {
const id = 'af322312feae';
const url = `https://localhost/rooms/${id}`;
const courseName = 'My Course';
courseService.findById.mockResolvedValue({ name: courseName } as Course);
describe('when url does not fit', () => {
it('should return undefined', async () => {
const url = `https://localhost/invalid/ef2345abe4e3b`;

const result = await courseUrlHandler.getMetaData(url);
const result = await courseUrlHandler.getMetaData(url);

expect(result).toEqual(expect.objectContaining({ title: courseName, type: 'course' }));
expect(result).toBeUndefined();
});
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,36 @@ describe(LessonUrlHandler.name, () => {
});

describe('getMetaData', () => {
it('should call lessonService with the correct id', async () => {
const id = 'af322312feae';
const url = `https://localhost/topics/${id}`;
describe('when url fits', () => {
it('should call lessonService with the correct id', async () => {
const id = 'af322312feae';
const url = `https://localhost/topics/${id}`;

await lessonUrlHandler.getMetaData(url);
await lessonUrlHandler.getMetaData(url);

expect(lessonService.findById).toHaveBeenCalledWith(id);
expect(lessonService.findById).toHaveBeenCalledWith(id);
});

it('should take the title from the lessons name', async () => {
const id = 'af322312feae';
const url = `https://localhost/topics/${id}`;
const lessonName = 'My lesson';
lessonService.findById.mockResolvedValue({ name: lessonName } as LessonEntity);

const result = await lessonUrlHandler.getMetaData(url);

expect(result).toEqual(expect.objectContaining({ title: lessonName, type: 'lesson' }));
});
});

it('should take the title from the lessons name', async () => {
const id = 'af322312feae';
const url = `https://localhost/topics/${id}`;
const lessonName = 'My lesson';
lessonService.findById.mockResolvedValue({ name: lessonName } as LessonEntity);
describe('when url does not fit', () => {
it('should return undefined', async () => {
const url = `https://localhost/invalid/ef2345abe4e3b`;

const result = await lessonUrlHandler.getMetaData(url);
const result = await lessonUrlHandler.getMetaData(url);

expect(result).toEqual(expect.objectContaining({ title: lessonName, type: 'lesson' }));
expect(result).toBeUndefined();
});
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,36 @@ describe(TaskUrlHandler.name, () => {
});

describe('getMetaData', () => {
it('should call taskService with the correct id', async () => {
const id = 'af322312feae';
const url = `https://localhost/homework/${id}`;
describe('when url fits', () => {
it('should call taskService with the correct id', async () => {
const id = 'af322312feae';
const url = `https://localhost/homework/${id}`;

await taskUrlHandler.getMetaData(url);
await taskUrlHandler.getMetaData(url);

expect(taskService.findById).toHaveBeenCalledWith(id);
expect(taskService.findById).toHaveBeenCalledWith(id);
});

it('should take the title from the tasks name', async () => {
const id = 'af322312feae';
const url = `https://localhost/homework/${id}`;
const taskName = 'My Task';
taskService.findById.mockResolvedValue({ name: taskName } as Task);

const result = await taskUrlHandler.getMetaData(url);

expect(result).toEqual(expect.objectContaining({ title: taskName, type: 'task' }));
});
});

it('should take the title from the tasks name', async () => {
const id = 'af322312feae';
const url = `https://localhost/homework/${id}`;
const taskName = 'My Task';
taskService.findById.mockResolvedValue({ name: taskName } as Task);
describe('when url does not fit', () => {
it('should return undefined', async () => {
const url = `https://localhost/invalid/ef2345abe4e3b`;

const result = await taskUrlHandler.getMetaData(url);
const result = await taskUrlHandler.getMetaData(url);

expect(result).toEqual(expect.objectContaining({ title: taskName, type: 'task' }));
expect(result).toBeUndefined();
});
});
});
});

0 comments on commit 50c6888

Please sign in to comment.