summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
Diffstat (limited to 'spec')
-rw-r--r--spec/controllers/projects/pages_domains_controller_spec.rb18
-rw-r--r--spec/features/dashboard/shortcuts_spec.rb4
-rw-r--r--spec/features/projects/pages_lets_encrypt_spec.rb16
-rw-r--r--spec/frontend/ide/components/repo_commit_section_spec.js134
-rw-r--r--spec/javascripts/ide/components/repo_commit_section_spec.js113
-rw-r--r--spec/models/pages_domain_spec.rb18
-rw-r--r--spec/services/pages_domains/retry_acme_order_service_spec.rb37
-rw-r--r--spec/views/projects/pages/show.html.haml_spec.rb4
-rw-r--r--spec/views/projects/pages_domains/show.html.haml_spec.rb2
9 files changed, 230 insertions, 116 deletions
diff --git a/spec/controllers/projects/pages_domains_controller_spec.rb b/spec/controllers/projects/pages_domains_controller_spec.rb
index ef5e831d26c..c78c5fe2886 100644
--- a/spec/controllers/projects/pages_domains_controller_spec.rb
+++ b/spec/controllers/projects/pages_domains_controller_spec.rb
@@ -181,6 +181,24 @@ describe Projects::PagesDomainsController do
end
end
+ describe 'POST retry_auto_ssl' do
+ before do
+ pages_domain.update!(auto_ssl_enabled: true, auto_ssl_failed: true)
+ end
+
+ let(:params) { request_params.merge(id: pages_domain.domain) }
+
+ it 'calls retry service and redirects' do
+ expect_next_instance_of(PagesDomains::RetryAcmeOrderService, pages_domain) do |service|
+ expect(service).to receive(:execute)
+ end
+
+ post :retry_auto_ssl, params: params
+
+ expect(response).to redirect_to project_pages_domain_path(project, pages_domain)
+ end
+ end
+
describe 'DELETE destroy' do
it "deletes the pages domain" do
expect do
diff --git a/spec/features/dashboard/shortcuts_spec.rb b/spec/features/dashboard/shortcuts_spec.rb
index 2cd9cbc4471..6907c681417 100644
--- a/spec/features/dashboard/shortcuts_spec.rb
+++ b/spec/features/dashboard/shortcuts_spec.rb
@@ -26,6 +26,10 @@ describe 'Dashboard shortcuts', :js do
check_page_title('To-Do List')
+ find('body').send_keys([:shift, 'G'])
+
+ check_page_title('Groups')
+
find('body').send_keys([:shift, 'P'])
check_page_title('Projects')
diff --git a/spec/features/projects/pages_lets_encrypt_spec.rb b/spec/features/projects/pages_lets_encrypt_spec.rb
index 4f9c1903344..da9b191271a 100644
--- a/spec/features/projects/pages_lets_encrypt_spec.rb
+++ b/spec/features/projects/pages_lets_encrypt_spec.rb
@@ -85,6 +85,22 @@ describe "Pages with Let's Encrypt", :https_pages_enabled do
end
end
+ context "when we failed to obtain Let's Encrypt certificate", :js do
+ let(:domain) do
+ create(:pages_domain, auto_ssl_enabled: true, auto_ssl_failed: true, project: project)
+ end
+
+ it 'user can retry obtaining certificate' do
+ visit project_pages_domain_path(project, domain)
+
+ expect(page).to have_text("Something went wrong while obtaining the Let's Encrypt certificate.")
+
+ click_on('Retry')
+
+ expect(page).to have_text("GitLab is obtaining a Let's Encrypt SSL certificate for this domain. This process can take some time. Please try again later.")
+ end
+ end
+
shared_examples 'user sees private keys only for user provided certificate' do
shared_examples 'user do not see private key' do
it 'user do not see private key' do
diff --git a/spec/frontend/ide/components/repo_commit_section_spec.js b/spec/frontend/ide/components/repo_commit_section_spec.js
new file mode 100644
index 00000000000..5ea03eb1593
--- /dev/null
+++ b/spec/frontend/ide/components/repo_commit_section_spec.js
@@ -0,0 +1,134 @@
+import { mount } from '@vue/test-utils';
+import { createStore } from '~/ide/stores';
+import router from '~/ide/ide_router';
+import RepoCommitSection from '~/ide/components/repo_commit_section.vue';
+import { stageKeys } from '~/ide/constants';
+import { file } from '../helpers';
+
+const TEST_NO_CHANGES_SVG = 'nochangessvg';
+
+describe('RepoCommitSection', () => {
+ let wrapper;
+ let store;
+
+ function createComponent() {
+ wrapper = mount(RepoCommitSection, { store });
+ }
+
+ function setupDefaultState() {
+ store.state.noChangesStateSvgPath = 'svg';
+ store.state.committedStateSvgPath = 'commitsvg';
+ store.state.currentProjectId = 'abcproject';
+ store.state.currentBranchId = 'master';
+ store.state.projects.abcproject = {
+ web_url: '',
+ branches: {
+ master: {
+ workingReference: '1',
+ },
+ },
+ };
+
+ const files = [file('file1'), file('file2')].map(f =>
+ Object.assign(f, {
+ type: 'blob',
+ content: 'orginal content',
+ }),
+ );
+
+ store.state.rightPanelCollapsed = false;
+ store.state.currentBranch = 'master';
+ store.state.changedFiles = [];
+ store.state.stagedFiles = [{ ...files[0] }, { ...files[1] }];
+ store.state.stagedFiles.forEach(f =>
+ Object.assign(f, {
+ changed: true,
+ staged: true,
+ content: 'testing',
+ }),
+ );
+
+ files.forEach(f => {
+ store.state.entries[f.path] = f;
+ });
+ }
+
+ beforeEach(() => {
+ store = createStore();
+
+ jest.spyOn(store, 'dispatch');
+ jest.spyOn(router, 'push').mockImplementation();
+ });
+
+ afterEach(() => {
+ wrapper.destroy();
+ });
+
+ describe('empty Stage', () => {
+ beforeEach(() => {
+ store.state.noChangesStateSvgPath = TEST_NO_CHANGES_SVG;
+ store.state.committedStateSvgPath = 'svg';
+
+ createComponent();
+ });
+
+ it('renders no changes text', () => {
+ expect(
+ wrapper
+ .find('.js-empty-state')
+ .text()
+ .trim(),
+ ).toContain('No changes');
+ expect(wrapper.find('.js-empty-state img').attributes('src')).toBe(TEST_NO_CHANGES_SVG);
+ });
+ });
+
+ describe('default', () => {
+ beforeEach(() => {
+ setupDefaultState();
+
+ createComponent();
+ });
+
+ it('opens last opened file', () => {
+ expect(store.state.openFiles.length).toBe(1);
+ expect(store.state.openFiles[0].pending).toBe(true);
+ });
+
+ it('calls openPendingTab', () => {
+ expect(store.dispatch).toHaveBeenCalledWith('openPendingTab', {
+ file: store.getters.lastOpenedFile,
+ keyPrefix: stageKeys.staged,
+ });
+ });
+
+ it('renders a commit section', () => {
+ const allFiles = store.state.changedFiles.concat(store.state.stagedFiles);
+ const changedFileNames = wrapper
+ .findAll('.multi-file-commit-list > li')
+ .wrappers.map(x => x.text().trim());
+
+ expect(changedFileNames).toEqual(allFiles.map(x => x.path));
+ });
+ });
+
+ describe('with unstaged file', () => {
+ beforeEach(() => {
+ setupDefaultState();
+
+ store.state.changedFiles = store.state.stagedFiles.map(x =>
+ Object.assign(x, { staged: false }),
+ );
+ store.state.stagedFiles = [];
+
+ createComponent();
+ });
+
+ it('calls openPendingTab with unstaged prefix', () => {
+ expect(store.dispatch).toHaveBeenCalledWith('openPendingTab', {
+ file: store.getters.lastOpenedFile,
+ keyPrefix: stageKeys.unstaged,
+ });
+ });
+ });
+});
diff --git a/spec/javascripts/ide/components/repo_commit_section_spec.js b/spec/javascripts/ide/components/repo_commit_section_spec.js
deleted file mode 100644
index 0ba8c86a036..00000000000
--- a/spec/javascripts/ide/components/repo_commit_section_spec.js
+++ /dev/null
@@ -1,113 +0,0 @@
-import Vue from 'vue';
-import { createComponentWithStore } from 'spec/helpers/vue_mount_component_helper';
-import store from '~/ide/stores';
-import router from '~/ide/ide_router';
-import repoCommitSection from '~/ide/components/repo_commit_section.vue';
-import { file, resetStore } from '../helpers';
-
-describe('RepoCommitSection', () => {
- let vm;
-
- function createComponent() {
- const Component = Vue.extend(repoCommitSection);
-
- store.state.noChangesStateSvgPath = 'svg';
- store.state.committedStateSvgPath = 'commitsvg';
-
- vm = createComponentWithStore(Component, store);
-
- vm.$store.state.currentProjectId = 'abcproject';
- vm.$store.state.currentBranchId = 'master';
- vm.$store.state.projects.abcproject = {
- web_url: '',
- branches: {
- master: {
- workingReference: '1',
- },
- },
- };
-
- const files = [file('file1'), file('file2')].map(f =>
- Object.assign(f, {
- type: 'blob',
- content: 'orginal content',
- }),
- );
-
- vm.$store.state.rightPanelCollapsed = false;
- vm.$store.state.currentBranch = 'master';
- vm.$store.state.changedFiles = [];
- vm.$store.state.stagedFiles = [{ ...files[0] }, { ...files[1] }];
- vm.$store.state.stagedFiles.forEach(f =>
- Object.assign(f, {
- changed: true,
- content: 'testing',
- }),
- );
-
- files.forEach(f => {
- vm.$store.state.entries[f.path] = f;
- });
-
- return vm;
- }
-
- beforeEach(done => {
- spyOn(router, 'push');
-
- vm = createComponent();
-
- spyOn(vm, 'openPendingTab').and.callThrough();
-
- vm.$mount();
-
- Vue.nextTick(done);
- });
-
- afterEach(() => {
- vm.$destroy();
-
- resetStore(vm.$store);
- });
-
- describe('empty Stage', () => {
- it('renders no changes text', () => {
- resetStore(vm.$store);
- const Component = Vue.extend(repoCommitSection);
-
- store.state.noChangesStateSvgPath = 'nochangessvg';
- store.state.committedStateSvgPath = 'svg';
-
- vm.$destroy();
- vm = createComponentWithStore(Component, store).$mount();
-
- expect(vm.$el.querySelector('.js-empty-state').textContent.trim()).toContain('No changes');
- expect(vm.$el.querySelector('.js-empty-state img').getAttribute('src')).toBe('nochangessvg');
- });
- });
-
- it('renders a commit section', () => {
- const changedFileElements = [...vm.$el.querySelectorAll('.multi-file-commit-list > li')];
- const allFiles = vm.$store.state.changedFiles.concat(vm.$store.state.stagedFiles);
-
- expect(changedFileElements).toHaveLength(2);
-
- changedFileElements.forEach((changedFile, i) => {
- expect(changedFile.textContent.trim()).toContain(allFiles[i].path);
- });
- });
-
- describe('mounted', () => {
- it('opens last opened file', () => {
- expect(store.state.openFiles.length).toBe(1);
- expect(store.state.openFiles[0].pending).toBe(true);
- });
-
- it('calls openPendingTab', () => {
- expect(vm.openPendingTab).toHaveBeenCalledWith({
- file: vm.lastOpenedFile,
- keyPrefix: 'unstaged',
- });
- });
- });
-});
diff --git a/spec/models/pages_domain_spec.rb b/spec/models/pages_domain_spec.rb
index 4bf56e7b28b..fa2648979e9 100644
--- a/spec/models/pages_domain_spec.rb
+++ b/spec/models/pages_domain_spec.rb
@@ -536,6 +536,24 @@ describe PagesDomain do
'user_provided', 'gitlab_provided')
end
+ describe '#save' do
+ context 'when we failed to obtain ssl certificate' do
+ let(:domain) { create(:pages_domain, auto_ssl_enabled: true, auto_ssl_failed: true) }
+
+ it 'clears failure if auto ssl is disabled' do
+ expect do
+ domain.update!(auto_ssl_enabled: false)
+ end.to change { domain.auto_ssl_failed }.from(true).to(false)
+ end
+
+ it 'does not clear failure on unrelated updates' do
+ expect do
+ domain.update!(verified_at: Time.now)
+ end.not_to change { domain.auto_ssl_failed }.from(true)
+ end
+ end
+ end
+
describe '.for_removal' do
subject { described_class.for_removal }
diff --git a/spec/services/pages_domains/retry_acme_order_service_spec.rb b/spec/services/pages_domains/retry_acme_order_service_spec.rb
new file mode 100644
index 00000000000..0185f10864c
--- /dev/null
+++ b/spec/services/pages_domains/retry_acme_order_service_spec.rb
@@ -0,0 +1,37 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe PagesDomains::RetryAcmeOrderService do
+ let(:domain) { create(:pages_domain, auto_ssl_enabled: true, auto_ssl_failed: true) }
+
+ let(:service) { described_class.new(domain) }
+
+ it 'clears auto_ssl_failed' do
+ expect do
+ service.execute
+ end.to change { domain.auto_ssl_failed }.from(true).to(false)
+ end
+
+ it 'schedules renewal worker' do
+ expect(PagesDomainSslRenewalWorker).to receive(:perform_async).with(domain.id).and_return(nil).once
+
+ service.execute
+ end
+
+ it "doesn't schedule renewal worker if Let's Encrypt integration is not enabled" do
+ domain.update!(auto_ssl_enabled: false)
+
+ expect(PagesDomainSslRenewalWorker).not_to receive(:new)
+
+ service.execute
+ end
+
+ it "doesn't schedule renewal worker if auto ssl has not failed yet" do
+ domain.update!(auto_ssl_failed: false)
+
+ expect(PagesDomainSslRenewalWorker).not_to receive(:new)
+
+ service.execute
+ end
+end
diff --git a/spec/views/projects/pages/show.html.haml_spec.rb b/spec/views/projects/pages/show.html.haml_spec.rb
index 39384484279..63b66616f31 100644
--- a/spec/views/projects/pages/show.html.haml_spec.rb
+++ b/spec/views/projects/pages/show.html.haml_spec.rb
@@ -17,7 +17,7 @@ describe 'projects/pages/show' do
assign(:project, project)
allow(view).to receive(:current_user).and_return(user)
- assign(:domains, project.pages_domains)
+ assign(:domains, [domain.present(current_user: user)])
end
describe 'validation warning' do
@@ -47,7 +47,7 @@ describe 'projects/pages/show' do
describe "warning about failed Let's Encrypt" do
let(:error_message) do
- "Something went wrong while obtaining Let's Encrypt certificate for #{domain.domain}. "\
+ "Something went wrong while obtaining the Let's Encrypt certificate for #{domain.domain}. "\
"To retry visit your domain details."
end
diff --git a/spec/views/projects/pages_domains/show.html.haml_spec.rb b/spec/views/projects/pages_domains/show.html.haml_spec.rb
index 51c7a08fe96..7d502e74d10 100644
--- a/spec/views/projects/pages_domains/show.html.haml_spec.rb
+++ b/spec/views/projects/pages_domains/show.html.haml_spec.rb
@@ -7,7 +7,7 @@ describe 'projects/pages_domains/show' do
before do
assign(:project, project)
- assign(:domain, domain)
+ assign(:domain, domain.present)
stub_pages_setting(external_https: true)
end