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:
Diffstat (limited to 'spec')
-rw-r--r--spec/factories/ci/builds.rb2
-rw-r--r--spec/frontend/pages/projects/pipeline_schedules/shared/components/timezone_dropdown_spec.js116
-rw-r--r--spec/lib/atlassian/jira_connect/client_spec.rb93
-rw-r--r--spec/services/projects/container_repository/destroy_service_spec.rb22
-rw-r--r--spec/services/projects/destroy_service_spec.rb24
5 files changed, 65 insertions, 192 deletions
diff --git a/spec/factories/ci/builds.rb b/spec/factories/ci/builds.rb
index 3762defc4bf..15a88955e05 100644
--- a/spec/factories/ci/builds.rb
+++ b/spec/factories/ci/builds.rb
@@ -25,6 +25,8 @@ FactoryBot.define do
project { pipeline.project }
+ ref { pipeline.ref }
+
trait :with_token do
transient do
generate_token { true }
diff --git a/spec/frontend/pages/projects/pipeline_schedules/shared/components/timezone_dropdown_spec.js b/spec/frontend/pages/projects/pipeline_schedules/shared/components/timezone_dropdown_spec.js
deleted file mode 100644
index 4cac642bb50..00000000000
--- a/spec/frontend/pages/projects/pipeline_schedules/shared/components/timezone_dropdown_spec.js
+++ /dev/null
@@ -1,116 +0,0 @@
-import { formatUtcOffset, formatTimezone } from '~/lib/utils/datetime_utility';
-import { findTimezoneByIdentifier } from '~/pages/projects/pipeline_schedules/shared/components/timezone_dropdown';
-
-describe('Timezone Dropdown', () => {
- describe('formatUtcOffset', () => {
- it('will convert negative utc offsets in seconds to hours and minutes', () => {
- expect(formatUtcOffset(-21600)).toEqual('- 6');
- });
-
- it('will convert positive utc offsets in seconds to hours and minutes', () => {
- expect(formatUtcOffset(25200)).toEqual('+ 7');
- expect(formatUtcOffset(49500)).toEqual('+ 13.75');
- });
-
- it('will return 0 when given a string', () => {
- expect(formatUtcOffset('BLAH')).toEqual('0');
- expect(formatUtcOffset('$%$%')).toEqual('0');
- });
-
- it('will return 0 when given an array', () => {
- expect(formatUtcOffset(['an', 'array'])).toEqual('0');
- });
-
- it('will return 0 when given an object', () => {
- expect(formatUtcOffset({ some: '', object: '' })).toEqual('0');
- });
-
- it('will return 0 when given null', () => {
- expect(formatUtcOffset(null)).toEqual('0');
- });
-
- it('will return 0 when given undefined', () => {
- expect(formatUtcOffset(undefined)).toEqual('0');
- });
-
- it('will return 0 when given empty input', () => {
- expect(formatUtcOffset('')).toEqual('0');
- });
- });
-
- describe('formatTimezone', () => {
- it('given name: "Chatham Is.", offset: "49500", will format for display as "[UTC + 13.75] Chatham Is."', () => {
- expect(
- formatTimezone({
- name: 'Chatham Is.',
- offset: 49500,
- identifier: 'Pacific/Chatham',
- }),
- ).toEqual('[UTC + 13.75] Chatham Is.');
- });
-
- it('given name: "Saskatchewan", offset: "-21600", will format for display as "[UTC - 6] Saskatchewan"', () => {
- expect(
- formatTimezone({
- name: 'Saskatchewan',
- offset: -21600,
- identifier: 'America/Regina',
- }),
- ).toEqual('[UTC - 6] Saskatchewan');
- });
-
- it('given name: "Accra", offset: "0", will format for display as "[UTC 0] Accra"', () => {
- expect(
- formatTimezone({
- name: 'Accra',
- offset: 0,
- identifier: 'Africa/Accra',
- }),
- ).toEqual('[UTC 0] Accra');
- });
- });
-
- describe('findTimezoneByIdentifier', () => {
- const tzList = [
- {
- identifier: 'Asia/Tokyo',
- name: 'Sapporo',
- offset: 32400,
- },
- {
- identifier: 'Asia/Hong_Kong',
- name: 'Hong Kong',
- offset: 28800,
- },
- {
- identifier: 'Asia/Dhaka',
- name: 'Dhaka',
- offset: 21600,
- },
- ];
-
- const identifier = 'Asia/Dhaka';
- it('returns the correct object if the identifier exists', () => {
- const res = findTimezoneByIdentifier(tzList, identifier);
-
- expect(res).toBe(tzList[2]);
- });
-
- it('returns null if it doesnt find the identifier', () => {
- const res = findTimezoneByIdentifier(tzList, 'Australia/Melbourne');
-
- expect(res).toBeNull();
- });
-
- it('returns null if there is no identifier given', () => {
- expect(findTimezoneByIdentifier(tzList)).toBeNull();
- expect(findTimezoneByIdentifier(tzList, '')).toBeNull();
- });
-
- it('returns null if there is an empty or invalid array given', () => {
- expect(findTimezoneByIdentifier([], identifier)).toBeNull();
- expect(findTimezoneByIdentifier(null, identifier)).toBeNull();
- expect(findTimezoneByIdentifier(undefined, identifier)).toBeNull();
- });
- });
-});
diff --git a/spec/lib/atlassian/jira_connect/client_spec.rb b/spec/lib/atlassian/jira_connect/client_spec.rb
index 0ae0f02c46e..a8ee28d3714 100644
--- a/spec/lib/atlassian/jira_connect/client_spec.rb
+++ b/spec/lib/atlassian/jira_connect/client_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-RSpec.describe Atlassian::JiraConnect::Client do
+RSpec.describe Atlassian::JiraConnect::Client, feature_category: :integrations do
include StubRequests
subject(:client) { described_class.new('https://gitlab-test.atlassian.net', 'sample_secret') }
@@ -119,7 +119,7 @@ RSpec.describe Atlassian::JiraConnect::Client do
let(:errors) { [{ 'message' => 'X' }, { 'message' => 'Y' }] }
let(:processed) { subject.send(:handle_response, response, 'foo') { |x| [:data, x] } }
- context 'the response is 200 OK' do
+ context 'when the response is 200 OK' do
let(:response) { double(code: 200, parsed_response: :foo) }
it 'yields to the block' do
@@ -127,7 +127,7 @@ RSpec.describe Atlassian::JiraConnect::Client do
end
end
- context 'the response is 202 accepted' do
+ context 'when the response is 202 accepted' do
let(:response) { double(code: 202, parsed_response: :foo) }
it 'yields to the block' do
@@ -135,15 +135,15 @@ RSpec.describe Atlassian::JiraConnect::Client do
end
end
- context 'the response is 400 bad request' do
+ context 'when the response is 400 bad request' do
let(:response) { double(code: 400, parsed_response: errors) }
it 'extracts the errors messages' do
- expect(processed).to eq('errorMessages' => %w(X Y), 'responseCode' => 400)
+ expect(processed).to eq('errorMessages' => %w[X Y], 'responseCode' => 400)
end
end
- context 'the response is 401 forbidden' do
+ context 'when the response is 401 forbidden' do
let(:response) { double(code: 401, parsed_response: nil) }
it 'reports that our JWT is wrong' do
@@ -151,7 +151,7 @@ RSpec.describe Atlassian::JiraConnect::Client do
end
end
- context 'the response is 403' do
+ context 'when the response is 403' do
let(:response) { double(code: 403, parsed_response: nil) }
it 'reports that the App is misconfigured' do
@@ -159,7 +159,7 @@ RSpec.describe Atlassian::JiraConnect::Client do
end
end
- context 'the response is 413' do
+ context 'when the response is 413' do
let(:response) { double(code: 413, parsed_response: errors) }
it 'extracts the errors messages' do
@@ -167,7 +167,7 @@ RSpec.describe Atlassian::JiraConnect::Client do
end
end
- context 'the response is 429' do
+ context 'when the response is 429' do
let(:response) { double(code: 429, parsed_response: nil) }
it 'reports that we exceeded the rate limit' do
@@ -175,7 +175,7 @@ RSpec.describe Atlassian::JiraConnect::Client do
end
end
- context 'the response is 503' do
+ context 'when the response is 503' do
let(:response) { double(code: 503, parsed_response: nil) }
it 'reports that the service is unavailable' do
@@ -183,7 +183,7 @@ RSpec.describe Atlassian::JiraConnect::Client do
end
end
- context 'the response is anything else' do
+ context 'when the response is anything else' do
let(:response) { double(code: 1000, parsed_response: :something) }
it 'reports that this was unanticipated' do
@@ -192,6 +192,26 @@ RSpec.describe Atlassian::JiraConnect::Client do
end
end
+ describe '#request_body_schema' do
+ let(:response) { instance_double(HTTParty::Response, success?: true, code: 200, request: request) }
+
+ context 'with valid JSON request body' do
+ let(:request) { instance_double(HTTParty::Request, raw_body: '{ "foo": 1, "bar": 2 }') }
+
+ it 'returns the request body' do
+ expect(subject.send(:request_body_schema, response)).to eq({ "foo" => nil, "bar" => nil })
+ end
+ end
+
+ context 'with invalid JSON request body' do
+ let(:request) { instance_double(HTTParty::Request, raw_body: 'invalid json') }
+
+ it 'reports the invalid json' do
+ expect(subject.send(:request_body_schema, response)).to eq('Request body includes invalid JSON')
+ end
+ end
+ end
+
describe '#store_deploy_info' do
let_it_be(:environment) { create(:environment, name: 'DEV', project: project) }
let_it_be(:deployments) do
@@ -222,7 +242,7 @@ RSpec.describe Atlassian::JiraConnect::Client do
before do
path = '/rest/deployments/0.1/bulk'
- stub_full_request('https://gitlab-test.atlassian.net' + path, method: :post)
+ stub_full_request("https://gitlab-test.atlassian.net#{path}", method: :post)
.with(body: body, headers: expected_headers(path))
.to_return(body: response_body, headers: { 'Content-Type': 'application/json' })
end
@@ -232,7 +252,9 @@ RSpec.describe Atlassian::JiraConnect::Client do
end
it 'only sends information about relevant MRs' do
- expect(subject).to receive(:post).with('/rest/deployments/0.1/bulk', { deployments: have_attributes(size: 6) }).and_call_original
+ expect(subject).to receive(:post).with(
+ '/rest/deployments/0.1/bulk', { deployments: have_attributes(size: 6) }
+ ).and_call_original
subject.send(:store_deploy_info, project: project, deployments: deployments)
end
@@ -243,7 +265,7 @@ RSpec.describe Atlassian::JiraConnect::Client do
subject.send(:store_deploy_info, project: project, deployments: deployments.take(1))
end
- context 'there are errors' do
+ context 'when there are errors' do
let(:rejections) do
[{ errors: [{ message: 'X' }, { message: 'Y' }] }, { errors: [{ message: 'Z' }] }]
end
@@ -251,7 +273,9 @@ RSpec.describe Atlassian::JiraConnect::Client do
it 'reports the errors' do
response = subject.send(:store_deploy_info, project: project, deployments: deployments)
- expect(response['errorMessages']).to eq(%w(X Y Z))
+ expect(response['errorMessages']).to eq(%w[X Y Z])
+ expect(response['responseCode']).to eq(200)
+ expect(response['requestBody']).to be_a(Hash)
end
end
end
@@ -282,7 +306,7 @@ RSpec.describe Atlassian::JiraConnect::Client do
feature_flags.first.update!(description: 'RELEVANT-123')
feature_flags.second.update!(description: 'RELEVANT-123')
path = '/rest/featureflags/0.1/bulk'
- stub_full_request('https://gitlab-test.atlassian.net' + path, method: :post)
+ stub_full_request("https://gitlab-test.atlassian.net#{path}", method: :post)
.with(body: body, headers: expected_headers(path))
.to_return(body: response_body, headers: { 'Content-Type': 'application/json' })
end
@@ -292,9 +316,9 @@ RSpec.describe Atlassian::JiraConnect::Client do
end
it 'only sends information about relevant MRs' do
- expect(subject).to receive(:post).with('/rest/featureflags/0.1/bulk', {
- flags: have_attributes(size: 2), properties: Hash
- }).and_call_original
+ expect(subject).to receive(:post).with(
+ '/rest/featureflags/0.1/bulk', { flags: have_attributes(size: 2), properties: Hash }
+ ).and_call_original
subject.send(:store_ff_info, project: project, feature_flags: feature_flags)
end
@@ -305,7 +329,7 @@ RSpec.describe Atlassian::JiraConnect::Client do
subject.send(:store_ff_info, project: project, feature_flags: [feature_flags.last])
end
- context 'there are errors' do
+ context 'when there are errors' do
let(:failures) do
{
a: [{ message: 'X' }, { message: 'Y' }],
@@ -343,7 +367,7 @@ RSpec.describe Atlassian::JiraConnect::Client do
before do
path = '/rest/builds/0.1/bulk'
- stub_full_request('https://gitlab-test.atlassian.net' + path, method: :post)
+ stub_full_request("https://gitlab-test.atlassian.net#{path}", method: :post)
.with(body: body, headers: expected_headers(path))
.to_return(body: response_body, headers: { 'Content-Type': 'application/json' })
end
@@ -366,7 +390,7 @@ RSpec.describe Atlassian::JiraConnect::Client do
subject.send(:store_build_info, project: project, pipelines: pipelines.take(1))
end
- context 'there are errors' do
+ context 'when there are errors' do
let(:failures) do
[{ errors: [{ message: 'X' }, { message: 'Y' }] }, { errors: [{ message: 'Z' }] }]
end
@@ -374,7 +398,9 @@ RSpec.describe Atlassian::JiraConnect::Client do
it 'reports the errors' do
response = subject.send(:store_build_info, project: project, pipelines: pipelines)
- expect(response['errorMessages']).to eq(%w(X Y Z))
+ expect(response['errorMessages']).to eq(%w[X Y Z])
+ expect(response['responseCode']).to eq(200)
+ expect(response['requestBody']).to be_a(Hash)
end
end
@@ -385,19 +411,21 @@ RSpec.describe Atlassian::JiraConnect::Client do
subject.send(:store_build_info, project: project, pipelines: pipelines)
end
- pipelines << create(:ci_pipeline, head_pipeline_of: create(:merge_request, :jira_branch))
+ pipelines << create(:ci_pipeline, project: project, head_pipeline_of: create(:merge_request, :jira_branch, source_project: project))
- expect { subject.send(:store_build_info, project: project, pipelines: pipelines) }.not_to exceed_query_limit(baseline)
+ expect do
+ subject.send(:store_build_info, project: project, pipelines: pipelines)
+ end.not_to exceed_query_limit(baseline)
end
end
describe '#store_dev_info' do
- let_it_be(:merge_requests) { create_list(:merge_request, 2, :unique_branches) }
+ let_it_be(:merge_requests) { create_list(:merge_request, 2, :unique_branches, source_project: project) }
before do
path = '/rest/devinfo/0.10/bulk'
- stub_full_request('https://gitlab-test.atlassian.net' + path, method: :post)
+ stub_full_request("https://gitlab-test.atlassian.net#{path}", method: :post)
.with(headers: expected_headers(path))
end
@@ -406,11 +434,16 @@ RSpec.describe Atlassian::JiraConnect::Client do
end
it 'avoids N+1 database queries' do
- control_count = ActiveRecord::QueryRecorder.new { subject.send(:store_dev_info, project: project, merge_requests: merge_requests) }.count
+ control_count = ActiveRecord::QueryRecorder.new do
+ subject.send(:store_dev_info, project: project, merge_requests: merge_requests)
+ end.count
- merge_requests << create(:merge_request, :unique_branches)
+ merge_requests << create(:merge_request, :unique_branches, source_project: project)
- expect { subject.send(:store_dev_info, project: project, merge_requests: merge_requests) }.not_to exceed_query_limit(control_count)
+ expect do
+ subject.send(:store_dev_info, project: project,
+ merge_requests: merge_requests)
+ end.not_to exceed_query_limit(control_count)
end
end
diff --git a/spec/services/projects/container_repository/destroy_service_spec.rb b/spec/services/projects/container_repository/destroy_service_spec.rb
index b6196a11e32..0ec0aecaa04 100644
--- a/spec/services/projects/container_repository/destroy_service_spec.rb
+++ b/spec/services/projects/container_repository/destroy_service_spec.rb
@@ -75,28 +75,6 @@ RSpec.describe Projects::ContainerRepository::DestroyService do
end
end
- context 'when use_delete_tags_service_on_destroy_service feature flag is disabled' do
- before do
- stub_feature_flags(use_delete_tags_service_on_destroy_service: false)
- stub_container_registry_tags(repository: :any, tags: [])
- end
-
- it 'deletes the repository' do
- expect(repository).to receive(:delete_tags!).and_call_original
- expect { subject.execute(repository) }.to change { ContainerRepository.count }.by(-1)
- end
-
- context 'when destroy fails' do
- it 'set delete_status' do
- allow(repository).to receive(:destroy).and_return(false)
-
- subject.execute(repository)
-
- expect(repository).to be_delete_failed
- end
- end
- end
-
def expect_cleanup_tags_service_with(container_repository:, return_status:, disable_timeout: true)
delete_tags_service = instance_double(Projects::ContainerRepository::CleanupTagsService)
diff --git a/spec/services/projects/destroy_service_spec.rb b/spec/services/projects/destroy_service_spec.rb
index d53867866f0..49896d7b6b5 100644
--- a/spec/services/projects/destroy_service_spec.rb
+++ b/spec/services/projects/destroy_service_spec.rb
@@ -358,30 +358,6 @@ RSpec.describe Projects::DestroyService, :aggregate_failures, :event_store_publi
destroy_project(project, user)
end
end
-
- context 'when use_delete_tags_service_on_destroy_service feature flag is disabled' do
- before do
- stub_feature_flags(use_delete_tags_service_on_destroy_service: false)
- end
-
- context 'when image repository deletion succeeds' do
- it 'removes tags' do
- expect_any_instance_of(ContainerRepository)
- .to receive(:delete_tags!).and_return(true)
-
- destroy_project(project, user)
- end
- end
-
- context 'when image repository deletion fails' do
- it 'raises an exception' do
- expect_any_instance_of(ContainerRepository)
- .to receive(:delete_tags!).and_raise(RuntimeError)
-
- expect(destroy_project(project, user)).to be false
- end
- end
- end
end
context 'when there are tags for legacy root repository' do