debian-mirror-gitlab/spec/requests/api/appearance_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

148 lines
6.5 KiB
Ruby
Raw Permalink Normal View History

2020-03-13 15:44:24 +05:30
# frozen_string_literal: true
require 'spec_helper'
2023-06-20 00:43:36 +05:30
RSpec.describe API::Appearance, 'Appearance', :aggregate_failures, feature_category: :navigation do
2020-03-13 15:44:24 +05:30
let_it_be(:user) { create(:user) }
let_it_be(:admin) { create(:admin) }
2023-04-23 21:23:45 +05:30
let_it_be(:path) { "/application/appearance" }
2020-03-13 15:44:24 +05:30
describe "GET /application/appearance" do
2023-04-23 21:23:45 +05:30
it_behaves_like 'GET request permissions for admin mode'
2020-03-13 15:44:24 +05:30
context 'as an admin user' do
it "returns appearance" do
2023-06-20 00:43:36 +05:30
get api(path, admin, admin_mode: true)
2020-03-13 15:44:24 +05:30
expect(json_response).to be_an Hash
expect(json_response['description']).to eq('')
expect(json_response['email_header_and_footer_enabled']).to be(false)
2023-03-17 16:20:25 +05:30
expect(json_response['pwa_icon']).to be_nil
2020-03-13 15:44:24 +05:30
expect(json_response['favicon']).to be_nil
expect(json_response['footer_message']).to eq('')
expect(json_response['header_logo']).to be_nil
expect(json_response['header_message']).to eq('')
expect(json_response['logo']).to be_nil
expect(json_response['message_background_color']).to eq('#E75E40')
expect(json_response['message_font_color']).to eq('#FFFFFF')
expect(json_response['new_project_guidelines']).to eq('')
2020-05-24 23:13:21 +05:30
expect(json_response['profile_image_guidelines']).to eq('')
2020-03-13 15:44:24 +05:30
expect(json_response['title']).to eq('')
2023-04-23 21:23:45 +05:30
expect(json_response['pwa_name']).to eq('')
2023-03-17 16:20:25 +05:30
expect(json_response['pwa_short_name']).to eq('')
2023-04-23 21:23:45 +05:30
expect(json_response['pwa_description']).to eq('')
2020-03-13 15:44:24 +05:30
end
end
end
describe "PUT /application/appearance" do
2023-05-27 22:25:52 +05:30
it_behaves_like 'PUT request permissions for admin mode' do
let(:params) { { title: "Test" } }
end
2020-03-13 15:44:24 +05:30
context 'as an admin user' do
context "instance basics" do
it "allows updating the settings" do
2023-06-20 00:43:36 +05:30
put api(path, admin, admin_mode: true), params: {
2020-03-13 15:44:24 +05:30
title: "GitLab Test Instance",
description: "gitlab-test.example.com",
2023-04-23 21:23:45 +05:30
pwa_name: "GitLab PWA Test",
pwa_short_name: "GitLab PWA",
pwa_description: "This is GitLab as PWA",
2020-05-24 23:13:21 +05:30
new_project_guidelines: "Please read the FAQs for help.",
profile_image_guidelines: "Custom profile image guidelines"
2020-03-13 15:44:24 +05:30
}
expect(json_response).to be_an Hash
expect(json_response['description']).to eq('gitlab-test.example.com')
expect(json_response['email_header_and_footer_enabled']).to be(false)
2023-03-17 16:20:25 +05:30
expect(json_response['pwa_icon']).to be_nil
2020-03-13 15:44:24 +05:30
expect(json_response['favicon']).to be_nil
expect(json_response['footer_message']).to eq('')
expect(json_response['header_logo']).to be_nil
expect(json_response['header_message']).to eq('')
expect(json_response['logo']).to be_nil
expect(json_response['message_background_color']).to eq('#E75E40')
expect(json_response['message_font_color']).to eq('#FFFFFF')
expect(json_response['new_project_guidelines']).to eq('Please read the FAQs for help.')
2020-05-24 23:13:21 +05:30
expect(json_response['profile_image_guidelines']).to eq('Custom profile image guidelines')
2020-03-13 15:44:24 +05:30
expect(json_response['title']).to eq('GitLab Test Instance')
2023-04-23 21:23:45 +05:30
expect(json_response['pwa_name']).to eq('GitLab PWA Test')
2023-03-17 16:20:25 +05:30
expect(json_response['pwa_short_name']).to eq('GitLab PWA')
2023-04-23 21:23:45 +05:30
expect(json_response['pwa_description']).to eq('This is GitLab as PWA')
2020-03-13 15:44:24 +05:30
end
end
context "system header and footer" do
it "allows updating the settings" do
settings = {
footer_message: "This is a Header",
header_message: "This is a Footer",
message_font_color: "#ffffff",
message_background_color: "#009999",
email_header_and_footer_enabled: true
}
2023-06-20 00:43:36 +05:30
put api(path, admin, admin_mode: true), params: settings
2020-03-13 15:44:24 +05:30
2020-04-08 14:13:33 +05:30
expect(response).to have_gitlab_http_status(:ok)
2020-03-13 15:44:24 +05:30
settings.each do |attribute, value|
expect(Appearance.current.public_send(attribute)).to eq(value)
end
end
context "fails on invalid color values" do
it "with message_font_color" do
2023-06-20 00:43:36 +05:30
put api(path, admin, admin_mode: true), params: { message_font_color: "No Color" }
2020-03-13 15:44:24 +05:30
2020-04-08 14:13:33 +05:30
expect(response).to have_gitlab_http_status(:bad_request)
2020-03-13 15:44:24 +05:30
expect(json_response['message']['message_font_color']).to contain_exactly('must be a valid color code')
end
it "with message_background_color" do
2023-06-20 00:43:36 +05:30
put api(path, admin, admin_mode: true), params: { message_background_color: "#1" }
2020-03-13 15:44:24 +05:30
2020-04-08 14:13:33 +05:30
expect(response).to have_gitlab_http_status(:bad_request)
2020-03-13 15:44:24 +05:30
expect(json_response['message']['message_background_color']).to contain_exactly('must be a valid color code')
end
end
end
context "instance logos" do
let_it_be(:appearance) { create(:appearance) }
it "allows updating the image files" do
2023-06-20 00:43:36 +05:30
put api(path, admin, admin_mode: true), params: {
2020-03-13 15:44:24 +05:30
logo: fixture_file_upload("spec/fixtures/dk.png", "image/png"),
header_logo: fixture_file_upload("spec/fixtures/dk.png", "image/png"),
2023-03-17 16:20:25 +05:30
pwa_icon: fixture_file_upload("spec/fixtures/dk.png", "image/png"),
2020-03-13 15:44:24 +05:30
favicon: fixture_file_upload("spec/fixtures/dk.png", "image/png")
}
2020-04-08 14:13:33 +05:30
expect(response).to have_gitlab_http_status(:ok)
2020-03-13 15:44:24 +05:30
expect(json_response['logo']).to eq("/uploads/-/system/appearance/logo/#{appearance.id}/dk.png")
expect(json_response['header_logo']).to eq("/uploads/-/system/appearance/header_logo/#{appearance.id}/dk.png")
2023-03-17 16:20:25 +05:30
expect(json_response['pwa_icon']).to eq("/uploads/-/system/appearance/pwa_icon/#{appearance.id}/dk.png")
2020-03-13 15:44:24 +05:30
expect(json_response['favicon']).to eq("/uploads/-/system/appearance/favicon/#{appearance.id}/dk.png")
end
context "fails on invalid color images" do
it "with string instead of file" do
2023-06-20 00:43:36 +05:30
put api(path, admin, admin_mode: true), params: { logo: 'not-a-file.png' }
2020-03-13 15:44:24 +05:30
2020-04-08 14:13:33 +05:30
expect(response).to have_gitlab_http_status(:bad_request)
2020-03-13 15:44:24 +05:30
expect(json_response['error']).to eq("logo is invalid")
end
it "with .svg file instead of .png" do
2023-06-20 00:43:36 +05:30
put api(path, admin, admin_mode: true), params: { favicon: fixture_file_upload("spec/fixtures/logo_sample.svg", "image/svg") }
2020-03-13 15:44:24 +05:30
2020-04-08 14:13:33 +05:30
expect(response).to have_gitlab_http_status(:bad_request)
2020-03-13 15:44:24 +05:30
expect(json_response['message']['favicon']).to contain_exactly("You are not allowed to upload \"svg\" files, allowed types: png, ico")
end
end
end
end
end
end