import { afterEach, describe, expect, it, vi } from 'vitest'; import { boardLink, fetchShowcase, hasContent } from './taskstream'; const showcase = { project: { id: 'p', key: 'WEB', name: 'Web', description: null }, activeSprint: null, roadmap: [], releases: [], goodFirst: [ { key: 'WEB-9', title: 'Typo', type: 'TASK', path: '/p/WEB/issues/WEB-9' }, ], }; describe('TaskStream showcase', () => { afterEach(() => vi.unstubAllGlobals()); it('reads a showcase, and goes without it when TaskStream fails', async () => { vi.stubGlobal( 'fetch', vi.fn(async () => new Response(JSON.stringify(showcase))), ); expect(await fetchShowcase('https://api.ts/showcase')).toEqual(showcase); vi.stubGlobal( 'fetch', vi.fn(async () => new Response('nope', { status: 404 })), ); expect(await fetchShowcase('https://api.ts/showcase')).toBeNull(); vi.stubGlobal( 'fetch', vi.fn(async () => { throw new Error('down'); }), ); expect(await fetchShowcase('https://api.ts/showcase')).toBeNull(); }); it('builds links into the board and knows an empty one', () => { expect( boardLink('https://taskstream.pireon.dev/', '/p/WEB/issues/WEB-9'), ).toBe('https://taskstream.pireon.dev/p/WEB/issues/WEB-9'); expect(hasContent(showcase)).toBe(true); expect(hasContent({ ...showcase, goodFirst: [] })).toBe(false); }); it('counts a board that takes proposals as something to show', () => { const empty = { ...showcase, goodFirst: [] }; expect( hasContent({ ...empty, proposals: { open: true, path: '/p/WEB/proponer', top: [] }, }), ).toBe(true); expect( hasContent({ ...empty, proposals: { open: false, path: null, top: [] } }), ).toBe(false); }); });