Move link preview and MIME tests to TypeScript

This commit is contained in:
Evan Hahn 2022-03-07 17:20:04 -06:00 committed by GitHub
parent 114316745d
commit 0c28561473
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 36 deletions

View File

@ -1,31 +0,0 @@
// Copyright 2018-2020 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
const { assert } = require('chai');
const MIME = require('../../../ts/types/MIME');
describe('MIME', () => {
describe('isJPEG', () => {
it('should return true for `image/jpeg`', () => {
assert.isTrue(MIME.isJPEG('image/jpeg'));
});
[
'jpg',
'jpeg',
'image/jpg', // invalid MIME type: https://stackoverflow.com/a/37266399/125305
'image/gif',
'image/tiff',
'application/json',
0,
false,
null,
undefined,
].forEach(value => {
it(`should return false for \`${value}\``, () => {
assert.isFalse(MIME.isJPEG(value));
});
});
});
});

View File

@ -1,13 +1,13 @@
// Copyright 2019-2020 Signal Messenger, LLC
// Copyright 2019-2022 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
const { assert } = require('chai');
import { assert } from 'chai';
const {
import {
findLinks,
isLinkSafeToPreview,
isLinkSneaky,
} = require('../../ts/types/LinkPreview');
} from '../../types/LinkPreview';
describe('Link previews', () => {
describe('#isLinkSafeToPreview', () => {

View File

@ -1,4 +1,4 @@
// Copyright 2021 Signal Messenger, LLC
// Copyright 2018-2022 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import { assert } from 'chai';
@ -12,11 +12,29 @@ describe('MIME', () => {
});
it('returns false for non-GIFs', () => {
assert.isFalse(MIME.isGif(''));
assert.isFalse(MIME.isGif('gif'));
assert.isFalse(MIME.isGif('image/jpeg'));
assert.isFalse(MIME.isGif('text/plain'));
});
});
describe('isJPEG', () => {
it('should return true for `image/jpeg`', () => {
assert.isTrue(MIME.isJPEG('image/jpeg'));
});
it('returns false for non-JPEGs', () => {
assert.isFalse(MIME.isJPEG(''));
assert.isFalse(MIME.isJPEG('jpg'));
assert.isFalse(MIME.isJPEG('jpeg'));
assert.isFalse(MIME.isJPEG('image/jpg')); // invalid MIME type: https://stackoverflow.com/a/37266399/125305
assert.isFalse(MIME.isJPEG('image/gif'));
assert.isFalse(MIME.isJPEG('image/tiff'));
assert.isFalse(MIME.isJPEG('application/json'));
});
});
describe('isLongMessage', () => {
it('returns true for long messages', () => {
assert.isTrue(MIME.isLongMessage('text/x-signal-plain'));