@@ -38,15 +38,61 @@ module BulletinBoard
3838 it { is_expected . not_to be_configured }
3939 end
4040
41- describe "cast_vote" do
42- let ( :election_data ) do
43- { election_id : "test.1" }
41+ describe "open_ballot_box" do
42+ let ( :election_id ) { "test.1" }
43+
44+ context "when everything went ok" do
45+ before do
46+ stub_wisper_publisher ( "Decidim::BulletinBoard::Authority::OpenBallotBox" , :call , :ok , double ( status : "vote" ) )
47+ end
48+
49+ it "calls the OpenBallotBox command and returns the new status" do
50+ election = subject . open_ballot_box ( election_id )
51+ expect ( election . status ) . to eq ( "vote" )
52+ end
53+ end
54+
55+ context "when something went wrong" do
56+ before do
57+ stub_wisper_publisher ( "Decidim::BulletinBoard::Authority::OpenBallotBox" , :call , :error , "something went wrong" )
58+ end
59+
60+ it "calls the CastVote command and throws an error" do
61+ expect { subject . open_ballot_box ( election_id ) } . to raise_error ( "something went wrong" )
62+ end
63+ end
64+ end
65+
66+ describe "close_ballot_box" do
67+ let ( :election_id ) { "test.1" }
68+
69+ context "when everything went ok" do
70+ before do
71+ stub_wisper_publisher ( "Decidim::BulletinBoard::Authority::CloseBallotBox" , :call , :ok , double ( status : "tally" ) )
72+ end
73+
74+ it "calls the CloseBallotBox command and returns the new status" do
75+ election = subject . close_ballot_box ( election_id )
76+ expect ( election . status ) . to eq ( "tally" )
77+ end
4478 end
45- let ( :voter_data ) do
46- { voter_id : "voter.1" }
79+
80+ context "when something went wrong" do
81+ before do
82+ stub_wisper_publisher ( "Decidim::BulletinBoard::Authority::CloseBallotBox" , :call , :error , "something went wrong" )
83+ end
84+
85+ it "calls the CastVote command and throws an error" do
86+ expect { subject . close_ballot_box ( election_id ) } . to raise_error ( "something went wrong" )
87+ end
4788 end
89+ end
90+
91+ describe "cast_vote" do
92+ let ( :election_id ) { "test.1" }
93+ let ( :voter_id ) { "voter.1" }
4894 let ( :encrypted_vote ) do
49- { question_1 : "aNsWeR 1" }
95+ { question_1 : "aNsWeR 1" } . to_json
5096 end
5197
5298 context "when everything went ok" do
@@ -55,7 +101,7 @@ module BulletinBoard
55101 end
56102
57103 it "calls the CastVote command and return the result" do
58- pending_message = subject . cast_vote ( election_data , voter_data , encrypted_vote )
104+ pending_message = subject . cast_vote ( election_id , voter_id , encrypted_vote )
59105 expect ( pending_message . status ) . to eq ( "enqueued" )
60106 end
61107 end
@@ -66,7 +112,7 @@ module BulletinBoard
66112 end
67113
68114 it "calls the CastVote command and throws an error" do
69- expect { subject . cast_vote ( election_data , voter_data , encrypted_vote ) } . to raise_error ( "something went wrong" )
115+ expect { subject . cast_vote ( election_id , voter_id , encrypted_vote ) } . to raise_error ( "something went wrong" )
70116 end
71117 end
72118 end
0 commit comments