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

mozilla / blurts-server / 23c5b31a-229c-43de-b92e-ad2b9e49241b

pending completion
23c5b31a-229c-43de-b92e-ad2b9e49241b

push

circleci

Amri Toufali
use period instead of colon in case error is blank

282 of 1421 branches covered (19.85%)

Branch coverage included in aggregate %.

2 of 2 new or added lines in 1 file covered. (100.0%)

959 of 3929 relevant lines covered (24.41%)

4.06 hits per line

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

0.0
/src/client/js/partials/settings.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 settingsPartial = document.querySelector("[data-partial='settings']")
×
6

7
function init () {
8
  document.body.addEventListener('email-added', handleEvent)
×
9
}
10

11
function handleEvent (e) {
12
  switch (true) {
×
13
    case e.type === 'email-added':
14
      document.querySelector('dialog[data-partial="add-email"]')
×
15
        .addEventListener('close', () => window.location.reload(), { once: true })
×
16
      break
×
17
  }
18
}
19

20
const settingsAlertOptionsInputs = document.getElementsByClassName('js-settings-alert-options-input')
×
21
if (settingsAlertOptionsInputs?.length) {
×
22
  for (const inputElement of settingsAlertOptionsInputs) {
×
23
    inputElement.addEventListener('change', async event => {
×
24
      try {
×
25
        const communicationOption = event.target.getAttribute('data-alert-option')
×
26
        const csrfToken = document
×
27
          .querySelector('.js-settings[data-csrf-token]')
28
          .getAttribute('data-csrf-token')
29

30
        const response = await fetch('/api/v1/user/update-comm-option', {
×
31
          headers: {
32
            'Content-Type': 'application/json',
33
            'x-csrf-token': csrfToken
34
          },
35
          mode: 'same-origin',
36
          method: 'POST',
37
          body: JSON.stringify({ communicationOption })
38
        })
39

40
        if (response && response.redirected === true) {
×
41
          throw response.error
×
42
        }
43
      } catch (err) {
44
        throw new Error(`Updating communication option failed: ${err}`)
×
45
      }
46
      event.preventDefault()
×
47
      return false
×
48
    })
49
  }
50
}
51

52
const settingsRemoveEmailButtons = document.getElementsByClassName('js-remove-email-button')
×
53
if (settingsRemoveEmailButtons?.length) {
×
54
  for (const removeEmailButton of settingsRemoveEmailButtons) {
×
55
    removeEmailButton.addEventListener('click', async event => {
×
56
      try {
×
57
        const subscriberId = event.target.getAttribute('data-subscriber-id')
×
58
        const emailId = event.target.getAttribute('data-email-id')
×
59
        const csrfToken = document
×
60
          .querySelector('.js-settings[data-csrf-token]')
61
          .getAttribute('data-csrf-token')
62

63
        const response = await fetch('/api/v1/user/remove-email', {
×
64
          headers: {
65
            'Content-Type': 'application/json',
66
            'x-csrf-token': csrfToken
67
          },
68
          mode: 'same-origin',
69
          method: 'POST',
70
          body: JSON.stringify({ emailId, subscriberId })
71
        })
72

73
        if (response && response.redirected === true) {
×
74
          return window.location.reload(true)
×
75
        }
76
      } catch (err) {
77
        console.error(`Error: ${err}`)
×
78
      }
79
    })
80
  }
81
}
82

83
const settingsResendEmailLinks = document.getElementsByClassName('js-settings-resend-email')
×
84
if (settingsResendEmailLinks?.length) {
×
85
  for (const resendEmailLink of settingsResendEmailLinks) {
×
86
    resendEmailLink.addEventListener('click', async event => {
×
87
      try {
×
88
        const emailId = event.target.getAttribute('data-email-id')
×
89
        const csrfToken = document
×
90
          .querySelector('.js-settings[data-csrf-token]')
91
          .getAttribute('data-csrf-token')
92

93
        const response = await fetch('/api/v1/user/resend-email', {
×
94
          headers: {
95
            'Content-Type': 'application/json',
96
            'x-csrf-token': csrfToken
97
          },
98
          mode: 'same-origin',
99
          method: 'POST',
100
          body: JSON.stringify({ emailId })
101
        })
102

103
        if (!response.ok) {
×
104
          // TODO: localize error messages
105
          const toast = document.createElement('toast-alert')
×
106
          toast.textContent = `Re-sending verification email failed. ${response.statusText}`
×
107
          document.body.append(toast)
×
108
        }
109

110
        if (response?.redirected) {
×
111
          throw response.error
×
112
        }
113
      } catch (err) {
114
        throw new Error(`Re-sending verification email failed. ${err}`)
×
115
      }
116
      event.preventDefault()
×
117
      return false
×
118
    })
119
  }
120
}
121

122
if (settingsPartial) 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