2020-09-10 08:08:54 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
RSpec.describe 'InstanceStatisticsMeasurements' do
|
|
|
|
include GraphqlHelpers
|
|
|
|
|
|
|
|
let(:current_user) { create(:user, :admin) }
|
|
|
|
let!(:instance_statistics_measurement_1) { create(:instance_statistics_measurement, :project_count, recorded_at: 20.days.ago, count: 5) }
|
|
|
|
let!(:instance_statistics_measurement_2) { create(:instance_statistics_measurement, :project_count, recorded_at: 10.days.ago, count: 10) }
|
|
|
|
|
2020-11-03 10:09:05 -05:00
|
|
|
let(:arguments) { 'identifier: PROJECTS' }
|
|
|
|
let(:query) { graphql_query_for(:instanceStatisticsMeasurements, arguments, 'nodes { count identifier }') }
|
2020-09-10 08:08:54 -04:00
|
|
|
|
|
|
|
before do
|
|
|
|
post_graphql(query, current_user: current_user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns measurement objects' do
|
2020-10-07 14:08:34 -04:00
|
|
|
expect(graphql_data.dig('instanceStatisticsMeasurements', 'nodes')).to eq([
|
|
|
|
{ "count" => 10, 'identifier' => 'PROJECTS' },
|
|
|
|
{ "count" => 5, 'identifier' => 'PROJECTS' }
|
|
|
|
])
|
2020-09-10 08:08:54 -04:00
|
|
|
end
|
2020-11-03 10:09:05 -05:00
|
|
|
|
|
|
|
context 'with recorded_at filters' do
|
|
|
|
let(:arguments) { %(identifier: PROJECTS, recordedAfter: "#{15.days.ago.to_date}", recordedBefore: "#{5.days.ago.to_date}") }
|
|
|
|
|
|
|
|
it 'returns filtered measurement objects' do
|
|
|
|
expect(graphql_data.dig('instanceStatisticsMeasurements', 'nodes')).to eq([
|
|
|
|
{ "count" => 10, 'identifier' => 'PROJECTS' }
|
|
|
|
])
|
|
|
|
end
|
|
|
|
end
|
2020-09-10 08:08:54 -04:00
|
|
|
end
|