Basic structure of the project
- Added a model with in-memory database, and routes, controller and middleware to enable making initial CRUD calls to endpoints; - Added jest and an initial test.
This commit is contained in:
parent
74c1ee1b7b
commit
9c4ea4ca90
11 changed files with 3841 additions and 1 deletions
22
tests/topicController.test.ts
Normal file
22
tests/topicController.test.ts
Normal file
|
@ -0,0 +1,22 @@
|
|||
import { Request, Response } from 'express';
|
||||
import { getTopics } from '../src/controllers/topicController';
|
||||
import { topics } from '../src/models/topic';
|
||||
|
||||
describe('Topic Controller', () => {
|
||||
it('should return an empty array when no topics exist', () => {
|
||||
// Create mock objects for Request, Response, and NextFunction
|
||||
const req = {} as Request;
|
||||
const res = {
|
||||
json: jest.fn(),
|
||||
} as unknown as Response;
|
||||
|
||||
// Ensure that our in-memory store is empty
|
||||
topics.length = 0;
|
||||
|
||||
// Execute our controller function
|
||||
getTopics(req, res, jest.fn());
|
||||
|
||||
// Expect that res.json was called with an empty array
|
||||
expect(res.json).toHaveBeenCalledWith([]);
|
||||
});
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue