Files
shakespeare/src/hooks/useDiscoverPlugins.test.ts
T
2025-12-04 17:56:35 -06:00

85 lines
2.7 KiB
TypeScript

import { describe, it, expect } from 'vitest';
import type { NostrEvent } from '@nostrify/nostrify';
describe('useDiscoverPlugins', () => {
it('should validate NIP-34 event structure', () => {
// Example of a valid NIP-34 repository announcement event
const validEvent: NostrEvent = {
id: 'test-event-id',
pubkey: 'test-pubkey',
created_at: Math.floor(Date.now() / 1000),
kind: 30617,
tags: [
['d', 'test-plugin'],
['name', 'Test Plugin'],
['description', 'A test Shakespeare plugin'],
['clone', 'https://github.com/user/test-plugin.git'],
['web', 'https://github.com/user/test-plugin'],
['t', 'shakespeare-plugin'],
],
content: '',
sig: 'test-signature',
};
// Verify the event has the correct kind
expect(validEvent.kind).toBe(30617);
// Verify required tags exist
const dTag = validEvent.tags.find(([name]) => name === 'd')?.[1];
const nameTag = validEvent.tags.find(([name]) => name === 'name')?.[1];
const tTag = validEvent.tags.find(([name, value]) => name === 't' && value === 'shakespeare-plugin');
expect(dTag).toBe('test-plugin');
expect(nameTag).toBe('Test Plugin');
expect(tTag).toBeDefined();
});
it('should identify required fields for plugin discovery', () => {
const event: NostrEvent = {
id: 'test-event-id',
pubkey: 'test-pubkey',
created_at: Math.floor(Date.now() / 1000),
kind: 30617,
tags: [
['d', 'minimal-plugin'],
['name', 'Minimal Plugin'],
['t', 'shakespeare-plugin'],
],
content: '',
sig: 'test-signature',
};
const dTag = event.tags.find(([name]) => name === 'd')?.[1];
const nameTag = event.tags.find(([name]) => name === 'name')?.[1];
// These are the minimum required fields
expect(dTag).toBeDefined();
expect(nameTag).toBeDefined();
});
it('should handle optional fields gracefully', () => {
const event: NostrEvent = {
id: 'test-event-id',
pubkey: 'test-pubkey',
created_at: Math.floor(Date.now() / 1000),
kind: 30617,
tags: [
['d', 'plugin-without-optional'],
['name', 'Plugin Without Optional Fields'],
['t', 'shakespeare-plugin'],
],
content: '',
sig: 'test-signature',
};
const descriptionTag = event.tags.find(([name]) => name === 'description')?.[1];
const cloneTag = event.tags.find(([name]) => name === 'clone')?.[1];
const webTag = event.tags.find(([name]) => name === 'web')?.[1];
// Optional fields should be undefined
expect(descriptionTag).toBeUndefined();
expect(cloneTag).toBeUndefined();
expect(webTag).toBeUndefined();
});
});