mirror of
https://github.com/Permissionless-Software-Foundation/psf-memo.git
synced 2026-09-21 16:52:01 -07:00
- Add hardening tests to kill mutation survivors across client, DB, and indexer (hex guards, poll byte-limit boundaries, busy-flag defaults, parseTxid empty-string, polls controller handleError, memo-codes isMemoPrefix, normalizePollCreateDatas, storePollChildRecord returns). - Reduce duplication: extract shared reflect/isTooLong into MemoTxidAction (client), shared _run into the polls controller and configurable execute into PollReadUseCase (DB). - Refresh mutation manifests and Gherkin acceptance-mutation stamps. By architect.
67 lines
2.0 KiB
JavaScript
67 lines
2.0 KiB
JavaScript
/*
|
|
Unit tests for the Poll Option Page controller.
|
|
*/
|
|
|
|
'use strict'
|
|
|
|
const test = require('node:test')
|
|
const assert = require('node:assert/strict')
|
|
const PollOptionPage = require('../../src/services/poll-option-page')
|
|
const MemoPollOption = require('../../src/services/memo-poll-option')
|
|
|
|
const POLL_TXID = 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
|
|
|
|
function makeWallet () {
|
|
return {
|
|
walletInfo: { cashAddress: 'bitcoincash:qtest' },
|
|
broadcasts: [],
|
|
async getUtxos () { return [] },
|
|
async sendOpReturn (msg, prefix) {
|
|
this.broadcasts.push({ msg, prefix })
|
|
return 'aa'.repeat(32)
|
|
}
|
|
}
|
|
}
|
|
|
|
test('submit adds an option', async () => {
|
|
const wallet = makeWallet()
|
|
const memoPollOption = new MemoPollOption({ wallet, pollTxid: POLL_TXID })
|
|
const page = new PollOptionPage({ memoPollOption })
|
|
|
|
page.setInput('yes')
|
|
const result = await page.submit()
|
|
|
|
assert.equal(result.ok, true)
|
|
assert.equal(wallet.broadcasts.length, 1)
|
|
})
|
|
|
|
test('submit records a validation error for an empty option', async () => {
|
|
const wallet = makeWallet()
|
|
const memoPollOption = new MemoPollOption({ wallet, pollTxid: POLL_TXID })
|
|
const page = new PollOptionPage({ memoPollOption })
|
|
|
|
page.setInput('')
|
|
const result = await page.submit()
|
|
|
|
assert.equal(result.ok, false)
|
|
assert.equal(page.submitError, 'poll_option_validation')
|
|
assert.equal(wallet.broadcasts.length, 0)
|
|
})
|
|
|
|
test('remainingCount counts down from the option limit', () => {
|
|
const memoPollOption = new MemoPollOption({ pollTxid: POLL_TXID })
|
|
const page = new PollOptionPage({ memoPollOption })
|
|
|
|
page.setInput('')
|
|
assert.equal(page.remainingCount(), MemoPollOption.MAX_OPTION_BYTES)
|
|
page.setInput('yes')
|
|
assert.equal(page.remainingCount(), MemoPollOption.MAX_OPTION_BYTES - 3)
|
|
})
|
|
|
|
test('starts with the in-flight flag cleared', () => {
|
|
const memoPollOption = new MemoPollOption({ pollTxid: POLL_TXID })
|
|
const page = new PollOptionPage({ memoPollOption })
|
|
|
|
assert.equal(page.adding, false)
|
|
})
|