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; let createdPage: ghost.Page; 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 pages', async () => { const pages = await testGhostInstance.getPages(); expect(pages).toBeArray(); console.log(`Found ${pages.length} pages`); if (pages.length > 0) { expect(pages[0]).toBeInstanceOf(ghost.Page); console.log(`First page: ${pages[0].getTitle()} (${pages[0].getSlug()})`); } }); tap.test('should get pages with limit', async () => { const pages = await testGhostInstance.getPages({ limit: 3 }); expect(pages).toBeArray(); expect(pages.length).toBeLessThanOrEqual(3); }); tap.test('should filter pages with minimatch pattern', async () => { const pages = await testGhostInstance.getPages(); if (pages.length > 0) { const firstPageSlug = pages[0].getSlug(); const pattern = `${firstPageSlug.charAt(0)}*`; const filteredPages = await testGhostInstance.getPages({ filter: pattern }); expect(filteredPages).toBeArray(); console.log(`Filtered pages with pattern '${pattern}': found ${filteredPages.length}`); } }); tap.test('should get page by slug', async () => { const pages = await testGhostInstance.getPages({ limit: 1 }); if (pages.length > 0) { const page = await testGhostInstance.getPageBySlug(pages[0].getSlug()); expect(page).toBeInstanceOf(ghost.Page); expect(page.getSlug()).toEqual(pages[0].getSlug()); console.log(`Got page by slug: ${page.getTitle()}`); } }); tap.test('should get page by ID', async () => { const pages = await testGhostInstance.getPages({ limit: 1 }); if (pages.length > 0) { const page = await testGhostInstance.getPageById(pages[0].getId()); expect(page).toBeInstanceOf(ghost.Page); expect(page.getId()).toEqual(pages[0].getId()); } }); tap.test('should create page', async () => { const timestamp = Date.now(); createdPage = await testGhostInstance.createPage({ title: `Test Page ${timestamp}`, html: '
This is a test page created by automated tests.
', status: 'published' } as any); expect(createdPage).toBeInstanceOf(ghost.Page); expect(createdPage.getTitle()).toEqual(`Test Page ${timestamp}`); console.log(`Created page: ${createdPage.getId()}`); }); tap.test('should access page methods', async () => { if (createdPage) { expect(createdPage.getId()).toBeTruthy(); expect(createdPage.getTitle()).toBeTruthy(); expect(createdPage.getSlug()).toBeTruthy(); const json = createdPage.toJson(); expect(json).toBeTruthy(); expect(json.id).toEqual(createdPage.getId()); } }); tap.test('should update page', async () => { if (createdPage) { const updatedPage = await createdPage.update({ ...createdPage.pageData, html: 'This page has been updated.
', updated_at: new Date().toISOString() }); expect(updatedPage).toBeInstanceOf(ghost.Page); console.log(`Updated page: ${updatedPage.getId()}`); } }); tap.test('should delete page', async () => { if (createdPage) { await createdPage.delete(); console.log(`Deleted page: ${createdPage.getId()}`); } }); export default tap.start();