/home/techb158/trellopowerup.abdallabala.com/test
NameSizeModeActions
assessmentAnalytics.test.mjs51270644editdlrm
riskEngine.test.mjs16990644editdlrm
store.test.mjs30980644editdlrm
Edit: /home/techb158/trellopowerup.abdallabala.com/test/store.test.mjs (3098B)
import assert from 'node:assert/strict'; import path from 'node:path'; import test from 'node:test'; process.env.COSMIC_STORE_FILE = path.join( process.env.TEMP || process.env.TMP || '.', `cosmic-store-test-${process.pid}-${Date.now()}.json` ); const { deleteAssessmentsByCard, listAssessmentsByBoard, listAssessmentsByBoardCard, listAssessmentsByCard, saveAssessment } = await import('../src/store.js'); function assessment({ id, boardId, cardId, score, createdAt }) { return saveAssessment({ id, boardId, cardId, input: { risks: [] }, score: { score, status: 'low', gate: { deploymentReady: true } }, createdAt }); } test('assessment history is returned newest first for card and board queries', () => { const boardId = `board-${Date.now()}`; const cardId = `card-${Date.now()}`; assessment({ id: `${cardId}-old`, boardId, cardId, score: 42, createdAt: '2026-07-06T10:00:00.000Z' }); assessment({ id: `${cardId}-new`, boardId, cardId, score: 18, createdAt: '2026-07-06T11:00:00.000Z' }); const cardHistory = listAssessmentsByCard(cardId); assert.equal(cardHistory[0].id, `${cardId}-new`); assert.equal(cardHistory[1].id, `${cardId}-old`); const boardHistory = listAssessmentsByBoard(boardId).filter((item) => item.cardId === cardId); assert.equal(boardHistory[0].id, `${cardId}-new`); assert.equal(boardHistory[1].id, `${cardId}-old`); }); test('deleteAssessmentsByCard removes only assessments for the selected board card', () => { const boardId = `delete-board-${Date.now()}`; const cardId = `delete-card-${Date.now()}`; const otherCardId = `delete-other-card-${Date.now()}`; assessment({ id: `${cardId}-old-delete`, boardId, cardId, score: 55, createdAt: '2026-07-06T12:00:00.000Z' }); assessment({ id: `${cardId}-new-delete`, boardId, cardId, score: 22, createdAt: '2026-07-06T13:00:00.000Z' }); assessment({ id: `${otherCardId}-keep`, boardId, cardId: otherCardId, score: 11, createdAt: '2026-07-06T14:00:00.000Z' }); const result = deleteAssessmentsByCard(boardId, cardId); assert.equal(result.deleted, 2); assert.equal(listAssessmentsByCard(cardId).length, 0); assert.equal(listAssessmentsByCard(otherCardId).length, 1); assert.equal(listAssessmentsByBoard(boardId).some((item) => item.cardId === cardId), false); }); test('listAssessmentsByBoardCard scopes latest history to one board card pair', () => { const cardId = `shared-card-${Date.now()}`; const boardId = `board-a-${Date.now()}`; const otherBoardId = `board-b-${Date.now()}`; assessment({ id: `${cardId}-board-a`, boardId, cardId, score: 31, createdAt: '2026-07-06T15:00:00.000Z' }); assessment({ id: `${cardId}-board-b`, boardId: otherBoardId, cardId, score: 88, createdAt: '2026-07-06T16:00:00.000Z' }); const scopedHistory = listAssessmentsByBoardCard(boardId, cardId); assert.equal(scopedHistory.length, 1); assert.equal(scopedHistory[0].id, `${cardId}-board-a`); });