This repository has been archived by the owner on Mar 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
/
post_attachment_opengraph.test.jsx
72 lines (56 loc) · 2.52 KB
/
post_attachment_opengraph.test.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {Client4} from 'mattermost-redux/client';
import PostAttachmentOpenGraph from './post_attachment_opengraph';
describe('PostAttachmentOpenGraph', () => {
describe('getBestImageUrl', () => {
test('should return nothing with no OpenGraph metadata', () => {
const data = null;
expect(PostAttachmentOpenGraph.getBestImageUrl(data, false)).toEqual(null);
});
test('should return nothing with missing OpenGraph images', () => {
const data = {};
expect(PostAttachmentOpenGraph.getBestImageUrl(data, false)).toEqual(null);
});
test('should return nothing with no OpenGraph images', () => {
const data = {
images: [],
};
expect(PostAttachmentOpenGraph.getBestImageUrl(data, false)).toEqual(null);
});
test('should return secure_url if specified', () => {
const data = {
images: [{
secure_url: 'https://example.com/image.png',
url: 'https://example.com/image.png',
}],
};
expect(PostAttachmentOpenGraph.getBestImageUrl(data, false)).toEqual(data.images[0].secure_url);
});
test('should return url if secure_url is not specified', () => {
const data = {
images: [{
secure_url: '',
url: 'https://example.com/image.png',
}],
};
expect(PostAttachmentOpenGraph.getBestImageUrl(data, false)).toEqual(data.images[0].url);
});
test('should return a proxied image URL if the image proxy is enabled', () => {
const data = {
images: [{
url: 'https://example.com/image.png',
}],
};
expect(PostAttachmentOpenGraph.getBestImageUrl(data, true).endsWith(`/api/v4/image?url=${encodeURIComponent(data.images[0].url)}`)).toEqual(true);
});
test('should not mangle a URL that is already proxied if the image proxy is enabled', () => {
const data = {
images: [{
url: `${Client4.getBaseRoute()}/image?url=${encodeURIComponent('https://example.com/image.png')}`,
}],
};
expect(PostAttachmentOpenGraph.getBestImageUrl(data, true)).toEqual(data.images[0].url);
});
});
});