import * as Fs from 'fs'; import * as Os from 'os'; import * as Path from 'path'; import Axios from 'axios'; import { DyNTS_defaultNotFoundPageHtml } from '../../_collections/default-not-found-page.const'; import { DyNTS_AppIntegrationTest_Mock } from '../mock/app-integration-test.mock'; let INTEGRATION_BASE_URL: string = ''; const INTEGRATION_READY_TIMEOUT_MS: number = 10000; describe('| DyNTS_AppExtended (integration)', (): void => { beforeAll((): void => { jasmine.DEFAULT_TIMEOUT_INTERVAL = INTEGRATION_READY_TIMEOUT_MS + 5000; }); let app: DyNTS_AppIntegrationTest_Mock; let tempDir: string = ''; beforeAll(async (): Promise => { tempDir = Fs.mkdtempSync(Path.join(Os.tmpdir(), 'dynts-int-')); const indexContent: string = 'Integration test index'; Fs.writeFileSync(Path.join(tempDir, 'index.html'), indexContent, { encoding: 'utf-8' }); DyNTS_AppIntegrationTest_Mock.integrationStaticRoot = tempDir; app = new DyNTS_AppIntegrationTest_Mock(); await app.ready(INTEGRATION_READY_TIMEOUT_MS); INTEGRATION_BASE_URL = `http://localhost:${app.resolvedPort}`; }); afterAll(async (): Promise => { try { if (app?.started) { await app.stop(); } } catch { // stop() hiba (pl. socket server már leállt) ne szakítsa meg a suite-ot } if (tempDir && Fs.existsSync(tempDir)) { Fs.rmSync(tempDir, { recursive: true }); } }); it('| app elindul és started true', (): void => { expect(app.started).toBe(true); }); it('| GET nem létező path -> 404 és default "Page not found" HTML', async (): Promise => { const response = await Axios.get(`${INTEGRATION_BASE_URL}/nonexistent-path-xyz`, { validateStatus: (): boolean => true, responseType: 'text', }); expect(response.status).toBe(404); expect(response.headers['content-type']).toContain('html'); expect(typeof response.data).toBe('string'); expect((response.data as string).trim()).toContain('Page not found'); expect(response.data).toBe(DyNTS_defaultNotFoundPageHtml); }); it('| GET /index.html -> 200 és static tartalom', async (): Promise => { const response = await Axios.get(`${INTEGRATION_BASE_URL}/index.html`, { responseType: 'text', }); expect(response.status).toBe(200); expect(response.data).toContain('Integration test index'); }); it('| GET API base path alatt (mock route) -> 200', async (): Promise => { const response = await Axios.get(`${INTEGRATION_BASE_URL}/api/test-0/test-base`, { responseType: 'text', }); expect(response.status).toBe(200); expect(response.data).toBe('test-base'); }); it('| GET API másik endpoint -> 200', async (): Promise => { const response = await Axios.get(`${INTEGRATION_BASE_URL}/api/test-0/test-simple`, { responseType: 'text', }); expect(response.status).toBe(200); expect(response.data).toBe('test-simple'); }); });