summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-10-08 21:08:52 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-10-08 21:08:52 +0000
commitb0980f5557a8621fb08785b06be950ee46796c18 (patch)
tree39ceec05cf89f69adb79a427f673031cd2d5c070 /spec
parent2ac48330152821211934d8aee396679d5895c5fe (diff)
downloadgitlab-ce-b0980f5557a8621fb08785b06be950ee46796c18.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r--spec/db/schema_spec.rb1
-rw-r--r--spec/frontend/editor/editor_lite_spec.js147
-rw-r--r--spec/graphql/types/root_storage_statistics_type_spec.rb3
-rw-r--r--spec/migrations/migrate_compliance_framework_enum_to_database_framework_record_spec.rb70
-rw-r--r--spec/models/project_services/prometheus_service_spec.rb12
-rw-r--r--spec/support/helpers/snowplow_helpers.rb12
6 files changed, 197 insertions, 48 deletions
diff --git a/spec/db/schema_spec.rb b/spec/db/schema_spec.rb
index 69cd08d82e1..993ebea2541 100644
--- a/spec/db/schema_spec.rb
+++ b/spec/db/schema_spec.rb
@@ -31,6 +31,7 @@ RSpec.describe 'Database schema' do
ci_trigger_requests: %w[commit_id],
cluster_providers_aws: %w[security_group_id vpc_id access_key_id],
cluster_providers_gcp: %w[gcp_project_id operation_id],
+ compliance_management_frameworks: %w[group_id],
commit_user_mentions: %w[commit_id],
deploy_keys_projects: %w[deploy_key_id],
deployments: %w[deployable_id environment_id user_id],
diff --git a/spec/frontend/editor/editor_lite_spec.js b/spec/frontend/editor/editor_lite_spec.js
index e566d3a4b38..bc17435c6d4 100644
--- a/spec/frontend/editor/editor_lite_spec.js
+++ b/spec/frontend/editor/editor_lite_spec.js
@@ -1,4 +1,5 @@
import { editor as monacoEditor, languages as monacoLanguages, Uri } from 'monaco-editor';
+import waitForPromises from 'helpers/wait_for_promises';
import Editor from '~/editor/editor_lite';
import { DEFAULT_THEME, themes } from '~/ide/lib/themes';
import { EDITOR_LITE_INSTANCE_ERROR_NO_EL, URI_PREFIX } from '~/editor/constants';
@@ -253,55 +254,125 @@ describe('Base editor', () => {
const MyExt3 = {
foo: foo2,
};
- beforeEach(() => {
- instance = editor.createInstance({ el: editorEl, blobPath, blobContent });
- });
- it('is extensible with the extensions', () => {
- expect(instance.foo).toBeUndefined();
+ describe('basic functionality', () => {
+ beforeEach(() => {
+ instance = editor.createInstance({ el: editorEl, blobPath, blobContent });
+ });
- editor.use(MyExt1);
- expect(instance.foo).toEqual(foo1);
- });
+ it('is extensible with the extensions', () => {
+ expect(instance.foo).toBeUndefined();
- it('does not fail if no extensions supplied', () => {
- const spy = jest.spyOn(global.console, 'error');
- editor.use();
+ instance.use(MyExt1);
+ expect(instance.foo).toEqual(foo1);
+ });
- expect(spy).not.toHaveBeenCalled();
- });
+ it('does not fail if no extensions supplied', () => {
+ const spy = jest.spyOn(global.console, 'error');
+ instance.use();
- it('is extensible with multiple extensions', () => {
- expect(instance.foo).toBeUndefined();
- expect(instance.bar).toBeUndefined();
+ expect(spy).not.toHaveBeenCalled();
+ });
- editor.use([MyExt1, MyExt2]);
+ it('is extensible with multiple extensions', () => {
+ expect(instance.foo).toBeUndefined();
+ expect(instance.bar).toBeUndefined();
- expect(instance.foo).toEqual(foo1);
- expect(instance.bar).toEqual(bar);
- });
+ instance.use([MyExt1, MyExt2]);
- it('uses the last definition of a method in case of an overlap', () => {
- editor.use([MyExt1, MyExt2, MyExt3]);
- expect(instance).toEqual(
- expect.objectContaining({
- foo: foo2,
- bar,
- }),
- );
+ expect(instance.foo).toEqual(foo1);
+ expect(instance.bar).toEqual(bar);
+ });
+
+ it('uses the last definition of a method in case of an overlap', () => {
+ instance.use([MyExt1, MyExt2, MyExt3]);
+ expect(instance).toEqual(
+ expect.objectContaining({
+ foo: foo2,
+ bar,
+ }),
+ );
+ });
+
+ it('correctly resolves references withing extensions', () => {
+ const FunctionExt = {
+ inst() {
+ return this;
+ },
+ mod() {
+ return this.getModel();
+ },
+ };
+ instance.use(FunctionExt);
+ expect(instance.inst()).toEqual(editor.instances[0]);
+ });
});
- it('correctly resolves references withing extensions', () => {
- const FunctionExt = {
- inst() {
- return this;
- },
- mod() {
- return this.getModel();
- },
+ describe('extensions as an instance parameter', () => {
+ let editorExtensionSpy;
+ const instanceConstructor = (extensions = []) => {
+ return editor.createInstance({
+ el: editorEl,
+ blobPath,
+ blobContent,
+ blobGlobalId,
+ extensions,
+ });
};
- editor.use(FunctionExt);
- expect(instance.inst()).toEqual(editor.instances[0]);
+
+ beforeEach(() => {
+ editorExtensionSpy = jest.spyOn(Editor, 'pushToImportsArray').mockImplementation(arr => {
+ arr.push(
+ Promise.resolve({
+ default: {},
+ }),
+ );
+ });
+ });
+
+ it.each([undefined, [], [''], ''])(
+ 'does not fail and makes no fetch if extensions is %s',
+ () => {
+ instance = instanceConstructor(null);
+ expect(editorExtensionSpy).not.toHaveBeenCalled();
+ },
+ );
+
+ it.each`
+ type | value | callsCount
+ ${'simple string'} | ${'foo'} | ${1}
+ ${'combined string'} | ${'foo, bar'} | ${2}
+ ${'array of strings'} | ${['foo', 'bar']} | ${2}
+ `('accepts $type as an extension parameter', ({ value, callsCount }) => {
+ instance = instanceConstructor(value);
+ expect(editorExtensionSpy).toHaveBeenCalled();
+ expect(editorExtensionSpy.mock.calls).toHaveLength(callsCount);
+ });
+
+ it.each`
+ desc | path | expectation
+ ${'~/editor'} | ${'foo'} | ${'~/editor/foo'}
+ ${'~/CUSTOM_PATH with leading slash'} | ${'/my_custom_path/bar'} | ${'~/my_custom_path/bar'}
+ ${'~/CUSTOM_PATH without leading slash'} | ${'my_custom_path/delta'} | ${'~/my_custom_path/delta'}
+ `('fetches extensions from $desc path', ({ path, expectation }) => {
+ instance = instanceConstructor(path);
+ expect(editorExtensionSpy).toHaveBeenCalledWith(expect.any(Array), expectation);
+ });
+
+ it('emits editor-ready event after all extensions were applied', async () => {
+ const calls = [];
+ const eventSpy = jest.fn().mockImplementation(() => {
+ calls.push('event');
+ });
+ const useSpy = jest.spyOn(editor, 'use').mockImplementation(() => {
+ calls.push('use');
+ });
+ editorEl.addEventListener('editor-ready', eventSpy);
+ instance = instanceConstructor('foo, bar');
+ await waitForPromises();
+ expect(useSpy.mock.calls).toHaveLength(2);
+ expect(calls).toEqual(['use', 'use', 'event']);
+ });
});
describe('multiple instances', () => {
diff --git a/spec/graphql/types/root_storage_statistics_type_spec.rb b/spec/graphql/types/root_storage_statistics_type_spec.rb
index f01c55cbccb..79d474f13ad 100644
--- a/spec/graphql/types/root_storage_statistics_type_spec.rb
+++ b/spec/graphql/types/root_storage_statistics_type_spec.rb
@@ -7,7 +7,8 @@ RSpec.describe GitlabSchema.types['RootStorageStatistics'] do
it 'has all the required fields' do
expect(described_class).to have_graphql_fields(:storage_size, :repository_size, :lfs_objects_size,
- :build_artifacts_size, :packages_size, :wiki_size, :snippets_size)
+ :build_artifacts_size, :packages_size, :wiki_size, :snippets_size,
+ :pipeline_artifacts_size)
end
specify { expect(described_class).to require_graphql_authorizations(:read_statistics) }
diff --git a/spec/migrations/migrate_compliance_framework_enum_to_database_framework_record_spec.rb b/spec/migrations/migrate_compliance_framework_enum_to_database_framework_record_spec.rb
new file mode 100644
index 00000000000..cd2ec81abb7
--- /dev/null
+++ b/spec/migrations/migrate_compliance_framework_enum_to_database_framework_record_spec.rb
@@ -0,0 +1,70 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+require Rails.root.join('db', 'post_migrate', '20201005094331_migrate_compliance_framework_enum_to_database_framework_record.rb')
+
+RSpec.describe MigrateComplianceFrameworkEnumToDatabaseFrameworkRecord, schema: 20201005092753 do
+ let(:namespaces) { table(:namespaces) }
+ let(:projects) { table(:projects) }
+ let(:project_compliance_framework_settings) { table(:project_compliance_framework_settings) }
+ let(:compliance_management_frameworks) { table(:compliance_management_frameworks) }
+
+ let(:gdpr_framework) { 1 }
+ let(:sox_framework) { 5 }
+
+ let!(:root_group) { namespaces.create!(type: 'Group', name: 'a', path: 'a') }
+ let!(:sub_group) { namespaces.create!(type: 'Group', name: 'b', path: 'b', parent_id: root_group.id) }
+ let!(:sub_sub_group) { namespaces.create!(type: 'Group', name: 'c', path: 'c', parent_id: sub_group.id) }
+
+ let!(:namespace) { namespaces.create!(name: 'd', path: 'd') }
+
+ let!(:project_on_root_level) { projects.create!(namespace_id: root_group.id) }
+ let!(:project_on_sub_sub_level_1) { projects.create!(namespace_id: sub_sub_group.id) }
+ let!(:project_on_sub_sub_level_2) { projects.create!(namespace_id: sub_sub_group.id) }
+ let!(:project_on_namespace) { projects.create!(namespace_id: namespace.id) }
+
+ let!(:project_on_root_level_compliance_setting) { project_compliance_framework_settings.create!(project_id: project_on_root_level.id, framework: gdpr_framework) }
+ let!(:project_on_sub_sub_level_compliance_setting_1) { project_compliance_framework_settings.create!(project_id: project_on_sub_sub_level_1.id, framework: sox_framework) }
+ let!(:project_on_sub_sub_level_compliance_setting_2) { project_compliance_framework_settings.create!(project_id: project_on_sub_sub_level_2.id, framework: gdpr_framework) }
+ let!(:project_on_namespace_level_compliance_setting) { project_compliance_framework_settings.create!(project_id: project_on_namespace.id, framework: gdpr_framework) }
+
+ subject { described_class.new.up }
+
+ context 'when Gitlab.ee? is true' do
+ before do
+ expect(Gitlab).to receive(:ee?).and_return(true)
+ end
+
+ it 'updates the project settings' do
+ subject
+
+ gdpr_framework = compliance_management_frameworks.find_by(namespace_id: root_group.id, name: 'GDPR')
+ expect(project_on_root_level_compliance_setting.reload.framework_id).to eq(gdpr_framework.id)
+ expect(project_on_sub_sub_level_compliance_setting_2.reload.framework_id).to eq(gdpr_framework.id)
+
+ sox_framework = compliance_management_frameworks.find_by(namespace_id: root_group.id, name: 'SOX')
+ expect(project_on_sub_sub_level_compliance_setting_1.reload.framework_id).to eq(sox_framework.id)
+
+ gdpr_framework = compliance_management_frameworks.find_by(namespace_id: namespace.id, name: 'GDPR')
+ expect(project_on_namespace_level_compliance_setting.reload.framework_id).to eq(gdpr_framework.id)
+ end
+
+ it 'adds two framework records' do
+ subject
+
+ expect(compliance_management_frameworks.count).to eq(3)
+ end
+ end
+
+ context 'when Gitlab.ee? is false' do
+ before do
+ expect(Gitlab).to receive(:ee?).and_return(false)
+ end
+
+ it 'does nothing' do
+ subject
+
+ expect(compliance_management_frameworks.count).to eq(0)
+ end
+ end
+end
diff --git a/spec/models/project_services/prometheus_service_spec.rb b/spec/models/project_services/prometheus_service_spec.rb
index 16837e2b93a..76fc5a826c9 100644
--- a/spec/models/project_services/prometheus_service_spec.rb
+++ b/spec/models/project_services/prometheus_service_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-RSpec.describe PrometheusService, :use_clean_rails_memory_store_caching do
+RSpec.describe PrometheusService, :use_clean_rails_memory_store_caching, :snowplow do
include PrometheusHelpers
include ReactiveCachingHelpers
@@ -421,18 +421,16 @@ RSpec.describe PrometheusService, :use_clean_rails_memory_store_caching do
context "enabling manual_configuration" do
it "tracks enable event" do
service.update!(manual_configuration: false)
-
- expect(Gitlab::Tracking).to receive(:event).with('cluster:services:prometheus', 'enabled_manual_prometheus')
-
service.update!(manual_configuration: true)
+
+ expect_snowplow_event(category: 'cluster:services:prometheus', action: 'enabled_manual_prometheus')
end
it "tracks disable event" do
service.update!(manual_configuration: true)
-
- expect(Gitlab::Tracking).to receive(:event).with('cluster:services:prometheus', 'disabled_manual_prometheus')
-
service.update!(manual_configuration: false)
+
+ expect_snowplow_event(category: 'cluster:services:prometheus', action: 'disabled_manual_prometheus')
end
end
end
diff --git a/spec/support/helpers/snowplow_helpers.rb b/spec/support/helpers/snowplow_helpers.rb
index 83a5b7e48bc..3bde01c6fbf 100644
--- a/spec/support/helpers/snowplow_helpers.rb
+++ b/spec/support/helpers/snowplow_helpers.rb
@@ -32,8 +32,16 @@ module SnowplowHelpers
# end
# end
def expect_snowplow_event(category:, action:, **kwargs)
- expect(Gitlab::Tracking).to have_received(:event)
- .with(category, action, **kwargs).at_least(:once)
+ # This check will no longer be needed with Ruby 2.7 which
+ # would not pass any arguments when using **kwargs.
+ # https://gitlab.com/gitlab-org/gitlab/-/issues/263430
+ if kwargs.present?
+ expect(Gitlab::Tracking).to have_received(:event)
+ .with(category, action, **kwargs).at_least(:once)
+ else
+ expect(Gitlab::Tracking).to have_received(:event)
+ .with(category, action).at_least(:once)
+ end
end
# Asserts that no call to `Gitlab::Tracking#event` was made.