feat(classes.ghost): Add members, settings and webhooks support; implement Member class and add tests
This commit is contained in:
186
test/test.ts.old
Normal file
186
test/test.ts.old
Normal file
@@ -0,0 +1,186 @@
|
||||
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';
|
||||
|
||||
// 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: 'http://localhost:2368',
|
||||
adminApiKey: await testQenv.getEnvVarOnDemand('ADMIN_APIKEY'),
|
||||
contentApiKey: await testQenv.getEnvVarOnDemand('CONTENT_APIKEY'),
|
||||
});
|
||||
expect(testGhostInstance).toBeInstanceOf(ghost.Ghost);
|
||||
});
|
||||
|
||||
tap.test('should get posts', async () => {
|
||||
const posts = await testGhostInstance.getPosts();
|
||||
expect(posts).toBeArray();
|
||||
expect(posts[0]).toBeInstanceOf(ghost.Post);
|
||||
console.log(JSON.stringify(posts[0].postData, null, 2));
|
||||
posts.map((post) => {
|
||||
// console.log(JSON.stringify(post.postData, null, 2));
|
||||
console.log(`-> ${post.getTitle()}`);
|
||||
console.log(`by ${post.getAuthor().name}`)
|
||||
console.log(post.getExcerpt());
|
||||
console.log(`===============`)
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
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.test('should get members', async () => {
|
||||
try {
|
||||
const members = await testGhostInstance.getMembers({ limit: 10 });
|
||||
expect(members).toBeArray();
|
||||
console.log(`Found ${members.length} members`);
|
||||
if (members.length > 0) {
|
||||
console.log(`First member: ${members[0].getEmail()}`);
|
||||
}
|
||||
} catch (error: any) {
|
||||
if (error.message?.includes('members') || error.statusCode === 403) {
|
||||
console.log('Members feature not available or requires permissions');
|
||||
} else {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
tap.test('should get settings', async () => {
|
||||
try {
|
||||
const settings = await testGhostInstance.getSettings();
|
||||
expect(settings).toBeTruthy();
|
||||
console.log(`Retrieved ${settings.settings?.length || 0} settings`);
|
||||
} catch (error: any) {
|
||||
if (error.message?.includes('undefined') || error.statusCode === 403) {
|
||||
console.log('Settings API not available or requires different permissions');
|
||||
} else {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
tap.test('should get webhooks', async () => {
|
||||
try {
|
||||
const webhooks = await testGhostInstance.getWebhooks();
|
||||
expect(webhooks).toBeArray();
|
||||
console.log(`Found ${webhooks.length} webhooks`);
|
||||
} catch (error: any) {
|
||||
if (error.message?.includes('not a function') || error.statusCode === 403) {
|
||||
console.log('Webhooks API not available in this Ghost version');
|
||||
} else {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
tap.start()
|
Reference in New Issue
Block a user