const assert = require('assert/strict');
const ObjectID = require('bson-objectid');
const Mention = require('../lib/Mention');
const validInput = {
source: 'https://source.com',
target: 'https://target.com',
sourceTitle: 'Title!',
sourceExcerpt: 'Excerpt!'
};
describe('Mention', function () {
describe('toJSON', function () {
it('Returns a object with the expected properties', async function () {
const mention = await Mention.create(validInput);
const actual = Object.keys(mention.toJSON());
const expected = [
'id',
'source',
'target',
'timestamp',
'payload',
'resourceId',
'resourceType',
'sourceTitle',
'sourceSiteTitle',
'sourceAuthor',
'sourceExcerpt',
'sourceFavicon',
'sourceFeaturedImage',
'verified'
];
assert.deepEqual(actual, expected);
});
});
describe('verify', function () {
it('Does basic check for the target URL and updates verified property', async function () {
const mention = await Mention.create(validInput);
assert(!mention.verified);
mention.verify('');
assert(mention.verified);
mention.verify('');
assert(!mention.verified);
});
it('Does check for Image targets', async function () {
const mention = await Mention.create({
...validInput,
target: 'https://target.com/image.jpg'
});
assert(!mention.verified);
mention.verify('');
assert(mention.verified);
mention.verify('');
assert(!mention.verified);
});
it('Does check for Video targets', async function () {
const mention = await Mention.create({
...validInput,
target: 'https://target.com/video.mp4'
});
assert(!mention.verified);
mention.verify('