Skip to content

Commit

Permalink
Maintenance: GraphQL RSpec could allow indifferent access
Browse files Browse the repository at this point in the history
  • Loading branch information
mgruner committed Nov 5, 2024
1 parent 29540ed commit bcfc319
Show file tree
Hide file tree
Showing 56 changed files with 186 additions and 186 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
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
Expand Down
64 changes: 33 additions & 31 deletions spec/graphql/gql/mutations/channel/email/add_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,29 +35,29 @@
end
let(:inbound_configuration) do
{
'adapter' => 'imap',
'host' => 'nonexisting.host.local',
'port' => 993,
'ssl' => 'ssl',
'user' => '[email protected]',
'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: '[email protected]',
password: 'password',
folder: 'some_folder',
keepOnServer: true,
sslVerify: false,
archive: true,
archiveBefore: '2012-03-04T00:00:00',
}
end
let(:group) { create(:group) }

let(:variables) do
{
input: {
'inboundConfiguration' => inbound_configuration,
'outboundConfiguration' => outbound_configuration,
groupId: gql.id(group),
emailAddress: '[email protected]',
emailRealname: 'John Doe'
inboundConfiguration: inbound_configuration,
outboundConfiguration: outbound_configuration,
groupId: gql.id(group),
emailAddress: '[email protected]',
emailRealname: 'John Doe'
}
}
end
Expand All @@ -70,8 +70,8 @@
let(:admin) { create(:admin) }
let(:options_outbound) do
{
'adapter' => 'smtp',
'options' => {
adapter: 'smtp',
options: {
host: 'nonexisting.host.local',
port: 25,
user: '[email protected]',
Expand All @@ -82,24 +82,26 @@
end
let(:options_inbound) do
{
'adapter' => 'imap',
'options' => {
'host' => 'nonexisting.host.local',
'port' => 993,
'ssl' => 'ssl',
'user' => '[email protected]',
'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: '[email protected]',
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

Expand Down
6 changes: 3 additions & 3 deletions spec/graphql/gql/mutations/form/upload_cache/add_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
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
Expand All @@ -65,7 +65,7 @@
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
Expand All @@ -79,7 +79,7 @@
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,17 @@
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
Expand Down
6 changes: 3 additions & 3 deletions spec/graphql/gql/mutations/link/add_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
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 }
Expand All @@ -75,8 +75,8 @@
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
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))
Expand All @@ -65,7 +65,7 @@
end

it 'returns empty rexponse' do
expect(gql.result.data['onlineNotifications']).to be_nil
expect(gql.result.data[:onlineNotifications]).to be_nil
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
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

Expand Down
10 changes: 5 additions & 5 deletions spec/graphql/gql/mutations/organization/update_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@
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

context 'when updating organization with empty name' 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

Expand All @@ -66,15 +66,15 @@
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

context 'when updating organization name without attributes' 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

Expand Down Expand Up @@ -124,7 +124,7 @@
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(
[
Expand Down
6 changes: 3 additions & 3 deletions spec/graphql/gql/mutations/tag/assignment/add_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@

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
Expand Down Expand Up @@ -74,7 +74,7 @@
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
Expand Down
4 changes: 2 additions & 2 deletions spec/graphql/gql/mutations/tag/assignment/remove_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@

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

context 'when trying to remove a nonassigned tag' do
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
Expand Down
4 changes: 2 additions & 2 deletions spec/graphql/gql/mutations/tag/assignment/update_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@

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 match_array(tags_list)
end

it 'removes the tag' do
(tags_list + ['tag3']).each { |elem| object.tag_add elem }
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(tags_list)
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@

it 'works as expected' do
gql.execute(query, variables: variables)
expect(gql.result.data['quotableFrom']).to eq(expected_response)
expect(gql.result.data[:quotableFrom]).to eq(expected_response)
end
end

Expand All @@ -123,7 +123,7 @@

it 'works as expected' do
gql.execute(query, variables: variables)
expect(gql.result.data['quotableFrom']).to eq(expected_response)
expect(gql.result.data[:quotableFrom]).to eq(expected_response)
end
end
end
Expand All @@ -143,7 +143,7 @@

it 'works as expected' do
gql.execute(query, variables: variables)
expect(gql.result.data['quotableTo']).to eq(expected_response)
expect(gql.result.data[:quotableTo]).to eq(expected_response)
end
end

Expand All @@ -157,7 +157,7 @@

it 'works as expected' do
gql.execute(query, variables: variables)
expect(gql.result.data['quotableTo']).to eq(expected_response)
expect(gql.result.data[:quotableTo]).to eq(expected_response)
end
end

Expand All @@ -171,7 +171,7 @@

it 'works as expected' do
gql.execute(query, variables: variables)
expect(gql.result.data['quotableTo']).to eq(expected_response)
expect(gql.result.data[:quotableTo]).to eq(expected_response)
end
end

Expand All @@ -185,7 +185,7 @@

it 'works as expected' do
gql.execute(query, variables: variables)
expect(gql.result.data['quotableTo']).to eq(expected_response)
expect(gql.result.data[:quotableTo]).to eq(expected_response)
end
end
end
Expand All @@ -200,7 +200,7 @@

it 'works as expected' do
gql.execute(query, variables: variables)
expect(gql.result.data['quotableCc']).to eq(expected_response)
expect(gql.result.data[:quotableCc]).to eq(expected_response)
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
it 'creates the attachment' do
expect_any_instance_of(Whatsapp::Retry::Media).to receive(:process).and_return(true) # rubocop:disable RSpec/StubbedMock
gql.execute(query, variables: variables)
expect(gql.result.data['success']).to be true
expect(gql.result.data[:success]).to be true
end
end

Expand All @@ -47,8 +47,8 @@
article.preferences.delete(:whatsapp)
article.save!
gql.execute(query, variables: variables)
expect(gql.result.data['success']).not_to be true
expect(gql.result.data['errors'].first).to include(
expect(gql.result.data[:success]).not_to be true
expect(gql.result.data[:errors].first).to include(
{ 'message' => 'Retrying to download the sent media via WhatsApp failed. The given article is not a media article.' }
)
end
Expand Down
Loading

0 comments on commit bcfc319

Please sign in to comment.