mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-05 08:23:34 +00:00
Replace the hardcoded 'moderator' npub pattern with a 'curator' field that accepts any note1/nevent1/naddr1 identifier. The p-tag pubkeys from the resolved event are used as authors in a kind 31990 (#t:shakespeare) query. Client-side filter ensures only apps with a 30617 git repo reference are shown, guaranteeing the 'Edit with Shakespeare' button can be rendered. All moderation controls (approve/feature/hide/etc.) are removed from AppShowcaseCard. AppShowcase is simplified to a flat grid.
202 lines
6.3 KiB
TypeScript
202 lines
6.3 KiB
TypeScript
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
import { render, waitFor } from '@testing-library/react';
|
|
import { SentryProvider } from './SentryProvider';
|
|
import { AppContext } from '@/contexts/AppContext';
|
|
import * as sentryModule from '@/lib/sentry';
|
|
|
|
// Mock the sentry module
|
|
vi.mock('@/lib/sentry', () => ({
|
|
initializeSentry: vi.fn(() => Promise.resolve()),
|
|
disableSentry: vi.fn(() => Promise.resolve()),
|
|
isSentryInitialized: vi.fn(() => false),
|
|
}));
|
|
|
|
describe('SentryProvider', () => {
|
|
const mockUpdateConfig = vi.fn();
|
|
|
|
beforeEach(() => {
|
|
vi.clearAllMocks();
|
|
});
|
|
|
|
it('initializes Sentry when both DSN and sentryEnabled are true', async () => {
|
|
const config = {
|
|
sentryDsn: 'https://[email protected]/123',
|
|
sentryEnabled: true,
|
|
theme: 'light' as const,
|
|
relayMetadata: {
|
|
relays: [{ url: 'wss://relay.test', read: true, write: true }],
|
|
updatedAt: 0,
|
|
},
|
|
graspMetadata: {
|
|
relays: [],
|
|
updatedAt: 0,
|
|
},
|
|
templates: [{ name: 'Test', description: 'Test template', url: 'https://test.git' }],
|
|
esmUrl: 'https://esm.test',
|
|
corsProxy: 'https://proxy.test/{href}',
|
|
gitProxyOrigins: ['https://github.com', 'https://gitlab.com'],
|
|
faviconUrl: 'https://favicon.test/{href}',
|
|
ngitWebUrl: 'https://nostrhub.io/{naddr}',
|
|
previewDomain: 'test.dev',
|
|
showcaseEnabled: false,
|
|
showcaseCurator: '',
|
|
fsPathProjects: '/projects',
|
|
fsPathConfig: '/config',
|
|
fsPathTmp: '/tmp',
|
|
fsPathPlugins: '/plugins',
|
|
fsPathTemplates: '/templates',
|
|
plausibleDomain: '',
|
|
plausibleEndpoint: '',
|
|
};
|
|
|
|
render(
|
|
<AppContext.Provider value={{ config, defaultConfig: config, updateConfig: mockUpdateConfig }}>
|
|
<SentryProvider>
|
|
<div>Test</div>
|
|
</SentryProvider>
|
|
</AppContext.Provider>
|
|
);
|
|
|
|
await waitFor(() => {
|
|
expect(sentryModule.initializeSentry).toHaveBeenCalledWith('https://[email protected]/123');
|
|
});
|
|
});
|
|
|
|
it('does not initialize Sentry when DSN is empty', async () => {
|
|
const config = {
|
|
sentryDsn: '',
|
|
sentryEnabled: true,
|
|
theme: 'light' as const,
|
|
relayMetadata: {
|
|
relays: [{ url: 'wss://relay.test', read: true, write: true }],
|
|
updatedAt: 0,
|
|
},
|
|
graspMetadata: {
|
|
relays: [],
|
|
updatedAt: 0,
|
|
},
|
|
templates: [{ name: 'Test', description: 'Test template', url: 'https://test.git' }],
|
|
esmUrl: 'https://esm.test',
|
|
corsProxy: 'https://proxy.test/{href}',
|
|
gitProxyOrigins: ['https://github.com', 'https://gitlab.com'],
|
|
faviconUrl: 'https://favicon.test/{href}',
|
|
ngitWebUrl: 'https://nostrhub.io/{naddr}',
|
|
previewDomain: 'test.dev',
|
|
showcaseEnabled: false,
|
|
showcaseCurator: '',
|
|
fsPathProjects: '/projects',
|
|
fsPathConfig: '/config',
|
|
fsPathTmp: '/tmp',
|
|
fsPathPlugins: '/plugins',
|
|
fsPathTemplates: '/templates',
|
|
plausibleDomain: '',
|
|
plausibleEndpoint: '',
|
|
};
|
|
|
|
render(
|
|
<AppContext.Provider value={{ config, defaultConfig: config, updateConfig: mockUpdateConfig }}>
|
|
<SentryProvider>
|
|
<div>Test</div>
|
|
</SentryProvider>
|
|
</AppContext.Provider>
|
|
);
|
|
|
|
// Wait a bit to ensure no initialization happens
|
|
await new Promise(resolve => setTimeout(resolve, 100));
|
|
|
|
expect(sentryModule.initializeSentry).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it('does not initialize Sentry when sentryEnabled is false', async () => {
|
|
const config = {
|
|
sentryDsn: 'https://[email protected]/123',
|
|
sentryEnabled: false,
|
|
theme: 'light' as const,
|
|
relayMetadata: {
|
|
relays: [{ url: 'wss://relay.test', read: true, write: true }],
|
|
updatedAt: 0,
|
|
},
|
|
graspMetadata: {
|
|
relays: [],
|
|
updatedAt: 0,
|
|
},
|
|
templates: [{ name: 'Test', description: 'Test template', url: 'https://test.git' }],
|
|
esmUrl: 'https://esm.test',
|
|
corsProxy: 'https://proxy.test/{href}',
|
|
gitProxyOrigins: ['https://github.com', 'https://gitlab.com'],
|
|
faviconUrl: 'https://favicon.test/{href}',
|
|
ngitWebUrl: 'https://nostrhub.io/{naddr}',
|
|
previewDomain: 'test.dev',
|
|
showcaseEnabled: false,
|
|
showcaseCurator: '',
|
|
fsPathProjects: '/projects',
|
|
fsPathConfig: '/config',
|
|
fsPathTmp: '/tmp',
|
|
fsPathPlugins: '/plugins',
|
|
fsPathTemplates: '/templates',
|
|
plausibleDomain: '',
|
|
plausibleEndpoint: '',
|
|
};
|
|
|
|
render(
|
|
<AppContext.Provider value={{ config, defaultConfig: config, updateConfig: mockUpdateConfig }}>
|
|
<SentryProvider>
|
|
<div>Test</div>
|
|
</SentryProvider>
|
|
</AppContext.Provider>
|
|
);
|
|
|
|
// Wait a bit to ensure no initialization happens
|
|
await new Promise(resolve => setTimeout(resolve, 100));
|
|
|
|
expect(sentryModule.initializeSentry).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it('disables Sentry when it was initialized but conditions change', async () => {
|
|
// Mock that Sentry is initialized
|
|
vi.mocked(sentryModule.isSentryInitialized).mockReturnValue(true);
|
|
|
|
const config = {
|
|
sentryDsn: '',
|
|
sentryEnabled: false,
|
|
theme: 'light' as const,
|
|
relayMetadata: {
|
|
relays: [{ url: 'wss://relay.test', read: true, write: true }],
|
|
updatedAt: 0,
|
|
},
|
|
graspMetadata: {
|
|
relays: [],
|
|
updatedAt: 0,
|
|
},
|
|
templates: [{ name: 'Test', description: 'Test template', url: 'https://test.git' }],
|
|
esmUrl: 'https://esm.test',
|
|
corsProxy: 'https://proxy.test/{href}',
|
|
gitProxyOrigins: ['https://github.com', 'https://gitlab.com'],
|
|
faviconUrl: 'https://favicon.test/{href}',
|
|
ngitWebUrl: 'https://nostrhub.io/{naddr}',
|
|
previewDomain: 'test.dev',
|
|
showcaseEnabled: false,
|
|
showcaseCurator: '',
|
|
fsPathProjects: '/projects',
|
|
fsPathConfig: '/config',
|
|
fsPathTmp: '/tmp',
|
|
fsPathPlugins: '/plugins',
|
|
fsPathTemplates: '/templates',
|
|
plausibleDomain: '',
|
|
plausibleEndpoint: '',
|
|
};
|
|
|
|
render(
|
|
<AppContext.Provider value={{ config, defaultConfig: config, updateConfig: mockUpdateConfig }}>
|
|
<SentryProvider>
|
|
<div>Test</div>
|
|
</SentryProvider>
|
|
</AppContext.Provider>
|
|
);
|
|
|
|
await waitFor(() => {
|
|
expect(sentryModule.disableSentry).toHaveBeenCalled();
|
|
});
|
|
});
|
|
});
|