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

CaptainFact / captain-fact-frontend / 13509561802

24 Feb 2025 10:56PM UTC coverage: 5.504% (-1.4%) from 6.953%
13509561802

push

github

web-flow
Release (#1375)

* chore(deps-dev): Bump @babel/preset-env from 7.20.2 to 7.26.9 (#1371)

Bumps [@babel/preset-env](https://github.com/babel/babel/tree/HEAD/packages/babel-preset-env) from 7.20.2 to 7.26.9.
- [Release notes](https://github.com/babel/babel/releases)
- [Changelog](https://github.com/babel/babel/blob/main/CHANGELOG.md)
- [Commits](https://github.com/babel/babel/commits/v7.26.9/packages/babel-preset-env)

---
updated-dependencies:
- dependency-name: "@babel/preset-env"
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Misc styles & GraphQL fixes (#1374)

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

43 of 1647 branches covered (2.61%)

Branch coverage included in aggregate %.

192 of 2623 relevant lines covered (7.32%)

0.17 hits per line

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

47.5
/app/API/http_api/index.js
1
import 'isomorphic-fetch'
2

3
import { trimEnd } from 'lodash'
4

5
import { HTTP_API_URL } from '../../config'
6
import { getFromLocalStorage, LOCAL_STORAGE_KEYS } from '../../lib/local_storage'
7
import { optionsToQueryString } from '../../lib/url_utils'
8
import parseServerError from '../server_error'
9

10
class CaptainFactHttpApi {
11
  constructor(baseUrl, token) {
12
    this.baseUrl = `${trimEnd(baseUrl, '/')}/`
1✔
13
    this.hasToken = !!token
1✔
14
    this.headers = { 'Content-Type': 'application/json' }
1✔
15
    if (token) {
1!
16
      this.headers.authorization = `Bearer ${token}`
×
17
    }
18
  }
19

20
  setAuthorizationToken(token) {
21
    if (token) {
×
22
      this.hasToken = true
×
23
      this.headers.authorization = `Bearer ${token}`
×
24
    }
25
  }
26

27
  resetToken() {
28
    this.hasToken = false
×
29
    delete this.headers.authorization
×
30
  }
31

32
  prepareResponse(promise) {
33
    return new Promise((fulfill, reject) => {
1✔
34
      return promise
1✔
35
        .then((response) => {
36
          return response.text().then((body) => {
1✔
37
            const parsedBody = body ? JSON.parse(body) : null
1!
38
            if (!response.ok) {
1!
39
              reject(parseServerError(parsedBody))
×
40
            } else {
41
              fulfill(parsedBody)
1✔
42
            }
43
          })
44
        })
45
        .catch((e) => {
46
          // eslint-disable-next-line no-console
47
          console.error(e)
×
48
          // Special case when no internet connection
49
          reject('noInternet')
×
50
        })
51
    })
52
  }
53

54
  makeRequest(resourceUrl, requestType, data) {
55
    const response = fetch(this.baseUrl + resourceUrl, {
×
56
      method: requestType,
57
      body: data ? JSON.stringify(data) : '',
×
58
      headers: this.headers,
59
    })
60
    return this.prepareResponse(response)
×
61
  }
62

63
  /**
64
   * Send a get request against the given `resourceUrl`.
65
   * @param {string} resourceUrl
66
   * @param {object} [options] - A map of options to convert to query
67
   *                               string http://url?option1=xxx&option2=yyy
68
   * @returns {Promise}
69
   */
70
  get(resourceUrl, options) {
71
    const queryString = optionsToQueryString(options)
1✔
72
    const url = this.baseUrl + resourceUrl + queryString
1✔
73
    const response = fetch(url, { headers: this.headers })
1✔
74
    return this.prepareResponse(response)
1✔
75
  }
76

77
  post(resourceUrl, data) {
78
    return this.makeRequest(resourceUrl, 'POST', data)
×
79
  }
80

81
  put(resourceUrl, data) {
82
    return this.makeRequest(resourceUrl, 'PUT', data)
×
83
  }
84

85
  delete(resourceUrl, data) {
86
    return this.makeRequest(resourceUrl, 'DELETE', data)
×
87
  }
88
}
89

90
// Configure HttpApi
91
const token = getFromLocalStorage(LOCAL_STORAGE_KEYS.TOKEN)
1✔
92
const HttpApi = new CaptainFactHttpApi(HTTP_API_URL, token)
1✔
93

94
export default HttpApi
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

© 2026 Coveralls, Inc