Browse Source

Maintenance: GraphQL RSpec could allow indifferent access

Martin Gruner 4 months ago
parent
commit
bcfc3193cb

+ 1 - 1
spec/graphql/gql/mutations/admin_password_auth_verify_spec.rb

@@ -68,7 +68,7 @@ RSpec.describe Gql::Mutations::AdminPasswordAuthVerify, type: :graphql do
           let(:token) { Token.last.token }
 
           it 'returns the login' do
-            expect(gql.result.data['login']).to eq User.last.login
+            expect(gql.result.data[:login]).to eq User.last.login
           end
         end
       end

+ 33 - 31
spec/graphql/gql/mutations/channel/email/add_spec.rb

@@ -35,17 +35,17 @@ RSpec.describe Gql::Mutations::Channel::Email::Add, type: :graphql do
   end
   let(:inbound_configuration) do
     {
-      'adapter'       => 'imap',
-      'host'          => 'nonexisting.host.local',
-      'port'          => 993,
-      'ssl'           => 'ssl',
-      'user'          => 'some@example.com',
-      'password'      => 'password',
-      'folder'        => 'some_folder',
-      'keepOnServer'  => true,
-      'sslVerify'     => false,
-      'archive'       => true,
-      'archiveBefore' => '2012-03-04T00:00:00',
+      adapter:       'imap',
+      host:          'nonexisting.host.local',
+      port:          993,
+      ssl:           'ssl',
+      user:          'some@example.com',
+      password:      'password',
+      folder:        'some_folder',
+      keepOnServer:  true,
+      sslVerify:     false,
+      archive:       true,
+      archiveBefore: '2012-03-04T00:00:00',
     }
   end
   let(:group) { create(:group) }
@@ -53,11 +53,11 @@ RSpec.describe Gql::Mutations::Channel::Email::Add, type: :graphql do
   let(:variables) do
     {
       input: {
-        'inboundConfiguration' => inbound_configuration,
-        'outboundConfiguration' => outbound_configuration,
-        groupId: gql.id(group),
-        emailAddress: 'some.sender@example.com',
-        emailRealname: 'John Doe'
+        inboundConfiguration:  inbound_configuration,
+        outboundConfiguration: outbound_configuration,
+        groupId:               gql.id(group),
+        emailAddress:          'some.sender@example.com',
+        emailRealname:         'John Doe'
       }
     }
   end
