优化
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`Test "plugin:com.msgbyte.linkinfo" service Test "plugin:com.msgbyte.linkmeta.fetch" normal 1`] = `
|
||||
Object {
|
||||
"contentType": "text/html",
|
||||
"description": undefined,
|
||||
"favicons": Array [
|
||||
"https://www.baidu.com/favicon.ico",
|
||||
],
|
||||
"images": Array [],
|
||||
"isCache": false,
|
||||
"mediaType": "website",
|
||||
"siteName": undefined,
|
||||
"title": "",
|
||||
"url": "https://www.baidu.com/?fortest",
|
||||
"videos": Array [],
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`Test "plugin:com.msgbyte.linkinfo" service Test "plugin:com.msgbyte.linkmeta.fetch" pure image 1`] = `
|
||||
Object {
|
||||
"contentType": "image/jpeg",
|
||||
"favicons": Array [
|
||||
"https://www.w3schools.com/favicon.ico",
|
||||
],
|
||||
"isCache": true,
|
||||
"mediaType": "image",
|
||||
"url": "https://www.w3schools.com/html/pic_trulli.jpg",
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`Test "plugin:com.msgbyte.linkinfo" service Test "plugin:com.msgbyte.linkmeta.fetch" pure mp3 1`] = `
|
||||
Object {
|
||||
"contentType": "audio/mpeg",
|
||||
"favicons": Array [
|
||||
"https://www.w3schools.com/favicon.ico",
|
||||
],
|
||||
"isCache": true,
|
||||
"mediaType": "audio",
|
||||
"url": "https://www.w3schools.com/html/horse.mp3",
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`Test "plugin:com.msgbyte.linkinfo" service Test "plugin:com.msgbyte.linkmeta.fetch" pure ogg 1`] = `
|
||||
Object {
|
||||
"contentType": "video/ogg",
|
||||
"favicons": Array [
|
||||
"https://www.w3schools.com/favicon.ico",
|
||||
],
|
||||
"isCache": true,
|
||||
"mediaType": "video",
|
||||
"url": "https://www.w3schools.com/html/horse.ogg",
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`Test "plugin:com.msgbyte.linkinfo" service Test "plugin:com.msgbyte.linkmeta.fetch" pure video 1`] = `
|
||||
Object {
|
||||
"contentType": "video/mp4",
|
||||
"favicons": Array [
|
||||
"https://www.w3schools.com/favicon.ico",
|
||||
],
|
||||
"isCache": true,
|
||||
"mediaType": "video",
|
||||
"url": "https://www.w3schools.com/html/mov_bbb.mp4",
|
||||
}
|
||||
`;
|
||||
80
server/plugins/com.msgbyte.linkmeta/test/linkmeta.spec.ts
Normal file
80
server/plugins/com.msgbyte.linkmeta/test/linkmeta.spec.ts
Normal file
@@ -0,0 +1,80 @@
|
||||
import { createTestServiceBroker } from '../../../test/utils';
|
||||
import LinkmetaService from '../services/linkmeta.service';
|
||||
import { Types } from 'mongoose';
|
||||
import _ from 'lodash';
|
||||
|
||||
describe('Test "plugin:com.msgbyte.linkinfo" service', () => {
|
||||
const { broker, service, insertTestData } =
|
||||
createTestServiceBroker<LinkmetaService>(LinkmetaService);
|
||||
|
||||
describe('Test "plugin:com.msgbyte.linkmeta.fetch"', () => {
|
||||
test('normal', async () => {
|
||||
const url = 'https://www.baidu.com/?fortest';
|
||||
const meta: any = await broker.call('plugin:com.msgbyte.linkmeta.fetch', {
|
||||
url,
|
||||
});
|
||||
|
||||
try {
|
||||
expect(meta).toHaveProperty('url', url);
|
||||
expect(meta).toHaveProperty('isCache', false);
|
||||
expect(meta).toHaveProperty('title');
|
||||
expect(meta).toHaveProperty('siteName');
|
||||
expect(meta).toHaveProperty('description');
|
||||
expect(meta).toHaveProperty('mediaType', 'website');
|
||||
expect(meta).toHaveProperty('contentType', 'text/html');
|
||||
expect(meta).toHaveProperty('images');
|
||||
expect(meta).toHaveProperty('videos');
|
||||
expect(meta).toHaveProperty('favicons');
|
||||
expect(meta).toMatchSnapshot();
|
||||
|
||||
const metaWithCache: any = await broker.call(
|
||||
'plugin:com.msgbyte.linkmeta.fetch',
|
||||
{
|
||||
url,
|
||||
}
|
||||
);
|
||||
expect(metaWithCache).toHaveProperty('isCache', true);
|
||||
} finally {
|
||||
await service.adapter.model.deleteOne({
|
||||
url,
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
test('pure video', async () => {
|
||||
const url = 'https://www.w3schools.com/html/mov_bbb.mp4';
|
||||
const meta: any = await broker.call('plugin:com.msgbyte.linkmeta.fetch', {
|
||||
url,
|
||||
});
|
||||
|
||||
expect(meta).toMatchSnapshot();
|
||||
});
|
||||
|
||||
test('pure image', async () => {
|
||||
const url = 'https://www.w3schools.com/html/pic_trulli.jpg';
|
||||
const meta: any = await broker.call('plugin:com.msgbyte.linkmeta.fetch', {
|
||||
url,
|
||||
});
|
||||
|
||||
expect(meta).toMatchSnapshot();
|
||||
});
|
||||
|
||||
test('pure ogg', async () => {
|
||||
const url = 'https://www.w3schools.com/html/horse.ogg';
|
||||
const meta: any = await broker.call('plugin:com.msgbyte.linkmeta.fetch', {
|
||||
url,
|
||||
});
|
||||
|
||||
expect(meta).toMatchSnapshot();
|
||||
});
|
||||
|
||||
test('pure mp3', async () => {
|
||||
const url = 'https://www.w3schools.com/html/horse.mp3';
|
||||
const meta: any = await broker.call('plugin:com.msgbyte.linkmeta.fetch', {
|
||||
url,
|
||||
});
|
||||
|
||||
expect(meta).toMatchSnapshot();
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user