pull/1381/head
Audric Ackermann 4 years ago
parent a58a1a4fba
commit 0eb730f1ba

@ -2,32 +2,26 @@
// 'use strict'; // 'use strict';
// FIXME audric enable back those test // FIXME audric enable back those test
// describe('ConversationCollection', () => { describe('ConversationCollection', () => {
// textsecure.messaging = new textsecure.MessageSender(); // textsecure.messaging = new textsecure.MessageSender();
// before(clearDatabase); // before(clearDatabase);
// after(clearDatabase); // after(clearDatabase);
// it('should be ordered newest to oldest', () => { // it('should be ordered newest to oldest', () => {
// const conversations = new Whisper.ConversationCollection(); // const conversations = new Whisper.ConversationCollection();
// // Timestamps // // Timestamps
// const today = new Date(); // const today = new Date();
// const tomorrow = new Date(); // const tomorrow = new Date();
// tomorrow.setDate(today.getDate() + 1); // tomorrow.setDate(today.getDate() + 1);
// // Add convos // // Add convos
// conversations.add({ timestamp: today }); // conversations.add({ timestamp: today });
// conversations.add({ timestamp: tomorrow }); // conversations.add({ timestamp: tomorrow });
// const { models } = conversations; // const { models } = conversations;
// const firstTimestamp = models[0].get('timestamp').getTime(); // const firstTimestamp = models[0].get('timestamp').getTime();
// const secondTimestamp = models[1].get('timestamp').getTime(); // const secondTimestamp = models[1].get('timestamp').getTime();
// // Compare timestamps // // Compare timestamps
// assert(firstTimestamp > secondTimestamp); // assert(firstTimestamp > secondTimestamp);
// }); // });
// }); // });
// describe('Conversation', () => { // describe('Conversation', () => {
// const attributes = { // const attributes = {
// type: 'private', // type: 'private',
@ -38,7 +32,6 @@
// await window.Signal.Data.saveConversation(convo.attributes, { // await window.Signal.Data.saveConversation(convo.attributes, {
// Conversation: Whisper.Conversation, // Conversation: Whisper.Conversation,
// }); // });
// // const message = convo.messageCollection.add({ // // const message = convo.messageCollection.add({
// // body: 'hello world', // // body: 'hello world',
// // conversationId: convo.id, // // conversationId: convo.id,
@ -49,7 +42,6 @@
// // await message.commit(false); // // await message.commit(false);
// }); // });
// after(clearDatabase); // after(clearDatabase);
// it('sorts its contacts in an intl-friendly way', () => { // it('sorts its contacts in an intl-friendly way', () => {
// const convo = new Whisper.Conversation({ // const convo = new Whisper.Conversation({
// id: '051d11d01e56d9bfc3d74115c33225a632321b509ac17a13fdeac71165d09b94ab', // id: '051d11d01e56d9bfc3d74115c33225a632321b509ac17a13fdeac71165d09b94ab',
@ -69,12 +61,10 @@
// name: 'Á', // name: 'Á',
// }) // })
// ); // );
// assert.strictEqual(convo.contactCollection.at('0').get('name'), 'Á'); // assert.strictEqual(convo.contactCollection.at('0').get('name'), 'Á');
// assert.strictEqual(convo.contactCollection.at('1').get('name'), 'B'); // assert.strictEqual(convo.contactCollection.at('1').get('name'), 'B');
// assert.strictEqual(convo.contactCollection.at('2').get('name'), 'C'); // assert.strictEqual(convo.contactCollection.at('2').get('name'), 'C');
// }); // });
// it('contains its own messages', async () => { // it('contains its own messages', async () => {
// const convo = new Whisper.ConversationCollection().add({ // const convo = new Whisper.ConversationCollection().add({
// id: '051d11d01e56d9bfc3d74115c33225a632321b509ac17a13fdeac71165d09b94ab', // id: '051d11d01e56d9bfc3d74115c33225a632321b509ac17a13fdeac71165d09b94ab',
@ -82,7 +72,6 @@
// await convo.fetchMessages(); // await convo.fetchMessages();
// assert.notEqual(convo.messageCollection.length, 0); // assert.notEqual(convo.messageCollection.length, 0);
// }); // });
// it('contains only its own messages', async () => { // it('contains only its own messages', async () => {
// const convo = new Whisper.ConversationCollection().add({ // const convo = new Whisper.ConversationCollection().add({
// id: '052d11d01e56d9bfc3d74115c33225a632321b509ac17a13fdeac71165d09b94ab', // id: '052d11d01e56d9bfc3d74115c33225a632321b509ac17a13fdeac71165d09b94ab',
@ -90,7 +79,6 @@
// await convo.fetchMessages(); // await convo.fetchMessages();
// assert.strictEqual(convo.messageCollection.length, 0); // assert.strictEqual(convo.messageCollection.length, 0);
// }); // });
// it('adds conversation to message collection upon leaving group', async () => { // it('adds conversation to message collection upon leaving group', async () => {
// const convo = new Whisper.ConversationCollection().add({ // const convo = new Whisper.ConversationCollection().add({
// type: 'group', // type: 'group',
@ -99,7 +87,6 @@
// await convo.leaveGroup(); // await convo.leaveGroup();
// assert.notEqual(convo.messageCollection.length, 0); // assert.notEqual(convo.messageCollection.length, 0);
// }); // });
// it('has a title', () => { // it('has a title', () => {
// const convos = new Whisper.ConversationCollection(); // const convos = new Whisper.ConversationCollection();
// let convo = convos.add(attributes); // let convo = convos.add(attributes);
@ -107,14 +94,11 @@
// convo.getTitle(), // convo.getTitle(),
// '051d11d01e56d9bfc3d74115c33225a632321b509ac17a13fdeac71165d09b94ab' // '051d11d01e56d9bfc3d74115c33225a632321b509ac17a13fdeac71165d09b94ab'
// ); // );
// convo = convos.add({ type: '' }); // convo = convos.add({ type: '' });
// assert.equal(convo.getTitle(), 'Unknown group'); // assert.equal(convo.getTitle(), 'Unknown group');
// convo = convos.add({ name: 'name' }); // convo = convos.add({ name: 'name' });
// assert.equal(convo.getTitle(), 'name'); // assert.equal(convo.getTitle(), 'name');
// }); // });
// it('returns the number', () => { // it('returns the number', () => {
// const convos = new Whisper.ConversationCollection(); // const convos = new Whisper.ConversationCollection();
// let convo = convos.add(attributes); // let convo = convos.add(attributes);
@ -122,11 +106,9 @@
// convo.getNumber(), // convo.getNumber(),
// '051d11d01e56d9bfc3d74115c33225a632321b509ac17a13fdeac71165d09b94ab' // '051d11d01e56d9bfc3d74115c33225a632321b509ac17a13fdeac71165d09b94ab'
// ); // );
// convo = convos.add({ type: '' }); // convo = convos.add({ type: '' });
// assert.equal(convo.getNumber(), ''); // assert.equal(convo.getNumber(), '');
// }); // });
// describe('when set to private', () => { // describe('when set to private', () => {
// it('correctly validates hex numbers', () => { // it('correctly validates hex numbers', () => {
// const regularId = new Whisper.Conversation({ // const regularId = new Whisper.Conversation({
@ -142,7 +124,6 @@
// assert.ok(regularId.isValid()); // assert.ok(regularId.isValid());
// assert.notOk(invalidId.isValid()); // assert.notOk(invalidId.isValid());
// }); // });
// it('correctly validates length', () => { // it('correctly validates length', () => {
// const regularId33 = new Whisper.Conversation({ // const regularId33 = new Whisper.Conversation({
// type: 'private', // type: 'private',
@ -168,4 +149,4 @@
// assert.notOk(longId.isValid()); // assert.notOk(longId.isValid());
// }); // });
// }); // });
// }); });

