Commit fe1dd4ec authored by Tyler Amos's avatar Tyler Amos

Test real field values for GraphQL LicenseType

Using resolve_field Graphql helper method to test actual values of
fields defined bye LicenseType and CurrentLicenseType.
parent 375b33e3
......@@ -3,7 +3,10 @@
require 'spec_helper'
RSpec.describe GitlabSchema.types['CurrentLicense'], :enable_admin_mode do
include GraphqlHelpers
let_it_be(:admin) { create(:admin) }
let_it_be(:last_synced_at) { DateTime.current - 1.day }
let_it_be(:licensee) do
{
'Name' => 'User Example',
......@@ -12,7 +15,14 @@ RSpec.describe GitlabSchema.types['CurrentLicense'], :enable_admin_mode do
}
end
let_it_be(:license) { create_current_license(licensee: licensee, cloud_licensing_enabled: true) }
let_it_be(:license) do
create_current_license(
licensee: licensee,
cloud_licensing_enabled: true,
last_synced_at: last_synced_at,
next_sync_at: last_synced_at + 1.day
)
end
let(:fields) do
%w[last_sync billable_users_count maximum_user_count users_over_license_count]
......@@ -61,4 +71,34 @@ RSpec.describe GitlabSchema.types['CurrentLicense'], :enable_admin_mode do
expect(result_as_json['data']['currentLicense']['usersOverLicenseCount']).to eq(5)
end
end
describe 'field values' do
subject { resolve_field(field_name, license) }
describe 'last_sync' do
let(:field_name) { :last_sync }
it { is_expected.to eq(last_synced_at.change(usec: 0)) }
end
describe 'billable_users_count' do
let(:field_name) { :billable_users_count }
before do
allow(license).to receive(:daily_billable_users_count).and_return(10)
end
it { is_expected.to eq(10) }
end
describe 'maximum_user_count' do
let(:field_name) { :maximum_user_count }
before do
allow(license).to receive(:maximum_user_count).and_return(20)
end
it { is_expected.to eq(20) }
end
end
end
# frozen_string_literal: true
RSpec.shared_examples_for 'license type fields' do |keys|
include GraphqlHelpers
context 'with license type fields' do
let(:license_fields) do
%w[id type plan name email company starts_at expires_at block_changes_at activated_at users_in_license_count]
end
it { expect(described_class).to include_graphql_fields(*license_fields) }
describe 'field values' do
let_it_be(:starts_at) { Date.current - 3.months }
let_it_be(:expires_at) { Date.current + 9.months }
let_it_be(:block_changes_at) { Date.current + 10.months }
let_it_be(:activated_at) { DateTime.current - 2.months }
let_it_be(:licensee) do
{
'Name' => 'User Example',
'Email' => 'user@example.com',
'Company' => 'Example Inc.'
}
end
let_it_be(:restrictions) do
{
id: 5,
plan: 'ultimate',
active_user_count: 25
}
end
let_it_be(:license) do
create_current_license(
licensee: licensee,
restrictions: restrictions,
starts_at: starts_at,
expires_at: expires_at,
block_changes_at: block_changes_at,
activated_at: activated_at,
cloud_licensing_enabled: true
)
end
subject { resolve_field(field_name, license) }
describe 'id' do
let(:field_name) { :id }
it { is_expected.to eq(license.to_global_id) }
end
describe 'type' do
let(:field_name) { :type }
it { is_expected.to eq(License::CLOUD_LICENSE_TYPE) }
end
describe 'plan' do
let(:field_name) { :plan }
it { is_expected.to eq('ultimate') }
end
describe 'name' do
let(:field_name) { :name }
it { is_expected.to eq('User Example') }
end
describe 'email' do
let(:field_name) { :email }
it { is_expected.to eq('user@example.com') }
end
describe 'company' do
let(:field_name) { :company }
it { is_expected.to eq('Example Inc.') }
end
describe 'starts_at' do
let(:field_name) { :starts_at }
it { is_expected.to eq(starts_at) }
end
describe 'expires_at' do
let(:field_name) { :expires_at }
it { is_expected.to eq(expires_at) }
end
describe 'block_changes_at' do
let(:field_name) { :block_changes_at }
it { is_expected.to eq(block_changes_at) }
end
describe 'activated_at' do
let(:field_name) { :activated_at }
it { is_expected.to eq(activated_at.change(usec: 0)) }
end
describe 'users_in_license_count' do
let(:field_name) { :users_in_license_count }
it { is_expected.to eq(25) }
end
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment