Files
shd.build/src/lib/server/os-protocol-profiles.test.ts
T
jb 57068b61cd
Validate and deploy production / validate (push) Canceled after 0s
Validate and deploy production / deploy (push) Canceled after 0s
Validate and deploy staging / validate (push) Successful in 28s
Validate and deploy staging / deploy (push) Successful in 1m3s
feat: expand ISAC content modeling
2026-08-03 01:23:20 -04:00

97 lines
2.5 KiB
TypeScript

import { connect } from '@tursodatabase/database';
import { afterEach, describe, expect, it } from 'vitest';
import {
getOsProtocolProfileAttributeIds,
type OsProtocolAttributeType,
} from './os-protocol-profiles';
const databases: Array<Awaited<ReturnType<typeof connect>>> = [];
afterEach(async () => {
await Promise.all(databases.splice(0).map((database) => database.close()));
});
async function databaseWithAttributes() {
const database = await connect(':memory:');
databases.push(database);
await database.exec(`CREATE TABLE stat_attributes (
id TEXT PRIMARY KEY,
name TEXT NOT NULL,
unit TEXT NOT NULL,
active INTEGER NOT NULL
)`);
for (const [id, name, unit] of [
['firepower-flat', 'Firepower', ''],
['firepower-percent', 'Firepower', '%'],
['toughness-flat', 'Toughness', ''],
['toughness-percent', 'Toughness', '%'],
['engineering-flat', 'Engineering', ''],
['weapon-damage-flat', 'Weapon Damage', ''],
['weapon-damage-percent', 'Weapon Damage', '%'],
['skill-damage-percent', 'Skill Damage', '%'],
['health-flat', 'Health', ''],
]) {
await (
await database.prepare(
'INSERT INTO stat_attributes(id,name,unit,active) VALUES(?,?,?,1)',
)
).run(id, name, unit);
}
return database;
}
describe('OS Protocol profile Attributes', () => {
it.each([
[
'Firepower',
{
Core: 'firepower-flat',
Damage: 'weapon-damage-flat',
Health: 'health-flat',
},
],
[
'Toughness',
{
Core: 'toughness-flat',
Damage: 'weapon-damage-flat',
Health: 'health-flat',
},
],
[
'Engineering',
{
Core: 'engineering-flat',
Damage: 'skill-damage-percent',
Health: 'health-flat',
},
],
] as const)('resolves the exact %s role rows', async (type, expected) => {
const database = await databaseWithAttributes();
await expect(
getOsProtocolProfileAttributeIds(
database,
type as OsProtocolAttributeType,
),
).resolves.toEqual(expected);
});
it('reports a missing required role without selecting a similarly named row', async () => {
const database = await databaseWithAttributes();
await (
await database.prepare(
"DELETE FROM stat_attributes WHERE id='weapon-damage-flat'",
)
).run();
await expect(
getOsProtocolProfileAttributeIds(database, 'Firepower'),
).resolves.toEqual({
Core: 'firepower-flat',
Damage: null,
Health: 'health-flat',
});
});
});