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 @@ -28,7 +28,7 @@ def show
2828 end
2929
3030 def create
31- result = Project ::Create . call ( project_hash : project_params )
31+ result = Project ::Create . call ( project_hash : project_params , current_user : )
3232
3333 if result . success?
3434 @project = result [ :project ]
Original file line number Diff line number Diff line change @@ -13,7 +13,7 @@ def resolve(**input)
1313 components : input [ :components ] &.map ( &:to_h )
1414 )
1515
16- response = Project ::Create . call ( project_hash :)
16+ response = Project ::Create . call ( project_hash :, current_user : context [ :current_user ] )
1717 raise GraphQL ::ExecutionError , response [ :error ] unless response . success?
1818
1919 { project : response [ :project ] }
Original file line number Diff line number Diff line change 33class Project
44 class Create
55 class << self
6- def call ( project_hash :)
6+ def call ( project_hash :, current_user : )
77 response = OperationResponse . new
8- response [ :project ] = build_project ( project_hash )
8+ response [ :project ] = build_project ( project_hash , current_user )
99 response [ :project ] . save!
1010 response
1111 rescue StandardError => e
@@ -16,9 +16,9 @@ def call(project_hash:)
1616
1717 private
1818
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 ) )
2222 new_project . components . build ( project_hash [ :components ] )
2323 new_project
2424 end
Original file line number Diff line number Diff line change 33require 'rails_helper'
44
55RSpec . 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 : ) }
77
8- let ( :user_id ) { 'e0675b6c-dc48-4cd6-8c04-0f7ac05af51a' }
8+ let ( :current_user ) { create ( :user ) }
9+ let ( :user_id ) { current_user . id }
910
1011 before do
1112 mock_phrase_generation
1617 let ( :project_hash ) { ActionController ::Parameters . new ( { } ) . merge ( user_id :) }
1718
1819 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 : ) }
2021
2122 let ( :project_hash ) do
2223 {
Original file line number Diff line number Diff line change 2929 expect ( response ) . to have_http_status ( :created )
3030 end
3131
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 )
3435 data = JSON . parse ( response . body , symbolize_names : true )
3536
3637 expect ( data [ :identifier ] ) . to eq ( generated_identifier )
213214 let ( :params ) do
214215 {
215216 project : {
217+ identifier : 'test-project' ,
216218 name : 'Test Project' ,
217219 locale : 'fr' ,
218220 project_type : Project ::Types ::SCRATCH ,
230232 expect ( response ) . to have_http_status ( :created )
231233 end
232234
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+
233242 it 'sets the project name to the specified value' do
234243 post ( '/api/projects' , headers :, params :)
235244 data = JSON . parse ( response . body , symbolize_names : true )
You can’t perform that action at this time.
0 commit comments