-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
207d5fd
commit 81af7fb
Showing
16 changed files
with
628 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,12 @@ | ||
/* eslint-disable no-console */ | ||
/* global page, beforeAll */ | ||
|
||
const { VERBOSE } = process.env; | ||
beforeAll(async function () { | ||
const isVerbose = VERBOSE === 'true'; | ||
// global.MailgunClient = null; | ||
page.on('console', (message) => console.debug(`Browser console -> ${message.type()} ${message.text()}`)) | ||
page.on('console', (message) => isVerbose && console.debug(`Browser console -> ${message.type()} ${message.text()}`)) | ||
.on('pageerror', ({ message }) => console.error(`Browser page error -> ${message}`)) | ||
.on('request', (req) => console.log(`Browser send request -> ${req.url()}`)) | ||
.on('response', (response) => console.log(`Browser got response -> ${response.status()} ${response.url()}`)) | ||
.on('requestfailed', (request) => console.log(`Browser request failed ->${request.failure().errorText} ${request.url()}`)); | ||
.on('request', (req) => isVerbose && console.log(`Browser send request -> ${req.url()}`)) | ||
.on('response', (response) => isVerbose && console.log(`Browser got response -> ${response.status()} ${response.url()}`)) | ||
.on('requestfailed', (request) => console.error(`Browser request failed ->${request.failure().errorText} ${request.url()}`)); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
tests/integration/browser/tests/esm-dynamic/import.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* eslint-disable @typescript-eslint/ban-types */ | ||
/* eslint-disable tsdoc/syntax */ | ||
import { | ||
describe, | ||
expect, | ||
test, | ||
beforeAll | ||
} from '@jest/globals'; | ||
import 'jest-puppeteer'; | ||
import { IMailgunClient } from '../../../../../lib/Interfaces/index.js'; | ||
|
||
type Window = globalThis.Window & { | ||
mailgunClient?: IMailgunClient | ||
definitionsExport?: { | ||
Enums: object, | ||
Interfaces: object, | ||
} | ||
packageExport?: Function | ||
}; | ||
|
||
describe('AMD import validation', () => { | ||
beforeAll(async () => { | ||
await page.goto('http://localhost:3000/pages/ESM.html'); | ||
await page.waitForFunction(function () { return typeof (window as Window).mailgunClient !== 'undefined'; }); | ||
await page.waitForFunction(function () { return typeof (window as Window).packageExport !== 'undefined'; }); | ||
await page.waitForFunction(function () { return typeof (window as Window).definitionsExport !== 'undefined'; }); | ||
}); | ||
|
||
test('AMD package exports function', async () => { | ||
const isFunction = await page.evaluate(() => (typeof (window as Window).packageExport === 'function')); | ||
expect(isFunction).toBe(true); | ||
}); | ||
|
||
test('AMD definitions exports object', async () => { | ||
const definitionsExport = await page.evaluate(() => (window as Window).definitionsExport); | ||
expect(typeof definitionsExport).toBe('object'); | ||
expect(definitionsExport).toEqual(expect.objectContaining({ | ||
Enums: expect.any(Object), | ||
Interfaces: expect.any(Object), | ||
})); | ||
}); | ||
|
||
test('AMD client has expected structure', async () => { | ||
const client = await page.evaluate(() => (window as Window).mailgunClient); | ||
const expected = ['request', 'domains', 'webhooks', 'events', 'stats', 'suppressions', 'messages', 'routes', 'ips', 'ip_pools', 'lists', 'validate']; | ||
expect(client).toBeDefined(); | ||
expect(typeof client).toBe('object'); | ||
expect(Object.keys(client as IMailgunClient)).toEqual(expect.arrayContaining(expected)); | ||
}); | ||
}); |
120 changes: 120 additions & 0 deletions
120
tests/integration/browser/tests/esm-dynamic/messages.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
import { | ||
afterAll, | ||
beforeAll, | ||
describe, | ||
expect, | ||
test | ||
} from '@jest/globals'; | ||
import { successResponse } from '../../../tests_data/messageResponses'; | ||
import { IMailgunClient } from '../../../../../lib/Interfaces'; | ||
import { MailgunMessageData } from '../../../../../lib/Types'; | ||
import 'jest-puppeteer'; | ||
|
||
const serverUrl = 'http://localhost:3000'; | ||
|
||
type ExtendedWindow = globalThis.Window & { | ||
mailgunClient?: IMailgunClient | ||
packageExport?: object | ||
}; | ||
|
||
describe('Send message functionality (AMD)', () => { | ||
beforeAll(async () => { | ||
await page.goto('http://localhost:3000/pages/ESM.html'); | ||
await page.waitForFunction(function () { return typeof (window as ExtendedWindow).mailgunClient !== 'undefined'; }); | ||
await page.setRequestInterception(true); | ||
|
||
page.on('request', (request) => { | ||
const isExpectedUrls = [`${serverUrl}/v3/test.domain.com/messages`, `${serverUrl}/v3/test.domain.com/messages.mime`]; | ||
if (isExpectedUrls.includes(request.url())) { | ||
request.respond({ | ||
status: 200, | ||
contentType: 'application/json', | ||
body: JSON.stringify(successResponse.body) | ||
}); | ||
} else { | ||
request.continue(); | ||
} | ||
}); | ||
}); | ||
|
||
afterAll(async () => { | ||
await page.setRequestInterception(false); | ||
}); | ||
|
||
test('Sends plain email (AMD)', async () => { | ||
const result = await page.evaluate( | ||
(domain, messageData) => (window as ExtendedWindow)?.mailgunClient?.messages.create( | ||
domain, | ||
messageData | ||
), | ||
'test.domain.com', { | ||
to: '[email protected]', | ||
from: '[email protected]', | ||
subject: 'howdy!', | ||
text: 'Hello world!' | ||
} | ||
); | ||
expect(typeof result).toBe('object'); | ||
expect(result).toEqual({ | ||
status: 200, | ||
message: 'Queued. Thank you.', | ||
id: '<[email protected]>' | ||
}); | ||
}); | ||
|
||
test('Sends mime email (AMD)', async () => { | ||
const result = await page.evaluate( | ||
(domain, messageData) => (window as ExtendedWindow).mailgunClient?.messages.create( | ||
domain, | ||
messageData | ||
), | ||
'test.domain.com', { | ||
to: '[email protected]', | ||
from: '[email protected]', | ||
subject: 'howdy!', | ||
message: 'hello world!' | ||
} | ||
); | ||
expect(typeof result).toBe('object'); | ||
expect(result).toEqual({ | ||
status: 200, | ||
message: 'Queued. Thank you.', | ||
id: '<[email protected]>' | ||
}); | ||
}); | ||
|
||
test('Sends an attachment (AMD)', async () => { | ||
await page.waitForSelector('input[type=file]', { timeout: 3000 }); | ||
const input = await page.$('input[type=file]'); | ||
expect(input).toBeTruthy(); | ||
await input?.uploadFile('../../../tests_data/img/mailgun.png'); | ||
|
||
const result = await page.evaluate( | ||
async (domain, messageData, pageInput) => { | ||
const messageDataCopy: MailgunMessageData = { ...messageData }; | ||
if (pageInput && pageInput.files?.length) { | ||
const mailgunLogo = pageInput.files[0]; | ||
messageDataCopy.attachment = [{ | ||
filename: mailgunLogo.name, | ||
data: mailgunLogo | ||
}]; | ||
} | ||
return (window as ExtendedWindow).mailgunClient?.messages.create(domain, messageDataCopy); | ||
}, | ||
'test.domain.com', { | ||
to: '[email protected]', | ||
from: '[email protected]', | ||
subject: 'howdy!', | ||
text: 'test', | ||
attachment: [] | ||
}, | ||
input | ||
); | ||
expect(typeof result).toBe('object'); | ||
expect(result).toEqual({ | ||
status: 200, | ||
message: 'Queued. Thank you.', | ||
id: '<[email protected]>' | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* eslint-disable @typescript-eslint/ban-types */ | ||
/* eslint-disable tsdoc/syntax */ | ||
import { | ||
describe, | ||
expect, | ||
test, | ||
beforeAll | ||
} from '@jest/globals'; | ||
import 'jest-puppeteer'; | ||
import { IMailgunClient } from '../../../../../lib/Interfaces/index.js'; | ||
|
||
type Window = globalThis.Window & { | ||
mailgunClient?: IMailgunClient | ||
definitionsExport?: { | ||
Enums: object, | ||
Interfaces: object, | ||
} | ||
packageExport?: Function | ||
}; | ||
|
||
describe('AMD import validation', () => { | ||
beforeAll(async () => { | ||
await page.goto('http://localhost:3000/pages/ESM.html'); | ||
await page.waitForFunction(function () { return typeof (window as Window).mailgunClient !== 'undefined'; }); | ||
await page.waitForFunction(function () { return typeof (window as Window).packageExport !== 'undefined'; }); | ||
await page.waitForFunction(function () { return typeof (window as Window).definitionsExport !== 'undefined'; }); | ||
}); | ||
|
||
test('AMD package exports function', async () => { | ||
const isFunction = await page.evaluate(() => (typeof (window as Window).packageExport === 'function')); | ||
expect(isFunction).toBe(true); | ||
}); | ||
|
||
test('AMD definitions exports object', async () => { | ||
const definitionsExport = await page.evaluate(() => (window as Window).definitionsExport); | ||
expect(typeof definitionsExport).toBe('object'); | ||
expect(definitionsExport).toEqual(expect.objectContaining({ | ||
Enums: expect.any(Object), | ||
Interfaces: expect.any(Object), | ||
})); | ||
}); | ||
|
||
test('AMD client has expected structure', async () => { | ||
const client = await page.evaluate(() => (window as Window).mailgunClient); | ||
const expected = ['request', 'domains', 'webhooks', 'events', 'stats', 'suppressions', 'messages', 'routes', 'ips', 'ip_pools', 'lists', 'validate']; | ||
expect(client).toBeDefined(); | ||
expect(typeof client).toBe('object'); | ||
expect(Object.keys(client as IMailgunClient)).toEqual(expect.arrayContaining(expected)); | ||
}); | ||
}); |
Oops, something went wrong.