Skip to content

Commit

Permalink
fix: only send total amount of voting participants (#200)
Browse files Browse the repository at this point in the history
* fix: only send total amount of voting participants

* test: update frontend test
  • Loading branch information
edalholt authored Sep 25, 2023
1 parent 3c9cd08 commit ef377e4
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 13 deletions.
2 changes: 1 addition & 1 deletion backend/controllers/votation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export async function getAllVotations(req: RequestWithNtnuiNo, res: Response) {
title: vote.title,
caseNumber: vote.caseNumber,
voteText: vote.voteText,
voted: vote.voted,
voted: vote.voted.length,
options: optionList,
isActive: isActive,
maximumOptions: vote.maximumOptions,
Expand Down
2 changes: 1 addition & 1 deletion backend/types/vote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export type VoteResponseType = {
title: string;
caseNumber: number;
voteText: string;
voted: number[];
voted: number;
options: OptionType[];
maximumOptions: number;
isActive: boolean;
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/EditAssembly.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ export function EditAssembly(state: { group: UserDataGroupType }) {
title: votationTemplate ? votationTemplate.title : "Placeholder",
caseNumber: 0.1,
voteText: votationTemplate ? votationTemplate.voteText : "",
voted: [],
voted: 0,
options: votationTemplate ? votationTemplate.options : [],
maximumOptions: 1,
isFinished: false,
Expand Down
11 changes: 5 additions & 6 deletions frontend/src/components/Results.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export function Results({
{option.title}
</Text>
<Progress
value={100 * (option.voteCount / votation.voted.length)}
value={100 * (option.voteCount / votation.voted)}
my="xs"
size="xl"
radius="md"
Expand All @@ -95,10 +95,10 @@ export function Results({
label={
option.voteCount +
"/" +
votation.voted.length +
votation.voted +
" (" +
Number(
100 * (option.voteCount / votation.voted.length || 0)
100 * (option.voteCount / votation.voted || 0)
).toFixed(2) +
"%)"
}
Expand All @@ -108,9 +108,8 @@ export function Results({
})}
<Text color={"white"}>
{" "}
{(votation.numberParticipants || 0) -
votation.voted.length} of {votation.numberParticipants || 0}{" "}
participants did not vote
{(votation.numberParticipants || 0) - votation.voted} of{" "}
{votation.numberParticipants || 0} participants did not vote
</Text>
<Button mt={15} onClick={() => addCase(votation)}>
Duplicate votation
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/tests/Results.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describe("Result component test", () => {
_id: "5",
title: "Testvotering",
voteText: "Dette er en testvotering",
voted: [1, 2, 4, 7, 9],
voted: 5,
options: [testOption1, testOption2],
maximumOptions: 1,
isFinished: true,
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/types/votes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export interface VoteType {
_id: string;
title: string;
voteText: string;
voted: number[];
voted: number;
options: OptionType[];
maximumOptions: number;
isFinished: boolean;
Expand Down
4 changes: 2 additions & 2 deletions frontend/test/setup/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const vote2: VoteType = {
_id: "1",
title: "Test",
voteText: "Testing",
voted: [1, 2],
voted: 2,
options: [{ _id: "1", title: "Case1", voteCount: 0 }],
maximumOptions: 1,
isFinished: false,
Expand All @@ -57,7 +57,7 @@ const vote1: VoteType = {
_id: "2",
title: "Test2",
voteText: "Testing2",
voted: [1, 2],
voted: 2,
options: [{ _id: "2", title: "Case2", voteCount: 0 }],
maximumOptions: 1,
isFinished: false,
Expand Down

0 comments on commit ef377e4

Please sign in to comment.