2020-03-13 15:44:24 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
RSpec.describe 'Getting Grafana Integration' do
|
2020-03-13 15:44:24 +05:30
|
|
|
include GraphqlHelpers
|
|
|
|
|
|
|
|
let_it_be(:project) { create(:project, :repository) }
|
|
|
|
let_it_be(:current_user) { project.owner }
|
|
|
|
let_it_be(:grafana_integration) { create(:grafana_integration, project: project) }
|
|
|
|
|
|
|
|
let(:fields) do
|
|
|
|
<<~QUERY
|
|
|
|
#{all_graphql_fields_for('GrafanaIntegration'.classify)}
|
|
|
|
QUERY
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:query) do
|
|
|
|
graphql_query_for(
|
|
|
|
'project',
|
|
|
|
{ 'fullPath' => project.full_path },
|
|
|
|
query_graphql_field('grafanaIntegration', {}, fields)
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with grafana integration data' do
|
|
|
|
let(:integration_data) { graphql_data['project']['grafanaIntegration'] }
|
|
|
|
|
|
|
|
context 'without project admin permissions' do
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
project.add_developer(user)
|
|
|
|
post_graphql(query, current_user: user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'a working graphql query'
|
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
specify { expect(integration_data).to be nil }
|
2020-03-13 15:44:24 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
context 'with project admin permissions' do
|
|
|
|
before do
|
|
|
|
post_graphql(query, current_user: current_user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'a working graphql query'
|
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
specify { expect(integration_data['token']).to eql grafana_integration.masked_token }
|
|
|
|
specify { expect(integration_data['grafanaUrl']).to eql grafana_integration.grafana_url }
|
2020-03-13 15:44:24 +05:30
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
specify do
|
2020-03-13 15:44:24 +05:30
|
|
|
expect(
|
|
|
|
integration_data['createdAt']
|
|
|
|
).to eql grafana_integration.created_at.strftime('%Y-%m-%dT%H:%M:%SZ')
|
|
|
|
end
|
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
specify do
|
2020-03-13 15:44:24 +05:30
|
|
|
expect(
|
|
|
|
integration_data['updatedAt']
|
|
|
|
).to eql grafana_integration.updated_at.strftime('%Y-%m-%dT%H:%M:%SZ')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|