BREAKING CHANGE(classes.ghost): Remove Settings and Webhooks browse/read APIs, remove noisy console.error logs, and update tests/docs
This commit is contained in:
@@ -1,62 +0,0 @@
|
||||
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 settings', async () => {
|
||||
try {
|
||||
const settings = await testGhostInstance.getSettings();
|
||||
expect(settings).toBeTruthy();
|
||||
console.log(`Retrieved ${settings.settings?.length || 0} settings`);
|
||||
if (settings.settings && settings.settings.length > 0) {
|
||||
console.log(`Sample setting: ${settings.settings[0].key}`);
|
||||
}
|
||||
} catch (error: any) {
|
||||
if (error.message?.includes('undefined') || error.statusCode === 403) {
|
||||
console.log('Settings API not available in this Ghost version - skipping test');
|
||||
} else {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
tap.test('should update settings', async () => {
|
||||
try {
|
||||
const settings = await testGhostInstance.getSettings();
|
||||
if (settings.settings && settings.settings.length > 0) {
|
||||
const titleSetting = settings.settings.find((s: any) => s.key === 'title');
|
||||
if (titleSetting) {
|
||||
const originalTitle = titleSetting.value;
|
||||
|
||||
const updated = await testGhostInstance.updateSettings([
|
||||
{
|
||||
key: 'title',
|
||||
value: originalTitle
|
||||
}
|
||||
]);
|
||||
expect(updated).toBeTruthy();
|
||||
console.log('Settings updated successfully');
|
||||
}
|
||||
}
|
||||
} catch (error: any) {
|
||||
if (error.message?.includes('undefined') || error.statusCode === 403) {
|
||||
console.log('Settings API not available - skipping test');
|
||||
} else {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
export default tap.start();
|
@@ -16,91 +16,26 @@ tap.test('initialize Ghost instance', async () => {
|
||||
expect(testGhostInstance).toBeInstanceOf(ghost.Ghost);
|
||||
});
|
||||
|
||||
tap.test('should get all webhooks', async () => {
|
||||
try {
|
||||
const webhooks = await testGhostInstance.getWebhooks();
|
||||
expect(webhooks).toBeArray();
|
||||
console.log(`Found ${webhooks.length} webhooks`);
|
||||
if (webhooks.length > 0) {
|
||||
console.log(`First webhook: ${webhooks[0].name || 'unnamed'}`);
|
||||
}
|
||||
} catch (error: any) {
|
||||
if (error.message?.includes('not a function') || error.statusCode === 403) {
|
||||
console.log('Webhooks API not available in this Ghost version - skipping test');
|
||||
} else {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
tap.test('should create webhook', async () => {
|
||||
try {
|
||||
const timestamp = Date.now();
|
||||
createdWebhook = await testGhostInstance.createWebhook({
|
||||
event: 'post.published',
|
||||
target_url: `https://example.com/webhook/${timestamp}`,
|
||||
name: `Test Webhook ${timestamp}`
|
||||
});
|
||||
expect(createdWebhook).toBeTruthy();
|
||||
expect(createdWebhook.id).toBeTruthy();
|
||||
console.log(`Created webhook: ${createdWebhook.id}`);
|
||||
} catch (error: any) {
|
||||
if (error.message?.includes('not a function') || error.statusCode === 403) {
|
||||
console.log('Webhooks API not available - skipping test');
|
||||
} else {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
tap.test('should get webhook by ID', async () => {
|
||||
if (createdWebhook) {
|
||||
try {
|
||||
const webhook = await testGhostInstance.getWebhookById(createdWebhook.id);
|
||||
expect(webhook).toBeTruthy();
|
||||
expect(webhook.id).toEqual(createdWebhook.id);
|
||||
console.log(`Got webhook by ID: ${webhook.id}`);
|
||||
} catch (error: any) {
|
||||
if (error.message?.includes('not a function') || error.statusCode === 403) {
|
||||
console.log('Webhooks API not available - skipping test');
|
||||
} else {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
const timestamp = Date.now();
|
||||
createdWebhook = await testGhostInstance.createWebhook({
|
||||
event: 'post.published',
|
||||
target_url: `https://example.com/webhook/${timestamp}`,
|
||||
name: `Test Webhook ${timestamp}`
|
||||
});
|
||||
expect(createdWebhook).toBeTruthy();
|
||||
expect(createdWebhook.id).toBeTruthy();
|
||||
});
|
||||
|
||||
tap.test('should update webhook', async () => {
|
||||
if (createdWebhook) {
|
||||
try {
|
||||
const updatedWebhook = await testGhostInstance.updateWebhook(createdWebhook.id, {
|
||||
target_url: 'https://example.com/webhook/updated'
|
||||
});
|
||||
expect(updatedWebhook).toBeTruthy();
|
||||
console.log(`Updated webhook: ${updatedWebhook.id}`);
|
||||
} catch (error: any) {
|
||||
if (error.message?.includes('not a function') || error.statusCode === 403) {
|
||||
console.log('Webhooks API not available - skipping test');
|
||||
} else {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
const updatedWebhook = await testGhostInstance.updateWebhook(createdWebhook.id, {
|
||||
target_url: 'https://example.com/webhook/updated'
|
||||
});
|
||||
expect(updatedWebhook).toBeTruthy();
|
||||
});
|
||||
|
||||
tap.test('should delete webhook', async () => {
|
||||
if (createdWebhook) {
|
||||
try {
|
||||
await testGhostInstance.deleteWebhook(createdWebhook.id);
|
||||
console.log(`Deleted webhook: ${createdWebhook.id}`);
|
||||
} catch (error: any) {
|
||||
if (error.message?.includes('not a function') || error.statusCode === 403) {
|
||||
console.log('Webhooks API not available - skipping test');
|
||||
} else {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
await testGhostInstance.deleteWebhook(createdWebhook.id);
|
||||
});
|
||||
|
||||
export default tap.start();
|
||||
|
Reference in New Issue
Block a user