ghost/test/test.ts

34 lines
1.1 KiB
TypeScript

import { expect, expectAsync, 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'
let testGhostInstance: ghost.Ghost;
tap.test('should create a valid instance of Ghost', async () => {
testGhostInstance = new ghost.Ghost({
baseUrl: 'https://coffee.link',
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.start()