2019-12-10 07:53:40 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe GitlabSchema.types['Snippet'] do
|
|
|
|
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,
|
2019-12-10 07:53:40 +00:00
|
|
|
:web_url, :raw_url, :notes, :discussions,
|
2020-01-22 12:08:40 +00:00
|
|
|
: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
|
|
|
|
|
|
|
describe '#blob' do
|
|
|
|
let_it_be(:user) { create(:user) }
|
|
|
|
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
|