vocdoni/vocdoni-sdk

bug: maxCensusSize is always undefined

elboletaire opened this issue · 1 comments

Describe the bug

PublishedElection has a maxCensusSize getter that should return the information received via census.maxCensusSize field in the API, but it's always undefined.

To Reproduce

Grab any election information, and try to access the value via election.maxCensusSize

Current behavior

Returns undefined

Expected behavior

Should return the expected maxCensusSize value the API is properly returning.

Additional context

API response:
imatge

Stored published election data in memory:
imatge

Looks like the issue is that it is being expected via params.maxCensusSize, but when building it in the client we're not passing the expected maxCensusSize param. Trace:

  • Election's maxCensusSize definition:
    this._maxCensusSize = params.maxCensusSize;
  • PublishedElection passing to super:
    maxCensusSize: params.maxCensusSize,
  • Client creating PublishedElection (here's where's missing):

    vocdoni-sdk/src/client.ts

    Lines 513 to 562 in 6b8347e

    PublishedElection.build({
    id: electionInfo.electionId,
    organizationId: electionInfo.organizationId,
    title: electionInfo.metadata?.title,
    description: electionInfo.metadata?.description,
    header: electionInfo.metadata?.media.header,
    streamUri: electionInfo.metadata?.media.streamUri,
    meta: electionInfo.metadata?.meta,
    startDate: electionInfo.startDate,
    endDate: electionInfo.endDate,
    census: new PublishedCensus(
    electionInfo.census.censusRoot,
    electionInfo.census.censusURL,
    Census.censusTypeFromCensusOrigin(electionInfo.census.censusOrigin),
    censusInfo.size,
    censusInfo.weight
    ),
    status: electionInfo.status,
    voteCount: electionInfo.voteCount,
    finalResults: electionInfo.finalResults,
    results: electionInfo.result,
    metadataURL: electionInfo.metadataURL,
    creationTime: electionInfo.creationTime,
    electionType: {
    autoStart: electionInfo.electionMode.autoStart,
    interruptible: electionInfo.electionMode.interruptible,
    dynamicCensus: electionInfo.electionMode.dynamicCensus,
    secretUntilTheEnd: electionInfo.voteMode.encryptedVotes,
    anonymous: electionInfo.voteMode.anonymous,
    },
    voteType: {
    uniqueChoices: electionInfo.voteMode.uniqueValues,
    maxVoteOverwrites: electionInfo.tallyMode.maxVoteOverwrites,
    costFromWeight: electionInfo.voteMode.costFromWeight,
    costExponent: electionInfo.tallyMode.costExponent,
    maxCount: electionInfo.tallyMode.maxCount,
    maxValue: electionInfo.tallyMode.maxValue,
    maxTotalCost: electionInfo.tallyMode.maxTotalCost,
    },
    questions: electionInfo.metadata?.questions.map((question, qIndex) => ({
    title: question.title,
    description: question.description,
    choices: question.choices.map((choice, cIndex) => ({
    title: choice.title,
    value: choice.value,
    results: electionInfo.result ? electionInfo.result[qIndex][cIndex] : null,
    })),
    })),
    raw: electionInfo,
    })