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:
authorNick Thomas <nick@gitlab.com>2018-10-03 02:00:38 +0300
committerNick Thomas <nick@gitlab.com>2018-10-05 13:34:43 +0300
commit25bd49e4f57fe15f9d61dc9376a5b7dc35b30f64 (patch)
treefaef4e9d73e9845413462013c868eace19a11abf /spec
parentae014e189773f7299c12c1050334b3e8fe7b15d8 (diff)
Backport project template API to CE
Diffstat (limited to 'spec')
-rw-r--r--spec/finders/license_template_finder_spec.rb4
-rw-r--r--spec/finders/template_finder_spec.rb11
-rw-r--r--spec/fixtures/api/schemas/public_api/v4/license.json30
-rw-r--r--spec/fixtures/api/schemas/public_api/v4/template.json12
-rw-r--r--spec/fixtures/api/schemas/public_api/v4/template_list.json15
-rw-r--r--spec/javascripts/api_spec.js64
-rw-r--r--spec/models/license_template_spec.rb2
-rw-r--r--spec/requests/api/project_templates_spec.rb145
8 files changed, 231 insertions, 52 deletions
diff --git a/spec/finders/license_template_finder_spec.rb b/spec/finders/license_template_finder_spec.rb
index a97903103c9..f6f40bf33cc 100644
--- a/spec/finders/license_template_finder_spec.rb
+++ b/spec/finders/license_template_finder_spec.rb
@@ -2,7 +2,7 @@ require 'spec_helper'
describe LicenseTemplateFinder do
describe '#execute' do
- subject(:result) { described_class.new(params).execute }
+ subject(:result) { described_class.new(nil, params).execute }
let(:categories) { categorised_licenses.keys }
let(:categorised_licenses) { result.group_by(&:category) }
@@ -31,7 +31,7 @@ describe LicenseTemplateFinder do
it 'returns all licenses known by the Licensee gem' do
from_licensee = Licensee::License.all.map { |l| l.key }
- expect(result.map(&:id)).to match_array(from_licensee)
+ expect(result.map(&:key)).to match_array(from_licensee)
end
it 'correctly copies all attributes' do
diff --git a/spec/finders/template_finder_spec.rb b/spec/finders/template_finder_spec.rb
index 1d399e8194f..114af9461e0 100644
--- a/spec/finders/template_finder_spec.rb
+++ b/spec/finders/template_finder_spec.rb
@@ -4,6 +4,8 @@ describe TemplateFinder do
using RSpec::Parameterized::TableSyntax
describe '#build' do
+ let(:project) { build_stubbed(:project) }
+
where(:type, :expected_class) do
:dockerfiles | described_class
:gitignores | described_class
@@ -12,9 +14,10 @@ describe TemplateFinder do
end
with_them do
- subject { described_class.build(type) }
+ subject(:finder) { described_class.build(type, project) }
it { is_expected.to be_a(expected_class) }
+ it { expect(finder.project).to eq(project) }
end
end
@@ -27,19 +30,19 @@ describe TemplateFinder do
with_them do
it 'returns all vendored templates when no name is specified' do
- result = described_class.new(type).execute
+ result = described_class.new(type, nil).execute
expect(result).to include(have_attributes(name: vendored_name))
end
it 'returns only the specified vendored template when a name is specified' do
- result = described_class.new(type, name: vendored_name).execute
+ result = described_class.new(type, nil, name: vendored_name).execute
expect(result).to have_attributes(name: vendored_name)
end
it 'returns nil when an unknown name is specified' do
- result = described_class.new(type, name: 'unknown').execute
+ result = described_class.new(type, nil, name: 'unknown').execute
expect(result).to be_nil
end
diff --git a/spec/fixtures/api/schemas/public_api/v4/license.json b/spec/fixtures/api/schemas/public_api/v4/license.json
new file mode 100644
index 00000000000..38c8c3e9192
--- /dev/null
+++ b/spec/fixtures/api/schemas/public_api/v4/license.json
@@ -0,0 +1,30 @@
+{
+ "type": "object",
+ "required": [
+ "key",
+ "name",
+ "nickname",
+ "popular",
+ "html_url",
+ "source_url",
+ "description",
+ "conditions",
+ "permissions",
+ "limitations",
+ "content"
+ ],
+ "properties": {
+ "key": { "type": "string" },
+ "name": { "type": "string" },
+ "nickname": { "type": ["null", "string"] },
+ "popular": { "type": "boolean" },
+ "html_url": { "type": ["null", "string"] },
+ "source_url": { "type": ["null", "string"] },
+ "description": { "type": ["null", "string"] },
+ "conditions": { "type": "array", "items": { "type": "string" } },
+ "permissions": { "type": "array", "items": { "type": "string" } },
+ "limitations": { "type": "array", "items": { "type": "string" } },
+ "content": { "type": "string" }
+ },
+ "additionalProperties": false
+}
diff --git a/spec/fixtures/api/schemas/public_api/v4/template.json b/spec/fixtures/api/schemas/public_api/v4/template.json
new file mode 100644
index 00000000000..38601aa6b45
--- /dev/null
+++ b/spec/fixtures/api/schemas/public_api/v4/template.json
@@ -0,0 +1,12 @@
+{
+ "type": "object",
+ "required": [
+ "name",
+ "content"
+ ],
+ "properties": {
+ "name": { "type": "string" },
+ "content": { "type": "string" }
+ },
+ "additionalProperties": false
+}
diff --git a/spec/fixtures/api/schemas/public_api/v4/template_list.json b/spec/fixtures/api/schemas/public_api/v4/template_list.json
new file mode 100644
index 00000000000..2336dafb17b
--- /dev/null
+++ b/spec/fixtures/api/schemas/public_api/v4/template_list.json
@@ -0,0 +1,15 @@
+{
+ "type": "array",
+ "items": {
+ "type": "object",
+ "required": [
+ "key",
+ "name"
+ ],
+ "properties": {
+ "key": { "type": "string" },
+ "name": { "type": "string" }
+ },
+ "additionalProperties": false
+ }
+}
diff --git a/spec/javascripts/api_spec.js b/spec/javascripts/api_spec.js
index 54cb6d84109..091edf13cfe 100644
--- a/spec/javascripts/api_spec.js
+++ b/spec/javascripts/api_spec.js
@@ -250,71 +250,45 @@ describe('Api', () => {
});
});
- describe('licenseText', () => {
- it('fetches a license text', done => {
- const licenseKey = "driver's license";
- const data = { unused: 'option' };
- const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/templates/licenses/${licenseKey}`;
+ describe('issueTemplate', () => {
+ it('fetches an issue template', done => {
+ const namespace = 'some namespace';
+ const project = 'some project';
+ const templateKey = ' template #%?.key ';
+ const templateType = 'template type';
+ const expectedUrl = `${dummyUrlRoot}/${namespace}/${project}/templates/${templateType}/${encodeURIComponent(
+ templateKey,
+ )}`;
mock.onGet(expectedUrl).reply(200, 'test');
- Api.licenseText(licenseKey, data, response => {
+ Api.issueTemplate(namespace, project, templateKey, templateType, (error, response) => {
expect(response).toBe('test');
done();
});
});
});
- describe('gitignoreText', () => {
- it('fetches a gitignore text', done => {
- const gitignoreKey = 'ignore git';
- const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/templates/gitignores/${gitignoreKey}`;
- mock.onGet(expectedUrl).reply(200, 'test');
-
- Api.gitignoreText(gitignoreKey, response => {
- expect(response).toBe('test');
- done();
- });
- });
- });
+ describe('projectTemplates', () => {
+ it('fetches a list of templates', done => {
+ const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/projects/gitlab-org%2Fgitlab-ce/templates/licenses`;
- describe('gitlabCiYml', () => {
- it('fetches a .gitlab-ci.yml', done => {
- const gitlabCiYmlKey = 'Y CI ML';
- const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/templates/gitlab_ci_ymls/${gitlabCiYmlKey}`;
mock.onGet(expectedUrl).reply(200, 'test');
- Api.gitlabCiYml(gitlabCiYmlKey, response => {
+ Api.projectTemplates('gitlab-org/gitlab-ce', 'licenses', {}, response => {
expect(response).toBe('test');
done();
});
});
});
- describe('dockerfileYml', () => {
- it('fetches a Dockerfile', done => {
- const dockerfileYmlKey = 'a giant whale';
- const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/templates/dockerfiles/${dockerfileYmlKey}`;
- mock.onGet(expectedUrl).reply(200, 'test');
-
- Api.dockerfileYml(dockerfileYmlKey, response => {
- expect(response).toBe('test');
- done();
- });
- });
- });
+ describe('projectTemplate', () => {
+ it('fetches a single template', done => {
+ const data = { unused: 'option' };
+ const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/projects/gitlab-org%2Fgitlab-ce/templates/licenses/test%20license`;
- describe('issueTemplate', () => {
- it('fetches an issue template', done => {
- const namespace = 'some namespace';
- const project = 'some project';
- const templateKey = ' template #%?.key ';
- const templateType = 'template type';
- const expectedUrl = `${dummyUrlRoot}/${namespace}/${project}/templates/${templateType}/${encodeURIComponent(
- templateKey,
- )}`;
mock.onGet(expectedUrl).reply(200, 'test');
- Api.issueTemplate(namespace, project, templateKey, templateType, (error, response) => {
+ Api.projectTemplate('gitlab-org/gitlab-ce', 'licenses', 'test license', data, response => {
expect(response).toBe('test');
done();
});
diff --git a/spec/models/license_template_spec.rb b/spec/models/license_template_spec.rb
index c633e1908d4..dd912eefac1 100644
--- a/spec/models/license_template_spec.rb
+++ b/spec/models/license_template_spec.rb
@@ -54,6 +54,6 @@ describe LicenseTemplate do
end
def build_template(content)
- described_class.new(id: 'foo', name: 'foo', category: :Other, content: content)
+ described_class.new(key: 'foo', name: 'foo', category: :Other, content: content)
end
end
diff --git a/spec/requests/api/project_templates_spec.rb b/spec/requests/api/project_templates_spec.rb
new file mode 100644
index 00000000000..86e33f23951
--- /dev/null
+++ b/spec/requests/api/project_templates_spec.rb
@@ -0,0 +1,145 @@
+require 'spec_helper'
+
+describe API::ProjectTemplates do
+ let(:public_project) { create(:project, :public) }
+ let(:private_project) { create(:project, :private) }
+ let(:developer) { create(:user) }
+
+ before do
+ private_project.add_developer(developer)
+ end
+
+ describe 'GET /projects/:id/templates/:type' do
+ it 'returns dockerfiles' do
+ get api("/projects/#{public_project.id}/templates/dockerfiles")
+
+ expect(response).to have_gitlab_http_status(200)
+ expect(response).to include_pagination_headers
+ expect(response).to match_response_schema('public_api/v4/template_list')
+ expect(json_response).to satisfy_one { |template| template['key'] == 'Binary' }
+ end
+
+ it 'returns gitignores' do
+ get api("/projects/#{public_project.id}/templates/gitignores")
+
+ expect(response).to have_gitlab_http_status(200)
+ expect(response).to include_pagination_headers
+ expect(response).to match_response_schema('public_api/v4/template_list')
+ expect(json_response).to satisfy_one { |template| template['key'] == 'Actionscript' }
+ end
+
+ it 'returns gitlab_ci_ymls' do
+ get api("/projects/#{public_project.id}/templates/gitlab_ci_ymls")
+
+ expect(response).to have_gitlab_http_status(200)
+ expect(response).to include_pagination_headers
+ expect(response).to match_response_schema('public_api/v4/template_list')
+ expect(json_response).to satisfy_one { |template| template['key'] == 'Android' }
+ end
+
+ it 'returns licenses' do
+ get api("/projects/#{public_project.id}/templates/licenses")
+
+ expect(response).to have_gitlab_http_status(200)
+ expect(response).to include_pagination_headers
+ expect(response).to match_response_schema('public_api/v4/template_list')
+ expect(json_response).to satisfy_one { |template| template['key'] == 'mit' }
+ end
+
+ it 'returns 400 for an unknown template type' do
+ get api("/projects/#{public_project.id}/templates/unknown")
+
+ expect(response).to have_gitlab_http_status(400)
+ end
+
+ it 'denies access to an anonymous user on a private project' do
+ get api("/projects/#{private_project.id}/templates/licenses")
+
+ expect(response).to have_gitlab_http_status(404)
+ end
+
+ it 'permits access to a developer on a private project' do
+ get api("/projects/#{private_project.id}/templates/licenses", developer)
+
+ expect(response).to have_gitlab_http_status(200)
+ expect(response).to match_response_schema('public_api/v4/template_list')
+ end
+ end
+
+ describe 'GET /projects/:id/templates/licenses' do
+ it 'returns key and name for the listed licenses' do
+ get api("/projects/#{public_project.id}/templates/licenses")
+
+ expect(response).to have_gitlab_http_status(200)
+ expect(response).to match_response_schema('public_api/v4/template_list')
+ end
+ end
+
+ describe 'GET /projects/:id/templates/:type/:key' do
+ it 'returns a specific dockerfile' do
+ get api("/projects/#{public_project.id}/templates/dockerfiles/Binary")
+
+ expect(response).to have_gitlab_http_status(200)
+ expect(response).to match_response_schema('public_api/v4/template')
+ expect(json_response['name']).to eq('Binary')
+ end
+
+ it 'returns a specific gitignore' do
+ get api("/projects/#{public_project.id}/templates/gitignores/Actionscript")
+
+ expect(response).to have_gitlab_http_status(200)
+ expect(response).to match_response_schema('public_api/v4/template')
+ expect(json_response['name']).to eq('Actionscript')
+ end
+
+ it 'returns a specific gitlab_ci_yml' do
+ get api("/projects/#{public_project.id}/templates/gitlab_ci_ymls/Android")
+
+ expect(response).to have_gitlab_http_status(200)
+ expect(response).to match_response_schema('public_api/v4/template')
+ expect(json_response['name']).to eq('Android')
+ end
+
+ it 'returns a specific license' do
+ get api("/projects/#{public_project.id}/templates/licenses/mit")
+
+ expect(response).to have_gitlab_http_status(200)
+ expect(response).to match_response_schema('public_api/v4/license')
+ end
+
+ it 'returns 404 for an unknown specific template' do
+ get api("/projects/#{public_project.id}/templates/licenses/unknown")
+
+ expect(response).to have_gitlab_http_status(404)
+ end
+
+ it 'denies access to an anonymous user on a private project' do
+ get api("/projects/#{private_project.id}/templates/licenses/mit")
+
+ expect(response).to have_gitlab_http_status(404)
+ end
+
+ it 'permits access to a developer on a private project' do
+ get api("/projects/#{private_project.id}/templates/licenses/mit", developer)
+
+ expect(response).to have_gitlab_http_status(200)
+ expect(response).to match_response_schema('public_api/v4/license')
+ end
+ end
+
+ describe 'GET /projects/:id/templates/licenses/:key' do
+ it 'fills placeholders in the license' do
+ get api("/projects/#{public_project.id}/templates/licenses/agpl-3.0"),
+ project: 'Project Placeholder',
+ fullname: 'Fullname Placeholder'
+
+ expect(response).to have_gitlab_http_status(200)
+ expect(response).to match_response_schema('public_api/v4/license')
+
+ content = json_response['content']
+
+ expect(content).to include('Project Placeholder')
+ expect(content).to include("Copyright (C) #{Time.now.year} Fullname Placeholder")
+ end
+ end
+end