hub-scope-filter.test.mjs
47 lines 1.9 KB
Raw
sha256:8d46372e39d2d5a54fd93a8b1c27922fe0d9b22a72197345f1d2c71701cc4ce2 feat(auth): persistent login system + C7 session introspection Human minor ⚠ breaking 17 days ago
1 import { describe, it } from 'node:test';
2 import assert from 'node:assert';
3 import {
4 applyScopeFilterToNotes,
5 applyScopeFilterToProposals,
6 } from '../hub/lib/scope-filter.mjs';
7
8 describe('applyScopeFilterToProposals', () => {
9 it('returns all proposals when scope is empty', () => {
10 const ps = [{ path: 'inbox/a.md' }, { path: 'projects/foo/x.md' }];
11 assert.deepStrictEqual(applyScopeFilterToProposals(ps, null), ps);
12 assert.deepStrictEqual(applyScopeFilterToProposals(ps, {}), ps);
13 });
14
15 it('filters by folder prefix like notes', () => {
16 const scope = { folders: ['inbox'] };
17 const ps = [{ path: 'inbox/a.md' }, { path: 'other/b.md' }];
18 assert.deepStrictEqual(applyScopeFilterToProposals(ps, scope), [{ path: 'inbox/a.md' }]);
19 });
20
21 it('filters by project from path projects/slug/', () => {
22 const scope = { projects: ['foo'] };
23 const ps = [{ path: 'projects/foo/note.md' }, { path: 'projects/bar/note.md' }];
24 assert.deepStrictEqual(applyScopeFilterToProposals(ps, scope), [{ path: 'projects/foo/note.md' }]);
25 });
26
27 it('filters by project from parsed frontmatter object', () => {
28 const scope = { projects: ['alpha'] };
29 const ps = [
30 { path: 'x.md', frontmatter: { project: 'alpha' } },
31 { path: 'y.md', frontmatter: { project: 'beta' } },
32 ];
33 assert.deepStrictEqual(applyScopeFilterToProposals(ps, scope), [{ path: 'x.md', frontmatter: { project: 'alpha' } }]);
34 });
35
36 it('matches applyScopeFilterToNotes for same path set', () => {
37 const scope = { folders: ['inbox'], projects: ['p1'] };
38 const notes = [
39 { path: 'inbox/n.md', project: null },
40 { path: 'deep/x.md', project: 'p1' },
41 ];
42 const proposals = [{ path: 'inbox/n.md' }, { path: 'deep/x.md', project: 'p1' }];
43 const nf = applyScopeFilterToNotes(notes, scope).map((n) => n.path).sort();
44 const pf = applyScopeFilterToProposals(proposals, scope).map((p) => p.path).sort();
45 assert.deepStrictEqual(pf, nf);
46 });
47 });
File History 2 commits
sha256:8d46372e39d2d5a54fd93a8b1c27922fe0d9b22a72197345f1d2c71701cc4ce2 feat(auth): persistent login system + C7 session introspection Human minor 17 days ago