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

Error when testing mail #95

Closed
unkobweb opened this issue Mar 15, 2024 · 1 comment
Closed

Error when testing mail #95

unkobweb opened this issue Mar 15, 2024 · 1 comment
Assignees
Labels
Type: Bug The issue has indentified a bug

Comments

@unkobweb
Copy link

unkobweb commented Mar 15, 2024

Package version

9.2.0

Describe the bug

Hi, i tried to do like the documentation :

import { test } from '@japa/runner'
import mail from '@adonisjs/mail/services/main'
import VerifyEmailNotification from '#mails/verify_email'

test.group('Users | register', () => {
  test('create a new user account', async ({ client, route }) => {
    /**
     * Turn on the fake mode
     */
    const { mails } = mail.fake()
    
    /**
     * Make an API call
     */
    await client
      .post(route('users.store'))
      .send(userData)
      
    /**
     * Assert the controller indeed sent the
     * VerifyEmailNotification mail
     */
    mails.assertSent(VerifyEmailNotification, ({ message }) => {
      return message
        .hasTo(userData.email)
        .hasSubject('Verify email address')
    })
  })
})

And here is my code with all errors :
Capture d'écran 2024-03-15 000728
And here is my mail class :

import env from '#start/env'
import { BaseMail } from '@adonisjs/mail'

export default class SendPasswordTokenNotification extends BaseMail {
  from = env.get('SENDER_EMAIL')
  subject = 'Votre code de réinitialisation de mot de passe'

  to: string
  payload: any

  constructor(private email: string, private data: { token: string }) {
    super()
    this.to = email
    this.payload = data
  }
  /**
   * The "prepare" method is called automatically when
   * the email is sent or queued.
   */
  prepare() {
    this.message.to(this.to)
    this.message.htmlView('emails/send_password_token', this.payload)
  }
}

(I don't know if it's the good way to pass data in the mail class but the documentation doesn't show it :/)

Reproduction repo

No response

@thetutlage thetutlage transferred this issue from adonisjs/mail Mar 21, 2024
@thetutlage thetutlage transferred this issue from adonisjs/v6-docs Mar 27, 2024
@thetutlage
Copy link
Member

There was an issue with assertSent method and other similar methods where they did not allow Mail classes that accepts constructor argument. This issue has been fixed.

Another issue is with the docs related to the following code snippet.

return message
        .hasTo(userData.email)
        .hasSubject('Verify email address')

It should be

return message.hasTo(userData.email) && message.hasSubject('Verify email address')

Will fix the docs next

@thetutlage thetutlage self-assigned this Mar 27, 2024
@thetutlage thetutlage added the Type: Bug The issue has indentified a bug label Mar 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug The issue has indentified a bug
Projects
None yet
Development

No branches or pull requests

2 participants