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

thelinmichael / spotify-web-api-node / #215

18 Mar 2025 01:34AM UTC coverage: 96.978%. Remained the same
#215

push

travis-ci

web-flow
Bump actions/setup-node from 4.2.0 to 4.3.0

Bumps [actions/setup-node](https://github.com/actions/setup-node) from 4.2.0 to 4.3.0.
- [Release notes](https://github.com/actions/setup-node/releases)
- [Commits](https://github.com/actions/setup-node/compare/v4.2.0...v4.3.0)

---
updated-dependencies:
- dependency-name: actions/setup-node
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

132 of 147 branches covered (89.8%)

353 of 364 relevant lines covered (96.98%)

35.13 hits per line

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

96.51
/src/base-request.js
1
'use strict';
2

3
var Request = function (builder) {
5✔
4
  if (!builder) {
154!
5
    throw new Error('No builder supplied to constructor');
×
6
  }
7

8
  this.host = builder.host;
154✔
9
  this.port = builder.port;
154✔
10
  this.scheme = builder.scheme;
154✔
11
  this.queryParameters = builder.queryParameters;
154✔
12
  this.bodyParameters = builder.bodyParameters;
154✔
13
  this.headers = builder.headers;
154✔
14
  this.path = builder.path;
154✔
15
  this.timeout = builder.timeout;
154✔
16
};
17

18
Request.prototype._getter = function (key) {
5✔
19
  return function () {
40✔
20
    return this[key];
1,031✔
21
  };
22
};
23

24
Request.prototype.getHost = Request.prototype._getter('host');
5✔
25

26
Request.prototype.getPort = Request.prototype._getter('port');
5✔
27

28
Request.prototype.getScheme = Request.prototype._getter('scheme');
5✔
29

30
Request.prototype.getPath = Request.prototype._getter('path');
5✔
31

32
Request.prototype.getQueryParameters = Request.prototype._getter(
5✔
33
  'queryParameters'
34
);
35

36
Request.prototype.getBodyParameters = Request.prototype._getter(
5✔
37
  'bodyParameters'
38
);
39

40
Request.prototype.getHeaders = Request.prototype._getter('headers');
5✔
41

42
Request.prototype.getTimeout = Request.prototype._getter('timeout');
5✔
43

44
Request.prototype.getURI = function () {
5✔
45
  if (!this.scheme || !this.host || !this.port) {
148!
46
    throw new Error('Missing components necessary to construct URI');
×
47
  }
48
  var uri = this.scheme + '://' + this.host;
148✔
49
  if (
148✔
50
    (this.scheme === 'http' && this.port !== 80) ||
432✔
51
    (this.scheme === 'https' && this.port !== 443)
52
  ) {
53
    uri += ':' + this.port;
13✔
54
  }
55
  if (this.path) {
148✔
56
    uri += this.path;
136✔
57
  }
58
  return uri;
148✔
59
};
60

61
Request.prototype.getURL = function () {
5✔
62
  var uri = this.getURI();
3✔
63
  if (this.getQueryParameters()) {
3!
64
    return uri + this.getQueryParameterString(this.getQueryParameters());
3✔
65
  } else {
66
    return uri;
×
67
  }
68
};
69

70
Request.prototype.getQueryParameterString = function () {
5✔
71
  var queryParameters = this.getQueryParameters();
7✔
72
  if (queryParameters) {
7✔
73
    return (
6✔
74
      '?' +
75
      Object.keys(queryParameters)
76
        .filter(function (key) {
77
          return queryParameters[key] !== undefined;
25✔
78
        })
79
        .map(function (key) {
80
          return key + '=' + queryParameters[key];
23✔
81
        })
82
        .join('&')
83
    );
84
  }
85
};
86

87
Request.prototype.execute = function (method, callback) {
5✔
88
  if (callback) {
132✔
89
    method(this, callback);
34✔
90
    return;
34✔
91
  }
92
  var _self = this;
98✔
93

94
  return new Promise(function (resolve, reject) {
98✔
95
    method(_self, function (error, result) {
98✔
96
      if (error) {
98✔
97
        reject(error);
1✔
98
      } else {
99
        resolve(result);
97✔
100
      }
101
    });
102
  });
103
};
104

105
var Builder = function () {};
5✔
106

107
Builder.prototype._setter = function (key) {
5✔
108
  return function (value) {
25✔
109
    this[key] = value;
589✔
110
    return this;
589✔
111
  };
112
};
113

114
Builder.prototype.withHost = Builder.prototype._setter('host');
5✔
115

116
Builder.prototype.withPort = Builder.prototype._setter('port');
5✔
117

118
Builder.prototype.withScheme = Builder.prototype._setter('scheme');
5✔
119

120
Builder.prototype.withPath = Builder.prototype._setter('path');
5✔
121

122
Builder.prototype._assigner = function (key) {
5✔
123
  return function () {
15✔
124
    for (var i = 0; i < arguments.length; i++) {
246✔
125
      this[key] = this._assign(this[key], arguments[i]);
271✔
126
    }
127

128
    return this;
246✔
129
  };
130
};
131

132
Builder.prototype.withQueryParameters = Builder.prototype._assigner(
5✔
133
  'queryParameters'
134
);
135

136
Builder.prototype.withBodyParameters = Builder.prototype._assigner(
5✔
137
  'bodyParameters'
138
);
139

140
Builder.prototype.withHeaders = Builder.prototype._assigner('headers');
5✔
141

142
Builder.prototype.withTimeout = Builder.prototype._setter('timeout');
5✔
143

144
Builder.prototype.withAuth = function (accessToken) {
5✔
145
  if (accessToken) {
130✔
146
    this.withHeaders({ Authorization: 'Bearer ' + accessToken });
78✔
147
  }
148
  return this;
130✔
149
};
150

151
Builder.prototype._assign = function (src, obj) {
5✔
152
  if (obj && Array.isArray(obj)) {
271✔
153
    return obj;
4✔
154
  }
155
  if (obj && typeof obj === 'string') {
267✔
156
    return obj;
1✔
157
  }
158
  if (obj && Object.keys(obj).length > 0) {
266✔
159
    return Object.assign(src || {}, obj);
242✔
160
  }
161
  return src;
24✔
162
};
163

164
Builder.prototype.build = function () {
5✔
165
  return new Request(this);
154✔
166
};
167

168
module.exports.builder = function () {
5✔
169
  return new Builder();
154✔
170
};
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