Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit eb41ab0

Browse files
committed
test: fix indentation
1 parent 59e2aae commit eb41ab0

File tree

2 files changed

+24
-21
lines changed

2 files changed

+24
-21
lines changed

__TESTS__/unit/url/url.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ describe('Tests for URL configuration', () => {
103103

104104
//just added for playground
105105
it('Should include query params', function () {
106-
const image = createNewImage('sample', {cloudName: 'demo'}, {queryParams: '_i=abcde&_t=false'}});
106+
const image = createNewImage('sample', {cloudName: 'demo'}, {queryParams: '_i=abcde&_z=1234&_t=false'});
107107
const url = image.toURL();
108108
expect(url).toEqual(`https://res.cloudinary.com/demo/image/upload/sample?_i=abcde&_z=1234&_t=false`);
109109
});

src/assets/CloudinaryFile.ts

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -288,13 +288,14 @@ class CloudinaryFile {
288288
// 2. If we got an object we have to check if URLSearchParams is available, and only then use it
289289
// Beause we want to throw a meaningful Error in case it's not - we can wrap the below code in a try catch clause
290290
// 3. If it already was a string then we can skip the parsing but still we need to assign it to `queryParamsString`
291-
//
292291

293-
const shouldAddAnalytics = this.urlConfig.analytics !== false && !(publicID.includes('?'));
292+
const shouldAddAnalytics = this.urlConfig.analytics !== false && !(publicID.includes('?'));
294293

295-
if (typeof(this.urlConfig.queryParams) === 'object'){ //#1
294+
let queryParamsString = '';
296295

297-
try { //#2
296+
if (typeof(this.urlConfig.queryParams) === 'object'){ //#1
297+
298+
try {
298299
const queryParams = new URLSearchParams(this.urlConfig.queryParams as Record<string, string>);
299300
// urlConfig.analytics is true by default, has to be explicitly set to false to overwrite
300301
// Don't add analytics when publicId includes a '?' to not risk changing existing query params
@@ -303,31 +304,33 @@ class CloudinaryFile {
303304
queryParams.set("_a", getSDKAnalyticsSignature(trackedAnalytics));
304305
}
305306

306-
const queryParamsString = queryParams.toString();
307+
queryParamsString = queryParams.toString();
307308

308-
} catch(){
309-
//TODO: improve error message, consult with docs team.
310-
throw "Error: URLSearchParams is not available."; //#2
309+
} catch(err) {
310+
//TODO: improve error message, consult with docs team.
311+
console.error("Error: URLSearchParams is not available");
312+
//throw "Error: URLSearchParams is not available."; //#2
311313
}
312-
}
314+
}
313315

314-
//if (typeof(this.urlConfig.queryParams) === 'string'){ //#3
315-
else{ //#3
316-
//assign to queryParamsString
317-
let queryParamsString = this.urlConfig.queryParams || '';
316+
//if (typeof(this.urlConfig.queryParams) === 'string'){ //#3
317+
else{ //#3
318+
//assign to queryParamsString
319+
queryParamsString = this.urlConfig.queryParams || '';
318320

319321
if (shouldAddAnalytics) {
320-
queryParams.set("_a", getSDKAnalyticsSignature(trackedAnalytics));
321-
queryParamsString += (queryParamsString.length > 0 ? "&" :"") + "_a=" + getSDKAnalyticsSignature(trackedAnalytics);
322+
// queryParams.set("_a", getSDKAnalyticsSignature(trackedAnalytics));
323+
queryParamsString += (queryParamsString.length > 0 ? "&" :"") + "_a=" + getSDKAnalyticsSignature(trackedAnalytics);
322324
}
323325

324-
}
325326

326-
if (queryParamsString) {
327-
return `${safeURL}?${queryParamsString}`;
328-
} else {
329-
return safeURL;
327+
if (queryParamsString) {
328+
return `${safeURL}?${queryParamsString}`;
329+
} else {
330+
return safeURL;
331+
}
330332
}
333+
331334
}
332335
}
333336
}

0 commit comments

Comments
 (0)