@@ -3,8 +3,9 @@ def perform
3
3
create_entities
4
4
5
5
create_authorization_request ( :api_entreprise )
6
- create_authorization_request ( :api_entreprise , :submitted , attributes : { intitule : 'Marché publics' , description : very_long_description } )
7
- create_authorization_request ( :api_particulier , :refused , attributes : { intitule : 'Vente de données personnelles' } )
6
+ create_authorization_request ( :api_entreprise , :submitted , attributes : { intitule : 'Marché publics' , description : very_long_description , applicant : another_demandeur } )
7
+ create_authorization_request ( :api_entreprise , :validated , attributes : { intitule : 'Marché publics' , contact_technique_email : demandeur . email , applicant : foreign_demandeur } )
8
+ create_authorization_request ( :api_particulier , :refused , attributes : { intitule : 'Vente de données personnelles' , applicant : another_demandeur } )
8
9
create_authorization_request ( :api_particulier , :changes_requested , attributes : { intitule : 'Tarification cantine' } )
9
10
create_authorization_request ( :portail_hubee_demarche_certdc )
10
11
@@ -19,25 +20,44 @@ def perform
19
20
def flushdb
20
21
raise 'Not in production!' if production?
21
22
22
- load_all_models!
23
+ ActiveRecord ::Base . connection . tables . each do |table |
24
+ next if table == 'schema_migrations'
23
25
24
- ActiveRecord ::Base . connection . transaction do
25
- ApplicationRecord . descendants . each ( &:delete_all )
26
+ ActiveRecord ::Base . connection . execute ( "TRUNCATE TABLE #{ table } CASCADE;" )
26
27
end
27
28
end
28
29
29
30
private
30
31
31
32
def create_entities
32
33
clamart_organization . users << demandeur
34
+ clamart_organization . users << another_demandeur
35
+
33
36
dinum_organization . users << api_entreprise_instructor
37
+ dinum_organization . users << foreign_demandeur
34
38
end
35
39
36
40
def demandeur
37
41
@demandeur ||= User . create! (
38
42
email : 'user@yopmail.com' ,
39
43
external_id : '1' ,
40
- current_organization : clamart_organization
44
+ current_organization : clamart_organization ,
45
+ )
46
+ end
47
+
48
+ def another_demandeur
49
+ @another_demandeur ||= User . create! (
50
+ email : 'user10@yopmail.com' ,
51
+ external_id : '10' ,
52
+ current_organization : clamart_organization ,
53
+ )
54
+ end
55
+
56
+ def foreign_demandeur
57
+ @foreign_demandeur ||= User . create! (
58
+ email : 'user11@yopmail.com' ,
59
+ external_id : '11' ,
60
+ current_organization : dinum_organization ,
41
61
)
42
62
end
43
63
@@ -72,12 +92,14 @@ def create_authorization_request(kind, status = :draft, attributes: {}, traits:
72
92
traits << kind
73
93
traits << status
74
94
95
+ applicant = attributes . delete ( :applicant ) || demandeur
96
+
75
97
authorization_request = FactoryBot . create (
76
98
:authorization_request ,
77
99
*traits ,
78
100
{
79
- applicant : demandeur ,
80
- organization : clamart_organization ,
101
+ applicant :,
102
+ organization : applicant . current_organization ,
81
103
} . merge ( attributes )
82
104
)
83
105
@@ -109,6 +131,12 @@ def create_events_for(authorization_request, status)
109
131
# rubocop:enable Metrics/AbcSize, Metrics/MethodLength
110
132
111
133
def create_event ( authorization_request , status , attributes = { } )
134
+ attributes [ :user ] = if %i[ create submit ] . include? ( status )
135
+ authorization_request . applicant
136
+ else
137
+ api_entreprise_instructor
138
+ end
139
+
112
140
FactoryBot . create (
113
141
:authorization_request_event ,
114
142
status ,
0 commit comments