@@ -70,8 +70,8 @@ RSpec.describe Gql::Mutations::Channel::Email::Add, type: :graphql do
     let(:admin) { create(:admin) }
     let(:options_outbound) do
       {
-        'adapter' => 'smtp',
-        'options' => {
+        adapter: 'smtp',
+        options: {
           host:       'nonexisting.host.local',
           port:       25,
           user:       'some@example.com',
@@ -82,24 +82,26 @@ RSpec.describe Gql::Mutations::Channel::Email::Add, type: :graphql do
     end
     let(:options_inbound) do
       {
-        'adapter' => 'imap',
-        'options' => {
-          'host'           => 'nonexisting.host.local',
-          'port'           => 993,
-          'ssl'            => 'ssl',
-          'user'           => 'some@example.com',
-          'password'       => 'password',
-          'folder'         => 'some_folder',
-          'keep_on_server' => true,
-          'ssl_verify'     => false,
-          'archive'        => true,
-          'archive_before' => '2012-03-04T00:00:00'.to_time, # rubocop:disable Rails/TimeZone
+        adapter: 'imap',
+        options: {
+          host:           'nonexisting.host.local',
+          port:           993,
+          ssl:            'ssl',
+          user:           'some@example.com',
+          password:       'password',
+          folder:         'some_folder',
+          keep_on_server: true,
+          ssl_verify:     false,
+          archive:        true,
+          archive_before: '2012-03-04T00:00:00'.to_time, # rubocop:disable Rails/TimeZone
         }
       }
     end
 
     it 'creates the channel' do
-      expect(gql.result.data['channel']).to include({ 'options' => include({ 'inbound' => options_inbound, 'outbound' => options_outbound }) })
+      expect(gql.result.data[:channel]).to include(options: include(
+        inbound: options_inbound, outbound: options_outbound
+      ))
     end
   end
 

+ 3 - 3
spec/graphql/gql/mutations/form/upload_cache/add_spec.rb

@@ -51,7 +51,7 @@ RSpec.describe Gql::Mutations::Form::UploadCache::Add, type: :graphql do
     end
 
     it 'creates Store entry' do
-      expect(gql.result.data['uploadedFiles']).to eq(expected_response)
+      expect(gql.result.data[:uploadedFiles]).to eq(expected_response)
     end
 
     it 'does not mark uploaded file as inline' do
@@ -65,7 +65,7 @@ RSpec.describe Gql::Mutations::Form::UploadCache::Add, type: :graphql do
         let(:inline) { true }
 
         it 'creates Store entry' do
-          expect(gql.result.data['uploadedFiles']).to eq(expected_response)
+          expect(gql.result.data[:uploadedFiles]).to eq(expected_response)
         end
 
         it 'marks uploaded file as inline' do
@@ -79,7 +79,7 @@ RSpec.describe Gql::Mutations::Form::UploadCache::Add, type: :graphql do
         let(:inline) { false }
 
         it 'creates Store entry' do
-          expect(gql.result.data['uploadedFiles']).to eq(expected_response)
+          expect(gql.result.data[:uploadedFiles]).to eq(expected_response)
         end
 
         it 'does not mark uploaded file as inline' do

+ 8 - 10
spec/graphql/gql/mutations/knowledge_base/answer/suggestion/content/transform_spec.rb

@@ -47,19 +47,17 @@ RSpec.describe Gql::Mutations::KnowledgeBase::Answer::Suggestion::Content::Trans
       let(:copied_attachments) { Store.list(object: 'UploadCache', o_id: '5570fac8-8868-40b7-89e7-1cdabbd954ba') }
 
       it 'converts inline images to base64 data' do
-        expect(gql.result.data['body']).to include('src="data:image/jpeg;base64,')
+        expect(gql.result.data[:body]).to include('src="data:image/jpeg;base64,')
       end
 
       it 'contains attachments' do
-        expect(gql.result.data['attachments']).to eq([
-                                                       {
-                                                         'id'          => Gql::ZammadSchema.id_from_object(copied_attachments.first),
-                                                         'name'        => copied_attachments.first.filename,
-                                                         'size'        => copied_attachments.first.size.to_i,
-                                                         'type'        => copied_attachments.first.preferences['Content-Type'],
-                                                         'preferences' => copied_attachments.first.preferences,
-                                                       },
-                                                     ])
+        expect(gql.result.data[:attachments]).to match_array(include(
+                                                               id:          Gql::ZammadSchema.id_from_object(copied_attachments.first),
+                                                               name:        copied_attachments.first.filename,
+                                                               size:        copied_attachments.first.size.to_i,
+                                                               type:        copied_attachments.first.preferences['Content-Type'],
+                                                               preferences: copied_attachments.first.preferences,
+                                                             ))
       end
 
       context 'with not existing translation' do

+ 3 - 3
spec/graphql/gql/mutations/link/add_spec.rb

@@ -61,7 +61,7 @@ RSpec.describe Gql::Mutations::Link::Add, :aggregate_failures, type: :graphql do
     it 'adds link' do
       expect { gql.execute(mutation, variables: variables) }
         .to change(Link, :count).by(1)
-      expect(gql.result.data['link']).to eq(
+      expect(gql.result.data[:link]).to eq(
         {
           'type' => type,
           'item' => { 'id' => gql.id(to), 'title' => to.title }
@@ -75,8 +75,8 @@ RSpec.describe Gql::Mutations::Link::Add, :aggregate_failures, type: :graphql do
       it 'returns error' do
         expect { gql.execute(mutation, variables: variables) }
           .not_to change(Link, :count)
-        expect(gql.result.data['link']).to be_nil
-        expect(gql.result.data['errors']).to contain_exactly(
+        expect(gql.result.data[:link]).to be_nil
+        expect(gql.result.data[:errors]).to contain_exactly(
           hash_including('message' => 'Link already exists', 'field' => nil)
         )
       end

+ 2 - 2
spec/graphql/gql/mutations/online_notification/mark_all_as_seen_spec.rb

@@ -49,7 +49,7 @@ RSpec.describe Gql::Mutations::OnlineNotification::MarkAllAsSeen, authenticated_
     end
 
     it 'returns touched notifications' do
-      expect(gql.result.data['onlineNotifications'])
+      expect(gql.result.data[:onlineNotifications])
         .to contain_exactly(
           include('id' => gql.id(notification_a)),
           include('id' => gql.id(notification_b))
@@ -65,7 +65,7 @@ RSpec.describe Gql::Mutations::OnlineNotification::MarkAllAsSeen, authenticated_
     end
 
     it 'returns empty rexponse' do
-      expect(gql.result.data['onlineNotifications']).to be_nil
+      expect(gql.result.data[:onlineNotifications]).to be_nil
     end
   end
 

+ 1 - 1
spec/graphql/gql/mutations/online_notification/seen_spec.rb

@@ -40,7 +40,7 @@ RSpec.describe Gql::Mutations::OnlineNotification::Seen, :aggregate_failures, ty
         end
 
         it 'marks the existing notification as seen' do
-          expect(gql.result.data['success']).to be true
+          expect(gql.result.data[:success]).to be true
           expect(notification.reload).to have_attributes(seen: true)
         end
 

+ 5 - 5
spec/graphql/gql/mutations/organization/update_spec.rb

@@ -49,7 +49,7 @@ RSpec.describe Gql::Mutations::Organization::Update, type: :graphql do
       let(:input_payload) { { name: 'NewName', objectAttributeValues: [] } }
 
       it 'returns updated organization name' do
-        expect(gql.result.data['organization']).to include('name' => 'NewName')
+        expect(gql.result.data[:organization]).to include('name' => 'NewName')
       end
     end
 
@@ -57,7 +57,7 @@ RSpec.describe Gql::Mutations::Organization::Update, type: :graphql do
       let(:input_payload) { { name: '' } }
 
       it 'returns a user error' do
-        expect(gql.result.data['errors'].first).to include('field' => 'name', 'message' => 'Dieses Feld darf nicht leer sein')
+        expect(gql.result.data[:errors].first).to include('field' => 'name', 'message' => 'Dieses Feld darf nicht leer sein')
       end
     end
 
@@ -66,7 +66,7 @@ RSpec.describe Gql::Mutations::Organization::Update, type: :graphql do
       let(:other_org)     { create(:organization) }
 
       it 'returns a user error' do
-        expect(gql.result.data['errors'].first).to include('field' => 'name', 'message' => 'Dieses Feld wird bereits verwendet.')
+        expect(gql.result.data[:errors].first).to include('field' => 'name', 'message' => 'Dieses Feld wird bereits verwendet.')
       end
     end
 
@@ -74,7 +74,7 @@ RSpec.describe Gql::Mutations::Organization::Update, type: :graphql do
       let(:input_payload) { { name: 'NewName' } }
 
       it 'returns updated organization name' do
-        expect(gql.result.data['organization']).to include('name' => 'NewName')
+        expect(gql.result.data[:organization]).to include('name' => 'NewName')
       end
     end
 
@@ -124,7 +124,7 @@ RSpec.describe Gql::Mutations::Organization::Update, type: :graphql do
       end
 
       it 'returns updated organization object attributes' do
-        oas = gql.result.data['organization']['objectAttributeValues']
+        oas = gql.result.data[:organization][:objectAttributeValues]
 
         expect(oas.map { |oa| { oa['attribute']['name'] => oa['value'] } }).to eq(
           [

+ 3 - 3
spec/graphql/gql/mutations/tag/assignment/add_spec.rb

@@ -36,13 +36,13 @@ RSpec.describe Gql::Mutations::Tag::Assignment::Add, :aggregate_failures, type:
 
     context 'with ticket write permission' do
       it 'adds the tag' do
-        expect(gql.result.data['success']).to be(true)
+        expect(gql.result.data[:success]).to be(true)
         expect(object.reload.tag_list).to eq([tag])
       end
 
       it 'adds an already assigned tag' do
         gql.execute(query, variables: variables)
-        expect(gql.result.data['success']).to be(true)
+        expect(gql.result.data[:success]).to be(true)
         expect(object.reload.tag_list).to eq([tag])
       end
     end
@@ -74,7 +74,7 @@ RSpec.describe Gql::Mutations::Tag::Assignment::Add, :aggregate_failures, type:
         let(:user)   { create(:admin) }
 
         it 'adds the tag' do
-          expect(gql.result.data['success']).to be(true)
+          expect(gql.result.data[:success]).to be(true)
           expect(object.reload.tag_list).to eq([tag])
         end
       end

+ 2 - 2
spec/graphql/gql/mutations/tag/assignment/remove_spec.rb

@@ -35,7 +35,7 @@ RSpec.describe Gql::Mutations::Tag::Assignment::Remove, :aggregate_failures, typ
 
     context 'with ticket write permission' do
       it 'removes the tag' do
-        expect(gql.result.data['success']).to be(true)
+        expect(gql.result.data[:success]).to be(true)
         expect(object.reload.tag_list).to eq([])
       end
 
@@ -43,7 +43,7 @@ RSpec.describe Gql::Mutations::Tag::Assignment::Remove, :aggregate_failures, typ
         let(:object) { create(:ticket) }
 
         it 'returns success nevertheless' do
-          expect(gql.result.data['success']).to be(true)
+          expect(gql.result.data[:success]).to be(true)
         end
       end
     end

Some files were not shown because too many files changed in this diff