update tests
This commit is contained in:
110
test/test.tag.node+deno.ts
Normal file
110
test/test.tag.node+deno.ts
Normal file
@@ -0,0 +1,110 @@
|
||||
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 createdTag: ghost.Tag;
|
||||
|
||||
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 tags', async () => {
|
||||
const tags = await testGhostInstance.getTags();
|
||||
expect(tags).toBeArray();
|
||||
console.log(`Found ${tags.length} tags`);
|
||||
if (tags.length > 0) {
|
||||
console.log(`First tag: ${tags[0].name} (${tags[0].slug})`);
|
||||
}
|
||||
});
|
||||
|
||||
tap.test('should get tags with limit', async () => {
|
||||
const tags = await testGhostInstance.getTags({ limit: 3 });
|
||||
expect(tags).toBeArray();
|
||||
expect(tags.length).toBeLessThanOrEqual(3);
|
||||
});
|
||||
|
||||
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}': found ${filteredTags.length}`);
|
||||
filteredTags.forEach((tag) => {
|
||||
expect(tag.slug).toMatch(new RegExp(`^${firstTagSlug.charAt(0)}`));
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
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);
|
||||
expect(tag.getSlug()).toEqual(tags[0].slug);
|
||||
console.log(`Got tag by slug: ${tag.getName()}`);
|
||||
}
|
||||
});
|
||||
|
||||
tap.test('should get tag by ID', async () => {
|
||||
const tags = await testGhostInstance.getTags({ limit: 1 });
|
||||
if (tags.length > 0) {
|
||||
const tag = await testGhostInstance.getTagById(tags[0].id);
|
||||
expect(tag).toBeInstanceOf(ghost.Tag);
|
||||
expect(tag.getId()).toEqual(tags[0].id);
|
||||
}
|
||||
});
|
||||
|
||||
tap.test('should create tag', async () => {
|
||||
const timestamp = Date.now();
|
||||
createdTag = await testGhostInstance.createTag({
|
||||
name: `Test Tag ${timestamp}`,
|
||||
slug: `test-tag-${timestamp}`,
|
||||
description: 'A test tag created by automated tests'
|
||||
});
|
||||
expect(createdTag).toBeInstanceOf(ghost.Tag);
|
||||
expect(createdTag.getName()).toEqual(`Test Tag ${timestamp}`);
|
||||
console.log(`Created tag: ${createdTag.getId()}`);
|
||||
});
|
||||
|
||||
tap.test('should access tag methods', async () => {
|
||||
if (createdTag) {
|
||||
expect(createdTag.getId()).toBeTruthy();
|
||||
expect(createdTag.getName()).toBeTruthy();
|
||||
expect(createdTag.getSlug()).toBeTruthy();
|
||||
expect(createdTag.getDescription()).toBeTruthy();
|
||||
const json = createdTag.toJson();
|
||||
expect(json).toBeTruthy();
|
||||
expect(json.id).toEqual(createdTag.getId());
|
||||
}
|
||||
});
|
||||
|
||||
tap.test('should update tag', async () => {
|
||||
if (createdTag) {
|
||||
const updatedTag = await createdTag.update({
|
||||
description: 'Updated description for test tag'
|
||||
});
|
||||
expect(updatedTag).toBeInstanceOf(ghost.Tag);
|
||||
expect(updatedTag.getDescription()).toEqual('Updated description for test tag');
|
||||
console.log(`Updated tag: ${updatedTag.getId()}`);
|
||||
}
|
||||
});
|
||||
|
||||
tap.test('should delete tag', async () => {
|
||||
if (createdTag) {
|
||||
await createdTag.delete();
|
||||
console.log(`Deleted tag: ${createdTag.getId()}`);
|
||||
}
|
||||
});
|
||||
|
||||
export default tap.start();
|
Reference in New Issue
Block a user