@@ -234,5 +234,132 @@ module Decidim
234234 end
235235 end
236236 end
237+
238+ describe "GET review" do
239+ context "when the user is NOT the creator of the resource" do
240+ let ( :user ) { other_user }
241+
242+ it "does not allow access" do
243+ get ( :review , params :)
244+
245+ expect ( response ) . to have_http_status ( :redirect )
246+ expect ( flash [ :alert ] ) . to eq ( "You are not authorized to perform this action." )
247+ end
248+ end
249+
250+ context "when the user is the creator of the resource" do
251+ let ( :user ) { amendable . author }
252+
253+ it "allows access" do
254+ get ( :review , params :)
255+
256+ expect ( response ) . to have_http_status ( :ok )
257+ end
258+ end
259+ end
260+
261+ describe "PATCH accept" do
262+ let ( :emendation_params ) { { title : emendation . title , body : emendation . body } }
263+
264+ context "when the user is NOT the creator of the resource" do
265+ let ( :user ) { other_user }
266+
267+ it "does not accept the amendment" do
268+ patch :accept , params : params . merge ( emendation_params :)
269+
270+ expect ( response ) . to have_http_status ( :redirect )
271+ expect ( flash [ :alert ] ) . to eq ( "You are not authorized to perform this action." )
272+ end
273+ end
274+
275+ context "when the user is the creator of the resource" do
276+ let ( :user ) { amendable . author }
277+
278+ it "accepts the amendment" do
279+ patch :accept , params : params . merge ( emendation_params :)
280+
281+ expect ( response ) . to have_http_status ( :redirect )
282+ expect ( flash [ :notice ] ) . to eq ( "The amendment has been accepted successfully." )
283+ end
284+ end
285+
286+ context "when the resource is official" do
287+ let! ( :amendable ) { create ( :dummy_resource , component :, author : component . organization ) }
288+
289+ context "and the user is NOT an admin" do
290+ let ( :user ) { amendment . amender }
291+
292+ it "does not accept the amendment" do
293+ patch :accept , params : params . merge ( emendation_params :)
294+
295+ expect ( response ) . to have_http_status ( :redirect )
296+ expect ( flash [ :alert ] ) . to eq ( "You are not authorized to perform this action." )
297+ end
298+ end
299+
300+ context "and the user is an admin" do
301+ let ( :user ) { create ( :user , :confirmed , :admin , organization : component . organization ) }
302+
303+ it "accepts the amendment" do
304+ patch :accept , params : params . merge ( emendation_params :)
305+
306+ expect ( response ) . to have_http_status ( :redirect )
307+ expect ( flash [ :notice ] ) . to eq ( "The amendment has been accepted successfully." )
308+ end
309+ end
310+ end
311+ end
312+
313+ describe "PATCH reject" do
314+ let ( :emendation_params ) { { title : emendation . title , body : emendation . body } }
315+
316+ context "when the user is NOT the creator of the resource" do
317+ let ( :user ) { other_user }
318+
319+ it "does not accept the amendment" do
320+ patch :reject , params : params . merge ( emendation_params :)
321+
322+ expect ( response ) . to have_http_status ( :redirect )
323+ expect ( flash [ :alert ] ) . to eq ( "You are not authorized to perform this action." )
324+ end
325+ end
326+
327+ context "when the user is the creator of the resource" do
328+ let ( :user ) { amendable . author }
329+
330+ it "accepts the amendment" do
331+ patch :reject , params : params . merge ( emendation_params :)
332+
333+ expect ( response ) . to have_http_status ( :redirect )
334+ expect ( flash [ :notice ] ) . to eq ( "The amendment has been successfully rejected." )
335+ end
336+ end
337+
338+ context "when the resource is official" do
339+ let! ( :amendable ) { create ( :dummy_resource , component :, author : component . organization ) }
340+
341+ context "and the user is NOT an admin" do
342+ let ( :user ) { amendment . amender }
343+
344+ it "does not accept the amendment" do
345+ patch :reject , params : params . merge ( emendation_params :)
346+
347+ expect ( response ) . to have_http_status ( :redirect )
348+ expect ( flash [ :alert ] ) . to eq ( "You are not authorized to perform this action." )
349+ end
350+ end
351+
352+ context "and the user is an admin" do
353+ let ( :user ) { create ( :user , :confirmed , :admin , organization : component . organization ) }
354+
355+ it "accepts the amendment" do
356+ patch :reject , params : params . merge ( emendation_params :)
357+
358+ expect ( response ) . to have_http_status ( :redirect )
359+ expect ( flash [ :notice ] ) . to eq ( "The amendment has been successfully rejected." )
360+ end
361+ end
362+ end
363+ end
237364 end
238365end
0 commit comments