Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added missing maxCensusSize and manuallyEnded in fetchElection. #236

Merged
merged 2 commits into from
Aug 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Fixed

- Added missing `maxCensusSize` and `manuallyEnded` in `fetchElection`.

## [0.0.18] - 2023-08-01

### Added
Expand Down
5 changes: 5 additions & 0 deletions src/api/election.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,11 @@ export interface IElectionInfoResponse {
*/
result?: Array<Array<string>>;

/**
* If the election has been ended manually
*/
manuallyEnded: boolean;

/**
* The census of the election
*/
Expand Down
2 changes: 2 additions & 0 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,8 @@ export class VocdoniSDKClient {
censusInfo.size,
censusInfo.weight
),
maxCensusSize: electionInfo.census.maxCensusSize,
manuallyEnded: electionInfo.manuallyEnded,
status: electionInfo.status,
voteCount: electionInfo.voteCount,
finalResults: electionInfo.finalResults,
Expand Down
7 changes: 7 additions & 0 deletions src/types/election/published.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export interface IPublishedElectionParameters extends IElectionParameters {
voteCount: number;
finalResults: boolean;
results: Array<Array<string>>;
manuallyEnded: boolean;
creationTime: string;
metadataURL: string;
raw: object;
Expand All @@ -40,6 +41,7 @@ export class PublishedElection extends Election {
private readonly _status: ElectionStatus;
private readonly _voteCount: number;
private readonly _finalResults: boolean;
private readonly _manuallyEnded: boolean;
private readonly _results: Array<Array<string>>;
private readonly _creationTime: Date;
private readonly _metadataURL: string;
Expand Down Expand Up @@ -71,6 +73,7 @@ export class PublishedElection extends Election {
this._voteCount = params.voteCount;
this._finalResults = params.finalResults;
this._results = params.results;
this._manuallyEnded = params.manuallyEnded;
this._creationTime = new Date(params.creationTime);
this._metadataURL = params.metadataURL;
this._raw = params.raw;
Expand Down Expand Up @@ -162,6 +165,10 @@ export class PublishedElection extends Election {
return this._results;
}

get manuallyEnded(): boolean {
return this._manuallyEnded;
}

get creationTime(): Date {
return this._creationTime;
}
Expand Down
8 changes: 8 additions & 0 deletions test/integration/election.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ describe('Election integration tests', () => {
maxValue: 1,
maxTotalCost: 0,
});
expect(publishedElection.manuallyEnded).toBeFalsy();
expect(publishedElection.maxCensusSize).toEqual(1);
});
}, 85000);
it('should create an election with addresses census', async () => {
Expand Down Expand Up @@ -201,6 +203,7 @@ describe('Election integration tests', () => {
expect(election.census.size).toEqual(numVotes);
expect(election.census.weight).toEqual(BigInt(numVotes));
expect(election.status).toEqual(ElectionStatus.ONGOING);
expect(election.maxCensusSize).toEqual(numVotes);
})
.then(() =>
Promise.all(
Expand Down Expand Up @@ -284,6 +287,7 @@ describe('Election integration tests', () => {
expect(election.census.size).toEqual(numVotes);
expect(election.census.weight).toEqual(BigInt((numVotes * (numVotes + 1)) / 2));
expect(election.status).toEqual(ElectionStatus.ONGOING);
expect(election.maxCensusSize).toEqual(numVotes);
})
.then(() =>
Promise.all(
Expand Down Expand Up @@ -362,6 +366,7 @@ describe('Election integration tests', () => {
expect(election.census.size).toEqual(numVotes);
expect(election.census.weight).toEqual(BigInt(numVotes));
expect(election.status).toEqual(ElectionStatus.ONGOING);
expect(election.maxCensusSize).toEqual(numVotes);
})
.then(() =>
Promise.all(
Expand Down Expand Up @@ -443,6 +448,7 @@ describe('Election integration tests', () => {
expect(election.census.size).toEqual(numVotes);
expect(election.census.weight).toEqual(BigInt(numVotes));
expect(election.status).toEqual(ElectionStatus.ONGOING);
expect(election.maxCensusSize).toEqual(numVotes);
})
.then(() =>
Promise.all(
Expand Down Expand Up @@ -474,11 +480,13 @@ describe('Election integration tests', () => {
})
.then((election) => {
expect([ElectionStatus.ONGOING, ElectionStatus.UPCOMING]).toContain(election.status);
expect(election.manuallyEnded).toBeFalsy();
return client.endElection();
})
.then(() => client.fetchElection())
.then((election) => {
expect([ElectionStatus.ENDED, ElectionStatus.RESULTS]).toContain(election.status);
expect(election.manuallyEnded).toBeTruthy();
marcvelmer marked this conversation as resolved.
Show resolved Hide resolved
});
}, 85000);
it('should create an election and pause it successfully', async () => {
Expand Down