File tree Expand file tree Collapse file tree 5 files changed +22
-12
lines changed
lib/concepts/project/operations Expand file tree Collapse file tree 5 files changed +22
-12
lines changed Original file line number Diff line number Diff line change @@ -27,7 +27,7 @@ def show
27
27
end
28
28
29
29
def create
30
- result = Project ::Create . call ( project_hash : project_params )
30
+ result = Project ::Create . call ( project_hash : project_params , current_user : )
31
31
32
32
if result . success?
33
33
@project = result [ :project ]
Original file line number Diff line number Diff line change @@ -13,7 +13,7 @@ def resolve(**input)
13
13
components : input [ :components ] &.map ( &:to_h )
14
14
)
15
15
16
- response = Project ::Create . call ( project_hash :)
16
+ response = Project ::Create . call ( project_hash :, current_user : context [ :current_user ] )
17
17
raise GraphQL ::ExecutionError , response [ :error ] unless response . success?
18
18
19
19
{ project : response [ :project ] }
Original file line number Diff line number Diff line change 3
3
class Project
4
4
class Create
5
5
class << self
6
- def call ( project_hash :)
6
+ def call ( project_hash :, current_user : )
7
7
response = OperationResponse . new
8
- response [ :project ] = build_project ( project_hash )
8
+ response [ :project ] = build_project ( project_hash , current_user )
9
9
response [ :project ] . save!
10
10
response
11
11
rescue StandardError => e
@@ -16,9 +16,9 @@ def call(project_hash:)
16
16
17
17
private
18
18
19
- def build_project ( project_hash )
20
- identifier = PhraseIdentifier . generate
21
- new_project = Project . new ( project_hash . except ( :components ) . merge ( identifier : ) )
19
+ def build_project ( project_hash , current_user )
20
+ project_hash [ : identifier] = PhraseIdentifier . generate unless current_user &. experience_cs_admin?
21
+ new_project = Project . new ( project_hash . except ( :components ) )
22
22
new_project . components . build ( project_hash [ :components ] )
23
23
new_project
24
24
end
Original file line number Diff line number Diff line change 3
3
require 'rails_helper'
4
4
5
5
RSpec . describe Project ::Create , type : :unit do
6
- subject ( :create_project ) { described_class . call ( project_hash :) }
6
+ subject ( :create_project ) { described_class . call ( project_hash :, current_user : ) }
7
7
8
- let ( :user_id ) { 'e0675b6c-dc48-4cd6-8c04-0f7ac05af51a' }
8
+ let ( :current_user ) { create ( :user ) }
9
+ let ( :user_id ) { current_user . id }
9
10
10
11
before do
11
12
mock_phrase_generation
16
17
let ( :project_hash ) { ActionController ::Parameters . new ( { } ) . merge ( user_id :) }
17
18
18
19
context 'with valid content' do
19
- subject ( :create_project_with_content ) { described_class . call ( project_hash :) }
20
+ subject ( :create_project_with_content ) { described_class . call ( project_hash :, current_user : ) }
20
21
21
22
let ( :project_hash ) do
22
23
{
Original file line number Diff line number Diff line change 29
29
expect ( response ) . to have_http_status ( :created )
30
30
end
31
31
32
- it 'generates an identifier for the project' do
33
- post ( '/api/projects' , headers :, params :)
32
+ it 'generates an identifier for the project even if another identifier is specified' do
33
+ params_with_identifier = { project : { identifier : 'test-identifier' , components : [ ] } }
34
+ post ( '/api/projects' , headers :, params : params_with_identifier )
34
35
data = JSON . parse ( response . body , symbolize_names : true )
35
36
36
37
expect ( data [ :identifier ] ) . to eq ( generated_identifier )
213
214
let ( :params ) do
214
215
{
215
216
project : {
217
+ identifier : 'test-project' ,
216
218
name : 'Test Project' ,
217
219
locale : 'fr' ,
218
220
project_type : Project ::Types ::SCRATCH ,
230
232
expect ( response ) . to have_http_status ( :created )
231
233
end
232
234
235
+ it 'sets the project identifier to the specified (not the generated) value' do
236
+ post ( '/api/projects' , headers :, params :)
237
+ data = JSON . parse ( response . body , symbolize_names : true )
238
+
239
+ expect ( data [ :identifier ] ) . to eq ( 'test-project' )
240
+ end
241
+
233
242
it 'sets the project name to the specified value' do
234
243
post ( '/api/projects' , headers :, params :)
235
244
data = JSON . parse ( response . body , symbolize_names : true )
You can’t perform that action at this time.
0 commit comments