Version control and retrieval endpoints
This commit is contained in:
parent
bca3b6b699
commit
8ef27f33d6
6 changed files with 261 additions and 5 deletions
|
@ -1,6 +1,7 @@
|
|||
import { Request, Response } from 'express';
|
||||
import { getTopics } from '../src/controllers/topicController';
|
||||
import { getTopics, getTopicByIdRecursive } from '../src/controllers/topicController';
|
||||
import { topics } from '../src/models/topic';
|
||||
import { topicMocks, treeMock } from './mocks'
|
||||
|
||||
describe('Topic Controller', () => {
|
||||
it('should return an empty array when no topics exist', () => {
|
||||
|
@ -19,4 +20,21 @@ describe('Topic Controller', () => {
|
|||
// Expect that res.json was called with an empty array
|
||||
expect(res.json).toHaveBeenCalledWith([]);
|
||||
});
|
||||
|
||||
it('should return a recursive tree of a topic and its children', () => {
|
||||
// Create mock objects for Request, Response, and NextFunction
|
||||
const req = {} as Request;
|
||||
const res = {
|
||||
json: topicMocks
|
||||
} as unknown as Response;
|
||||
|
||||
// Load mock values into in-memory store
|
||||
topicMocks.forEach(t => topics.push(t))
|
||||
|
||||
// Retrieve recursive tree
|
||||
req.params = { id: topicMocks[1].id.toString() }
|
||||
getTopicByIdRecursive(req, res, jest.fn())
|
||||
|
||||
expect(res.json).toMatchObject(treeMock)
|
||||
})
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue