diff --git a/src/app/utils/sample-url-generation.spec.ts b/src/app/utils/sample-url-generation.spec.ts index bc0eac68f..712589d1f 100644 --- a/src/app/utils/sample-url-generation.spec.ts +++ b/src/app/utils/sample-url-generation.spec.ts @@ -34,13 +34,15 @@ describe('Sample Url Generation', () => { it('destructures sample url with % sign', () => { const name = 'DiegoS%40m365x214355.onmicrosoft.com'; const search = `?$select=displayName,mail&$filter=mail eq '${name}'`; + const parsedSearch = `?$select=displayName,mail&$filter=mail+eq+'${name}'`; + const url = `https://graph.microsoft.com/v1.0/users${search}`; const expectedUrl = { requestUrl: 'users', queryVersion: 'v1.0', - sampleUrl: url, - search + sampleUrl: `https://graph.microsoft.com/v1.0/users${parsedSearch}`, + search: parsedSearch }; const parsedUrl = parseSampleUrl(url); @@ -75,6 +77,23 @@ describe('Sample Url Generation', () => { expect(parsedUrl).toEqual(expectedUrl); }); + it('replaces whitespace with + sign', () => { + const search = '?filter=displayName eq \'All Company\''; + const parsedSearch= '?filter=displayName+eq+\'All+Company\''; + + const url = `https://graph.microsoft.com/v1.0/groups${search}`; + + const expectedUrl = { + requestUrl: 'groups', + queryVersion: 'v1.0', + sampleUrl:`https://graph.microsoft.com/v1.0/groups${parsedSearch}` , + search: parsedSearch + }; + + const parsedUrl = parseSampleUrl(url); + expect(parsedUrl).toEqual(expectedUrl); + }); + }); diff --git a/src/app/utils/sample-url-generation.ts b/src/app/utils/sample-url-generation.ts index 134fac03b..5ccc4a603 100644 --- a/src/app/utils/sample-url-generation.ts +++ b/src/app/utils/sample-url-generation.ts @@ -63,7 +63,7 @@ function generateSearchParameters(url: string, search: string) { } } } - return search; + return search.replace(/\s/g, '+'); } function generateSampleUrl( @@ -85,5 +85,5 @@ export function hasWhiteSpace(url: string): boolean { const parts = url.split('?'); return parts.length > 1 ? whitespaceChars.some((char) => parts[0].trimStart().includes(char)) : whitespaceChars.some((char) => parts[0].trim().includes(char)); - } +