Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: update tests #31

Merged
merged 1 commit into from
Oct 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ lib-cov

# Coverage directory used by tools like istanbul
coverage
.tap

# nyc test coverage
.nyc_output
Expand Down Expand Up @@ -61,5 +62,7 @@ profile*
.env
.envrc

# package-lock
# lockfiles
package-lock.json
yarn.lock
pnpm-lock.yaml
32 changes: 22 additions & 10 deletions index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,13 @@ const testMessage = {
replyTo: 'reply@ignoreme.com',
subject: 'This is a plain text subject',
html: testHtml,
text: 'This is a plain text email message.'
text: 'This is a plain text email message.',
attachments: [
{
filename: 'text1.txt',
content: 'hello world!'
}
]
}

const responseWhenTemplatesPresent = {
Expand All @@ -46,7 +52,13 @@ const responseWhenTemplatesPresent = {
replyTo: 'reply@ignoreme.com',
subject: 'This is a plain text subject',
html: testHtml,
text: 'This is a test text message to Test Name'
text: 'This is a test text message to Test Name',
attachments: [
{
filename: 'text1.txt',
content: 'hello world!'
}
]
}

test('mail, nodemailer & view decorators exist', async t => {
Expand Down Expand Up @@ -115,7 +127,7 @@ test('fastify-mail uses templates to send mail when point-of-view is registered

t.ok(fastify.hasDecorator('foo'))
t.same(sendMailStub.args[0], [responseWhenTemplatesPresent])
t.is(sendMailStub.args.length, 1)
t.equal(sendMailStub.args.length, 1)
})

test('fastify-mail uses string variables (for text and html) when a template is not present', async (t) => {
Expand Down Expand Up @@ -144,7 +156,7 @@ test('fastify-mail uses string variables (for text and html) when a template is

t.ok(fastify.hasDecorator('foo'))
t.same(sendMailStub.args[0], [testMessage])
t.is(sendMailStub.args.length, 1)
t.equal(sendMailStub.args.length, 1)
})

test('fastify-mail uses text template when available but defaults to provided html if no template is available', async (t) => {
Expand Down Expand Up @@ -177,7 +189,7 @@ test('fastify-mail uses text template when available but defaults to provided ht

t.ok(fastify.hasDecorator('foo'))
t.same(sendMailStub.args[0][0].html, testHtml)
t.is(sendMailStub.args.length, 1)
t.equal(sendMailStub.args.length, 1)
})

test('fastify-mail uses html template when available but defaults to provided text if no template is available', async (t) => {
Expand Down Expand Up @@ -211,7 +223,7 @@ test('fastify-mail uses html template when available but defaults to provided te
t.ok(fastify.hasDecorator('foo'))
t.same(sendMailStub.args[0][0].html, testHtml)
t.same(sendMailStub.args[0][0].text, 'This is a plain text email message.')
t.is(sendMailStub.args.length, 1)
t.equal(sendMailStub.args.length, 1)
})

test('fastify.mail.sendMail calls nodemailer.sendMail with correct arguments', async t => {
Expand All @@ -234,7 +246,7 @@ test('fastify.mail.sendMail calls nodemailer.sendMail with correct arguments', a
await fastify.mail.sendMail(testMessage, { templatePath: relative(__dirname, testTemplates), context: testContext })

t.same(sendMailStub.args[0], [responseWhenTemplatesPresent])
t.is(sendMailStub.args.length, 1)
t.equal(sendMailStub.args.length, 1)
})

test('fastify.mail.sendMail returns an error when required values are not present (from)', async (t) => {
Expand All @@ -245,7 +257,7 @@ test('fastify.mail.sendMail returns an error when required values are not presen
const { error } = await fastify.mail.sendMail({ to: 'to@ignoreme.com', subject: 'subject@ignoreme.com' })

t.ok(error instanceof TypeError)
t.is(error.message, '"from" must be defined')
t.equal(error.message, '"from" must be defined')
})

test('fastify.mail.sendMail returns an error multiple required values are missing', async (t) => {
Expand All @@ -256,7 +268,7 @@ test('fastify.mail.sendMail returns an error multiple required values are missin
const { error } = await fastify.mail.sendMail({ from: 'from@ignoreme.com' })

t.ok(error instanceof TypeError)
t.is(error.message, '"to" must be defined\n"subject" must be defined')
t.equal(error.message, '"to" must be defined\n"subject" must be defined')
})

test('fastify.mail.sendMail returns an error when no message is defined', async (t) => {
Expand All @@ -267,5 +279,5 @@ test('fastify.mail.sendMail returns an error when no message is defined', async
const { error } = await fastify.mail.sendMail()

t.ok(error instanceof TypeError)
t.is(error.message, 'message is not defined')
t.equal(error.message, 'message is not defined')
})
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"scripts": {
"lint": "standard",
"fix": "standard --fix",
"test": "tap -R classic",
"test": "tap --show-full-coverage",
"validate": "npm run lint && npm run test"
},
"repository": {
Expand Down Expand Up @@ -42,7 +42,7 @@
"lint-staged": "^10.2.11",
"sinon": "^9.2.2",
"standard": "^14.3.4",
"tap": "^14.11.0"
"tap": "^18.4.3"
},
"lint-staged": {
"*.js": "npm run fix"
Expand Down
Loading
Loading