2019-12-10 07:53:40 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe GitlabSchema.types['Snippet'] do
|
2020-03-19 09:09:27 +00:00
|
|
|
let_it_be(:user) { create(:user) }
|
|
|
|
|
2019-12-10 07:53:40 +00:00
|
|
|
it 'has the correct fields' do
|
|
|
|
expected_fields = [:id, :title, :project, :author,
|
2020-01-22 12:08:40 +00:00
|
|
|
:file_name, :description,
|
2019-12-13 09:08:01 +00:00
|
|
|
:visibility_level, :created_at, :updated_at,
|
2020-03-19 09:09:27 +00:00
|
|
|
:web_url, :raw_url, :ssh_url_to_repo, :http_url_to_repo,
|
|
|
|
:notes, :discussions, :user_permissions,
|
|
|
|
:description_html, :blob]
|
2019-12-10 07:53:40 +00:00
|
|
|
|
2020-03-18 18:09:35 +00:00
|
|
|
expect(described_class).to have_graphql_fields(*expected_fields)
|
2019-12-10 07:53:40 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
describe 'authorizations' do
|
|
|
|
it { expect(described_class).to require_graphql_authorizations(:read_snippet) }
|
|
|
|
end
|
2020-02-25 09:09:10 +00:00
|
|
|
|
2020-03-19 09:09:27 +00:00
|
|
|
shared_examples 'response without repository URLs' do
|
|
|
|
it 'does not respond with repository URLs' do
|
|
|
|
expect(response['sshUrlToRepo']).to be_nil
|
|
|
|
expect(response['httpUrlToRepo']).to be_nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-04-03 18:10:03 +00:00
|
|
|
shared_examples 'snippets with repositories' do
|
2020-03-19 09:09:27 +00:00
|
|
|
context 'when snippet has repository' do
|
2020-04-03 18:10:03 +00:00
|
|
|
let_it_be(:snippet) { create(:personal_snippet, :repository, :public, author: user) }
|
2020-03-19 09:09:27 +00:00
|
|
|
|
|
|
|
it 'responds with repository URLs' do
|
|
|
|
expect(response['sshUrlToRepo']).to eq(snippet.ssh_url_to_repo)
|
|
|
|
expect(response['httpUrlToRepo']).to eq(snippet.http_url_to_repo)
|
|
|
|
end
|
|
|
|
end
|
2020-04-03 18:10:03 +00:00
|
|
|
end
|
2020-03-19 09:09:27 +00:00
|
|
|
|
2020-04-03 18:10:03 +00:00
|
|
|
shared_examples 'snippets without repositories' do
|
2020-03-19 09:09:27 +00:00
|
|
|
context 'when snippet does not have a repository' do
|
2020-04-03 18:10:03 +00:00
|
|
|
let_it_be(:snippet) { create(:personal_snippet, :public, author: user) }
|
2020-03-19 09:09:27 +00:00
|
|
|
|
|
|
|
it_behaves_like 'response without repository URLs'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-04-03 18:10:03 +00:00
|
|
|
describe 'Repository URLs' do
|
|
|
|
let(:query) do
|
|
|
|
%(
|
|
|
|
{
|
|
|
|
snippets {
|
|
|
|
nodes {
|
|
|
|
sshUrlToRepo
|
|
|
|
httpUrlToRepo
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
|
|
|
end
|
|
|
|
let(:response) { subject.dig('data', 'snippets', 'nodes')[0] }
|
|
|
|
|
|
|
|
subject { GitlabSchema.execute(query, context: { current_user: user }).as_json }
|
|
|
|
|
|
|
|
context 'when RequestStore is disabled' do
|
|
|
|
it_behaves_like 'snippets with repositories'
|
|
|
|
it_behaves_like 'snippets without repositories'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when RequestStore is enabled', :request_store do
|
|
|
|
it_behaves_like 'snippets with repositories'
|
|
|
|
it_behaves_like 'snippets without repositories'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-02-25 09:09:10 +00:00
|
|
|
describe '#blob' do
|
|
|
|
let(:query_blob) { subject.dig('data', 'snippets', 'edges')[0]['node']['blob'] }
|
|
|
|
let(:query) do
|
|
|
|
%(
|
|
|
|
{
|
|
|
|
snippets {
|
|
|
|
edges {
|
|
|
|
node {
|
|
|
|
blob {
|
|
|
|
name
|
|
|
|
path
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
subject { GitlabSchema.execute(query, context: { current_user: user }).as_json }
|
|
|
|
|
|
|
|
context 'when snippet has repository' do
|
|
|
|
let!(:snippet) { create(:personal_snippet, :repository, :public, author: user) }
|
|
|
|
let(:blob) { snippet.blobs.first }
|
|
|
|
|
|
|
|
it 'returns blob from the repository' do
|
|
|
|
expect(query_blob['name']).to eq blob.name
|
|
|
|
expect(query_blob['path']).to eq blob.path
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when snippet does not have a repository' do
|
|
|
|
let!(:snippet) { create(:personal_snippet, :public, author: user) }
|
|
|
|
let(:blob) { snippet.blob }
|
|
|
|
|
|
|
|
it 'returns SnippetBlob type' do
|
|
|
|
expect(query_blob['name']).to eq blob.name
|
|
|
|
expect(query_blob['path']).to eq blob.path
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2019-12-10 07:53:40 +00:00
|
|
|
end
|