A calm place to write long-form, and publish it to the open social web.
skypress.blog/
1import { describe, expect, it } from 'vitest';
2import { errorScene, type ErrorKind } from './errors';
3
4const ALL_KINDS: ErrorKind[] = [
5 'writer-not-found',
6 'publication-not-found',
7 'article-not-found',
8 'not-found',
9 'server-error',
10];
11
12describe( 'errorScene', () => {
13 it( 'returns 404 for every not-found kind and 500 for server-error', () => {
14 expect( errorScene( 'writer-not-found' ).status ).toBe( 404 );
15 expect( errorScene( 'publication-not-found' ).status ).toBe( 404 );
16 expect( errorScene( 'article-not-found' ).status ).toBe( 404 );
17 expect( errorScene( 'not-found' ).status ).toBe( 404 );
18 expect( errorScene( 'server-error' ).status ).toBe( 500 );
19 } );
20
21 it( 'interpolates the handle into the writer-not-found copy', () => {
22 const scene = errorScene( 'writer-not-found', { handle: 'jeherve.com' } );
23 expect( scene.heading ).toBe( 'No writer at @jeherve.com' );
24 } );
25
26 it( 'interpolates handle + slug into the publication-not-found copy', () => {
27 const scene = errorScene( 'publication-not-found', {
28 handle: 'jeherve.com',
29 slug: 'tribulations',
30 } );
31 expect( scene.subline ).toContain( '@jeherve.com' );
32 expect( scene.subline ).toContain( 'tribulations' );
33 } );
34
35 it( 'interpolates the publication name into the article-not-found copy', () => {
36 const scene = errorScene( 'article-not-found', {
37 publicationName: 'Tribulations of a Software Engineer',
38 } );
39 expect( scene.subline ).toContain( 'Tribulations of a Software Engineer' );
40 } );
41
42 it( 'falls back gracefully when the article publication name is missing', () => {
43 const scene = errorScene( 'article-not-found' );
44 expect( scene.subline ).toContain( 'this publication' );
45 } );
46
47 it( 'keeps the horizon metaphor for the generic not-found heading', () => {
48 expect( errorScene( 'not-found' ).heading ).toBe(
49 'This page set below the horizon'
50 );
51 } );
52
53 it( 'never emits an em dash in any copy field (house rule)', () => {
54 for ( const kind of ALL_KINDS ) {
55 const scene = errorScene( kind, {
56 handle: 'x',
57 slug: 'y',
58 publicationName: 'Z',
59 } );
60 const text = `${ scene.eyebrow }${ scene.heading }${ scene.subline }`;
61 expect( text ).not.toContain( '—' ); // em dash
62 }
63 } );
64} );