From c5e1d77a8253e471a7b021229ac6c85743ba8343 Mon Sep 17 00:00:00 2001 From: rafaelsideguide <150964962+rafaelsideguide@users.noreply.github.com> Date: Tue, 3 Sep 2024 15:21:45 -0300 Subject: [PATCH] added invalid html tests --- apps/api/src/lib/__tests__/html-to-markdown.test.ts | 13 ++++++++++++- apps/api/src/lib/html-to-markdown.ts | 1 - 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/apps/api/src/lib/__tests__/html-to-markdown.test.ts b/apps/api/src/lib/__tests__/html-to-markdown.test.ts index 00db7758..3c68c959 100644 --- a/apps/api/src/lib/__tests__/html-to-markdown.test.ts +++ b/apps/api/src/lib/__tests__/html-to-markdown.test.ts @@ -25,5 +25,16 @@ describe('parseMarkdown', () => { await expect(parseMarkdown(html)).resolves.toBe(expectedMarkdown); }); - + it('should handle various types of invalid HTML gracefully', async () => { + const invalidHtmls = [ + { html: '
Unclosed tag', expected: 'Unclosed tag' }, + { html: '
Wrong nesting
', expected: '**Wrong nesting**' }, + { html: 'Link without closing tag', expected: '[Link without closing tag](http://example.com)' } + ]; + + for (const { html, expected } of invalidHtmls) { + await expect(parseMarkdown(html)).resolves.toBe(expected); + } + }); }); diff --git a/apps/api/src/lib/html-to-markdown.ts b/apps/api/src/lib/html-to-markdown.ts index a5f69962..103948f4 100644 --- a/apps/api/src/lib/html-to-markdown.ts +++ b/apps/api/src/lib/html-to-markdown.ts @@ -8,7 +8,6 @@ import dotenv from 'dotenv'; import { Logger } from './logger'; dotenv.config(); -// TODO: test with invalid html // TODO: create a singleton for the converter // TODO: add a timeout to the Go parser