UNPKG

@bluejeans/flexdoc-backend

Version:

FlexDoc backend integration for NestJS and other frameworks

106 lines 4.42 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const testing_1 = require("@nestjs/testing"); const flexdoc_module_1 = require("./flexdoc.module"); const setup_1 = require("./setup"); const core_1 = require("@nestjs/core"); jest.mock('./setup', () => ({ setupFlexDoc: jest.fn(), })); describe('FlexDocModule', () => { let app; let mockHttpAdapterHost; beforeEach(() => { app = { use: jest.fn(), }; mockHttpAdapterHost = { httpAdapter: { getInstance: jest.fn().mockReturnValue(app), }, }; jest.clearAllMocks(); }); describe('forRoot', () => { it('should register FlexDocModule with static options', async () => { const options = { path: '/api-docs', spec: { openapi: '3.0.0' }, }; const moduleRef = await testing_1.Test.createTestingModule({ imports: [flexdoc_module_1.FlexDocModule.forRoot(options)], providers: [ { provide: core_1.HttpAdapterHost, useValue: mockHttpAdapterHost, }, ], }).compile(); const module = moduleRef.get(flexdoc_module_1.FlexDocModule); expect(module).toBeDefined(); const onModuleInitHook = moduleRef.get(flexdoc_module_1.FlexDocModule); onModuleInitHook.onModuleInit(); expect(setup_1.setupFlexDoc).toHaveBeenCalledWith(expect.anything(), '/api-docs', expect.objectContaining({ spec: { openapi: '3.0.0' } })); }); }); describe('forRootAsync', () => { it('should register FlexDocModule with async options', async () => { const options = { path: '/api-docs', spec: { openapi: '3.0.0' }, }; const moduleRef = await testing_1.Test.createTestingModule({ imports: [ flexdoc_module_1.FlexDocModule.forRootAsync({ useFactory: () => options, }), ], providers: [ { provide: core_1.HttpAdapterHost, useValue: mockHttpAdapterHost, }, ], }).compile(); const module = moduleRef.get(flexdoc_module_1.FlexDocModule); expect(module).toBeDefined(); const onModuleInitHook = moduleRef.get(flexdoc_module_1.FlexDocModule); onModuleInitHook.onModuleInit(); expect(setup_1.setupFlexDoc).toHaveBeenCalledWith(expect.anything(), '/api-docs', expect.objectContaining({ spec: { openapi: '3.0.0' } })); }); it('should inject dependencies into the options factory', async () => { const mockServiceToken = 'MockService'; const mockService = { getSpec: jest.fn().mockReturnValue({ openapi: '3.0.0' }), }; const moduleRef = await testing_1.Test.createTestingModule({ providers: [ { provide: mockServiceToken, useValue: mockService, }, { provide: core_1.HttpAdapterHost, useValue: mockHttpAdapterHost, }, ], imports: [ flexdoc_module_1.FlexDocModule.forRootAsync({ useFactory: (service) => ({ path: '/api-docs', spec: service.getSpec(), }), inject: [mockServiceToken], }), ], }).compile(); const module = moduleRef.get(flexdoc_module_1.FlexDocModule); expect(module).toBeDefined(); const onModuleInitHook = moduleRef.get(flexdoc_module_1.FlexDocModule); onModuleInitHook.onModuleInit(); expect(mockService.getSpec).toHaveBeenCalled(); expect(setup_1.setupFlexDoc).toHaveBeenCalledWith(expect.anything(), '/api-docs', expect.objectContaining({ spec: { openapi: '3.0.0' } })); }); }); }); //# sourceMappingURL=flexdoc.module.test.js.map