Speak the scorecard's own band labels, not a second vocabulary
The Trainability and Deal Qualification Scorecard publishes five bands and an action for each — Decline, Defer, Scope down, Qualified conditional, Build — and `MOTION_BANDS` published four different ones with different edges. So a reader could read the scorecard, score a deal against the exact dimensions it defines, and be told "Strategic" by a band table that document has never heard of. Two answers to the same question from the same product. The scorecard wins, on two grounds. Its edges were chosen alongside the dimension weights they sit on top of, so 78 means something there and 7500 was a round number here. And every one of its labels is a verb the reader can act on: "Qualified" describes a deal, "Scope down" says what to do about it, which is the only reason to band a score rather than show it. The labels are now duplicated between the JSON a customer reads and the table the product renders, because a rendered label cannot reach into a seeded row. That duplication gets a test asserting the whole table verbatim, so re-authoring one copy alone fails rather than drifts. `apps/api/test/motion.test.ts` asserted the literal 'Strategic'. It now derives the band through the shared function, so a band-table change is caught by the test that owns the decision instead of by a write-path test that does not.
This commit is contained in:
@@ -27,7 +27,7 @@ import { strict as assert } from 'node:assert';
|
||||
import { describe, it } from 'node:test';
|
||||
import { getTableName, isSQLWrapper, isTable, type SQL } from 'drizzle-orm';
|
||||
import { PgDialect } from 'drizzle-orm/pg-core';
|
||||
import { motionScoreBasisPoints } from '@pig/core';
|
||||
import { motionBand, motionScoreBasisPoints } from '@pig/core';
|
||||
import type { Database, MotionTemplate } from '@pig/db';
|
||||
import { teamMemberships, users } from '@pig/db';
|
||||
import { Hono } from 'hono';
|
||||
@@ -783,7 +783,10 @@ describe('qualification scores', () => {
|
||||
|
||||
const written = log.inserted.find((row) => row.table === 'qualification_scores')?.row;
|
||||
assert.equal(written?.basisPoints, motionScoreBasisPoints(dimensions));
|
||||
assert.equal(written?.band, 'Strategic');
|
||||
// Derived from the score by the shared function, never asserted as a
|
||||
// literal here: a band table edited in @pig/core would otherwise be caught
|
||||
// by this test rather than by the one that owns the decision.
|
||||
assert.equal(written?.band, motionBand(motionScoreBasisPoints(dimensions)).label);
|
||||
assert.equal(typeof written?.basisPoints, 'number');
|
||||
assert.ok(Number.isInteger(written?.basisPoints), 'a score is an integer, exactly as money is');
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user