Skip to content

Commit

Permalink
fix: Fix poll.vote parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
neet committed Apr 8, 2023
1 parent 71e11ca commit 1a7114e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/mastodon/v1/repositories/poll-repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type { Poll } from '../entities';

export interface VotePollParams {
/** Array of own votes containing index for each option (starting from 0) */
readonly choices: string[];
readonly choices: number[];
}

export class PollRepository implements Repository<Poll> {
Expand All @@ -21,7 +21,7 @@ export class PollRepository implements Repository<Poll> {
* View a poll
* @param id ID of the poll in the database
* @return Poll
* @see https://docs.joinmastodon.org/methods/statuses/polls/
* @see https://docs.joinmastodon.org/methods/statuses/polls#get
*/
@version({ since: '2.8.0' })
fetch(id: string): Promise<Poll> {
Expand All @@ -33,7 +33,7 @@ export class PollRepository implements Repository<Poll> {
* @param id ID of the poll in the database
* @param params Parameters
* @return Poll
* @see https://docs.joinmastodon.org/methods/statuses/polls/
* @see https://docs.joinmastodon.org/methods/statuses/polls#vote
*/
@version({ since: '2.8.0' })
vote(id: string, params: VotePollParams): Promise<Poll> {
Expand Down
24 changes: 24 additions & 0 deletions tests/v1/polls.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/* eslint-disable @typescript-eslint/no-non-null-assertion */
it('handles poll', () => {
return clients.use(2, async ([alice, bob]) => {
const status = await alice.v1.statuses.create({
status: `Which fruits do you like?`,
poll: {
options: ['Apple', 'Banana', 'Orange'],
multiple: true,
expiresIn: 60 * 60 * 24,
},
});

try {
await bob.v1.polls.vote(status.poll!.id, {
choices: [0, 1],
});
const poll = await bob.v1.polls.fetch(status.poll!.id);
expect(poll.votesCount).toBe(2);
expect(poll.ownVotes).toEqual([0, 1]);
} finally {
await alice.v1.statuses.remove(status.id);
}
});
});

0 comments on commit 1a7114e

Please sign in to comment.