diff --git a/src/types/election/approval.ts b/src/types/election/approval.ts index fe687897..4b52d945 100644 --- a/src/types/election/approval.ts +++ b/src/types/election/approval.ts @@ -1,7 +1,7 @@ import { MultiLanguage } from '../../util/lang'; import { IElectionParameters, IVoteType } from './election'; import { UnpublishedElection } from './unpublished'; -import { ElectionMetadata, ElectionMetadataTemplate, ElectionResultsTypeNames } from '../metadata'; +import { ElectionMetadata, ElectionResultsTypeNames, getElectionMetadataTemplate } from '../metadata'; import { Vote } from '../vote'; export interface IApprovalElectionParameters extends IElectionParameters {} @@ -63,7 +63,7 @@ export class ApprovalElection extends UnpublishedElection { } public generateMetadata(): ElectionMetadata { - const metadata = ElectionMetadataTemplate; + const metadata = getElectionMetadataTemplate(); metadata.type = { name: ElectionResultsTypeNames.APPROVAL, diff --git a/src/types/election/budget.ts b/src/types/election/budget.ts index 8ba858f7..91cb6d9a 100644 --- a/src/types/election/budget.ts +++ b/src/types/election/budget.ts @@ -1,7 +1,12 @@ import { MultiLanguage } from '../../util/lang'; import { IElectionParameters, IVoteType } from './election'; import { UnpublishedElection } from './unpublished'; -import { ElectionMetadata, ElectionMetadataTemplate, ElectionResultsType, ElectionResultsTypeNames } from '../metadata'; +import { + ElectionMetadata, + ElectionResultsType, + ElectionResultsTypeNames, + getElectionMetadataTemplate, +} from '../metadata'; import { Vote } from '../vote'; export interface IBudgetElectionParametersInfo extends IElectionParameters { @@ -86,7 +91,7 @@ export class BudgetElection extends UnpublishedElection { } public generateMetadata(): ElectionMetadata { - const metadata = ElectionMetadataTemplate; + const metadata = getElectionMetadataTemplate(); metadata.type = { name: ElectionResultsTypeNames.BUDGET, diff --git a/src/types/election/multichoice.ts b/src/types/election/multichoice.ts index 4ec548e0..fa2de906 100644 --- a/src/types/election/multichoice.ts +++ b/src/types/election/multichoice.ts @@ -1,7 +1,7 @@ import { MultiLanguage } from '../../util/lang'; import { IElectionParameters, IVoteType } from './election'; import { UnpublishedElection } from './unpublished'; -import { ElectionMetadata, ElectionMetadataTemplate, ElectionResultsTypeNames } from '../metadata'; +import { ElectionMetadata, ElectionResultsTypeNames, getElectionMetadataTemplate } from '../metadata'; import { Vote } from '../vote'; export interface IMultiChoiceElectionParameters extends IElectionParameters { @@ -73,7 +73,7 @@ export class MultiChoiceElection extends UnpublishedElection { } public generateMetadata(): ElectionMetadata { - const metadata = ElectionMetadataTemplate; + const metadata = getElectionMetadataTemplate(); metadata.type = { name: ElectionResultsTypeNames.MULTIPLE_CHOICE, diff --git a/src/types/election/quadratic.ts b/src/types/election/quadratic.ts index 909f3a44..d9a27ea5 100644 --- a/src/types/election/quadratic.ts +++ b/src/types/election/quadratic.ts @@ -1,7 +1,12 @@ import { MultiLanguage } from '../../util/lang'; import { IElectionParameters, IVoteType } from './election'; import { UnpublishedElection } from './unpublished'; -import { ElectionMetadata, ElectionMetadataTemplate, ElectionResultsType, ElectionResultsTypeNames } from '../metadata'; +import { + ElectionMetadata, + ElectionResultsType, + ElectionResultsTypeNames, + getElectionMetadataTemplate, +} from '../metadata'; import { Vote } from '../vote'; export interface IQuadraticElectionParametersInfo extends IElectionParameters { @@ -91,7 +96,7 @@ export class QuadraticElection extends UnpublishedElection { } public generateMetadata(): ElectionMetadata { - const metadata = ElectionMetadataTemplate; + const metadata = getElectionMetadataTemplate(); metadata.type = { name: ElectionResultsTypeNames.QUADRATIC, diff --git a/src/types/election/unpublished.ts b/src/types/election/unpublished.ts index 50129af4..fd0025f4 100644 --- a/src/types/election/unpublished.ts +++ b/src/types/election/unpublished.ts @@ -2,7 +2,7 @@ import { MultiLanguage } from '../../util/lang'; import { checkValidElectionMetadata, ElectionMetadata, - ElectionMetadataTemplate, + getElectionMetadataTemplate, IChoice, IQuestion, } from '../metadata'; @@ -91,7 +91,7 @@ export class UnpublishedElection extends Election { public generateMetadata(metadata?: ElectionMetadata): ElectionMetadata { if (!metadata) { - metadata = ElectionMetadataTemplate; + metadata = getElectionMetadataTemplate(); } metadata.title = this.title; diff --git a/src/types/metadata/election.ts b/src/types/metadata/election.ts index bf9676f3..717107e4 100644 --- a/src/types/metadata/election.ts +++ b/src/types/metadata/election.ts @@ -191,3 +191,7 @@ export const ElectionMetadataTemplate: ElectionMetadata = { properties: {}, }, }; + +export const getElectionMetadataTemplate = () => { + return structuredClone(ElectionMetadataTemplate); +}; diff --git a/test/integration/other.test.ts b/test/integration/other.test.ts index 8969f741..01725e14 100644 --- a/test/integration/other.test.ts +++ b/test/integration/other.test.ts @@ -1,4 +1,4 @@ -import { ElectionMetadataTemplate, VocdoniSDKClient } from '../../src'; +import { ElectionMetadataTemplate, getElectionMetadataTemplate, VocdoniSDKClient } from '../../src'; // @ts-ignore import { clientParams } from './util/client.params'; @@ -11,7 +11,7 @@ describe('Other tests', () => { }); it('should calculate the correct IPFS hash with special characters', async () => { const client = new VocdoniSDKClient(clientParams()); - const election = ElectionMetadataTemplate; + const election = getElectionMetadataTemplate(); election.title = { default: 'Això és un títol', }; diff --git a/test/unit/types/metadata/election.test.ts b/test/unit/types/metadata/election.test.ts index f017082d..04a0b703 100644 --- a/test/unit/types/metadata/election.test.ts +++ b/test/unit/types/metadata/election.test.ts @@ -1,9 +1,9 @@ -import { ElectionMetadata, checkValidElectionMetadata, ElectionMetadataTemplate } from '../../../../src'; +import { ElectionMetadata, checkValidElectionMetadata, getElectionMetadataTemplate } from '../../../../src'; let electionMetadata: ElectionMetadata; beforeEach(() => { - electionMetadata = ElectionMetadataTemplate; + electionMetadata = getElectionMetadataTemplate(); }); describe('Election metadata', () => {