jest.mock("nodemailer")
import { TestConfiguration, mocks, API } from "../../../../tests"
const sendMailMock = mocks.email.mock()
import { EmailTemplatePurpose } from "../../../../constants"

describe("/api/global/email", () => {
  const config = new TestConfiguration()
  const api = new API(config)

  beforeAll(async () => {
    await config.beforeAll()
  })

  afterAll(async () => {
    await config.afterAll()
  })

  it("should be able to send an email (with mocking)", async () => {
    // initially configure settings
    await config.saveSmtpConfig()
    await config.saveSettingsConfig()

    const res = await api.emails.sendEmail(EmailTemplatePurpose.INVITATION)

    expect(res.body.message).toBeDefined()
    expect(sendMailMock).toHaveBeenCalled()
    const emailCall = sendMailMock.mock.calls[0][0]
    expect(emailCall.subject).toBe("Hello!")
    expect(emailCall.html).not.toContain("Invalid binding")
  })
})
