41 lines
1.2 KiB
TypeScript
41 lines
1.2 KiB
TypeScript
import assert from 'node:assert';
|
|
import path from 'node:path';
|
|
import fs from 'node:fs';
|
|
import { Yonexus } from '../src/index';
|
|
import { YonexusError } from '../src/models/errors';
|
|
|
|
const dataFile = path.resolve(process.cwd(), 'data/test-org.json');
|
|
if (fs.existsSync(dataFile)) fs.unlinkSync(dataFile);
|
|
|
|
const app = new Yonexus({ dataFile, registrars: ['orion'] });
|
|
|
|
app.registerAgent({ agentId: 'orion' }, 'orion', 'Orion', ['org_admin', 'agent']);
|
|
app.registerAgent({ agentId: 'orion' }, 'u1', 'U1', ['agent']);
|
|
const dept = app.createDepartment({ agentId: 'orion' }, 'Eng', 'org:yonexus');
|
|
const team = app.createTeam({ agentId: 'orion' }, 'API', dept.id);
|
|
app.assignIdentity({ agentId: 'orion' }, 'u1', dept.id, team.id, {
|
|
git_user_name: 'u1',
|
|
position: 'dev'
|
|
});
|
|
|
|
const result = app.queryAgents(
|
|
{ agentId: 'orion' },
|
|
{ deptId: dept.id },
|
|
{ filters: [{ field: 'git_user_name', op: 'eq', value: 'u1' }] }
|
|
);
|
|
assert.equal(result.length, 1);
|
|
|
|
let thrown = false;
|
|
try {
|
|
app.queryAgents(
|
|
{ agentId: 'orion' },
|
|
{ deptId: dept.id },
|
|
{ filters: [{ field: 'team', op: 'eq', value: 'API' }] }
|
|
);
|
|
} catch (e) {
|
|
thrown = e instanceof YonexusError && e.code === 'FIELD_NOT_QUERYABLE';
|
|
}
|
|
assert.equal(thrown, true);
|
|
|
|
console.log('smoke test passed');
|