mirror of
https://github.com/Permissionless-Software-Foundation/psf-memo.git
synced 2026-09-21 16:52:01 -07:00
- 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.
42 lines
983 B
JavaScript
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')
|
|
})
|
|
})
|