Files
psf-memo/psf-memo-db/test/unit/use-cases/get-poll-votes.unit.js
T
Chris Troutner cf05de6630 Implement poll actions (create, option, vote) across client, indexer, and DB
- Client: add MemoPollCreate, MemoPollOption, MemoPollVote services and page controllers.
- Indexer: add create-poll, add-poll-option, and poll-vote handlers with new poll DB adapters.
- DB: add polls/pollOptions/pollVotes stores, PollQuery adapter, GET /polls/:txid endpoints, and use cases.
- Add Gherkin acceptance handlers and focused unit tests for all three components.

By coder.
2026-08-28 14:50:05 -07:00

42 lines
983 B
JavaScript

/*
Unit tests for the GetPollVotes use case.
*/
import { assert } from 'chai'
import GetPollVotes from '../../../src/use-cases/get-poll-votes.js'
describe('GetPollVotes', () => {
it('should throw 400 when txid is missing', async () => {
const useCase = new GetPollVotes({
adapters: {
pollQuery: {
async getPollVotes () { return [] }
}
}
})
try {
await useCase.execute({})
assert.fail('expected error')
} catch (err) {
assert.equal(err.status, 400)
}
})
it('should return the votes for the poll', async () => {
const useCase = new GetPollVotes({
adapters: {
pollQuery: {
async getPollVotes (txid) {
return [{ txid: 'vote-1', pollTxid: txid, comment: 'yes' }]
}
}
}
})
const result = await useCase.execute({ txid: 'poll-1' })
assert.equal(result.votes.length, 1)
assert.equal(result.votes[0].comment, 'yes')
})
})