UNPKG

@bluejeans/flexdoc-backend

Version:

FlexDoc backend integration for NestJS and other frameworks

66 lines 2.64 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const setup_1 = require("./setup"); const template_1 = require("./template"); jest.mock('./template', () => ({ generateFlexDocHTML: jest.fn().mockReturnValue('<html>Mocked HTML</html>'), })); describe('setupFlexDoc', () => { let mockApp; let mockReq; let mockRes; let handler; beforeEach(() => { jest.clearAllMocks(); mockApp = { use: jest.fn().mockImplementation((path, middleware) => { handler = middleware; }), }; mockReq = {}; mockRes = { setHeader: jest.fn(), send: jest.fn(), }; }); it('should register middleware at the specified path', () => { (0, setup_1.setupFlexDoc)(mockApp, '/docs', { spec: { openapi: '3.0.0' } }); expect(mockApp.use).toHaveBeenCalledWith('/docs', expect.any(Function)); }); it('should normalize path to include leading slash', () => { (0, setup_1.setupFlexDoc)(mockApp, 'docs', { spec: { openapi: '3.0.0' } }); expect(mockApp.use).toHaveBeenCalledWith('/docs', expect.any(Function)); }); it('should generate HTML with spec when middleware is called', () => { const spec = { openapi: '3.0.0', info: { title: 'Test API', version: '1.0.0' }, }; (0, setup_1.setupFlexDoc)(mockApp, '/docs', { spec }); handler(mockReq, mockRes); expect(template_1.generateFlexDocHTML).toHaveBeenCalledWith(spec, expect.any(Object)); expect(mockRes.setHeader).toHaveBeenCalledWith('Content-Type', 'text/html'); expect(mockRes.send).toHaveBeenCalledWith('<html>Mocked HTML</html>'); }); it('should pass null when spec is undefined', () => { (0, setup_1.setupFlexDoc)(mockApp, '/docs', { specUrl: 'https://example.com/openapi.json', }); handler(mockReq, mockRes); expect(template_1.generateFlexDocHTML).toHaveBeenCalledWith(null, expect.objectContaining({ specUrl: 'https://example.com/openapi.json', })); }); it('should pass flexDocOptions to generateFlexDocHTML', () => { const flexDocOptions = { theme: 'dark', }; (0, setup_1.setupFlexDoc)(mockApp, '/docs', { spec: { openapi: '3.0.0' }, options: flexDocOptions, }); handler(mockReq, mockRes); expect(template_1.generateFlexDocHTML).toHaveBeenCalledWith(expect.any(Object), expect.objectContaining(flexDocOptions)); }); }); //# sourceMappingURL=setup.test.js.map