diff --git a/app/package-lock.json b/app/package-lock.json index d94c363..8238cd0 100644 --- a/app/package-lock.json +++ b/app/package-lock.json @@ -1,12 +1,12 @@ { "name": "@weaponsforge/sendemail", - "version": "2.0.0", + "version": "2.0.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@weaponsforge/sendemail", - "version": "2.0.0", + "version": "2.0.1", "license": "MIT", "dependencies": { "commander": "^14.0.3", diff --git a/app/package.json b/app/package.json index f1a5cca..9dba357 100644 --- a/app/package.json +++ b/app/package.json @@ -1,6 +1,6 @@ { "name": "@weaponsforge/sendemail", - "version": "2.0.0", + "version": "2.0.1", "description": "Sends emails using Gmail SMTP with username/pw or Google OAuth2", "main": "dist/index.js", "types": "./dist/index.d.ts", diff --git a/app/src/__tests__/build.test.ts b/app/src/__tests__/build.test.ts new file mode 100644 index 0000000..6815969 --- /dev/null +++ b/app/src/__tests__/build.test.ts @@ -0,0 +1,83 @@ +import path from 'path' +import { beforeAll, describe, expect, it } from 'vitest' + +import { buildHtml } from '@/lib/email/build.js' +import { directory } from '@/utils/helpers.js' +import { EmailSchemaMessages } from '@/types/email.schema.js' + +// buildHtml resolves the EJS template relative to __dirname (set to the build.ts location) +beforeAll(() => { + globalThis.__dirname = path.resolve(directory(import.meta.url), '..', 'lib', 'email') +}) + +const TEST_RECIPIENTS = ['tester@gmail.com'] +const TEST_SENDER = 'sender@gmail.com' + +describe('buildHtml test', () => { + it('should return an HTML string from paragraph content', async () => { + const html = await buildHtml({ + content: ['Hello, World!', 'Second paragraph'], + recipients: TEST_RECIPIENTS, + sender: TEST_SENDER, + }) + + expect(typeof html).toBe('string') + expect(html.length).toBeGreaterThan(0) + }) + + it('should return an HTML string from wysiwyg content', async () => { + const html = await buildHtml({ + content: [], + recipients: TEST_RECIPIENTS, + sender: TEST_SENDER, + wysiwyg: '

Hello, wysiwyg!

', + }) + + expect(typeof html).toBe('string') + expect(html).toContain('Hello, wysiwyg!') + }) + + it('should strip script tags from wysiwyg content', async () => { + const html = await buildHtml({ + content: [], + recipients: TEST_RECIPIENTS, + sender: TEST_SENDER, + wysiwyg: '

Safe content

', + }) + + expect(html).not.toContain('