Skip to content

Commit e16ec52

Browse files
committed
Fix coverage
1 parent 3177576 commit e16ec52

File tree

2 files changed

+20
-60
lines changed

2 files changed

+20
-60
lines changed

sdk/src/http/Client.ts

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,7 @@ export default class Client extends EventEmitter {
125125
init.headers = init.headers || {};
126126

127127
// Sanity checks
128-
if (!init.url) {
129-
throw new Error('Url is not defined');
130-
}
128+
if (!init.url) {throw new Error('Url is not defined');}
131129
if (!init.method) {
132130
init.method = 'GET';
133131
}
@@ -214,13 +212,9 @@ export default class Client extends EventEmitter {
214212

215213
try {
216214
boundary = this.getContentType(response).match(/boundary=([^;]+)/i)[1]; //eslint-disable-line
217-
} catch (e) {
218-
throw new Error('Cannot find boundary');
219-
}
215+
} catch (e) { throw new Error('Cannot find boundary');}
220216

221-
if (!boundary) {
222-
throw new Error('Cannot find boundary');
223-
}
217+
if (!boundary) {throw new Error('Cannot find boundary');}
224218

225219
const parts = text.toString().split(Client._boundarySeparator + boundary);
226220

@@ -231,9 +225,7 @@ export default class Client extends EventEmitter {
231225
parts.pop();
232226
}
233227

234-
if (parts.length < 1) {
235-
throw new Error('No parts in body');
236-
}
228+
if (parts.length < 1) {throw new Error('No parts in body');}
237229

238230
// Step 2. Parse status info
239231

@@ -274,9 +266,7 @@ export default class Client extends EventEmitter {
274266
}
275267

276268
public async error(response: Response, skipOKCheck = false): Promise<string> {
277-
if (response.ok && !skipOKCheck) {
278-
return null;
279-
}
269+
if (response.ok && !skipOKCheck) {return null;}
280270

281271
let msg = (response.status ? `${response.status} ` : '') + (response.statusText ? response.statusText : '');
282272

sdk/src/platform/Platform.ts

Lines changed: 15 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -219,9 +219,7 @@ export default class Platform extends EventEmitter {
219219
}
220220

221221
// Append the URL prefix, if available
222-
if (this._urlPrefix) {
223-
builtUrl += this._urlPrefix;
224-
}
222+
if (this._urlPrefix) {builtUrl += this._urlPrefix;}
225223

226224
// Append the provided path
227225
builtUrl += path;
@@ -275,9 +273,7 @@ export default class Platform extends EventEmitter {
275273
* @throws {Error} If discovery is not enabled or if an error occurs during initialization.
276274
*/
277275
public async initDiscovery() {
278-
if (!this._discovery) {
279-
throw new Error('Discovery is not enabled!');
280-
}
276+
if (!this._discovery) {throw new Error('Discovery is not enabled!');}
281277
try {
282278
await this._discovery.init();
283279
this._discoveryInitPromise = null;
@@ -375,14 +371,10 @@ export default class Platform extends EventEmitter {
375371
const response =
376372
(url.startsWith('#') && getParts(url, '#')) || (url.startsWith('?') && getParts(url, '?')) || null;
377373

378-
if (!response) {
379-
throw new Error('Unable to parse response');
380-
}
374+
if (!response) {throw new Error('Unable to parse response');}
381375

382376
const queryString = new URLSearchParams(response);
383-
if (!queryString) {
384-
throw new Error('Unable to parse response');
385-
}
377+
if (!queryString) {throw new Error('Unable to parse response');}
386378

387379
const error = queryString.get('error_description') || queryString.get('error');
388380

@@ -411,13 +403,9 @@ export default class Platform extends EventEmitter {
411403
// clear check last timeout when user open loginWindow twice to avoid leak
412404
this._clearLoginWindowCheckTimeout();
413405
return new Promise((resolve, reject) => {
414-
if (typeof window === 'undefined') {
415-
throw new Error('This method can be used only in browser');
416-
}
406+
if (typeof window === 'undefined') {throw new Error('This method can be used only in browser');}
417407

418-
if (!url) {
419-
throw new Error('Missing mandatory URL parameter');
420-
}
408+
if (!url) {throw new Error('Missing mandatory URL parameter');}
421409

422410
const dualScreenLeft = window.screenLeft !== undefined ? window.screenLeft : 0;
423411
const dualScreenTop = window.screenTop !== undefined ? window.screenTop : 0;
@@ -587,9 +575,7 @@ export default class Platform extends EventEmitter {
587575
if (refresh_token_ttl) {
588576
body.refresh_token_ttl = refresh_token_ttl;
589577
}
590-
if (endpoint_id) {
591-
body.endpoint_id = endpoint_id;
592-
}
578+
if (endpoint_id) {body.endpoint_id = endpoint_id;}
593579
response = await this._tokenRequest(tokenEndpoint, body);
594580

595581
json = await response.clone().json();
@@ -655,13 +641,9 @@ export default class Platform extends EventEmitter {
655641
const authData = await this.auth().data();
656642

657643
// Perform sanity checks
658-
if (!authData.refresh_token) {
659-
throw new Error('Refresh token is missing');
660-
}
644+
if (!authData.refresh_token) {throw new Error('Refresh token is missing');}
661645
const refreshTokenValid = await this._auth.refreshTokenValid();
662-
if (!refreshTokenValid) {
663-
throw new Error('Refresh token has expired');
664-
}
646+
if (!refreshTokenValid) {throw new Error('Refresh token has expired');}
665647
const body: RefreshTokenBody = {
666648
grant_type: 'refresh_token',
667649
refresh_token: authData.refresh_token,
@@ -714,9 +696,7 @@ export default class Platform extends EventEmitter {
714696
* @returns A Promise resolving to a Response object.
715697
*/
716698
public async refresh(): Promise<Response> {
717-
if (this._authProxy) {
718-
throw new Error('Refresh is not supported in Auth Proxy mode');
719-
}
699+
if (this._authProxy) {throw new Error('Refresh is not supported in Auth Proxy mode');}
720700
if (!this._refreshPromise) {
721701
this._refreshPromise = (async () => {
722702
try {
@@ -738,9 +718,7 @@ export default class Platform extends EventEmitter {
738718
* @returns
739719
*/
740720
public async logout(): Promise<Response> {
741-
if (this._authProxy) {
742-
throw new Error('Logout is not supported in Auth Proxy mode');
743-
}
721+
if (this._authProxy) {throw new Error('Logout is not supported in Auth Proxy mode');}
744722
try {
745723
this.emit(this.events.beforeLogout);
746724

@@ -825,9 +803,7 @@ export default class Platform extends EventEmitter {
825803
let {retry, handleRateLimit} = options;
826804

827805
// Guard is for errors that come from polling
828-
if (!e.response || retry) {
829-
throw e;
830-
}
806+
if (!e.response || retry) {throw e;}
831807

832808
const {response} = e;
833809
const {status} = response;
@@ -881,9 +857,7 @@ export default class Platform extends EventEmitter {
881857
await this._discovery.refreshExternalData();
882858
}
883859
const discoveryData = await this._discovery.externalData();
884-
if (!discoveryData) {
885-
throw new Error('Discovery data is missing');
886-
}
860+
if (!discoveryData) {throw new Error('Discovery data is missing');}
887861
this._server = discoveryData.coreApi.baseUri;
888862
this._rcvServer = discoveryData.rcv.baseApiUri;
889863
if (discoveryData.tag) {
@@ -922,12 +896,8 @@ export default class Platform extends EventEmitter {
922896
* @returns A Promise resolving to a Response object or null.
923897
*/
924898
public async ensureLoggedIn(): Promise<Response | null> {
925-
if (this._authProxy) {
926-
return null;
927-
}
928-
if (await this._auth.accessTokenValid()) {
929-
return null;
930-
}
899+
if (this._authProxy) {return null;}
900+
if (await this._auth.accessTokenValid()) {return null;}
931901
await this.refresh();
932902
return null;
933903
}

0 commit comments

Comments
 (0)