-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathformat.seed-summary.test.ts
More file actions
88 lines (78 loc) · 3.36 KB
/
Copy pathformat.seed-summary.test.ts
File metadata and controls
88 lines (78 loc) · 3.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
import { printServerReady, type ServerReadyOptions, type SeedSourceSummary } from './format.js';
/**
* #3415/#3430 — the boot banner is the ONE place a developer reliably sees seed
* outcomes (SeedLoader's own logs are level-filtered and swallowed by the serve
* boot-quiet window). Assert the Seeds line prints per source, screams on
* rejections AND empty marketplace installs, marks fresh-DB heals, and stays
* silent when nothing was seeded.
*/
describe('printServerReady seed summary (#3415/#3430)', () => {
const base: ServerReadyOptions = {
port: 3000,
configFile: 'objectstack.config.ts',
isDev: true,
pluginCount: 1,
};
let lines: string[];
let spy: ReturnType<typeof vi.spyOn>;
beforeEach(() => {
lines = [];
spy = vi.spyOn(console, 'log').mockImplementation((...args: unknown[]) => {
lines.push(args.join(' '));
});
});
afterEach(() => spy.mockRestore());
const seedLines = () => lines.filter((l) => l.includes('Seeds:'));
const s = (o: Partial<SeedSourceSummary> & { source: string }): SeedSourceSummary => ({
inserted: 0, updated: 0, skipped: 0, rejected: 0, ...o,
});
it('prints a quiet one-liner for a clean config-app seed', () => {
printServerReady({ ...base, seeds: [s({ source: 'showcase', inserted: 42, updated: 6, skipped: 3 })] });
expect(seedLines()).toHaveLength(1);
expect(seedLines()[0]).toContain('showcase 51 rows');
expect(seedLines()[0]).not.toContain('⚠');
});
it('screams when records were rejected, naming the source', () => {
printServerReady({ ...base, seeds: [s({ source: 'showcase', inserted: 24, rejected: 14 })] });
expect(seedLines()).toHaveLength(1);
expect(seedLines()[0]).toContain('showcase 24 ok / 14 errors ⚠');
expect(lines.some((l) => l.includes('OS_LOG_LEVEL=info'))).toBe(true);
});
it('labels a marketplace package and marks a fresh-DB heal', () => {
printServerReady({
...base,
seeds: [s({ source: 'hotcrm', marketplace: true, inserted: 157, healed: true })],
});
expect(seedLines()).toHaveLength(1);
expect(seedLines()[0]).toContain('hotcrm(marketplace) 157 rows (healed on fresh db)');
expect(seedLines()[0]).not.toContain('⚠');
});
it('escalates an installed-but-empty marketplace package', () => {
printServerReady({
...base,
seeds: [s({ source: 'hotcrm', marketplace: true, emptyInstall: true })],
});
expect(seedLines()).toHaveLength(1);
expect(seedLines()[0]).toContain('hotcrm(marketplace) installed but 0 rows ⚠');
});
it('combines multiple sources on one line', () => {
printServerReady({
...base,
seeds: [
s({ source: 'showcase', inserted: 162 }),
s({ source: 'hotcrm', marketplace: true, inserted: 157, rejected: 5 }),
],
});
expect(seedLines()).toHaveLength(1);
expect(seedLines()[0]).toContain('showcase 162 rows');
expect(seedLines()[0]).toContain('hotcrm(marketplace) 157 ok / 5 errors ⚠');
});
it('stays silent when no summary was collected or nothing ran', () => {
printServerReady({ ...base });
printServerReady({ ...base, seeds: [] });
printServerReady({ ...base, seeds: [s({ source: 'showcase' })] });
expect(seedLines()).toHaveLength(0);
});
});