describe('luis:convert with URL imports', function() { before(function () { nock('https://vkstoragetest.blob.core.windows.net') .head(/.*/) .reply(200, { status: 'OK' })
describe('luis:convert with URL imports', () => { before(function () { nock('https://vkstoragetest.blob.core.windows.net') .head(/.*/) .reply(200, { status: 'OK' })
describe('luis:convert with URL imports', function() { before(function () { nock('https://vkstoragetest.blob.core.windows.net') .head(/.*/) .reply(200, { status: 'OK' })
test(`test extract a good link`, async () => { const url = 'https://medium.com/swlh/the-golden-rule-of-freelancing-d02a35c73baa'; const html = readFileSync('./test-data/golden-rule-of-freelancing.txt', 'utf8'); const {baseUrl, path} = parseUrl(url); nock(baseUrl).head(path).reply(200, ''); nock(baseUrl).get(path).reply(200, html, { 'Content-Type': 'text/html', }); const result = await extract(url); expect(result).toBeInstanceOf(Object); keys.forEach((k) => { expect(hasProperty(result, k)).toBe(true); }); });
test(`test extract oembed`, async () => { const link = 'https://twitter.com/ndaidong/status/1173592062878314497'; const url = 'https://publish.twitter.com/oembed?format=json&url=' + encodeURIComponent(link); const text = readFileSync('./test-data/tweet-oembed.json', 'utf8'); const json = JSON.parse(text); const {baseUrl, path} = parseUrl(url); nock(baseUrl).head(path).reply(200, ''); nock(baseUrl).get(path).reply(200, json, { 'Content-Type': 'application/json', }); const result = await extract(link); expect(result).toBeInstanceOf(Object); keys.forEach((k) => { expect(hasProperty(result, k)).toBe(true); }); });
.head('/User/Login') .replyWithError(404);
test(`test extract a fake link`, async () => { const url = 'http://somewhere.xyz'; const {baseUrl, path} = parseUrl(url); nock(baseUrl).head(path).reply(404); nock(baseUrl).get(path).reply(404); const fn = async () => { const re = await extract(url); return re; }; expect(fn()).rejects.toThrow(Error); });
test(`test retrieve from bad source`, async () => { const url = 'http://some.where/article/abc-xyz'; const {baseUrl, path} = parseUrl(url); nock(baseUrl).head(path).reply(200); nock(baseUrl).get(path).reply(200, '', { 'Content-Type': 'something/strange', }); const result = await retrieve(url); expect(result).toBe(null); });