@ -4,7 +4,7 @@
// import * as path from 'path'; // import * as path from 'path';
// import AbortController from 'abort-controller'; // import AbortController from 'abort-controller';
// import { IMAGE_JPEG, MIMEType } from '../../../types/MIME'; // import { IMAGE_JPEG, MIMEType } from '../../../types/MIME';
// FIXME audric enable back those test // // FIXME audric enable back those test
// import { // import {
// fetchLinkPreviewImage, // fetchLinkPreviewImage,
// fetchLinkPreviewMetadata, // fetchLinkPreviewMetadata,
@ -12,29 +12,25 @@
// import { TestUtils } from '../../test-utils'; // import { TestUtils } from '../../test-utils';
// import { globalAny } from '../../test-utils/utils'; // import { globalAny } from '../../test-utils/utils';
// // tslint:disable: no-http-string // tslint:disable: no-http-string
// describe('link preview fetching', () => { describe('link preview fetching', () => {
// // We'll use this to create a fake `fetch`. We'll want to call `.resolves` or // We'll use this to create a fake `fetch`. We'll want to call `.resolves` or
// // `.rejects` on it (meaning that it needs to be a Sinon Stub type), but we'll also // `.rejects` on it (meaning that it needs to be a Sinon Stub type), but we'll also
// // want it to be a fake `fetch`. `any` seems like the best "supertype" there. // want it to be a fake `fetch`. `any` seems like the best "supertype" there.
// // eslint-disable-next-line @typescript-eslint/no-explicit-any // eslint-disable-next-line @typescript-eslint/no-explicit-any
// function stub(): any { // function stub(): any {
// return sinon.stub(); // return sinon.stub();
// } // }
// let sandbox: sinon.SinonSandbox; // let sandbox: sinon.SinonSandbox;
// let warn: sinon.SinonStub; // let warn: sinon.SinonStub;
// beforeEach(() => { // beforeEach(() => {
// sandbox = sinon.createSandbox(); // sandbox = sinon.createSandbox();
// warn = sandbox.stub(window.log, 'warn'); // warn = sandbox.stub(window.log, 'warn');
// }); // });
// afterEach(() => { // afterEach(() => {
// sandbox.restore(); // sandbox.restore();
// }); // });
// // tslint:disable-next-line: max-func-body-length // // tslint:disable-next-line: max-func-body-length
// describe('fetchLinkPreviewMetadata', () => { // describe('fetchLinkPreviewMetadata', () => {
// const makeHtml = (stuffInHead: ReadonlyArray<string> = []) => ` // const makeHtml = (stuffInHead: ReadonlyArray<string> = []) => `
@ -44,7 +40,6 @@
// <body>should be ignored</body> // <body>should be ignored</body>
// </html> // </html>
// `; // `;
// const makeResponse = ({ // const makeResponse = ({
// status = 200, // status = 200,
// headers = {}, // headers = {},
@ -76,7 +71,6 @@
// bodyLength = null; // bodyLength = null;
// bodyStream = body; // bodyStream = body;
// } // }
// const headersObj = new Headers(); // const headersObj = new Headers();
// Object.entries({ // Object.entries({
// 'Content-Type': 'text/html; charset=utf-8', // 'Content-Type': 'text/html; charset=utf-8',
@ -87,7 +81,6 @@
// headersObj.set(headerName, headerValue); // headersObj.set(headerName, headerValue);
// } // }
// }); // });
// return { // return {
// headers: headersObj, // headers: headersObj,
// body: bodyStream, // body: bodyStream,
@ -96,7 +89,6 @@
// url, // url,
// }; // };
// }; // };
// it('handles the "kitchen sink" of results', async () => { // it('handles the "kitchen sink" of results', async () => {
// const fakeFetch = stub().resolves( // const fakeFetch = stub().resolves(
// makeResponse({ // makeResponse({
@ -108,7 +100,6 @@
// ]), // ]),
// }) // })
// ); // );
// assert.deepEqual( // assert.deepEqual(
// await fetchLinkPreviewMetadata( // await fetchLinkPreviewMetadata(
// fakeFetch, // fakeFetch,
@ -123,7 +114,6 @@
// } // }
// ); // );
// }); // });
// it('logs no warnings if everything goes smoothly', async () => { // it('logs no warnings if everything goes smoothly', async () => {
// const fakeFetch = stub().resolves( // const fakeFetch = stub().resolves(
// makeResponse({ // makeResponse({
@ -135,25 +125,20 @@
// ]), // ]),
// }) // })
// ); // );
// await fetchLinkPreviewMetadata( // await fetchLinkPreviewMetadata(
// fakeFetch, // fakeFetch,
// 'https://example.com', // 'https://example.com',
// new AbortController().signal // new AbortController().signal
// ); // );
// sinon.assert.notCalled(warn); // sinon.assert.notCalled(warn);
// }); // });
// it('sends "WhatsApp" as the User-Agent for compatibility', async () => { // it('sends "WhatsApp" as the User-Agent for compatibility', async () => {
// const fakeFetch = stub().resolves(makeResponse()); // const fakeFetch = stub().resolves(makeResponse());
// await fetchLinkPreviewMetadata( // await fetchLinkPreviewMetadata(
// fakeFetch, // fakeFetch,
// 'https://example.com', // 'https://example.com',
// new AbortController().signal // new AbortController().signal
// ); // );
// sinon.assert.calledWith( // sinon.assert.calledWith(
// fakeFetch, // fakeFetch,
// 'https://example.com', // 'https://example.com',
@ -164,10 +149,8 @@
// }) // })
// ); // );
// }); // });
// it('returns null if the request fails', async () => { // it('returns null if the request fails', async () => {
// const fakeFetch = stub().rejects(new Error('Test request failure')); // const fakeFetch = stub().rejects(new Error('Test request failure'));
// assert.isNull( // assert.isNull(
// await fetchLinkPreviewMetadata( // await fetchLinkPreviewMetadata(
// fakeFetch, // fakeFetch,
@ -175,19 +158,16 @@
// new AbortController().signal // new AbortController().signal
// ) // )
// ); // );
// sinon.assert.calledOnce(warn); // sinon.assert.calledOnce(warn);
// sinon.assert.calledWith( // sinon.assert.calledWith(
// warn, // warn,
// 'fetchLinkPreviewMetadata: failed to fetch link preview HTML; bailing' // 'fetchLinkPreviewMetadata: failed to fetch link preview HTML; bailing'
// ); // );
// }); // });
// it("returns null if the response status code isn't 2xx", async () => { // it("returns null if the response status code isn't 2xx", async () => {
// await Promise.all( // await Promise.all(
// [100, 304, 400, 404, 500, 0, -200].map(async status => { // [100, 304, 400, 404, 500, 0, -200].map(async status => {
// const fakeFetch = stub().resolves(makeResponse({ status })); // const fakeFetch = stub().resolves(makeResponse({ status }));
// assert.isNull( // assert.isNull(
// await fetchLinkPreviewMetadata( // await fetchLinkPreviewMetadata(
// fakeFetch, // fakeFetch,
@ -195,7 +175,6 @@
// new AbortController().signal // new AbortController().signal
// ) // )
// ); // );
// sinon.assert.calledWith( // sinon.assert.calledWith(
// warn, // warn,
// `fetchLinkPreviewMetadata: got a ${status} status code; bailing` // `fetchLinkPreviewMetadata: got a ${status} status code; bailing`
@ -203,23 +182,19 @@
// }) // })
// ); // );
// }); // });
// it("doesn't use fetch's automatic redirection behavior", async () => { // it("doesn't use fetch's automatic redirection behavior", async () => {
// const fakeFetch = stub().resolves(makeResponse()); // const fakeFetch = stub().resolves(makeResponse());
// await fetchLinkPreviewMetadata( // await fetchLinkPreviewMetadata(
// fakeFetch, // fakeFetch,
// 'https://example.com', // 'https://example.com',
// new AbortController().signal // new AbortController().signal
// ); // );
// sinon.assert.calledWith( // sinon.assert.calledWith(
// fakeFetch, // fakeFetch,
// 'https://example.com', // 'https://example.com',
// sinon.match({ redirect: 'manual' }) // sinon.match({ redirect: 'manual' })
// ); // );
// }); // });
// [301, 302, 303, 307, 308].forEach(status => { // [301, 302, 303, 307, 308].forEach(status => {
// it(`handles ${status} redirects`, async () => { // it(`handles ${status} redirects`, async () => {
// const fakeFetch = stub(); // const fakeFetch = stub();
@ -231,7 +206,6 @@
// }) // })
// ); // );
// fakeFetch.onSecondCall().resolves(makeResponse()); // fakeFetch.onSecondCall().resolves(makeResponse());
// assert.deepEqual( // assert.deepEqual(
// await fetchLinkPreviewMetadata( // await fetchLinkPreviewMetadata(
// fakeFetch, // fakeFetch,
@ -245,15 +219,12 @@
// imageHref: null, // imageHref: null,
// } // }
// ); // );
// sinon.assert.calledTwice(fakeFetch); // sinon.assert.calledTwice(fakeFetch);
// sinon.assert.calledWith(fakeFetch.getCall(0), 'https://example.com'); // sinon.assert.calledWith(fakeFetch.getCall(0), 'https://example.com');
// sinon.assert.calledWith(fakeFetch.getCall(1), 'https://example.com/2'); // sinon.assert.calledWith(fakeFetch.getCall(1), 'https://example.com/2');
// }); // });
// it(`returns null when seeing a ${status} status with no Location header`, async () => { // it(`returns null when seeing a ${status} status with no Location header`, async () => {
// const fakeFetch = stub().resolves(makeResponse({ status })); // const fakeFetch = stub().resolves(makeResponse({ status }));
// assert.isNull( // assert.isNull(
// await fetchLinkPreviewMetadata( // await fetchLinkPreviewMetadata(
// fakeFetch, // fakeFetch,
@ -263,7 +234,6 @@
// ); // );
// }); // });
// }); // });
// it('handles relative redirects', async () => { // it('handles relative redirects', async () => {
// const fakeFetch = stub(); // const fakeFetch = stub();
// fakeFetch.onFirstCall().resolves( // fakeFetch.onFirstCall().resolves(
@ -281,7 +251,6 @@
// }) // })
// ); // );
// fakeFetch.onThirdCall().resolves(makeResponse()); // fakeFetch.onThirdCall().resolves(makeResponse());
// assert.deepEqual( // assert.deepEqual(
// await fetchLinkPreviewMetadata( // await fetchLinkPreviewMetadata(
// fakeFetch, // fakeFetch,
@ -295,13 +264,11 @@
// imageHref: null, // imageHref: null,
// } // }
// ); // );
// sinon.assert.calledThrice(fakeFetch); // sinon.assert.calledThrice(fakeFetch);
// sinon.assert.calledWith(fakeFetch.getCall(0), 'https://example.com'); // sinon.assert.calledWith(fakeFetch.getCall(0), 'https://example.com');
// sinon.assert.calledWith(fakeFetch.getCall(1), 'https://example.com/2/'); // sinon.assert.calledWith(fakeFetch.getCall(1), 'https://example.com/2/');
// sinon.assert.calledWith(fakeFetch.getCall(2), 'https://example.com/2/3'); // sinon.assert.calledWith(fakeFetch.getCall(2), 'https://example.com/2/3');
// }); // });
// it('returns null if redirecting to an insecure HTTP URL', async () => { // it('returns null if redirecting to an insecure HTTP URL', async () => {
// const fakeFetch = stub().resolves( // const fakeFetch = stub().resolves(
// makeResponse({ // makeResponse({
@ -310,7 +277,6 @@
// body: null, // body: null,
// }) // })
// ); // );
// assert.isNull( // assert.isNull(
// await fetchLinkPreviewMetadata( // await fetchLinkPreviewMetadata(
// fakeFetch, // fakeFetch,
@ -318,10 +284,8 @@
// new AbortController().signal // new AbortController().signal
// ) // )
// ); // );
// sinon.assert.calledOnce(fakeFetch); // sinon.assert.calledOnce(fakeFetch);
// }); // });
// it("returns null if there's a redirection loop", async () => { // it("returns null if there's a redirection loop", async () => {
// const fakeFetch = stub(); // const fakeFetch = stub();
// fakeFetch.onFirstCall().resolves( // fakeFetch.onFirstCall().resolves(
@ -338,7 +302,6 @@
// body: null, // body: null,
// }) // })
// ); // );
// assert.isNull( // assert.isNull(
// await fetchLinkPreviewMetadata( // await fetchLinkPreviewMetadata(
// fakeFetch, // fakeFetch,
@ -346,10 +309,8 @@
// new AbortController().signal // new AbortController().signal
// ) // )
// ); // );
// sinon.assert.calledTwice(fakeFetch); // sinon.assert.calledTwice(fakeFetch);
// }); // });
// it('returns null if redirecting more than 20 times', async () => { // it('returns null if redirecting more than 20 times', async () => {
// const fakeFetch = stub().callsFake(async () => // const fakeFetch = stub().callsFake(async () =>
// makeResponse({ // makeResponse({
@ -359,7 +320,6 @@
// body: null, // body: null,
// }) // })
// ); // );
// assert.isNull( // assert.isNull(
// await fetchLinkPreviewMetadata( // await fetchLinkPreviewMetadata(
// fakeFetch, // fakeFetch,
@ -367,13 +327,10 @@
// new AbortController().signal // new AbortController().signal
// ) // )
// ); // );
// sinon.assert.callCount(fakeFetch, 20); // sinon.assert.callCount(fakeFetch, 20);
// }); // });
// it('returns null if the response has no body', async () => { // it('returns null if the response has no body', async () => {
// const fakeFetch = stub().resolves(makeResponse({ body: null })); // const fakeFetch = stub().resolves(makeResponse({ body: null }));
// assert.isNull( // assert.isNull(
// await fetchLinkPreviewMetadata( // await fetchLinkPreviewMetadata(
// fakeFetch, // fakeFetch,
@ -381,16 +338,13 @@
// new AbortController().signal // new AbortController().signal
// ) // )
// ); // );
// sinon.assert.calledWith( // sinon.assert.calledWith(
// warn, // warn,
// 'fetchLinkPreviewMetadata: no response body; bailing' // 'fetchLinkPreviewMetadata: no response body; bailing'
// ); // );
// }); // });
// it('returns null if the result body is too short', async () => { // it('returns null if the result body is too short', async () => {
// const fakeFetch = stub().resolves(makeResponse({ body: '<title>' })); // const fakeFetch = stub().resolves(makeResponse({ body: '<title>' }));
// assert.isNull( // assert.isNull(
// await fetchLinkPreviewMetadata( // await fetchLinkPreviewMetadata(
// fakeFetch, // fakeFetch,
@ -398,21 +352,18 @@
// new AbortController().signal // new AbortController().signal
// ) // )
// ); // );
// sinon.assert.calledOnce(warn); // sinon.assert.calledOnce(warn);
// sinon.assert.calledWith( // sinon.assert.calledWith(
// warn, // warn,
// 'fetchLinkPreviewMetadata: Content-Length is too short; bailing' // 'fetchLinkPreviewMetadata: Content-Length is too short; bailing'
// ); // );
// }); // });
// it('returns null if the result is meant to be downloaded', async () => { // it('returns null if the result is meant to be downloaded', async () => {
// const fakeFetch = stub().resolves( // const fakeFetch = stub().resolves(
// makeResponse({ // makeResponse({
// headers: { 'Content-Disposition': 'attachment' }, // headers: { 'Content-Disposition': 'attachment' },
// }) // })
// ); // );
// assert.isNull( // assert.isNull(
// await fetchLinkPreviewMetadata( // await fetchLinkPreviewMetadata(
// fakeFetch, // fakeFetch,
@ -420,21 +371,18 @@
// new AbortController().signal // new AbortController().signal
// ) // )
// ); // );
// sinon.assert.calledOnce(warn); // sinon.assert.calledOnce(warn);
// sinon.assert.calledWith( // sinon.assert.calledWith(
// warn, // warn,
// 'fetchLinkPreviewMetadata: Content-Disposition header is not inline; bailing' // 'fetchLinkPreviewMetadata: Content-Disposition header is not inline; bailing'
// ); // );
// }); // });
// it('allows an explitly inline Content-Disposition header', async () => { // it('allows an explitly inline Content-Disposition header', async () => {
// const fakeFetch = stub().resolves( // const fakeFetch = stub().resolves(
// makeResponse({ // makeResponse({
// headers: { 'Content-Disposition': 'inline' }, // headers: { 'Content-Disposition': 'inline' },
// }) // })
// ); // );
// assert.deepEqual( // assert.deepEqual(
// await fetchLinkPreviewMetadata( // await fetchLinkPreviewMetadata(
// fakeFetch, // fakeFetch,
@ -449,14 +397,12 @@
// } // }
// ); // );
// }); // });
// it('returns null if the Content-Type is not HTML', async () => { // it('returns null if the Content-Type is not HTML', async () => {
// const fakeFetch = stub().resolves( // const fakeFetch = stub().resolves(
// makeResponse({ // makeResponse({
// headers: { 'Content-Type': 'text/plain' }, // headers: { 'Content-Type': 'text/plain' },
// }) // })
// ); // );
// assert.isNull( // assert.isNull(
// await fetchLinkPreviewMetadata( // await fetchLinkPreviewMetadata(
// fakeFetch, // fakeFetch,
@ -464,21 +410,18 @@
// new AbortController().signal // new AbortController().signal
// ) // )
// ); // );
// sinon.assert.calledOnce(warn); // sinon.assert.calledOnce(warn);
// sinon.assert.calledWith( // sinon.assert.calledWith(
// warn, // warn,
// 'fetchLinkPreviewMetadata: Content-Type is not HTML; bailing' // 'fetchLinkPreviewMetadata: Content-Type is not HTML; bailing'
// ); // );
// }); // });
// it('accepts non-lowercase Content-Type headers', async () => { // it('accepts non-lowercase Content-Type headers', async () => {
// const fakeFetch = stub().resolves( // const fakeFetch = stub().resolves(
// makeResponse({ // makeResponse({
// headers: { 'Content-Type': 'TEXT/HTML; chArsEt=utf-8' }, // headers: { 'Content-Type': 'TEXT/HTML; chArsEt=utf-8' },
// }) // })
// ); // );
// assert.deepEqual( // assert.deepEqual(
// await fetchLinkPreviewMetadata( // await fetchLinkPreviewMetadata(
// fakeFetch, // fakeFetch,
@ -493,7 +436,6 @@
// } // }
// ); // );
// }); // });
// it('parses the response as UTF-8 if the body contains a byte order mark', async () => { // it('parses the response as UTF-8 if the body contains a byte order mark', async () => {
// const fakeFetch = stub().resolves( // const fakeFetch = stub().resolves(
// makeResponse({ // makeResponse({
@ -508,7 +450,6 @@
// })(), // })(),
// }) // })
// ); // );
// assert.deepEqual( // assert.deepEqual(
// await fetchLinkPreviewMetadata( // await fetchLinkPreviewMetadata(
// fakeFetch, // fakeFetch,
@ -523,11 +464,9 @@
// } // }
// ); // );
// }); // });
// it('respects the UTF-8 byte order mark above the Content-Type header', async () => { // it('respects the UTF-8 byte order mark above the Content-Type header', async () => {
// const bom = new Uint8Array([0xef, 0xbb, 0xbf]); // const bom = new Uint8Array([0xef, 0xbb, 0xbf]);
// const titleHtml = new TextEncoder().encode('<title>\u{1F389}</title>'); // const titleHtml = new TextEncoder().encode('<title>\u{1F389}</title>');
// const fakeFetch = stub().resolves( // const fakeFetch = stub().resolves(
// makeResponse({ // makeResponse({
// headers: { // headers: {
@ -549,12 +488,10 @@
// '🎉' // '🎉'
// ); // );
// }); // });
// it('respects the UTF-8 byte order mark above a <meta http-equiv> in the document', async () => { // it('respects the UTF-8 byte order mark above a <meta http-equiv> in the document', async () => {
// const bom = new Uint8Array([0xef, 0xbb, 0xbf]); // const bom = new Uint8Array([0xef, 0xbb, 0xbf]);
// const titleHtml = new TextEncoder().encode('<title>\u{1F389}</title>'); // const titleHtml = new TextEncoder().encode('<title>\u{1F389}</title>');
// const endHeadHtml = new TextEncoder().encode('</head>'); // const endHeadHtml = new TextEncoder().encode('</head>');
// const fakeFetch = stub().resolves( // const fakeFetch = stub().resolves(
// makeResponse({ // makeResponse({
// headers: { // headers: {
@ -580,12 +517,10 @@
// '🎉' // '🎉'
// ); // );
// }); // });
// it('respects the UTF-8 byte order mark above a <meta charset> in the document', async () => { // it('respects the UTF-8 byte order mark above a <meta charset> in the document', async () => {
// const bom = new Uint8Array([0xef, 0xbb, 0xbf]); // const bom = new Uint8Array([0xef, 0xbb, 0xbf]);
// const titleHtml = new TextEncoder().encode('<title>\u{1F389}</title>'); // const titleHtml = new TextEncoder().encode('<title>\u{1F389}</title>');
// const endHeadHtml = new TextEncoder().encode('</head>'); // const endHeadHtml = new TextEncoder().encode('</head>');
// const fakeFetch = stub().resolves( // const fakeFetch = stub().resolves(
// makeResponse({ // makeResponse({
// headers: { // headers: {
@ -611,11 +546,9 @@
// '🎉' // '🎉'
// ); // );
// }); // });
// it('respects the Content-Type header above anything in the HTML', async () => { // it('respects the Content-Type header above anything in the HTML', async () => {
// const titleHtml = new TextEncoder().encode('<title>\u{1F389}</title>'); // const titleHtml = new TextEncoder().encode('<title>\u{1F389}</title>');
// const endHeadHtml = new TextEncoder().encode('</head>'); // const endHeadHtml = new TextEncoder().encode('</head>');
// { // {
// const fakeFetch = stub().resolves( // const fakeFetch = stub().resolves(
// makeResponse({ // makeResponse({
@ -641,7 +574,6 @@
// '🎉' // '🎉'
// ); // );
// } // }
// { // {
// const fakeFetch = stub().resolves( // const fakeFetch = stub().resolves(
// makeResponse({ // makeResponse({
@ -668,7 +600,6 @@
// ); // );
// } // }
// }); // });
// it('prefers the Content-Type http-equiv in the HTML above <meta charset>', async () => { // it('prefers the Content-Type http-equiv in the HTML above <meta charset>', async () => {
// const fakeFetch = stub().resolves( // const fakeFetch = stub().resolves(
// makeResponse({ // makeResponse({
@ -682,7 +613,6 @@
// ]), // ]),
// }) // })
// ); // );
// assert.propertyVal( // assert.propertyVal(
// await fetchLinkPreviewMetadata( // await fetchLinkPreviewMetadata(
// fakeFetch, // fakeFetch,
@ -693,7 +623,6 @@
// '🎉' // '🎉'
// ); // );
// }); // });
// it('parses non-UTF8 encodings', async () => { // it('parses non-UTF8 encodings', async () => {
// const titleBytes = new Uint8Array([0x61, 0x71, 0x75, 0xed]); // const titleBytes = new Uint8Array([0x61, 0x71, 0x75, 0xed]);
// assert.notDeepEqual( // assert.notDeepEqual(
@ -701,7 +630,6 @@
// new TextDecoder('latin1').decode(titleBytes), // new TextDecoder('latin1').decode(titleBytes),
// 'Test data was not set up correctly' // 'Test data was not set up correctly'
// ); // );
// const fakeFetch = stub().resolves( // const fakeFetch = stub().resolves(
// makeResponse({ // makeResponse({
// headers: { // headers: {
@ -714,7 +642,6 @@
// })(), // })(),
// }) // })
// ); // );
// assert.propertyVal( // assert.propertyVal(
// await fetchLinkPreviewMetadata( // await fetchLinkPreviewMetadata(
// fakeFetch, // fakeFetch,
@ -725,7 +652,6 @@
// 'aquí' // 'aquí'
// ); // );
// }); // });
// it('handles incomplete bodies', async () => { // it('handles incomplete bodies', async () => {
// const fakeFetch = stub().resolves( // const fakeFetch = stub().resolves(
// makeResponse({ // makeResponse({
@ -737,7 +663,6 @@
// })(), // })(),
// }) // })
// ); // );
// assert.propertyVal( // assert.propertyVal(
// await fetchLinkPreviewMetadata( // await fetchLinkPreviewMetadata(
// fakeFetch, // fakeFetch,
@ -747,19 +672,15 @@
// 'title', // 'title',
// 'foo bar' // 'foo bar'
// ); // );
// sinon.assert.calledOnce(warn); // sinon.assert.calledOnce(warn);
// sinon.assert.calledWith( // sinon.assert.calledWith(
// warn, // warn,
// 'getHtmlDocument: error when reading body; continuing with what we got' // 'getHtmlDocument: error when reading body; continuing with what we got'
// ); // );
// }); // });
// it('stops reading the body after cancelation', async () => { // it('stops reading the body after cancelation', async () => {
// const shouldNeverBeCalled = sinon.stub(); // const shouldNeverBeCalled = sinon.stub();
// const abortController = new AbortController(); // const abortController = new AbortController();
// const fakeFetch = stub().resolves( // const fakeFetch = stub().resolves(
// makeResponse({ // makeResponse({
// body: (async function* body() { // body: (async function* body() {
@ -770,7 +691,6 @@
// })(), // })(),
// }) // })
// ); // );
// assert.isNull( // assert.isNull(
// await fetchLinkPreviewMetadata( // await fetchLinkPreviewMetadata(
// fakeFetch, // fakeFetch,
@ -778,13 +698,10 @@
// abortController.signal // abortController.signal
// ) // )
// ); // );
// sinon.assert.notCalled(shouldNeverBeCalled); // sinon.assert.notCalled(shouldNeverBeCalled);
// }); // });
// it('stops reading bodies after 500 kilobytes', async () => { // it('stops reading bodies after 500 kilobytes', async () => {
// const shouldNeverBeCalled = sinon.stub(); // const shouldNeverBeCalled = sinon.stub();
// const fakeFetch = stub().resolves( // const fakeFetch = stub().resolves(
// makeResponse({ // makeResponse({
// body: (async function* body() { // body: (async function* body() {
@ -802,7 +719,6 @@
// })(), // })(),
// }) // })
// ); // );
// assert.deepEqual( // assert.deepEqual(
// await fetchLinkPreviewMetadata( // await fetchLinkPreviewMetadata(
// fakeFetch, // fakeFetch,
@ -816,10 +732,8 @@
// imageHref: null, // imageHref: null,
// } // }
// ); // );
// sinon.assert.notCalled(shouldNeverBeCalled); // sinon.assert.notCalled(shouldNeverBeCalled);
// }); // });
// it("returns null if the HTML doesn't contain a title, even if it contains other values", async () => { // it("returns null if the HTML doesn't contain a title, even if it contains other values", async () => {
// const fakeFetch = stub().resolves( // const fakeFetch = stub().resolves(
// makeResponse({ // makeResponse({
@ -830,7 +744,6 @@
// ]), // ]),
// }) // })
// ); // );
// assert.isNull( // assert.isNull(
// await fetchLinkPreviewMetadata( // await fetchLinkPreviewMetadata(
// fakeFetch, // fakeFetch,
@ -838,14 +751,12 @@
// new AbortController().signal // new AbortController().signal
// ) // )
// ); // );
// sinon.assert.calledOnce(warn); // sinon.assert.calledOnce(warn);
// sinon.assert.calledWith( // sinon.assert.calledWith(
// warn, // warn,
// "parseMetadata: HTML document doesn't have a title; bailing" // "parseMetadata: HTML document doesn't have a title; bailing"
// ); // );
// }); // });
// it('prefers og:title to document.title', async () => { // it('prefers og:title to document.title', async () => {
// const fakeFetch = stub().resolves( // const fakeFetch = stub().resolves(
// makeResponse({ // makeResponse({
@ -855,7 +766,6 @@
// ]), // ]),
// }) // })
// ); // );
// assert.propertyVal( // assert.propertyVal(
// await fetchLinkPreviewMetadata( // await fetchLinkPreviewMetadata(
// fakeFetch, // fakeFetch,
@ -866,7 +776,6 @@
// 'foo bar' // 'foo bar'
// ); // );
// }); // });
// it('prefers og:description to <meta name="description">', async () => { // it('prefers og:description to <meta name="description">', async () => {
// const fakeFetch = stub().resolves( // const fakeFetch = stub().resolves(
// makeResponse({ // makeResponse({
@ -877,7 +786,6 @@
// ]), // ]),
// }) // })
// ); // );
// assert.propertyVal( // assert.propertyVal(
// await fetchLinkPreviewMetadata( // await fetchLinkPreviewMetadata(
// fakeFetch, // fakeFetch,
@ -888,7 +796,6 @@
// 'bar' // 'bar'
// ); // );
// }); // });
// it('parses <meta name="description">', async () => { // it('parses <meta name="description">', async () => {
// const fakeFetch = stub().resolves( // const fakeFetch = stub().resolves(
// makeResponse({ // makeResponse({
@ -898,7 +805,6 @@
// ]), // ]),
// }) // })
// ); // );
// assert.propertyVal( // assert.propertyVal(
// await fetchLinkPreviewMetadata( // await fetchLinkPreviewMetadata(
// fakeFetch, // fakeFetch,
@ -909,7 +815,6 @@
// 'bar' // 'bar'
// ); // );
// }); // });
// it('ignores empty descriptions', async () => { // it('ignores empty descriptions', async () => {
// const fakeFetch = stub().resolves( // const fakeFetch = stub().resolves(
// makeResponse({ // makeResponse({
@ -919,7 +824,6 @@
// ]), // ]),
// }) // })
// ); // );
// assert.propertyVal( // assert.propertyVal(
// await fetchLinkPreviewMetadata( // await fetchLinkPreviewMetadata(
// fakeFetch, // fakeFetch,
@ -930,7 +834,6 @@
// null // null
// ); // );
// }); // });
// it('parses absolute image URLs', async () => { // it('parses absolute image URLs', async () => {
// const fakeFetch = stub().resolves( // const fakeFetch = stub().resolves(
// makeResponse({ // makeResponse({
@ -940,7 +843,6 @@
// ]), // ]),
// }) // })
// ); // );
// assert.propertyVal( // assert.propertyVal(
// await fetchLinkPreviewMetadata( // await fetchLinkPreviewMetadata(
// fakeFetch, // fakeFetch,
@ -951,7 +853,6 @@
// 'https://example.com/image.jpg' // 'https://example.com/image.jpg'
// ); // );
// }); // });
// it('parses relative image URLs', async () => { // it('parses relative image URLs', async () => {
// const fakeFetch = stub().resolves( // const fakeFetch = stub().resolves(
// makeResponse({ // makeResponse({
@ -961,7 +862,6 @@
// ]), // ]),
// }) // })
// ); // );
// assert.propertyVal( // assert.propertyVal(
// await fetchLinkPreviewMetadata( // await fetchLinkPreviewMetadata(
// fakeFetch, // fakeFetch,
@ -972,7 +872,6 @@
// 'https://example.com/assets/image.jpg' // 'https://example.com/assets/image.jpg'
// ); // );
// }); // });
// it('relative image URL resolution is relative to the final URL after redirects, not the original URL', async () => { // it('relative image URL resolution is relative to the final URL after redirects, not the original URL', async () => {
// const fakeFetch = stub().resolves( // const fakeFetch = stub().resolves(
// makeResponse({ // makeResponse({
@ -983,7 +882,6 @@
// url: 'https://bar.example/assets/', // url: 'https://bar.example/assets/',
// }) // })
// ); // );
// assert.propertyVal( // assert.propertyVal(
// await fetchLinkPreviewMetadata( // await fetchLinkPreviewMetadata(
// fakeFetch, // fakeFetch,
@ -994,7 +892,6 @@
// 'https://bar.example/assets/image.jpg' // 'https://bar.example/assets/image.jpg'
// ); // );
// }); // });
// it('ignores empty image URLs', async () => { // it('ignores empty image URLs', async () => {
// const fakeFetch = stub().resolves( // const fakeFetch = stub().resolves(
// makeResponse({ // makeResponse({
@ -1004,7 +901,6 @@
// ]), // ]),
// }) // })
// ); // );
// assert.propertyVal( // assert.propertyVal(
// await fetchLinkPreviewMetadata( // await fetchLinkPreviewMetadata(
// fakeFetch, // fakeFetch,
@ -1015,7 +911,6 @@
// null // null
// ); // );
// }); // });
// it('ignores blank image URLs', async () => { // it('ignores blank image URLs', async () => {
// const fakeFetch = stub().resolves( // const fakeFetch = stub().resolves(
// makeResponse({ // makeResponse({
@ -1025,7 +920,6 @@
// ]), // ]),
// }) // })
// ); // );
// assert.propertyVal( // assert.propertyVal(
// await fetchLinkPreviewMetadata( // await fetchLinkPreviewMetadata(
// fakeFetch, // fakeFetch,
@ -1037,7 +931,6 @@
// ); // );
// }); // });
// }); // });
// // tslint:disable-next-line: max-func-body-length // // tslint:disable-next-line: max-func-body-length
// describe('fetchLinkPreviewImage', () => { // describe('fetchLinkPreviewImage', () => {
// const readFixture = async (filename: string): Promise<Uint8Array> => { // const readFixture = async (filename: string): Promise<Uint8Array> => {
@ -1047,7 +940,6 @@
// assert(result.length > 10, `Test failed to read fixture ${filename}`); // assert(result.length > 10, `Test failed to read fixture ${filename}`);
// return result; // return result;
// }; // };
// [ // [
// { // {
// title: 'JPEG', // title: 'JPEG',
@ -1078,7 +970,6 @@
// ].forEach(({ title, contentType, fixtureFilename }) => { // ].forEach(({ title, contentType, fixtureFilename }) => {
// it(`handles ${title} images`, async () => { // it(`handles ${title} images`, async () => {
// const fixture = await readFixture(fixtureFilename); // const fixture = await readFixture(fixtureFilename);
// const fakeFetch = stub().resolves( // const fakeFetch = stub().resolves(
// new Response(fixture, { // new Response(fixture, {
// headers: { // headers: {
@ -1087,7 +978,6 @@
// }, // },
// }) // })
// ); // );
// assert.deepEqual( // assert.deepEqual(
// await fetchLinkPreviewImage( // await fetchLinkPreviewImage(
// fakeFetch, // fakeFetch,
@ -1101,10 +991,8 @@
// ); // );
// }); // });
// }); // });
// it('returns null if the request fails', async () => { // it('returns null if the request fails', async () => {
// const fakeFetch = stub().rejects(new Error('Test request failure')); // const fakeFetch = stub().rejects(new Error('Test request failure'));
// assert.isNull( // assert.isNull(
// await fetchLinkPreviewImage( // await fetchLinkPreviewImage(
// fakeFetch, // fakeFetch,
@ -1112,17 +1000,14 @@
// new AbortController().signal // new AbortController().signal
// ) // )
// ); // );
// sinon.assert.calledOnce(warn); // sinon.assert.calledOnce(warn);
// sinon.assert.calledWith( // sinon.assert.calledWith(
// warn, // warn,
// 'fetchLinkPreviewImage: failed to fetch image; bailing' // 'fetchLinkPreviewImage: failed to fetch image; bailing'
// ); // );
// }); // });
// it("returns null if the response status code isn't 2xx", async () => { // it("returns null if the response status code isn't 2xx", async () => {
// const fixture = await readFixture('kitten-1-64-64.jpg'); // const fixture = await readFixture('kitten-1-64-64.jpg');
// await Promise.all( // await Promise.all(
// [400, 404, 500, 598].map(async status => { // [400, 404, 500, 598].map(async status => {
// const fakeFetch = stub().resolves( // const fakeFetch = stub().resolves(
@ -1134,7 +1019,6 @@
// }, // },
// }) // })
// ); // );
// assert.isNull( // assert.isNull(
// await fetchLinkPreviewImage( // await fetchLinkPreviewImage(
// fakeFetch, // fakeFetch,
@ -1142,7 +1026,6 @@
// new AbortController().signal // new AbortController().signal
// ) // )
// ); // );
// sinon.assert.calledWith( // sinon.assert.calledWith(
// warn, // warn,
// `fetchLinkPreviewImage: got a ${status} status code; bailing` // `fetchLinkPreviewImage: got a ${status} status code; bailing`
@ -1150,11 +1033,9 @@
// }) // })
// ); // );
// }); // });
// // Most of the redirect behavior is tested above. // // Most of the redirect behavior is tested above.
// it('handles 301 redirects', async () => { // it('handles 301 redirects', async () => {
// const fixture = await readFixture('kitten-1-64-64.jpg'); // const fixture = await readFixture('kitten-1-64-64.jpg');
// const fakeFetch = stub(); // const fakeFetch = stub();
// fakeFetch.onFirstCall().resolves( // fakeFetch.onFirstCall().resolves(
// new Response(null, { // new Response(null, {
@ -1172,7 +1053,6 @@
// }, // },
// }) // })
// ); // );
// assert.deepEqual( // assert.deepEqual(
// await fetchLinkPreviewImage( // await fetchLinkPreviewImage(
// fakeFetch, // fakeFetch,
@ -1184,7 +1064,6 @@
// contentType: IMAGE_JPEG, // contentType: IMAGE_JPEG,
// } // }
// ); // );
// sinon.assert.calledTwice(fakeFetch); // sinon.assert.calledTwice(fakeFetch);
// sinon.assert.calledWith(fakeFetch.getCall(0), 'https://example.com/img'); // sinon.assert.calledWith(fakeFetch.getCall(0), 'https://example.com/img');
// sinon.assert.calledWith( // sinon.assert.calledWith(
@ -1192,7 +1071,6 @@
// 'https://example.com/result.jpg' // 'https://example.com/result.jpg'
// ); // );
// }); // });
// it('returns null if the response is too small', async () => { // it('returns null if the response is too small', async () => {
// const fakeFetch = stub().resolves( // const fakeFetch = stub().resolves(
// new Response(await readFixture('kitten-1-64-64.jpg'), { // new Response(await readFixture('kitten-1-64-64.jpg'), {
@ -1202,7 +1080,6 @@
// }, // },
// }) // })
// ); // );
// assert.isNull( // assert.isNull(
// await fetchLinkPreviewImage( // await fetchLinkPreviewImage(
// fakeFetch, // fakeFetch,
@ -1210,14 +1087,12 @@
// new AbortController().signal // new AbortController().signal
// ) // )
// ); // );
// sinon.assert.calledOnce(warn); // sinon.assert.calledOnce(warn);
// sinon.assert.calledWith( // sinon.assert.calledWith(
// warn, // warn,
// 'fetchLinkPreviewImage: Content-Length is too short; bailing' // 'fetchLinkPreviewImage: Content-Length is too short; bailing'
// ); // );
// }); // });
// it('returns null if the response is too large', async () => { // it('returns null if the response is too large', async () => {
// const fakeFetch = stub().resolves( // const fakeFetch = stub().resolves(
// new Response(await readFixture('kitten-1-64-64.jpg'), { // new Response(await readFixture('kitten-1-64-64.jpg'), {
@ -1227,7 +1102,6 @@
// }, // },
// }) // })
// ); // );
// assert.isNull( // assert.isNull(
// await fetchLinkPreviewImage( // await fetchLinkPreviewImage(
// fakeFetch, // fakeFetch,
@ -1235,17 +1109,14 @@
// new AbortController().signal // new AbortController().signal
// ) // )
// ); // );
// sinon.assert.calledOnce(warn); // sinon.assert.calledOnce(warn);
// sinon.assert.calledWith( // sinon.assert.calledWith(
// warn, // warn,
// 'fetchLinkPreviewImage: Content-Length is too large or is unset; bailing' // 'fetchLinkPreviewImage: Content-Length is too large or is unset; bailing'
// ); // );
// }); // });
// it('returns null if the Content-Type is not a valid image', async () => { // it('returns null if the Content-Type is not a valid image', async () => {
// const fixture = await readFixture('kitten-1-64-64.jpg'); // const fixture = await readFixture('kitten-1-64-64.jpg');
// await Promise.all( // await Promise.all(
// ['', 'image/tiff', 'video/mp4', 'text/plain', 'application/html'].map( // ['', 'image/tiff', 'video/mp4', 'text/plain', 'application/html'].map(
// async contentType => { // async contentType => {
@ -1257,7 +1128,6 @@
// }, // },
// }) // })
// ); // );
// assert.isNull( // assert.isNull(
// await fetchLinkPreviewImage( // await fetchLinkPreviewImage(
// fakeFetch, // fakeFetch,
@ -1265,7 +1135,6 @@
// new AbortController().signal // new AbortController().signal
// ) // )
// ); // );
// sinon.assert.calledWith( // sinon.assert.calledWith(
// warn, // warn,
// 'fetchLinkPreviewImage: Content-Type is not an image; bailing' // 'fetchLinkPreviewImage: Content-Type is not an image; bailing'
@ -1274,16 +1143,13 @@
// ) // )
// ); // );
// }); // });
// it('sends "WhatsApp" as the User-Agent for compatibility', async () => { // it('sends "WhatsApp" as the User-Agent for compatibility', async () => {
// const fakeFetch = stub().resolves(new Response(null)); // const fakeFetch = stub().resolves(new Response(null));
// await fetchLinkPreviewImage( // await fetchLinkPreviewImage(
// fakeFetch, // fakeFetch,
// 'https://example.com/img', // 'https://example.com/img',
// new AbortController().signal // new AbortController().signal
// ); // );
// sinon.assert.calledWith( // sinon.assert.calledWith(
// fakeFetch, // fakeFetch,
// 'https://example.com/img', // 'https://example.com/img',
@ -1295,4 +1161,4 @@
// ); // );
// }); // });
// }); // });
// }); });

Loading…
Cancel
Save