feat(ghost): Implement Tag, Author and Page models; add advanced filtering, search, bulk operations, image upload, related-posts, update tests and bump dependencies
This commit is contained in:
114
test/test.ts
114
test/test.ts
@@ -1,14 +1,17 @@
|
||||
import { expect, expectAsync, tap } from '@push.rocks/tapbundle';
|
||||
import { expect, tap } from '@push.rocks/tapbundle';
|
||||
import * as qenv from '@push.rocks/qenv';
|
||||
const testQenv = new qenv.Qenv('./', './.nogit/');
|
||||
|
||||
import * as ghost from '../ts/index.js'
|
||||
import * as ghost from '../ts/index.js';
|
||||
|
||||
// make sure we can import the IPost type
|
||||
import {type IPost} from '../ts/index.js';
|
||||
|
||||
let testGhostInstance: ghost.Ghost;
|
||||
|
||||
tap.test('should create a valid instance of Ghost', async () => {
|
||||
testGhostInstance = new ghost.Ghost({
|
||||
baseUrl: 'https://coffee.link',
|
||||
baseUrl: 'http://localhost:2368',
|
||||
adminApiKey: await testQenv.getEnvVarOnDemand('ADMIN_APIKEY'),
|
||||
contentApiKey: await testQenv.getEnvVarOnDemand('CONTENT_APIKEY'),
|
||||
});
|
||||
@@ -30,4 +33,109 @@ tap.test('should get posts', async () => {
|
||||
|
||||
})
|
||||
|
||||
tap.test('should get all tags', async () => {
|
||||
const tags = await testGhostInstance.getTags();
|
||||
expect(tags).toBeArray();
|
||||
console.log(`Found ${tags.length} tags:`);
|
||||
tags.forEach((tag) => {
|
||||
console.log(`-> ${tag.name} (${tag.slug})`);
|
||||
});
|
||||
});
|
||||
|
||||
tap.test('should filter tags with minimatch pattern', async () => {
|
||||
const allTags = await testGhostInstance.getTags();
|
||||
|
||||
if (allTags.length > 0) {
|
||||
const firstTagSlug = allTags[0].slug;
|
||||
const pattern = `${firstTagSlug.charAt(0)}*`;
|
||||
|
||||
const filteredTags = await testGhostInstance.getTags({ filter: pattern });
|
||||
expect(filteredTags).toBeArray();
|
||||
console.log(`Filtered tags with pattern '${pattern}':`);
|
||||
filteredTags.forEach((tag) => {
|
||||
console.log(`-> ${tag.name} (${tag.slug})`);
|
||||
expect(tag.slug).toMatch(new RegExp(`^${firstTagSlug.charAt(0)}`));
|
||||
});
|
||||
} else {
|
||||
console.log('No tags available to test filtering');
|
||||
}
|
||||
});
|
||||
|
||||
tap.test('should get tag by slug', async () => {
|
||||
const tags = await testGhostInstance.getTags({ limit: 1 });
|
||||
if (tags.length > 0) {
|
||||
const tag = await testGhostInstance.getTagBySlug(tags[0].slug);
|
||||
expect(tag).toBeInstanceOf(ghost.Tag);
|
||||
console.log(`Got tag: ${tag.getName()} (${tag.getSlug()})`);
|
||||
}
|
||||
});
|
||||
|
||||
tap.test('should get all authors', async () => {
|
||||
const authors = await testGhostInstance.getAuthors();
|
||||
expect(authors).toBeArray();
|
||||
console.log(`Found ${authors.length} authors:`);
|
||||
authors.forEach((author) => {
|
||||
console.log(`-> ${author.getName()} (${author.getSlug()})`);
|
||||
});
|
||||
});
|
||||
|
||||
tap.test('should filter authors with minimatch pattern', async () => {
|
||||
const authors = await testGhostInstance.getAuthors();
|
||||
if (authors.length > 0) {
|
||||
const firstAuthorSlug = authors[0].getSlug();
|
||||
const pattern = `${firstAuthorSlug.charAt(0)}*`;
|
||||
const filteredAuthors = await testGhostInstance.getAuthors({ filter: pattern });
|
||||
expect(filteredAuthors).toBeArray();
|
||||
console.log(`Filtered authors with pattern '${pattern}':`);
|
||||
filteredAuthors.forEach((author) => {
|
||||
console.log(`-> ${author.getName()} (${author.getSlug()})`);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
tap.test('should get all pages', async () => {
|
||||
const pages = await testGhostInstance.getPages();
|
||||
expect(pages).toBeArray();
|
||||
console.log(`Found ${pages.length} pages:`);
|
||||
pages.forEach((page) => {
|
||||
console.log(`-> ${page.getTitle()} (${page.getSlug()})`);
|
||||
});
|
||||
});
|
||||
|
||||
tap.test('should filter posts by tag', async () => {
|
||||
const tags = await testGhostInstance.getTags({ limit: 1 });
|
||||
if (tags.length > 0) {
|
||||
const posts = await testGhostInstance.getPosts({ tag: tags[0].slug, limit: 5 });
|
||||
expect(posts).toBeArray();
|
||||
console.log(`Found ${posts.length} posts with tag '${tags[0].name}'`);
|
||||
}
|
||||
});
|
||||
|
||||
tap.test('should filter posts by featured status', async () => {
|
||||
const featuredPosts = await testGhostInstance.getPosts({ featured: true, limit: 5 });
|
||||
expect(featuredPosts).toBeArray();
|
||||
console.log(`Found ${featuredPosts.length} featured posts`);
|
||||
});
|
||||
|
||||
tap.test('should search posts', async () => {
|
||||
const searchResults = await testGhostInstance.searchPosts('the', { limit: 5 });
|
||||
expect(searchResults).toBeArray();
|
||||
console.log(`Found ${searchResults.length} posts matching 'the':`);
|
||||
searchResults.forEach((post) => {
|
||||
console.log(`-> ${post.getTitle()}`);
|
||||
});
|
||||
});
|
||||
|
||||
tap.test('should get related posts', async () => {
|
||||
const posts = await testGhostInstance.getPosts({ limit: 1 });
|
||||
if (posts.length > 0) {
|
||||
const relatedPosts = await testGhostInstance.getRelatedPosts(posts[0].getId(), 3);
|
||||
expect(relatedPosts).toBeArray();
|
||||
console.log(`Found ${relatedPosts.length} related posts for '${posts[0].getTitle()}'`);
|
||||
relatedPosts.forEach((post) => {
|
||||
console.log(`-> ${post.getTitle()}`);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
tap.start()
|
||||
|
Reference in New Issue
Block a user