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

CaptainFact / captain-fact-frontend / 20020625706

08 Dec 2025 07:49AM UTC coverage: 2.865% (-2.5%) from 5.41%
20020625706

push

github

Betree
refact: Move everythin to GraphQL, remove redux

38 of 2352 branches covered (1.62%)

Branch coverage included in aggregate %.

0 of 922 new or added lines in 45 files covered. (0.0%)

32 existing lines in 8 files now uncovered.

125 of 3338 relevant lines covered (3.74%)

0.11 hits per line

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

0.0
/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) {
UNCOV
12
    this.baseUrl = `${trimEnd(baseUrl, '/')}/`
×
UNCOV
13
    this.hasToken = !!token
×
UNCOV
14
    this.headers = { 'Content-Type': 'application/json' }
×
UNCOV
15
    if (token) {
×
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) {
UNCOV
33
    return new Promise((fulfill, reject) => {
×
UNCOV
34
      return promise
×
35
        .then((response) => {
UNCOV
36
          return response.text().then((body) => {
×
UNCOV
37
            const parsedBody = body ? JSON.parse(body) : null
×
UNCOV
38
            if (!response.ok) {
×
39
              reject(parseServerError(parsedBody))
×
40
            } else {
UNCOV
41
              fulfill(parsedBody)
×
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) {
UNCOV
71
    const queryString = optionsToQueryString(options)
×
UNCOV
72
    const url = this.baseUrl + resourceUrl + queryString
×
UNCOV
73
    const response = fetch(url, { headers: this.headers })
×
UNCOV
74
    return this.prepareResponse(response)
×
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
UNCOV
91
const token = getFromLocalStorage(LOCAL_STORAGE_KEYS.TOKEN)
×
UNCOV
92
const HttpApi = new CaptainFactHttpApi(HTTP_API_URL, token)
×
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