• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mozilla / blurts-server / 4040bc25-7f30-464b-958e-746a756a4e44

pending completion
4040bc25-7f30-464b-958e-746a756a4e44

push

circleci

GitHub
Merge pull request #2790 from mozilla/MNTOR-1056-Migrate-breach-alert-email

282 of 1375 branches covered (20.51%)

Branch coverage included in aggregate %.

174 of 174 new or added lines in 17 files covered. (100.0%)

959 of 3709 relevant lines covered (25.86%)

4.2 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/client/js/partials/email-preview.js
1
/* This Source Code Form is subject to the terms of the Mozilla Public
2
 * License, v. 2.0. If a copy of the MPL was not distributed with this
3
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4

5
const emailsPartial = document.querySelector("[data-partial='emailPreview']")
×
6
let emailPreviewForm
7
let emailTemplateSelect
8

9
function init () {
10
  emailPreviewForm = document.querySelector('.js-email-preview-form')
×
11
  emailTemplateSelect = emailsPartial.querySelector('.js-email custom-select')
×
12

13
  emailPreviewForm.addEventListener('submit', sendTestEmail)
×
14
  emailTemplateSelect.addEventListener('change', handleEvent)
×
15
}
16

17
function handleEvent (event) {
18
  const templateSelectChanged = event.target.matches(
×
19
    'custom-select[name="email-template"]'
20
  )
21

22
  if (templateSelectChanged) {
×
23
    const updatedPath = `/admin/emails/${event.target.value}`
×
24
    if (window.location.pathname !== updatedPath) {
×
25
      window.location.replace(updatedPath)
×
26
    }
27
  }
28
}
29

30
async function sendTestEmail (event) {
31
  event.preventDefault()
×
32
  const selectedRecipient = event.target.querySelector(
×
33
    'input[name="email-recipient-option"]:checked'
34
  ).value
35

36
  try {
×
37
    const csrfToken = document
×
38
      .querySelector('.js-email[data-csrf-token]')
39
      .getAttribute('data-csrf-token')
40

41
    const response = await fetch('/admin/send-test-email', {
×
42
      headers: {
43
        'Content-Type': 'application/json',
44
        'x-csrf-token': csrfToken
45
      },
46
      mode: 'same-origin',
47
      method: 'POST',
48
      body: JSON.stringify({
49
        emailId: emailTemplateSelect.value,
50
        recipient: selectedRecipient
51
      })
52
    })
53

54
    if (response?.redirected) {
×
55
      throw response.error
×
56
    }
57

58
    window.alert('Email sent!')
×
59
  } catch (err) {
60
    throw new Error(`Sending test email failed: ${err}`)
×
61
  }
62
}
63

64
if (emailsPartial) init()
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc