Skip to content

Commit f33fcb2

Browse files
committed
fix(fetchVotingEvidences api): reset votingResult any time it is recalculated
Make sure that the calculation of votingResult resuts the result each time it is performed
1 parent 5c05336 commit f33fcb2

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

src/api/voting-event-apis.ts

+3-5
Original file line numberDiff line numberDiff line change
@@ -393,13 +393,11 @@ export function fetchVotingEvidences(
393393
const techId: any = t._id;
394394
return techId.toHexString() === id;
395395
});
396+
tech.votingResult = {
397+
votesForRing: [],
398+
};
396399
const votesGroupedByRing = groupBy(votes, 'ring');
397400
Object.entries(votesGroupedByRing).forEach(([ring, votes]) => {
398-
if (!tech.votingResult) {
399-
tech.votingResult = {
400-
votesForRing: [],
401-
};
402-
}
403401
tech.votingResult.votesForRing.push({ ring, count: votes.length });
404402
});
405403
const votesGroupedByTag = new Map<string, Vote[]>();

src/mongodb/voting-event-apis.spec.ts

+17
Original file line numberDiff line numberDiff line change
@@ -1221,6 +1221,23 @@ describe('Operations on votingevents collection', () => {
12211221
expect(t1.votingResult.votesForRing[0].count).to.equal(2);
12221222
expect(t1.votingResult.votesForTag).to.be.undefined;
12231223
}),
1224+
// We move to the third step and want to check that the voting results are the same at least in terms of numbers
1225+
concatMap(() => mongodbService(cachedDb, ServiceNames.moveToNexFlowStep, { _id: votingEventId })),
1226+
concatMap(() => mongodbService(cachedDb, ServiceNames.getVotingEvent, votingEventId)),
1227+
tap((votingEvent: VotingEvent) => {
1228+
expect(votingEvent.round).to.equal(votingEventRound + 2);
1229+
const t0 = votingEvent.technologies.find(t => t.name === tech0.name);
1230+
expect(t0.votingResult.votesForRing.length).to.equal(1);
1231+
const productionTagRes = t0.votingResult.votesForTag.find(t => t.tag === productionTag);
1232+
expect(productionTagRes.count).to.equal(2);
1233+
const trainingTagRes = t0.votingResult.votesForTag.find(t => t.tag === trainingTag);
1234+
expect(trainingTagRes.count).to.equal(2);
1235+
const colleaguesTagRes = t0.votingResult.votesForTag.find(t => t.tag === colleaguesTag);
1236+
expect(colleaguesTagRes.count).to.equal(2);
1237+
const t1 = votingEvent.technologies.find(t => t.name === tech1.name);
1238+
expect(t1.votingResult.votesForRing.length).to.equal(1);
1239+
expect(t1.votingResult.votesForTag).to.be.undefined;
1240+
}),
12241241
)
12251242
.subscribe(
12261243
null,

0 commit comments

Comments
 (0)