From 2cc23fe9f2eb9ec14baf43ef972215a2ae0d4fe6 Mon Sep 17 00:00:00 2001 From: loiswells97 Date: Wed, 8 Mar 2023 16:06:50 +0000 Subject: [PATCH 01/12] Create draft PR for #152 From 0a192ab9d50f1c4ebe4d25059f7d6aba6b8939a4 Mon Sep 17 00:00:00 2001 From: Lois Wells Date: Wed, 8 Mar 2023 17:36:38 +0000 Subject: [PATCH 02/12] WIP: Remix mutation --- app/graphql/mutations/remix_project.rb | 41 +++++++++++++++++++ app/graphql/types/mutation_type.rb | 1 + app/graphql/types/remix_project_input_type.rb | 12 ++++++ 3 files changed, 54 insertions(+) create mode 100644 app/graphql/mutations/remix_project.rb create mode 100644 app/graphql/types/remix_project_input_type.rb diff --git a/app/graphql/mutations/remix_project.rb b/app/graphql/mutations/remix_project.rb new file mode 100644 index 000000000..86c87cc8a --- /dev/null +++ b/app/graphql/mutations/remix_project.rb @@ -0,0 +1,41 @@ +# frozen_string_literal: true + +module Mutations + class RemixProject < BaseMutation + description 'A mutation to remix an existing project' + input_object_class Types::RemixProjectInputType + + field :project, Types::ProjectType, description: 'The project that has been created' + + def resolve(**input) + # project = GlobalID.find(input[:id]) + project = Project.find_by(identifier: input[:identifier], locale: input[:locale]) + + unless context[:current_ability]&.can?(:read, project) + raise GraphQL::ExecutionError, 'You are not permitted to read that project' + end + + remix_params = { + project: { + name: project.name, + identifier: project.identifier, + components: project.components + } + } + response = Project::Remix.call(remix_params: remix_params, user_id: context[:current_user_id], project: project) + raise GraphQL::ExecutionError, response[:error] unless response.success? + + { project: response[:project] } + end + + def ready?(**_args) + return true if can_create_project? + + raise GraphQL::ExecutionError, 'You are not permitted to create a project' + end + + def can_create_project? + context[:current_ability]&.can?(:create, Project, user_id: context[:current_user_id]) + end + end +end diff --git a/app/graphql/types/mutation_type.rb b/app/graphql/types/mutation_type.rb index 547693db6..2e54e9fd6 100644 --- a/app/graphql/types/mutation_type.rb +++ b/app/graphql/types/mutation_type.rb @@ -5,5 +5,6 @@ class MutationType < Types::BaseObject field :create_project, mutation: Mutations::CreateProject, description: 'Create a project, complete with components' field :delete_project, mutation: Mutations::DeleteProject, description: 'Delete an existing project' field :update_project, mutation: Mutations::UpdateProject, description: 'Update fields on an existing project' + field :remix_project, mutation: Mutations::RemixProject, description: 'Remix a project' end end diff --git a/app/graphql/types/remix_project_input_type.rb b/app/graphql/types/remix_project_input_type.rb new file mode 100644 index 000000000..91bb9d45d --- /dev/null +++ b/app/graphql/types/remix_project_input_type.rb @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +module Types + class RemixProjectInputType < Types::BaseInputObject + description 'Represents a project during a remix' + + argument :identifier, String, required: true, description: 'The identifier of the project to remix' + argument :locale, String, required: true, description: 'The locale of the project to be remixed' + argument :name, String, required: false, description: 'The name of the project' + argument :project_type, String, required: false, description: 'The type of project, e.g. python, html' + end +end From 75c15591526525dc50a1baf18c58e712a0ca3fe5 Mon Sep 17 00:00:00 2001 From: Lois Wells Date: Thu, 9 Mar 2023 09:43:40 +0000 Subject: [PATCH 03/12] Getting remix mutation working --- app/graphql/mutations/remix_project.rb | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/app/graphql/mutations/remix_project.rb b/app/graphql/mutations/remix_project.rb index 86c87cc8a..f9ea418b9 100644 --- a/app/graphql/mutations/remix_project.rb +++ b/app/graphql/mutations/remix_project.rb @@ -8,21 +8,20 @@ class RemixProject < BaseMutation field :project, Types::ProjectType, description: 'The project that has been created' def resolve(**input) - # project = GlobalID.find(input[:id]) project = Project.find_by(identifier: input[:identifier], locale: input[:locale]) - unless context[:current_ability]&.can?(:read, project) - raise GraphQL::ExecutionError, 'You are not permitted to read that project' - end + # unless context[:current_ability]&.can?(:read, project) + # pp context[:current_ability] + # pp context[:current_user_id] + # raise GraphQL::ExecutionError, 'You are not permitted to read that project' + # end remix_params = { - project: { - name: project.name, - identifier: project.identifier, - components: project.components - } + name: project.name, + identifier: project.identifier, + components: project.components } - response = Project::Remix.call(remix_params: remix_params, user_id: context[:current_user_id], project: project) + response = Project::CreateRemix.call(params: remix_params, user_id: context[:current_user_id], original_project: project) raise GraphQL::ExecutionError, response[:error] unless response.success? { project: response[:project] } From c30f557d181d40e48fb4840149102e12bcbf639a Mon Sep 17 00:00:00 2001 From: Lois Wells Date: Thu, 9 Mar 2023 12:06:48 +0000 Subject: [PATCH 04/12] getting remix working with modified components --- app/graphql/mutations/remix_project.rb | 25 +++++++++---------- app/graphql/types/remix_project_input_type.rb | 5 ++-- .../project/operations/create_remix.rb | 5 +++- 3 files changed, 18 insertions(+), 17 deletions(-) diff --git a/app/graphql/mutations/remix_project.rb b/app/graphql/mutations/remix_project.rb index f9ea418b9..186eda133 100644 --- a/app/graphql/mutations/remix_project.rb +++ b/app/graphql/mutations/remix_project.rb @@ -8,20 +8,19 @@ class RemixProject < BaseMutation field :project, Types::ProjectType, description: 'The project that has been created' def resolve(**input) - project = Project.find_by(identifier: input[:identifier], locale: input[:locale]) - - # unless context[:current_ability]&.can?(:read, project) - # pp context[:current_ability] - # pp context[:current_user_id] - # raise GraphQL::ExecutionError, 'You are not permitted to read that project' - # end - - remix_params = { - name: project.name, - identifier: project.identifier, - components: project.components + original_project = GlobalID.find(input[:id]) + raise GraphQL::ExecutionError, 'Project not found' unless original_project + + unless context[:current_ability]&.can?(:show, original_project) + raise GraphQL::ExecutionError, 'You are not permitted to read that project' + end + + params = { + name: input[:name], + identifier: original_project.identifier, + components: input[:components].map{|component| component.to_h} } - response = Project::CreateRemix.call(params: remix_params, user_id: context[:current_user_id], original_project: project) + response = Project::CreateRemix.call(params: params, user_id: context[:current_user_id], original_project: original_project) raise GraphQL::ExecutionError, response[:error] unless response.success? { project: response[:project] } diff --git a/app/graphql/types/remix_project_input_type.rb b/app/graphql/types/remix_project_input_type.rb index 91bb9d45d..afc488bdf 100644 --- a/app/graphql/types/remix_project_input_type.rb +++ b/app/graphql/types/remix_project_input_type.rb @@ -4,9 +4,8 @@ module Types class RemixProjectInputType < Types::BaseInputObject description 'Represents a project during a remix' - argument :identifier, String, required: true, description: 'The identifier of the project to remix' - argument :locale, String, required: true, description: 'The locale of the project to be remixed' + argument :id, String, required: true, description: 'The ID of the project to update' argument :name, String, required: false, description: 'The name of the project' - argument :project_type, String, required: false, description: 'The type of project, e.g. python, html' + argument :components, [Types::ProjectComponentInputType], required: false, description: 'Any project components' end end diff --git a/lib/concepts/project/operations/create_remix.rb b/lib/concepts/project/operations/create_remix.rb index 38a9cdf2c..efd5d2a4b 100644 --- a/lib/concepts/project/operations/create_remix.rb +++ b/lib/concepts/project/operations/create_remix.rb @@ -12,6 +12,7 @@ def call(params:, user_id:, original_project:) remix_project(response, params, user_id, original_project) if response.success? response rescue StandardError => e + raise e Sentry.capture_exception(e) response[:error] = I18n.t('errors.project.remixing.cannot_save') response @@ -26,12 +27,14 @@ def validate_params(response, params, user_id, original_project) def remix_project(response, params, user_id, original_project) response[:project] = create_remix(original_project, params, user_id) - + puts 'trying to save' + pp response[:project] response[:project].save! response end def create_remix(original_project, params, user_id) + puts 'formatting remix' remix = original_project.dup.tap do |proj| proj.user_id = user_id proj.remixed_from_id = original_project.id From ffcb9f2577aa5db170ac8fa78f418805a19d3cab Mon Sep 17 00:00:00 2001 From: Lois Wells Date: Thu, 9 Mar 2023 12:09:31 +0000 Subject: [PATCH 05/12] tidying --- app/graphql/mutations/remix_project.rb | 4 ++-- lib/concepts/project/operations/create_remix.rb | 3 --- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/app/graphql/mutations/remix_project.rb b/app/graphql/mutations/remix_project.rb index 186eda133..74507d8a3 100644 --- a/app/graphql/mutations/remix_project.rb +++ b/app/graphql/mutations/remix_project.rb @@ -16,9 +16,9 @@ def resolve(**input) end params = { - name: input[:name], + name: input[:name] || original_project.name, identifier: original_project.identifier, - components: input[:components].map{|component| component.to_h} + components: input[:components].map{|component| component.to_h} || original_project.components } response = Project::CreateRemix.call(params: params, user_id: context[:current_user_id], original_project: original_project) raise GraphQL::ExecutionError, response[:error] unless response.success? diff --git a/lib/concepts/project/operations/create_remix.rb b/lib/concepts/project/operations/create_remix.rb index 3050c5bb8..e008b1a9d 100644 --- a/lib/concepts/project/operations/create_remix.rb +++ b/lib/concepts/project/operations/create_remix.rb @@ -12,7 +12,6 @@ def call(params:, user_id:, original_project:) remix_project(response, params, user_id, original_project) if response.success? response rescue StandardError => e - raise e Sentry.capture_exception(e) response[:error] = I18n.t('errors.project.remixing.cannot_save') response @@ -27,8 +26,6 @@ def validate_params(response, params, user_id, original_project) def remix_project(response, params, user_id, original_project) response[:project] = create_remix(original_project, params, user_id) - puts 'trying to save' - pp response[:project] response[:project].save! response end From a1d158d2e856ca50a7d1dc3cffb6b33c5af58e9f Mon Sep 17 00:00:00 2001 From: Lois Wells Date: Thu, 9 Mar 2023 12:19:11 +0000 Subject: [PATCH 06/12] fix remix rename bug --- lib/concepts/project/operations/create_remix.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/concepts/project/operations/create_remix.rb b/lib/concepts/project/operations/create_remix.rb index e008b1a9d..37cd96234 100644 --- a/lib/concepts/project/operations/create_remix.rb +++ b/lib/concepts/project/operations/create_remix.rb @@ -31,7 +31,7 @@ def remix_project(response, params, user_id, original_project) end def create_remix(original_project, params, user_id) - remix = format_project(original_project, user_id) + remix = format_project(original_project, params, user_id) original_project.images.each do |image| remix.images.attach(image.blob) @@ -44,8 +44,9 @@ def create_remix(original_project, params, user_id) remix end - def format_project(original_project, user_id) + def format_project(original_project, params, user_id) original_project.dup.tap do |proj| + proj.name = params[:name] proj.user_id = user_id proj.remixed_from_id = original_project.id proj.identifier = PhraseIdentifier.generate From 4b7d4f26c9f0d4410bb76840d7a461aa986c5685 Mon Sep 17 00:00:00 2001 From: Lois Wells Date: Thu, 9 Mar 2023 12:25:41 +0000 Subject: [PATCH 07/12] more tidying --- lib/concepts/project/operations/create_remix.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/concepts/project/operations/create_remix.rb b/lib/concepts/project/operations/create_remix.rb index 37cd96234..10a3dda5b 100644 --- a/lib/concepts/project/operations/create_remix.rb +++ b/lib/concepts/project/operations/create_remix.rb @@ -46,11 +46,11 @@ def create_remix(original_project, params, user_id) def format_project(original_project, params, user_id) original_project.dup.tap do |proj| + proj.identifier = PhraseIdentifier.generate + proj.locale = nil proj.name = params[:name] proj.user_id = user_id proj.remixed_from_id = original_project.id - proj.identifier = PhraseIdentifier.generate - proj.locale = nil end end end From b5969f771df9b876dafde6c9e747c2ad0178a82b Mon Sep 17 00:00:00 2001 From: Lois Wells Date: Thu, 9 Mar 2023 12:49:19 +0000 Subject: [PATCH 08/12] some tidying and test fixing --- app/graphql/mutations/remix_project.rb | 2 +- app/graphql/types/remix_project_input_type.rb | 6 +-- db/schema.graphql | 50 +++++++++++++++++++ spec/concepts/project/create_remix_spec.rb | 11 ++-- 4 files changed, 62 insertions(+), 7 deletions(-) diff --git a/app/graphql/mutations/remix_project.rb b/app/graphql/mutations/remix_project.rb index 74507d8a3..956732b90 100644 --- a/app/graphql/mutations/remix_project.rb +++ b/app/graphql/mutations/remix_project.rb @@ -18,7 +18,7 @@ def resolve(**input) params = { name: input[:name] || original_project.name, identifier: original_project.identifier, - components: input[:components].map{|component| component.to_h} || original_project.components + components: input[:components] ? input[:components]&.map(&:to_h) : original_project.components } response = Project::CreateRemix.call(params: params, user_id: context[:current_user_id], original_project: original_project) raise GraphQL::ExecutionError, response[:error] unless response.success? diff --git a/app/graphql/types/remix_project_input_type.rb b/app/graphql/types/remix_project_input_type.rb index afc488bdf..977461be6 100644 --- a/app/graphql/types/remix_project_input_type.rb +++ b/app/graphql/types/remix_project_input_type.rb @@ -4,8 +4,8 @@ module Types class RemixProjectInputType < Types::BaseInputObject description 'Represents a project during a remix' - argument :id, String, required: true, description: 'The ID of the project to update' - argument :name, String, required: false, description: 'The name of the project' - argument :components, [Types::ProjectComponentInputType], required: false, description: 'Any project components' + argument :id, String, required: true, description: 'The ID of the project to remix' + argument :name, String, required: false, description: 'The name of the remixed project' + argument :components, [Types::ProjectComponentInputType], required: false, description: 'The components of the remixed project' end end diff --git a/db/schema.graphql b/db/schema.graphql index 84719db7a..3537326da 100644 --- a/db/schema.graphql +++ b/db/schema.graphql @@ -239,6 +239,16 @@ type Mutation { input: DeleteProjectInput! ): DeleteProjectPayload + """ + Remix a project + """ + remixProject( + """ + Parameters for RemixProject + """ + input: RemixProjectInput! + ): RemixProjectPayload + """ Update fields on an existing project """ @@ -512,6 +522,46 @@ type Query { ): ProjectConnection } +""" +Represents a project during a remix +""" +input RemixProjectInput { + """ + A unique identifier for the client performing the mutation. + """ + clientMutationId: String + + """ + The components of the remixed project + """ + components: [ProjectComponentInput!] + + """ + The ID of the project to remix + """ + id: String! + + """ + The name of the remixed project + """ + name: String +} + +""" +Autogenerated return type of RemixProject. +""" +type RemixProjectPayload { + """ + A unique identifier for the client performing the mutation. + """ + clientMutationId: String + + """ + The project that has been created + """ + project: Project +} + """ Represents a project during an update """ diff --git a/spec/concepts/project/create_remix_spec.rb b/spec/concepts/project/create_remix_spec.rb index 058fe4816..21cd21d65 100644 --- a/spec/concepts/project/create_remix_spec.rb +++ b/spec/concepts/project/create_remix_spec.rb @@ -10,7 +10,7 @@ let(:remix_params) do component = original_project.components.first { - name: original_project.name, + name: 'My remixed project', identifier: original_project.identifier, components: [ { @@ -50,6 +50,11 @@ expect(remixed_project.locale).to be_nil end + it 'renames the project' do + remixed_project = create_remix[:project] + expect(remixed_project.name).to eq('My remixed project') + end + it 'assigns user_id to new project' do remixed_project = create_remix[:project] expect(remixed_project.user_id).to eq(user_id) @@ -58,8 +63,8 @@ it 'duplicates properties on new project' do remixed_project = create_remix[:project] - remixed_attrs = remixed_project.attributes.symbolize_keys.slice(:name, :project_type) - original_attrs = original_project.attributes.symbolize_keys.slice(:name, :project_type) + remixed_attrs = remixed_project.attributes.symbolize_keys.slice(:project_type) + original_attrs = original_project.attributes.symbolize_keys.slice(:project_type) expect(remixed_attrs).to eq(original_attrs) end From a3eba74257672edc940a8d7c3f70272d6ac62144 Mon Sep 17 00:00:00 2001 From: Lois Wells Date: Thu, 9 Mar 2023 17:13:57 +0000 Subject: [PATCH 09/12] rubocop fixes --- app/graphql/mutations/remix_project.rb | 18 ++++++++++++------ app/graphql/types/mutation_type.rb | 2 +- app/graphql/types/remix_project_input_type.rb | 4 +++- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/app/graphql/mutations/remix_project.rb b/app/graphql/mutations/remix_project.rb index 956732b90..316e8193a 100644 --- a/app/graphql/mutations/remix_project.rb +++ b/app/graphql/mutations/remix_project.rb @@ -10,17 +10,15 @@ class RemixProject < BaseMutation def resolve(**input) original_project = GlobalID.find(input[:id]) raise GraphQL::ExecutionError, 'Project not found' unless original_project - - unless context[:current_ability]&.can?(:show, original_project) - raise GraphQL::ExecutionError, 'You are not permitted to read that project' - end + raise GraphQL::ExecutionError, 'You are not permitted to read this project' unless can_read?(original_project) params = { name: input[:name] || original_project.name, identifier: original_project.identifier, - components: input[:components] ? input[:components]&.map(&:to_h) : original_project.components + components: remix_components(input, original_project) } - response = Project::CreateRemix.call(params: params, user_id: context[:current_user_id], original_project: original_project) + response = Project::CreateRemix.call(params:, user_id: context[:current_user_id], + original_project:) raise GraphQL::ExecutionError, response[:error] unless response.success? { project: response[:project] } @@ -35,5 +33,13 @@ def ready?(**_args) def can_create_project? context[:current_ability]&.can?(:create, Project, user_id: context[:current_user_id]) end + + def can_read?(original_project) + context[:current_ability]&.can?(:show, original_project) + end + + def remix_components(input, original_project) + input[:components] ? input[:components]&.map(&:to_h) : original_project.components + end end end diff --git a/app/graphql/types/mutation_type.rb b/app/graphql/types/mutation_type.rb index 2e54e9fd6..0bae85f7e 100644 --- a/app/graphql/types/mutation_type.rb +++ b/app/graphql/types/mutation_type.rb @@ -4,7 +4,7 @@ module Types class MutationType < Types::BaseObject field :create_project, mutation: Mutations::CreateProject, description: 'Create a project, complete with components' field :delete_project, mutation: Mutations::DeleteProject, description: 'Delete an existing project' - field :update_project, mutation: Mutations::UpdateProject, description: 'Update fields on an existing project' field :remix_project, mutation: Mutations::RemixProject, description: 'Remix a project' + field :update_project, mutation: Mutations::UpdateProject, description: 'Update fields on an existing project' end end diff --git a/app/graphql/types/remix_project_input_type.rb b/app/graphql/types/remix_project_input_type.rb index 977461be6..ab9ddda3c 100644 --- a/app/graphql/types/remix_project_input_type.rb +++ b/app/graphql/types/remix_project_input_type.rb @@ -4,8 +4,10 @@ module Types class RemixProjectInputType < Types::BaseInputObject description 'Represents a project during a remix' + argument :components, [Types::ProjectComponentInputType], + required: false, + description: 'The components of the remixed project' argument :id, String, required: true, description: 'The ID of the project to remix' argument :name, String, required: false, description: 'The name of the remixed project' - argument :components, [Types::ProjectComponentInputType], required: false, description: 'The components of the remixed project' end end From 1d8c3d1de62b626ec51131a9e200aab316ab3684 Mon Sep 17 00:00:00 2001 From: Lois Wells Date: Thu, 9 Mar 2023 17:14:19 +0000 Subject: [PATCH 10/12] Adding tests for remix mutation --- .../mutations/remix_project_mutation_spec.rb | 120 ++++++++++++++++++ 1 file changed, 120 insertions(+) create mode 100644 spec/graphql/mutations/remix_project_mutation_spec.rb diff --git a/spec/graphql/mutations/remix_project_mutation_spec.rb b/spec/graphql/mutations/remix_project_mutation_spec.rb new file mode 100644 index 000000000..30a38a61d --- /dev/null +++ b/spec/graphql/mutations/remix_project_mutation_spec.rb @@ -0,0 +1,120 @@ +# frozen_string_literal: true + +require 'rails_helper' + +RSpec.describe 'mutation RemixProject() { ... }' do + subject(:result) { execute_query(query: mutation, variables:) } + + let(:mutation) { 'mutation RemixProject($id: String!, $name: String, $components: [ProjectComponentInput!]) { + remixProject(input: { id: $id, name: $name, components: $components }) { + project { + id + } + } + } + ' } + let(:project) { create(:project, :with_default_component, user_id: SecureRandom.uuid) } + let(:project_id) { project.to_gid_param } + let(:variables) {{id: project_id}} + + before do + project + end + + it { expect(mutation).to be_a_valid_graphql_query } + + context 'when unauthenticated' do + let(:current_user_id) { nil } + + it 'does not create a project' do + expect { result }.not_to change(Project, :count) + end + + it 'returns "not permitted to create" error' do + expect(result.dig('errors', 0, 'message')).to match(/not permitted to create/) + end + end + + context 'when original project not found' do + let(:project_id) { SecureRandom.uuid } + let(:current_user_id) { SecureRandom.uuid } + + it 'returns "not found" error' do + expect(result.dig('errors', 0, 'message')).to match(/not found/) + end + + it 'does not create a project' do + expect { result }.not_to change(Project, :count) + end + end + + context 'when user cannot view original project' do + let(:current_user_id) { SecureRandom.uuid } + + it 'returns "not permitted to read" error' do + expect(result.dig('errors', 0, 'message')).to match(/not permitted to read/) + end + + it 'does not create a project' do + expect { result }.not_to change(Project, :count) + end + end + + context 'when authenticated and project exists' do + let(:current_user_id) { project.user_id } + let(:returned_gid) { result.dig('data', 'remixProject', 'project', 'id') } + let(:remixed_project) { GlobalID.find(returned_gid) } + + + it 'creates a project' do + expect { result }.to change(Project, :count).by(1) + end + + it 'returns graphql id for remixed project' do + expect(returned_gid).to eq Project.order(created_at: :asc).last.to_gid_param + end + + context 'when name and components not specified' do + + it 'uses original project name' do + expect(remixed_project.name).to eq(project.name) + end + + it 'uses original project components' do + expect(remixed_project.components[0].content).to eq(project.components[0].content) + end + end + + context 'when name and components specified' do + before do + variables[:name] = 'My amazing remix' + variables[:components] = [ + { + name: "main", + extension: "py", + default: true, + content: "print('this is amazing')" + } + ] + end + + it 'updates remixed project name if given' do + expect(remixed_project.name).to eq(variables[:name]) + end + + it 'updates remixed project components if given' do + expect(remixed_project.components[0].content).to eq(variables[:components][0][:content]) + end + end + + context 'when project creation fails' do + before do + allow(Project::CreateRemix).to receive(:call).and_return(OperationResponse[error: 'Something went wrong']) + end + + it 'returns an error' do + expect(result.dig('errors', 0, 'message')).to eq 'Something went wrong' + end + end + end +end From 0203de60bbff33b76c8dd96664181cbbdb94557f Mon Sep 17 00:00:00 2001 From: Lois Wells Date: Thu, 9 Mar 2023 17:17:23 +0000 Subject: [PATCH 11/12] more rubocop fixes --- .../mutations/remix_project_mutation_spec.rb | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/spec/graphql/mutations/remix_project_mutation_spec.rb b/spec/graphql/mutations/remix_project_mutation_spec.rb index 30a38a61d..428879338 100644 --- a/spec/graphql/mutations/remix_project_mutation_spec.rb +++ b/spec/graphql/mutations/remix_project_mutation_spec.rb @@ -5,17 +5,19 @@ RSpec.describe 'mutation RemixProject() { ... }' do subject(:result) { execute_query(query: mutation, variables:) } - let(:mutation) { 'mutation RemixProject($id: String!, $name: String, $components: [ProjectComponentInput!]) { + let(:mutation) do + 'mutation RemixProject($id: String!, $name: String, $components: [ProjectComponentInput!]) { remixProject(input: { id: $id, name: $name, components: $components }) { project { id } } } - ' } + ' + end let(:project) { create(:project, :with_default_component, user_id: SecureRandom.uuid) } let(:project_id) { project.to_gid_param } - let(:variables) {{id: project_id}} + let(:variables) { { id: project_id } } before do project @@ -65,7 +67,6 @@ let(:returned_gid) { result.dig('data', 'remixProject', 'project', 'id') } let(:remixed_project) { GlobalID.find(returned_gid) } - it 'creates a project' do expect { result }.to change(Project, :count).by(1) end @@ -75,7 +76,6 @@ end context 'when name and components not specified' do - it 'uses original project name' do expect(remixed_project.name).to eq(project.name) end @@ -90,8 +90,8 @@ variables[:name] = 'My amazing remix' variables[:components] = [ { - name: "main", - extension: "py", + name: 'main', + extension: 'py', default: true, content: "print('this is amazing')" } From 40ac5522289f719b02ea230d82541abadf10cd90 Mon Sep 17 00:00:00 2001 From: Lois Wells Date: Fri, 10 Mar 2023 09:17:24 +0000 Subject: [PATCH 12/12] tidying --- app/graphql/mutations/remix_project.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/graphql/mutations/remix_project.rb b/app/graphql/mutations/remix_project.rb index 316e8193a..9ff9db36f 100644 --- a/app/graphql/mutations/remix_project.rb +++ b/app/graphql/mutations/remix_project.rb @@ -39,7 +39,7 @@ def can_read?(original_project) end def remix_components(input, original_project) - input[:components] ? input[:components]&.map(&:to_h) : original_project.components + input[:components]&.map(&:to_h) || original_project.components end end end