Skip to content

Commit 98514aa

Browse files
lbarjakmagwas
authored andcommitted
a_user_with_all_assourances_can_show_the_vote
1 parent 111b531 commit 98514aa

File tree

5 files changed

+55
-31
lines changed

5 files changed

+55
-31
lines changed

Diff for: pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<groupId>org.rulez.demokracia</groupId>
77
<artifactId>PDEngine</artifactId>
8-
<version>0.0.1-feature_matrix.64f1423</version>
8+
<version>0.0.1-feature_for_show_vote_the_user_needs_a_counted_assurance_40.5a79d7b</version>
99
<packaging>war</packaging>
1010

1111
<name>PDEngine</name>

Diff for: src/main/java/org/rulez/demokracia/pdengine/VoteRegistry.java

+27-13
Original file line numberDiff line numberDiff line change
@@ -97,33 +97,48 @@ private void checkIfVotingEnabled(final Vote vote) {
9797

9898
@Override
9999
public void modifyVote(final VoteAdminInfo voteAdminInfo, final String voteName) {
100-
Vote vote = getVote(voteAdminInfo.voteId);
101-
vote.checkAdminKey(voteAdminInfo.adminKey);
102100
ValidationUtil.checkVoteName(voteName);
103-
104-
if (vote.hasIssuedBallots())
105-
throw new IllegalArgumentException("The vote cannot be modified there are ballots issued.");
101+
Vote vote = checkIfVoteCanBeModified(voteAdminInfo);
106102

107103
vote.name = voteName;
108104
}
109105

110106
public void deleteVote(final VoteAdminInfo adminInfo) {
111-
Vote vote = getVote(adminInfo.voteId);
112-
vote.checkAdminKey(adminInfo.adminKey);
113-
114-
if (vote.hasIssuedBallots())
115-
throw new IllegalArgumentException("This vote cannot be deleted it has issued ballots.");
107+
Vote vote = checkIfVoteCanBeModified(adminInfo);
116108

117109
session.remove(vote);
118110
}
119111

120-
public JSONObject showVote(final VoteAdminInfo adminInfo) {
112+
private Vote checkIfVoteCanBeModified(final VoteAdminInfo adminInfo) {
113+
Vote vote = checkAdminInfo(adminInfo);
114+
115+
if (vote.hasIssuedBallots())
116+
throw new IllegalArgumentException("This vote cannot be modified it has issued ballots.");
117+
return vote;
118+
}
119+
120+
private Vote checkAdminInfo(final VoteAdminInfo adminInfo) {
121121
Vote vote = getVote(adminInfo.voteId);
122122
vote.checkAdminKey(adminInfo.adminKey);
123+
return vote;
124+
}
125+
126+
@Override
127+
public JSONObject showVote(final VoteAdminInfo adminInfo) {
128+
Vote vote = checkAdminInfo(adminInfo);
129+
if (!adminInfo.adminKey.equals(vote.adminKey))
130+
checkAssurances(vote);
123131

124132
return vote.toJson(adminInfo.voteId);
125133
}
126134

135+
private void checkAssurances(final Vote vote) throws ReportedException {
136+
137+
for(String assurance : vote.countedAssurances)
138+
if (!this.hasAssurance(assurance))
139+
throw new ReportedException("missing assurances", assurance);
140+
}
141+
127142
@Override
128143
public String deleteChoice(final VoteAdminInfo voteAdminInfo, final String choiceId) {
129144
Vote vote = getVoteIfModifiable(voteAdminInfo.voteId, voteAdminInfo.adminKey);
@@ -164,8 +179,7 @@ public void modifyChoice(final VoteAdminInfo adminInfo, final String choiceId, f
164179

165180
@Override
166181
public void setVoteParameters(final VoteAdminInfo adminInfo, final VoteParameters voteParameters) {
167-
Vote vote = getVote(adminInfo.voteId);
168-
vote.checkAdminKey(adminInfo.adminKey);
182+
Vote vote = checkAdminInfo(adminInfo);
169183

170184
if (voteParameters.minEndorsements >= 0)
171185
vote.setParameters(voteParameters.minEndorsements, voteParameters.canAddin, voteParameters.canEndorse, voteParameters.canVote, voteParameters.canView);
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
package org.rulez.demokracia.pdengine;
22

3+
import static org.junit.Assert.assertNotNull;
4+
5+
import org.json.JSONObject;
36
import org.junit.Test;
47
import org.rulez.demokracia.pdengine.annotations.TestedBehaviour;
58
import org.rulez.demokracia.pdengine.annotations.TestedFeature;
69
import org.rulez.demokracia.pdengine.annotations.TestedOperation;
10+
import org.rulez.demokracia.pdengine.dataobjects.VoteAdminInfo;
711
import org.rulez.demokracia.pdengine.exception.ReportedException;
812
import org.rulez.demokracia.pdengine.testhelpers.CreatedDefaultVoteRegistry;
913

14+
@TestedFeature("Manage votes")
15+
@TestedOperation("show vote")
16+
@TestedBehaviour("if adminKey is anon, the user should have any of the countedAssurances")
1017
public class ForShowVoteTheUserNeedsACountedAssurance extends CreatedDefaultVoteRegistry {
11-
12-
public ForShowVoteTheUserNeedsACountedAssurance() {
13-
super();
14-
}
1518

1619
@Test
17-
@TestedFeature("Manage votes")
18-
@TestedOperation("show vote")
19-
@TestedBehaviour("if adminKey is anon, the user should have any of the countedAssurances")
2020
public void a_user_with_not_all_assourances_cannot_show_the_vote() throws ReportedException {
2121

2222
Vote vote = getTheVote();
@@ -26,9 +26,6 @@ public void a_user_with_not_all_assourances_cannot_show_the_vote() throws Report
2626
}
2727

2828
@Test
29-
@TestedFeature("Manage votes")
30-
@TestedOperation("show vote")
31-
@TestedBehaviour("if adminKey is anon, the user should have any of the countedAssurances")
3229
public void a_user_with_not_all_assourances_cannot_show_the_vote_even_with_more_assurances() throws ReportedException {
3330

3431
Vote vote = getTheVote();
@@ -37,10 +34,23 @@ public void a_user_with_not_all_assourances_cannot_show_the_vote_even_with_more_
3734

3835
assertAssurancesMissing(vote);
3936
}
37+
38+
@Test
39+
public void a_user_with_all_assourances_can_show_the_vote() throws ReportedException {
40+
41+
Vote vote = getTheVote();
42+
vote.countedAssurances.add("magyar");
43+
VoteAdminInfo aminInfo = new VoteAdminInfo(vote.id, "user");
44+
JSONObject voteJson = voteManager.showVote(aminInfo);
45+
46+
assertNotNull(voteJson);
47+
}
4048

41-
private void assertAssurancesMissing(Vote vote) {
42-
// assertThrows(
43-
// () -> voteManager.showVote(vote.id, "user")
44-
// ).assertMessageIs("missing assurances");
49+
private void assertAssurancesMissing(final Vote vote) {
50+
VoteAdminInfo aminInfo = new VoteAdminInfo(vote.id, "user");
51+
52+
assertThrows(
53+
() -> voteManager.showVote(aminInfo)
54+
).assertMessageIs("missing assurances");
4555
}
4656
}

Diff for: src/test/java/org/rulez/demokracia/pdengine/VoteDeleteValidationTest.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public void proper_voteId_and_adminKey_with_ballot_does_not_delete_vote() {
3838
vote.ballots.add("TestBallot");
3939
assertThrows(
4040
() -> voteManager.deleteVote(new VoteAdminInfo(voteId, adminInfo.adminKey))
41-
).assertMessageIs("This vote cannot be deleted it has issued ballots.");
41+
).assertMessageIs("This vote cannot be modified it has issued ballots.");
4242
}
4343

4444
@TestedBehaviour("deletes the vote with all parameters, choices, ballots and votes cast")
@@ -60,6 +60,6 @@ public void proper_voteId_and_adminKey_with_issued_ballots_does_not_delete_vote(
6060

6161
assertThrows(
6262
() -> voteManager.deleteVote(new VoteAdminInfo(voteId, adminInfo.adminKey))
63-
).assertMessageIs("This vote cannot be deleted it has issued ballots.");
63+
).assertMessageIs("This vote cannot be modified it has issued ballots.");
6464
}
6565
}

Diff for: src/test/java/org/rulez/demokracia/pdengine/VoteModificationValidationTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,6 @@ public void modifyVote_with_ballot_get_an_exception() {
5151
assertThrows(
5252
() -> voteManager.modifyVote(
5353
new VoteAdminInfo(voteId, adminInfo.adminKey), voteName)
54-
).assertMessageIs("The vote cannot be modified there are ballots issued.");
54+
).assertMessageIs("This vote cannot be modified it has issued ballots.");
5555
}
5656
}

0 commit comments

Comments
 (0)