fix: possibility to use the External Provider URI with query (#4956)
* [FIX] Possibility to use the External Provider URI with query * minor tweak --------- Co-authored-by: Gleidson Daniel Silva <gleidson10daniel@hotmail.com>
This commit is contained in:
parent
fd210c4713
commit
4b13045d1c
|
@ -0,0 +1,32 @@
|
|||
import { formatUrl } from './getAvatarUrl';
|
||||
|
||||
jest.mock('react-native', () => ({ PixelRatio: { get: () => 1 } }));
|
||||
|
||||
describe('formatUrl function', () => {
|
||||
test('formats the default URL to get the user avatar', () => {
|
||||
const url = 'https://mobile.rocket.chat/avatar/reinaldoneto';
|
||||
const size = 30;
|
||||
const query = '&extraparam=true';
|
||||
const expected = 'https://mobile.rocket.chat/avatar/reinaldoneto?format=png&size=30&extraparam=true';
|
||||
const result = formatUrl(url, size, query);
|
||||
expect(result).toEqual(expected);
|
||||
});
|
||||
|
||||
test('formats an external provider URI to get the user avatar', () => {
|
||||
const url = 'https://open.rocket.chat/avatar/reinaldoneto';
|
||||
const size = 30;
|
||||
const query = undefined;
|
||||
const expected = 'https://open.rocket.chat/avatar/reinaldoneto?format=png&size=30';
|
||||
const result = formatUrl(url, size, query);
|
||||
expect(result).toEqual(expected);
|
||||
});
|
||||
|
||||
test('formats an external provider URI that already includes a query to get the user avatar', () => {
|
||||
const url = 'https://open.rocket.chat/avatar?rcusername=reinaldoneto';
|
||||
const size = 30;
|
||||
const query = undefined;
|
||||
const expected = 'https://open.rocket.chat/avatar?rcusername=reinaldoneto&format=png&size=30';
|
||||
const result = formatUrl(url, size, query);
|
||||
expect(result).toEqual(expected);
|
||||
});
|
||||
});
|
|
@ -4,7 +4,10 @@ import { SubscriptionType } from '../../../definitions';
|
|||
import { IAvatar } from '../../../containers/Avatar/interfaces';
|
||||
import { compareServerVersion } from './compareServerVersion';
|
||||
|
||||
const formatUrl = (url: string, size: number, query?: string) => `${url}?format=png&size=${PixelRatio.get() * size}${query}`;
|
||||
export const formatUrl = (url: string, size: number, query?: string) => {
|
||||
const hasQuestionMark = /\/[^\/?]+\?/.test(url);
|
||||
return `${url}${hasQuestionMark ? '&' : '?'}format=png&size=${PixelRatio.get() * size}${query || ''}`;
|
||||
};
|
||||
|
||||
export const getAvatarURL = ({
|
||||
type,
|
||||
|
|
Loading…
Reference in New Issue