diff options
Diffstat (limited to 'spec/lib/atlassian')
5 files changed, 131 insertions, 0 deletions
diff --git a/spec/lib/atlassian/jira_connect/client_spec.rb b/spec/lib/atlassian/jira_connect/client_spec.rb new file mode 100644 index 00000000000..40ffec21b26 --- /dev/null +++ b/spec/lib/atlassian/jira_connect/client_spec.rb @@ -0,0 +1,36 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Atlassian::JiraConnect::Client do + include StubRequests + + subject { described_class.new('https://gitlab-test.atlassian.net', 'sample_secret') } + + around do |example| + Timecop.freeze { example.run } + end + + describe '#store_dev_info' do + it "calls the API with auth headers" do + expected_jwt = Atlassian::Jwt.encode( + Atlassian::Jwt.build_claims( + Atlassian::JiraConnect.app_key, + '/rest/devinfo/0.10/bulk', + 'POST' + ), + 'sample_secret' + ) + + stub_full_request('https://gitlab-test.atlassian.net/rest/devinfo/0.10/bulk', method: :post) + .with( + headers: { + 'Authorization' => "JWT #{expected_jwt}", + 'Content-Type' => 'application/json' + } + ) + + subject.store_dev_info(project: create(:project)) + end + end +end diff --git a/spec/lib/atlassian/jira_connect/serializers/author_entity_spec.rb b/spec/lib/atlassian/jira_connect/serializers/author_entity_spec.rb new file mode 100644 index 00000000000..f31cf929244 --- /dev/null +++ b/spec/lib/atlassian/jira_connect/serializers/author_entity_spec.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Atlassian::JiraConnect::Serializers::AuthorEntity do + subject { described_class.represent(user).as_json } + + context 'when object is a User model' do + let(:user) { build_stubbed(:user) } + + it 'exposes all fields' do + expect(subject.keys).to contain_exactly(:name, :email, :username, :url, :avatar) + end + end + + context 'when object is a CommitAuthor struct from a commit' do + let(:user) { Atlassian::JiraConnect::Serializers::CommitEntity::CommitAuthor.new('Full Name', 'user@example.com') } + + it 'exposes name and email only' do + expect(subject.keys).to contain_exactly(:name, :email) + end + end +end diff --git a/spec/lib/atlassian/jira_connect/serializers/branch_entity_spec.rb b/spec/lib/atlassian/jira_connect/serializers/branch_entity_spec.rb new file mode 100644 index 00000000000..e69e2aae94c --- /dev/null +++ b/spec/lib/atlassian/jira_connect/serializers/branch_entity_spec.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Atlassian::JiraConnect::Serializers::BranchEntity do + let(:project) { create(:project, :repository) } + let(:branch) { project.repository.find_branch('improve/awesome') } + + subject { described_class.represent(branch, project: project).as_json } + + it 'sets the hash of the branch name as the id' do + expect(subject[:id]).to eq('bbfba9b197ace5da93d03382a7ce50081ae89d99faac1f2326566941288871ce') + end +end diff --git a/spec/lib/atlassian/jira_connect/serializers/repository_entity_spec.rb b/spec/lib/atlassian/jira_connect/serializers/repository_entity_spec.rb new file mode 100644 index 00000000000..23ba1770827 --- /dev/null +++ b/spec/lib/atlassian/jira_connect/serializers/repository_entity_spec.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Atlassian::JiraConnect::Serializers::RepositoryEntity do + subject do + project = create(:project, :repository) + commits = [project.commit] + branches = [project.repository.find_branch('master')] + merge_requests = [create(:merge_request, source_project: project, target_project: project)] + + described_class.represent( + project, + commits: commits, + branches: branches, + merge_requests: merge_requests + ).to_json + end + + it { is_expected.to match_schema('jira_connect/repository') } +end diff --git a/spec/lib/atlassian/jira_issue_key_extractor_spec.rb b/spec/lib/atlassian/jira_issue_key_extractor_spec.rb new file mode 100644 index 00000000000..ce29e03f818 --- /dev/null +++ b/spec/lib/atlassian/jira_issue_key_extractor_spec.rb @@ -0,0 +1,37 @@ +# frozen_string_literal: true + +require 'fast_spec_helper' + +RSpec.describe Atlassian::JiraIssueKeyExtractor do + describe '.has_keys?' do + subject { described_class.has_keys?(string) } + + context 'when string contains Jira issue keys' do + let(:string) { 'Test some string TEST-01 with keys' } + + it { is_expected.to eq(true) } + end + + context 'when string does not contain Jira issue keys' do + let(:string) { 'string with no jira issue keys' } + + it { is_expected.to eq(false) } + end + end + + describe '#issue_keys' do + subject { described_class.new('TEST-01 Some A-100 issue title OTHER-02 ABC!-1 that mentions Jira issue').issue_keys } + + it 'returns all valid Jira issue keys' do + is_expected.to contain_exactly('TEST-01', 'OTHER-02') + end + + context 'when multiple strings are passed in' do + subject { described_class.new('TEST-01 Some A-100', 'issue title OTHER', '-02 ABC!-1 that mentions Jira issue').issue_keys } + + it 'returns all valid Jira issue keys in any of those string' do + is_expected.to contain_exactly('TEST-01') + end + end + end +end |