update tests
This commit is contained in:
107
test/test.author.node+deno.ts
Normal file
107
test/test.author.node+deno.ts
Normal file
@@ -0,0 +1,107 @@
|
||||
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';
|
||||
|
||||
let testGhostInstance: ghost.Ghost;
|
||||
|
||||
tap.test('initialize Ghost instance', 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 all authors', async () => {
|
||||
const authors = await testGhostInstance.getAuthors();
|
||||
expect(authors).toBeArray();
|
||||
console.log(`Found ${authors.length} authors`);
|
||||
if (authors.length > 0) {
|
||||
expect(authors[0]).toBeInstanceOf(ghost.Author);
|
||||
console.log(`First author: ${authors[0].getName()} (${authors[0].getSlug()})`);
|
||||
}
|
||||
});
|
||||
|
||||
tap.test('should get authors with limit', async () => {
|
||||
const authors = await testGhostInstance.getAuthors({ limit: 2 });
|
||||
expect(authors).toBeArray();
|
||||
expect(authors.length).toBeLessThanOrEqual(2);
|
||||
});
|
||||
|
||||
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}': found ${filteredAuthors.length}`);
|
||||
filteredAuthors.forEach((author) => {
|
||||
expect(author.getSlug()).toMatch(new RegExp(`^${firstAuthorSlug.charAt(0)}`));
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
tap.test('should get author by slug', async () => {
|
||||
const authors = await testGhostInstance.getAuthors({ limit: 1 });
|
||||
if (authors.length > 0) {
|
||||
const author = await testGhostInstance.getAuthorBySlug(authors[0].getSlug());
|
||||
expect(author).toBeInstanceOf(ghost.Author);
|
||||
expect(author.getSlug()).toEqual(authors[0].getSlug());
|
||||
console.log(`Got author by slug: ${author.getName()}`);
|
||||
}
|
||||
});
|
||||
|
||||
tap.test('should get author by ID', async () => {
|
||||
const authors = await testGhostInstance.getAuthors({ limit: 1 });
|
||||
if (authors.length > 0) {
|
||||
const author = await testGhostInstance.getAuthorById(authors[0].getId());
|
||||
expect(author).toBeInstanceOf(ghost.Author);
|
||||
expect(author.getId()).toEqual(authors[0].getId());
|
||||
}
|
||||
});
|
||||
|
||||
tap.test('should access author methods', async () => {
|
||||
const authors = await testGhostInstance.getAuthors({ limit: 1 });
|
||||
if (authors.length > 0) {
|
||||
const author = authors[0];
|
||||
expect(author.getId()).toBeTruthy();
|
||||
expect(author.getName()).toBeTruthy();
|
||||
expect(author.getSlug()).toBeTruthy();
|
||||
const json = author.toJson();
|
||||
expect(json).toBeTruthy();
|
||||
expect(json.id).toEqual(author.getId());
|
||||
}
|
||||
});
|
||||
|
||||
tap.test('should update author bio', async () => {
|
||||
try {
|
||||
const authors = await testGhostInstance.getAuthors({ limit: 1 });
|
||||
if (authors.length > 0) {
|
||||
const author = authors[0];
|
||||
const originalBio = author.getBio();
|
||||
|
||||
const updatedAuthor = await author.update({
|
||||
bio: 'Updated bio for testing'
|
||||
});
|
||||
expect(updatedAuthor).toBeInstanceOf(ghost.Author);
|
||||
expect(updatedAuthor.getBio()).toEqual('Updated bio for testing');
|
||||
console.log(`Updated author bio: ${updatedAuthor.getName()}`);
|
||||
|
||||
await updatedAuthor.update({
|
||||
bio: originalBio
|
||||
});
|
||||
}
|
||||
} catch (error: any) {
|
||||
if (error.type === 'NotImplementedError') {
|
||||
console.log('Author updates not supported in this Ghost version - skipping test');
|
||||
} else {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
export default tap.start();
|
Reference in New Issue
Block a user