[FIX] Possibility to use the External Provider URI with query
This commit is contained in:
parent
58391964cb
commit
8d720bd000
|
@ -0,0 +1,27 @@
|
||||||
|
import { formatUrl } from './getAvatarUrl';
|
||||||
|
|
||||||
|
jest.mock('react-native', () => ({ PixelRatio: { get: () => 1 } }));
|
||||||
|
|
||||||
|
describe('Test the formatURL', () => {
|
||||||
|
it('format as default to get the avatar from an user', () => {
|
||||||
|
const url = 'https://mobile.rocket.chat/avatar/reinaldoneto';
|
||||||
|
const size = 30;
|
||||||
|
const query = '&extraparam=true';
|
||||||
|
const expectedResult = `https://mobile.rocket.chat/avatar/reinaldoneto?format=png&size=30&extraparam=true`;
|
||||||
|
expect(formatUrl(url, size, query)).toBe(expectedResult);
|
||||||
|
});
|
||||||
|
it('format external provider uri to get the avatar from an user', () => {
|
||||||
|
const url = 'https://open.rocket.chat/avatar/reinaldoneto';
|
||||||
|
const size = 30;
|
||||||
|
const query = undefined;
|
||||||
|
const expectedResult = `https://open.rocket.chat/avatar/reinaldoneto?format=png&size=30`;
|
||||||
|
expect(formatUrl(url, size, query)).toBe(expectedResult);
|
||||||
|
});
|
||||||
|
it('format external provider uri that already adds a query to get the avatar from an user', () => {
|
||||||
|
const url = 'https://open.rocket.chat/avatar?rcusername=reinaldoneto';
|
||||||
|
const size = 30;
|
||||||
|
const query = undefined;
|
||||||
|
const expectedResult = `https://open.rocket.chat/avatar?rcusername=reinaldoneto&format=png&size=30`;
|
||||||
|
expect(formatUrl(url, size, query)).toBe(expectedResult);
|
||||||
|
});
|
||||||
|
});
|
|
@ -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,
|
||||||
|
|
Loading…
Reference in New Issue