fix(tests): Update testing setup and bump deps; add deno.lock and combined Node/Deno/Bun test
This commit is contained in:
		
							
								
								
									
										71
									
								
								test/test.node+deno+bun.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										71
									
								
								test/test.node+deno+bun.ts
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,71 @@ | ||||
| import { expect, tap } from '@push.rocks/tapbundle'; | ||||
| import { Qenv } from '@push.rocks/qenv'; | ||||
| import * as smartmail from '@push.rocks/smartmail'; | ||||
|  | ||||
| const testQenv = new Qenv('./', './.nogit'); | ||||
|  | ||||
| import * as mailgun from '../ts/index.js'; | ||||
| import { type IMailgunMessage } from '../ts/index.js'; | ||||
|  | ||||
| let testMailgunAccount: mailgun.MailgunAccount; | ||||
| let testSmartmail: smartmail.Smartmail<IMailgunMessage>; | ||||
|  | ||||
| tap.test('should create a mailgun account', async () => { | ||||
|   testMailgunAccount = new mailgun.MailgunAccount({ | ||||
|     apiToken: await testQenv.getEnvVarOnDemand('MAILGUN_API_TOKEN'), | ||||
|     region: 'eu', | ||||
|   }); | ||||
|   await testMailgunAccount.addSmtpCredentials( | ||||
|     await testQenv.getEnvVarOnDemand('MAILGUN_SMTP_CREDENTIALS'), | ||||
|   ); | ||||
|   expect(testMailgunAccount).toBeInstanceOf(mailgun.MailgunAccount); | ||||
| }); | ||||
|  | ||||
| tap.test('should create a smartmail', async () => { | ||||
|   testSmartmail = new smartmail.Smartmail({ | ||||
|     body: 'hi there. This is the body.', | ||||
|     from: 'Lossless GmbH <noreply@mail.lossless.com>', | ||||
|     subject: 'TestMessage from @mojoio/mailgun test', | ||||
|   }); | ||||
|   expect(testSmartmail).toBeInstanceOf(smartmail.Smartmail); | ||||
| }); | ||||
|  | ||||
| tap.test('should send a smartmail', async () => { | ||||
|   await testMailgunAccount.sendSmartMail( | ||||
|     testSmartmail, | ||||
|     'Sandbox Team <sandbox@mail.git.zone>', | ||||
|   ); | ||||
| }); | ||||
|  | ||||
| tap.test('should send a smartmail with empty body', async () => { | ||||
|   const emptyBodySmartmail = new smartmail.Smartmail<IMailgunMessage>({ | ||||
|     body: '', | ||||
|     from: 'Lossless GmbH <noreply@mail.lossless.one>', | ||||
|     subject: 'A message with no body from @mojoio/mailgun test', | ||||
|   }); | ||||
|   await testMailgunAccount.sendSmartMail( | ||||
|     emptyBodySmartmail, | ||||
|     'Sandbox Team <sandbox@mail.git.zone>', | ||||
|   ); | ||||
| }); | ||||
|  | ||||
| tap.test('should retrieve a mail using a retrieval url', async () => { | ||||
|   // Note: This test requires a valid message storage URL from a recently sent email | ||||
|   // Storage URLs are available for 3 days after sending via Events API or Mailgun dashboard | ||||
|   const result = await testMailgunAccount.retrieveSmartMailFromMessageUrl( | ||||
|     'https://api.eu.mailgun.net/v3/domains/mail.lossless.one/messages/AgMFnnnAKC8xp_dDa79LyoxhloxtaVmnRA==', | ||||
|   ); | ||||
|   console.log(result); | ||||
|  | ||||
|   // TODO handle empty body | ||||
|   if (false) { | ||||
|     result.options.subject = 'hi there. This is a testmail with attachment'; | ||||
|     result.options.from = 'noreply@mail.lossless.com'; | ||||
|     await testMailgunAccount.sendSmartMail( | ||||
|       result, | ||||
|       'Sandbox Team <sandbox@mail.git.zone>', | ||||
|     ); | ||||
|   } | ||||
| }); | ||||
|  | ||||
| export default tap.start(); | ||||
		Reference in New Issue
	
	Block a user