Compare commits

...

2 Commits

Author SHA1 Message Date
Reinaldo Neto 554a5f6b2d minor tweak 2023-03-08 17:40:17 -03:00
Reinaldo Neto 8d720bd000 [FIX] Possibility to use the External Provider URI with query 2023-03-08 17:35:54 -03:00
2 changed files with 36 additions and 1 deletions

View File

@ -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);
});
});

View File

@ -4,7 +4,10 @@ import { SubscriptionType } from '../../../definitions';
import { IAvatar } from '../../../containers/Avatar/interfaces'; import { IAvatar } from '../../../containers/Avatar/interfaces';
import { compareServerVersion } from './compareServerVersion'; 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 = ({ export const getAvatarURL = ({
type, type,