66
77module Decidim ::Valid
88 describe VerificationJob do
9- def pending_to_be_finished
10- pending ( "Implementation pending, this Decidim module does not support user verification" )
11- end
9+ let! ( :organization ) { create ( :organization , host : " #{ SecureRandom . hex ( 10 ) } .example.com" ) }
10+ let! ( :user ) { create ( :user , organization : ) }
11+ let! ( :identity ) { create ( :identity , provider : "idcat_mobil" , user : ) }
1212
13- let! ( :user ) { create ( :user ) }
14- let! ( :identity ) { create ( :identity , provider : "idecat_mobil" , user :) }
1513 let ( :oauth_data ) do
1614 {
1715 user_id : user . id ,
1816 identity_id : identity . id ,
1917 provider : "idcat_mobil" ,
20- uid : "idcat_mobil/ #{ user . id } " ,
18+ uid : "00000000K " ,
2119 email : user . email ,
22- name : "idcat_mobil " ,
23- nickname : nil ,
20+ name : "Alice " ,
21+ nickname : "alice" ,
2422 avatar_url : nil ,
25- raw_data : { }
23+ raw_data : {
24+ provider : :idcat_mobil ,
25+ uid : "00000000K" ,
26+ info : {
27+ email : user . email ,
28+ name : "Alice" ,
29+ prefix : "0034" ,
30+ phone : "972972972" ,
31+ surname1 : "COOPER" ,
32+ surname2 : "IRON" ,
33+ surnames : "COOPER IRON" ,
34+ country_code : "ES"
35+ } ,
36+ credentials : {
37+ token : "1/abcdefABCDEFGHIJKLMNOPQRSTUVWXYZabcdefgh" ,
38+ expires_at : 1_773_128_240 ,
39+ expires : true
40+ } ,
41+ extra : {
42+ identifier_type : "1" ,
43+ method : "idcatmobil" ,
44+ assurance_level : "low" ,
45+ status : "ok"
46+ }
47+ }
2648 }
2749 end
2850
29- # rubocop: disable Lint/ConstantDefinitionInBlock
30- class TestDecidimPublisher < Decidim ::Command
31- include Wisper ::Publisher
32- def initialize ( *args )
33- super
34- end
35- end
36-
37- # rubocop: enable Lint/ConstantDefinitionInBlock
38- def stub_decidim_publisher ( clazz , called_method , event_to_publish , *published_event_args )
39- stub_const ( clazz , Class . new ( TestDecidimPublisher ) do
40- define_method ( called_method ) do |*_args |
41- publish ( event_to_publish , *published_event_args )
42- end
43- end )
44- end
45-
4651 context "when omniauth_registration event is notified" do
4752 context "when authorization is created with success" do
4853 it "notifies the user for the success" do
49- pending_to_be_finished
50- stub_decidim_publisher ( "Decidim::Verifications::AuthorizeUser" , :call , :ok )
5154 expect ( Decidim ::EventsManager )
5255 . to receive ( :publish )
5356 . with (
5457 event : "decidim.verifications.idcat_mobil.ok" ,
5558 event_class : Decidim ::IdcatMobil ::VerificationSuccessNotification ,
59+ resource : user ,
5660 recipient_ids : [ user . id ] ,
5761 extra : {
5862 status : :ok ,
@@ -65,21 +69,25 @@ def stub_decidim_publisher(clazz, called_method, event_to_publish, *published_ev
6569 end
6670
6771 context "when authorization creation fails" do
72+ let ( :oauth_data ) do
73+ super ( ) . merge ( status : "invalid" , "status" => "invalid" )
74+ end
75+
6876 it "notifies the user for the failure" do
69- pending_to_be_finished
70- stub_decidim_publisher ( "Decidim::Verifications::AuthorizeUser" , :call , :invalid )
7177 expect ( Decidim ::EventsManager )
7278 . to receive ( :publish )
73- . with (
74- event : "decidim.verifications.idcat_mobil.invalid" ,
75- event_class : Decidim ::IdcatMobil ::VerificationInvalidNotification ,
76- recipient_ids : [ user . id ] ,
77- extra : {
78- status : :invalid ,
79- errors : [ ]
80- }
81- )
79+ . with ( hash_including (
80+ event : "decidim.verifications.idcat_mobil.invalid" ,
81+ event_class : Decidim ::IdcatMobil ::VerificationInvalidNotification ,
82+ resource : user ,
83+ recipient_ids : [ user . id ] ,
84+ extra : hash_including (
85+ status : :invalid ,
86+ errors : [ "Unique cannot be blank" ]
87+ )
88+ ) )
8289
90+ oauth_data . delete ( :uid )
8391 VerificationJob . new . perform ( oauth_data )
8492 end
8593 end
0 commit comments