Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-08-15 21:12:51 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2022-08-15 21:12:51 +0300
commitefbd20fd1ecd091f1270f73d617822a32c94376f (patch)
tree98bc700b5eaabb510d9af3a7ca6ddc847de9ac42 /spec
parent51d5328e82229d69456d3a43dd2cf10518bf64c7 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r--spec/features/groups/crm/contacts/create_spec.rb4
-rw-r--r--spec/finders/crm/contacts_finder_spec.rb61
-rw-r--r--spec/frontend/notes/components/noteable_note_spec.js2
-rw-r--r--spec/frontend/pages/projects/shared/permissions/components/settings_panel_spec.js20
-rw-r--r--spec/frontend/work_items/components/work_item_links/work_item_links_spec.js27
-rw-r--r--spec/graphql/resolvers/crm/contact_state_counts_resolver_spec.rb63
-rw-r--r--spec/graphql/resolvers/crm/contacts_resolver_spec.rb21
-rw-r--r--spec/graphql/types/customer_relations/contact_sort_enum_spec.rb28
-rw-r--r--spec/graphql/types/customer_relations/contact_state_counts_type_spec.rb17
-rw-r--r--spec/graphql/types/group_type_spec.rb11
-rw-r--r--spec/lib/gitlab/database/migrations/background_migration_helpers_spec.rb6
-rw-r--r--spec/migrations/20220802204737_remove_deactivated_user_highest_role_stats_spec.rb39
-rw-r--r--spec/models/customer_relations/contact_spec.rb53
-rw-r--r--spec/models/customer_relations/contact_state_counts_spec.rb60
-rw-r--r--spec/requests/api/graphql/crm/contacts_spec.rb24
-rw-r--r--spec/workers/pages/invalidate_domain_cache_worker_spec.rb12
-rw-r--r--spec/workers/users/deactivate_dormant_users_worker_spec.rb21
17 files changed, 426 insertions, 43 deletions
diff --git a/spec/features/groups/crm/contacts/create_spec.rb b/spec/features/groups/crm/contacts/create_spec.rb
index d6c6e3f1745..b10b2afe35c 100644
--- a/spec/features/groups/crm/contacts/create_spec.rb
+++ b/spec/features/groups/crm/contacts/create_spec.rb
@@ -22,7 +22,9 @@ RSpec.describe 'Create a CRM contact', :js do
fill_in 'description', with: 'VIP'
click_button 'Save changes'
- expect(page).to have_content 'gitlab@example.com'
+ wait_for_requests
+
+ expect(group.contacts.first.email).to eq('gitlab@example.com')
expect(page).to have_current_path("#{group_crm_contacts_path(group)}/", ignore_query: true)
end
end
diff --git a/spec/finders/crm/contacts_finder_spec.rb b/spec/finders/crm/contacts_finder_spec.rb
index dd5274a0574..43dcced53fd 100644
--- a/spec/finders/crm/contacts_finder_spec.rb
+++ b/spec/finders/crm/contacts_finder_spec.rb
@@ -141,6 +141,67 @@ RSpec.describe Crm::ContactsFinder do
expect(finder.execute).to match_array([search_test_b])
end
end
+
+ context 'when sorting' do
+ let_it_be(:search_test_c) do
+ create(
+ :contact,
+ group: search_test_group,
+ email: "a@test.com",
+ organization: create(:organization, name: "Company Z")
+ )
+ end
+
+ let_it_be(:search_test_d) do
+ create(
+ :contact,
+ group: search_test_group,
+ email: "b@test.com",
+ organization: create(:organization, name: "Company A")
+ )
+ end
+
+ it 'returns the contacts sorted by email in ascending order' do
+ finder = described_class.new(user, group: search_test_group, sort: { field: 'email', direction: :asc })
+
+ expect(finder.execute).to eq([search_test_c, search_test_d, search_test_a, search_test_b])
+ end
+
+ it 'returns the contacts sorted by description in ascending order' do
+ finder = described_class.new(user, group: search_test_group, sort: { field: 'description', direction: :desc })
+
+ results = finder.execute
+
+ expect(results[0]).to eq(search_test_b)
+ expect(results[1]).to eq(search_test_a)
+ end
+
+ it 'returns the contacts sorted by organization in ascending order' do
+ finder = described_class.new(user, group: search_test_group, sort: { field: 'organization', direction: :asc })
+
+ results = finder.execute
+
+ expect(results[0]).to eq(search_test_d)
+ expect(results[1]).to eq(search_test_c)
+ end
+ end
+ end
+ end
+
+ describe '.counts_by_state' do
+ let_it_be(:group) { create(:group, :crm_enabled) }
+ let_it_be(:active_contacts) { create_list(:contact, 3, group: group, state: :active) }
+ let_it_be(:inactive_contacts) { create_list(:contact, 2, group: group, state: :inactive) }
+
+ before do
+ group.add_developer(user)
+ end
+
+ it 'returns correct counts' do
+ counts = described_class.counts_by_state(user, group: group)
+
+ expect(counts["active"]).to eq(3)
+ expect(counts["inactive"]).to eq(2)
end
end
end
diff --git a/spec/frontend/notes/components/noteable_note_spec.js b/spec/frontend/notes/components/noteable_note_spec.js
index 59e2f15faa4..c2c3643abb0 100644
--- a/spec/frontend/notes/components/noteable_note_spec.js
+++ b/spec/frontend/notes/components/noteable_note_spec.js
@@ -285,7 +285,7 @@ describe('issue_note', () => {
await waitForPromises();
expect(alertSpy).not.toHaveBeenCalled();
expect(wrapper.vm.note.note_html).toBe(
- '<p><img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7"></p>\n',
+ '<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7">',
);
});
});
diff --git a/spec/frontend/pages/projects/shared/permissions/components/settings_panel_spec.js b/spec/frontend/pages/projects/shared/permissions/components/settings_panel_spec.js
index 85660d09baa..f908508c4b5 100644
--- a/spec/frontend/pages/projects/shared/permissions/components/settings_panel_spec.js
+++ b/spec/frontend/pages/projects/shared/permissions/components/settings_panel_spec.js
@@ -127,6 +127,7 @@ describe('Settings Panel', () => {
const findOperationsVisibilityInput = () =>
findOperationsSettings().findComponent(ProjectFeatureSetting);
const findConfirmDangerButton = () => wrapper.findComponent(ConfirmDanger);
+ const findEnvironmentsSettings = () => wrapper.findComponent({ ref: 'environments-settings' });
afterEach(() => {
wrapper.destroy();
@@ -786,4 +787,23 @@ describe('Settings Panel', () => {
expect(findOperationsSettings().exists()).toBe(true);
});
});
+
+ describe('Environments', () => {
+ describe('with feature flag', () => {
+ it('should show the environments toggle', () => {
+ wrapper = mountComponent({
+ glFeatures: { splitOperationsVisibilityPermissions: true },
+ });
+
+ expect(findEnvironmentsSettings().exists()).toBe(true);
+ });
+ });
+ describe('without feature flag', () => {
+ it('should not show the environments toggle', () => {
+ wrapper = mountComponent({});
+
+ expect(findEnvironmentsSettings().exists()).toBe(false);
+ });
+ });
+ });
});
diff --git a/spec/frontend/work_items/components/work_item_links/work_item_links_spec.js b/spec/frontend/work_items/components/work_item_links/work_item_links_spec.js
index 6c243cc8328..17c0277d461 100644
--- a/spec/frontend/work_items/components/work_item_links/work_item_links_spec.js
+++ b/spec/frontend/work_items/components/work_item_links/work_item_links_spec.js
@@ -1,5 +1,5 @@
import Vue, { nextTick } from 'vue';
-import { GlBadge, GlButton } from '@gitlab/ui';
+import { GlBadge, GlButton, GlAlert } from '@gitlab/ui';
import VueApollo from 'vue-apollo';
import { shallowMountExtended } from 'helpers/vue_test_utils_helper';
import createMockApollo from 'helpers/mock_apollo_helper';
@@ -39,12 +39,12 @@ describe('WorkItemLinks', () => {
const createComponent = async ({
data = {},
- response = workItemHierarchyResponse,
+ fetchHandler = jest.fn().mockResolvedValue(workItemHierarchyResponse),
mutationHandler = mutationChangeParentHandler,
} = {}) => {
mockApollo = createMockApollo(
[
- [getWorkItemLinksQuery, jest.fn().mockResolvedValue(response)],
+ [getWorkItemLinksQuery, fetchHandler],
[changeWorkItemParentMutation, mutationHandler],
[workItemQuery, childWorkItemQueryHandler],
],
@@ -71,6 +71,7 @@ describe('WorkItemLinks', () => {
await waitForPromises();
};
+ const findAlert = () => wrapper.findComponent(GlAlert);
const findToggleButton = () => wrapper.findByTestId('toggle-links');
const findLinksBody = () => wrapper.findByTestId('links-body');
const findEmptyState = () => wrapper.findByTestId('links-empty');
@@ -117,7 +118,9 @@ describe('WorkItemLinks', () => {
describe('when no child links', () => {
beforeEach(async () => {
- await createComponent({ response: workItemHierarchyEmptyResponse });
+ await createComponent({
+ fetchHandler: jest.fn().mockResolvedValue(workItemHierarchyEmptyResponse),
+ });
});
it('displays empty state if there are no children', () => {
@@ -133,6 +136,18 @@ describe('WorkItemLinks', () => {
expect(findFirstLinksMenu().exists()).toBe(true);
});
+ it('shows alert when list loading fails', async () => {
+ const errorMessage = 'Some error';
+ await createComponent({
+ fetchHandler: jest.fn().mockRejectedValue(new Error(errorMessage)),
+ });
+
+ await nextTick();
+
+ expect(findAlert().exists()).toBe(true);
+ expect(findAlert().text()).toBe(errorMessage);
+ });
+
it('renders confidentiality icon when child item is confidential', () => {
const children = wrapper.findAll('[data-testid="links-child"]');
const confidentialIcon = children.at(0).find('[data-testid="confidential-icon"]');
@@ -149,7 +164,9 @@ describe('WorkItemLinks', () => {
describe('when no permission to update', () => {
beforeEach(async () => {
- await createComponent({ response: workItemHierarchyNoUpdatePermissionResponse });
+ await createComponent({
+ fetchHandler: jest.fn().mockResolvedValue(workItemHierarchyNoUpdatePermissionResponse),
+ });
});
it('does not display button to toggle Add form', () => {
diff --git a/spec/graphql/resolvers/crm/contact_state_counts_resolver_spec.rb b/spec/graphql/resolvers/crm/contact_state_counts_resolver_spec.rb
new file mode 100644
index 00000000000..0128ec792b3
--- /dev/null
+++ b/spec/graphql/resolvers/crm/contact_state_counts_resolver_spec.rb
@@ -0,0 +1,63 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Resolvers::Crm::ContactStateCountsResolver do
+ include GraphqlHelpers
+
+ let_it_be(:user) { create(:user) }
+ let_it_be(:group) { create(:group, :crm_enabled) }
+
+ before_all do
+ create(:contact, group: group, email: "x@test.com")
+ create(:contact, group: group, email: "y@test.com", state: 'inactive')
+ create_list(:contact, 3, group: group)
+ create_list(:contact, 2, group: group, state: 'inactive')
+ end
+
+ describe '#resolve' do
+ context 'with unauthorized user' do
+ it 'does not raise an error and returns no counts' do
+ expect { resolve_counts(group) }.not_to raise_error
+ expect(resolve_counts(group).all).to be(0)
+ end
+ end
+
+ context 'with authorized user' do
+ before do
+ group.add_reporter(user)
+ end
+
+ context 'without parent' do
+ it 'returns no counts' do
+ expect(resolve_counts(nil).all).to be(0)
+ end
+ end
+
+ context 'with a group' do
+ context 'when no filter is provided' do
+ it 'returns the count of all contacts' do
+ counts = resolve_counts(group)
+ expect(counts.all).to eq(7)
+ expect(counts.active).to eq(4)
+ expect(counts.inactive).to eq(3)
+ end
+ end
+
+ context 'when search term is provided' do
+ it 'returns the correct counts' do
+ counts = resolve_counts(group, { search: "@test.com" })
+
+ expect(counts.all).to be(2)
+ expect(counts.active).to be(1)
+ expect(counts.inactive).to be(1)
+ end
+ end
+ end
+ end
+ end
+
+ def resolve_counts(parent, args = {}, context = { current_user: user })
+ resolve(described_class, obj: parent, args: args, ctx: context)
+ end
+end
diff --git a/spec/graphql/resolvers/crm/contacts_resolver_spec.rb b/spec/graphql/resolvers/crm/contacts_resolver_spec.rb
index 98da4aeac28..c7c2d11e114 100644
--- a/spec/graphql/resolvers/crm/contacts_resolver_spec.rb
+++ b/spec/graphql/resolvers/crm/contacts_resolver_spec.rb
@@ -16,6 +16,7 @@ RSpec.describe Resolvers::Crm::ContactsResolver do
last_name: "DEF",
email: "ghi@test.com",
description: "LMNO",
+ organization: create(:organization, group: group),
state: "inactive"
)
end
@@ -61,11 +62,29 @@ RSpec.describe Resolvers::Crm::ContactsResolver do
end
context 'when no filter is provided' do
- it 'returns all the contacts in the correct order' do
+ it 'returns all the contacts in the default order' do
expect(resolve_contacts(group)).to eq([contact_a, contact_b])
end
end
+ context 'when a sort is provided' do
+ it 'returns all the contacts in the correct order' do
+ expect(resolve_contacts(group, { sort: 'EMAIL_DESC' })).to eq([contact_b, contact_a])
+ end
+ end
+
+ context 'when a sort is provided needing offset_pagination' do
+ it 'returns all the contacts in the correct order' do
+ expect(resolve_contacts(group, { sort: 'ORGANIZATION_ASC' })).to eq([contact_a, contact_b])
+ end
+ end
+
+ context 'when filtering for all states' do
+ it 'returns all the contacts in the correct order' do
+ expect(resolve_contacts(group, { state: 'all' })).to eq([contact_a, contact_b])
+ end
+ end
+
context 'when search term is provided' do
it 'returns the correct contacts' do
expect(resolve_contacts(group, { search: "x@test.com" })).to contain_exactly(contact_b)
diff --git a/spec/graphql/types/customer_relations/contact_sort_enum_spec.rb b/spec/graphql/types/customer_relations/contact_sort_enum_spec.rb
new file mode 100644
index 00000000000..5b0538042c8
--- /dev/null
+++ b/spec/graphql/types/customer_relations/contact_sort_enum_spec.rb
@@ -0,0 +1,28 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe GitlabSchema.types['ContactSort'] do
+ specify { expect(described_class.graphql_name).to eq('ContactSort') }
+
+ it_behaves_like 'common sort values'
+
+ it 'exposes all the contact sort values' do
+ expect(described_class.values.keys).to include(
+ *%w[
+ FIRST_NAME_ASC
+ FIRST_NAME_DESC
+ LAST_NAME_ASC
+ LAST_NAME_DESC
+ EMAIL_ASC
+ EMAIL_DESC
+ PHONE_ASC
+ PHONE_DESC
+ DESCRIPTION_ASC
+ DESCRIPTION_DESC
+ ORGANIZATION_ASC
+ ORGANIZATION_DESC
+ ]
+ )
+ end
+end
diff --git a/spec/graphql/types/customer_relations/contact_state_counts_type_spec.rb b/spec/graphql/types/customer_relations/contact_state_counts_type_spec.rb
new file mode 100644
index 00000000000..b022febb90f
--- /dev/null
+++ b/spec/graphql/types/customer_relations/contact_state_counts_type_spec.rb
@@ -0,0 +1,17 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe GitlabSchema.types['ContactStateCounts'] do
+ let(:fields) do
+ %w[
+ all
+ active
+ inactive
+ ]
+ end
+
+ it { expect(described_class.graphql_name).to eq('ContactStateCounts') }
+ it { expect(described_class).to have_graphql_fields(fields) }
+ it { expect(described_class).to require_graphql_authorizations(:read_crm_contact) }
+end
diff --git a/spec/graphql/types/group_type_spec.rb b/spec/graphql/types/group_type_spec.rb
index ab81db8fec0..72b3bb90194 100644
--- a/spec/graphql/types/group_type_spec.rb
+++ b/spec/graphql/types/group_type_spec.rb
@@ -24,8 +24,8 @@ RSpec.describe GitlabSchema.types['Group'] do
dependency_proxy_blobs dependency_proxy_image_count
dependency_proxy_blob_count dependency_proxy_total_size
dependency_proxy_image_prefix dependency_proxy_image_ttl_policy
- shared_runners_setting timelogs organizations contacts work_item_types
- recent_issue_boards ci_variables
+ shared_runners_setting timelogs organizations contacts contact_state_counts
+ work_item_types recent_issue_boards ci_variables
]
expect(described_class).to include_graphql_fields(*expected_fields)
@@ -55,6 +55,13 @@ RSpec.describe GitlabSchema.types['Group'] do
end
end
+ describe 'contact_state_counts field' do
+ subject { described_class.fields['contactStateCounts'] }
+
+ it { is_expected.to have_graphql_type(Types::CustomerRelations::ContactStateCountsType) }
+ it { is_expected.to have_graphql_resolver(Resolvers::Crm::ContactStateCountsResolver) }
+ end
+
it_behaves_like 'a GraphQL type with labels' do
let(:labels_resolver_arguments) { [:search_term, :includeAncestorGroups, :includeDescendantGroups, :onlyGroupLabels] }
end
diff --git a/spec/lib/gitlab/database/migrations/background_migration_helpers_spec.rb b/spec/lib/gitlab/database/migrations/background_migration_helpers_spec.rb
index c423340a572..f21f1ac5e52 100644
--- a/spec/lib/gitlab/database/migrations/background_migration_helpers_spec.rb
+++ b/spec/lib/gitlab/database/migrations/background_migration_helpers_spec.rb
@@ -37,12 +37,6 @@ RSpec.describe Gitlab::Database::Migrations::BackgroundMigrationHelpers do
freeze_time { example.run }
end
- before do
- User.class_eval do
- include EachBatch
- end
- end
-
it 'returns the final expected delay' do
Sidekiq::Testing.fake! do
final_delay = model.queue_background_migration_jobs_by_range_at_intervals(User, 'FooJob', 10.minutes, batch_size: 2)
diff --git a/spec/migrations/20220802204737_remove_deactivated_user_highest_role_stats_spec.rb b/spec/migrations/20220802204737_remove_deactivated_user_highest_role_stats_spec.rb
new file mode 100644
index 00000000000..3ea286ca138
--- /dev/null
+++ b/spec/migrations/20220802204737_remove_deactivated_user_highest_role_stats_spec.rb
@@ -0,0 +1,39 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+require_migration!
+
+RSpec.describe RemoveDeactivatedUserHighestRoleStats do
+ let!(:users) { table(:users) }
+ let!(:user_highest_roles) { table(:user_highest_roles) }
+
+ let!(:user1) do
+ users.create!(username: 'user1', email: 'user1@example.com', projects_limit: 10, state: 'active')
+ end
+
+ let!(:user2) do
+ users.create!(username: 'user2', email: 'user2@example.com', projects_limit: 10, state: 'deactivated')
+ end
+
+ let!(:highest_role1) { user_highest_roles.create!(user_id: user1.id) }
+ let!(:highest_role2) { user_highest_roles.create!(user_id: user2.id) }
+
+ describe '#up' do
+ context 'when on gitlab.com' do
+ it 'does not change user highest role records' do
+ allow(Gitlab).to receive(:com?).and_return(true)
+ expect { migrate! }.not_to change(user_highest_roles, :count)
+ end
+ end
+
+ context 'when not on gitlab.com' do
+ it 'removes all user highest role records for deactivated users' do
+ allow(Gitlab).to receive(:com?).and_return(false)
+ migrate!
+ expect(user_highest_roles.pluck(:user_id)).to contain_exactly(
+ user1.id
+ )
+ end
+ end
+ end
+end
diff --git a/spec/models/customer_relations/contact_spec.rb b/spec/models/customer_relations/contact_spec.rb
index f91546f5240..27f3c4d6e62 100644
--- a/spec/models/customer_relations/contact_spec.rb
+++ b/spec/models/customer_relations/contact_spec.rb
@@ -226,15 +226,58 @@ RSpec.describe CustomerRelations::Contact, type: :model do
end
end
- describe '.sort_by_name' do
+ describe '.counts_by_state' do
+ before do
+ create_list(:contact, 3, group: group)
+ create_list(:contact, 2, group: group, state: 'inactive')
+ end
+
+ it 'returns only active contacts' do
+ counts = group.contacts.counts_by_state
+
+ expect(counts['active']).to be(3)
+ expect(counts['inactive']).to be(2)
+ end
+ end
+
+ describe 'sorting' do
+ let_it_be(:organization_a) { create(:organization, name: 'a') }
+ let_it_be(:organization_b) { create(:organization, name: 'b') }
let_it_be(:contact_a) { create(:contact, group: group, first_name: "c", last_name: "d") }
- let_it_be(:contact_b) { create(:contact, group: group, first_name: "a", last_name: "b") }
- let_it_be(:contact_c) { create(:contact, group: group, first_name: "e", last_name: "d") }
+ let_it_be(:contact_b) do
+ create(:contact,
+ group: group,
+ first_name: "a",
+ last_name: "b",
+ phone: "123",
+ organization: organization_a)
+ end
- context 'when sorting the contacts' do
- it 'sorts them by last name then first name in ascendent order' do
+ let_it_be(:contact_c) do
+ create(:contact,
+ group: group,
+ first_name: "e",
+ last_name: "d",
+ phone: "456",
+ organization: organization_b)
+ end
+
+ describe '.sort_by_name' do
+ it 'sorts them by last name then first name in ascending order' do
expect(group.contacts.sort_by_name).to eq([contact_b, contact_a, contact_c])
end
end
+
+ describe '.sort_by_organization' do
+ it 'sorts them by organization in descending order' do
+ expect(group.contacts.sort_by_organization(:desc)).to eq([contact_c, contact_b, contact_a])
+ end
+ end
+
+ describe '.sort_by_field' do
+ it 'sorts them by phone in ascending order' do
+ expect(group.contacts.sort_by_field('phone', :asc)).to eq([contact_b, contact_c, contact_a])
+ end
+ end
end
end
diff --git a/spec/models/customer_relations/contact_state_counts_spec.rb b/spec/models/customer_relations/contact_state_counts_spec.rb
new file mode 100644
index 00000000000..a19f6f08489
--- /dev/null
+++ b/spec/models/customer_relations/contact_state_counts_spec.rb
@@ -0,0 +1,60 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe CustomerRelations::ContactStateCounts do
+ let_it_be(:user) { create(:user) }
+ let_it_be(:group) { create(:group, :crm_enabled) }
+
+ let(:counter) { described_class.new(user, group, params) }
+ let(:params) { {} }
+
+ before_all do
+ group.add_reporter(user)
+ create(:contact, group: group, first_name: 'filter')
+ create(:contact, group: group, last_name: 'filter')
+ create(:contact, group: group)
+ create(:contact, group: group, state: 'inactive', email: 'filter@example.com')
+ create(:contact, group: group, state: 'inactive')
+ end
+
+ describe '.declarative_policy_class' do
+ subject { described_class.declarative_policy_class }
+
+ it { is_expected.to eq('CustomerRelations::ContactPolicy') }
+ end
+
+ describe '#all' do
+ it 'returns the total number of contacts' do
+ expect(counter.all).to be(5)
+ end
+ end
+
+ describe '#active' do
+ it 'returns the number of active contacts' do
+ expect(counter.active).to be(3)
+ end
+ end
+
+ describe '#inactive' do
+ it 'returns the number of inactive contacts' do
+ expect(counter.inactive).to be(2)
+ end
+ end
+
+ describe 'when filtered' do
+ let(:params) { { search: 'filter' } }
+
+ it '#all returns the number of contacts with a filter' do
+ expect(counter.all).to be(3)
+ end
+
+ it '#active returns the number of active contacts with a filter' do
+ expect(counter.active).to be(2)
+ end
+
+ it '#inactive returns the number of inactive contacts with a filter' do
+ expect(counter.inactive).to be(1)
+ end
+ end
+end
diff --git a/spec/requests/api/graphql/crm/contacts_spec.rb b/spec/requests/api/graphql/crm/contacts_spec.rb
index 7e824140894..a676e92dc3b 100644
--- a/spec/requests/api/graphql/crm/contacts_spec.rb
+++ b/spec/requests/api/graphql/crm/contacts_spec.rb
@@ -12,11 +12,11 @@ RSpec.describe 'getting CRM contacts' do
create(
:contact,
group: group,
- first_name: "ABC",
- last_name: "DEF",
- email: "ghi@test.com",
- description: "LMNO",
- state: "inactive"
+ first_name: "PQR",
+ last_name: "STU",
+ email: "aaa@test.com",
+ description: "YZ",
+ state: "active"
)
end
@@ -26,9 +26,9 @@ RSpec.describe 'getting CRM contacts' do
group: group,
first_name: "ABC",
last_name: "DEF",
- email: "vwx@test.com",
- description: "YZ",
- state: "active"
+ email: "ghi@test.com",
+ description: "LMNO",
+ state: "inactive"
)
end
@@ -36,9 +36,9 @@ RSpec.describe 'getting CRM contacts' do
create(
:contact,
group: group,
- first_name: "PQR",
- last_name: "STU",
- email: "aaa@test.com",
+ first_name: "JKL",
+ last_name: "MNO",
+ email: "vwx@test.com",
description: "YZ",
state: "active"
)
@@ -51,7 +51,7 @@ RSpec.describe 'getting CRM contacts' do
it_behaves_like 'sorted paginated query' do
let(:sort_argument) { {} }
let(:first_param) { 2 }
- let(:all_records) { [contact_a, contact_b, contact_c] }
+ let(:all_records) { [contact_b, contact_c, contact_a] }
let(:data_path) { [:group, :contacts] }
def pagination_query(params)
diff --git a/spec/workers/pages/invalidate_domain_cache_worker_spec.rb b/spec/workers/pages/invalidate_domain_cache_worker_spec.rb
index df1b91ff0e5..75d7c9f82b4 100644
--- a/spec/workers/pages/invalidate_domain_cache_worker_spec.rb
+++ b/spec/workers/pages/invalidate_domain_cache_worker_spec.rb
@@ -104,6 +104,18 @@ RSpec.describe Pages::InvalidateDomainCacheWorker do
{ type: :namespace, id: 5 }
]
+ it_behaves_like 'clears caches with',
+ event_class: Groups::GroupPathChangedEvent,
+ event_data: {
+ group_id: 1,
+ root_namespace_id: 2,
+ old_path: 'old_path',
+ new_path: 'new_path'
+ },
+ caches: [
+ { type: :namespace, id: 2 }
+ ]
+
context 'when namespace based cache keys are duplicated' do
# de-dups namespace cache keys
it_behaves_like 'clears caches with',
diff --git a/spec/workers/users/deactivate_dormant_users_worker_spec.rb b/spec/workers/users/deactivate_dormant_users_worker_spec.rb
index 297301c45e2..263ca31e0a0 100644
--- a/spec/workers/users/deactivate_dormant_users_worker_spec.rb
+++ b/spec/workers/users/deactivate_dormant_users_worker_spec.rb
@@ -25,20 +25,13 @@ RSpec.describe Users::DeactivateDormantUsersWorker do
context 'when automatic deactivation of dormant users is enabled' do
before do
stub_application_setting(deactivate_dormant_users: true)
- stub_const("#{described_class.name}::PAUSE_SECONDS", 0)
end
it 'deactivates dormant users' do
- freeze_time do
- stub_const("#{described_class.name}::BATCH_SIZE", 1)
-
- expect(worker).to receive(:sleep).twice
-
- worker.perform
+ worker.perform
- expect(User.dormant.count).to eq(0)
- expect(User.with_no_activity.count).to eq(0)
- end
+ expect(User.dormant.count).to eq(0)
+ expect(User.with_no_activity.count).to eq(0)
end
where(:user_type, :expected_state) do
@@ -78,6 +71,14 @@ RSpec.describe Users::DeactivateDormantUsersWorker do
expect(inactive_recently_created.reload.state).to eq('active')
end
+
+ it 'triggers update of highest user role for deactivated users', :clean_gitlab_redis_shared_state do
+ [dormant, inactive].each do |user|
+ expect(UpdateHighestRoleWorker).to receive(:perform_in).with(anything, user.id)
+ end
+
+ worker.perform
+ end
end
context 'when automatic deactivation of dormant users is disabled' do