Files
smartfeed/test/test.creation.node+bun+deno.ts

102 lines
3.0 KiB
TypeScript

import { expect, tap } from '@git.zone/tstest/tapbundle';
import * as smartfeed from '../ts/index.js';
tap.test('should create a Smartfeed instance', async () => {
const testSmartFeed = new smartfeed.Smartfeed();
expect(testSmartFeed).toBeInstanceOf(smartfeed.Smartfeed);
});
tap.test('should create a feed with valid options', async () => {
const testSmartFeed = new smartfeed.Smartfeed();
const feed = testSmartFeed.createFeed({
domain: 'example.com',
title: 'Example Feed',
category: 'Technology',
company: 'Example Inc',
companyDomain: 'https://example.com',
companyEmail: 'hello@example.com',
description: 'An example technology feed',
});
expect(feed).toBeInstanceOf(smartfeed.Feed);
expect(feed.options.domain).toEqual('example.com');
expect(feed.options.title).toEqual('Example Feed');
});
tap.test('should create a feed with HTTPS URLs', async () => {
const testSmartFeed = new smartfeed.Smartfeed();
const feed = testSmartFeed.createFeed({
domain: 'secure.example.com',
title: 'Secure Feed',
category: 'Security',
company: 'Secure Inc',
companyDomain: 'https://secure.example.com',
companyEmail: 'security@example.com',
description: 'A secure feed',
});
expect(feed.options.companyDomain).toEqual('https://secure.example.com');
});
tap.test('should add items to feed', async () => {
const testSmartFeed = new smartfeed.Smartfeed();
const feed = testSmartFeed.createFeed({
domain: 'blog.example.com',
title: 'Example Blog',
category: 'Blogging',
company: 'Example Inc',
companyDomain: 'https://example.com',
companyEmail: 'blog@example.com',
description: 'A blog about examples',
});
feed.addItem({
title: 'First Post',
authorName: 'John Doe',
imageUrl: 'https://example.com/image1.jpg',
timestamp: Date.now(),
url: 'https://example.com/posts/first',
content: 'This is the first post',
});
feed.addItem({
title: 'Second Post',
authorName: 'Jane Doe',
imageUrl: 'https://example.com/image2.jpg',
timestamp: Date.now(),
url: 'https://example.com/posts/second',
content: 'This is the second post',
});
expect(feed.items.length).toEqual(2);
expect(feed.items[0].title).toEqual('First Post');
expect(feed.items[1].title).toEqual('Second Post');
});
tap.test('should add items with custom IDs', async () => {
const testSmartFeed = new smartfeed.Smartfeed();
const feed = testSmartFeed.createFeed({
domain: 'example.com',
title: 'Example Feed',
category: 'Technology',
company: 'Example Inc',
companyDomain: 'https://example.com',
companyEmail: 'hello@example.com',
description: 'An example feed',
});
feed.addItem({
title: 'Post with custom ID',
authorName: 'John Doe',
imageUrl: 'https://example.com/image.jpg',
timestamp: Date.now(),
url: 'https://example.com/posts/custom',
content: 'This post has a custom ID',
id: 'custom-id-123',
});
expect(feed.items.length).toEqual(1);
});
export default tap.start();