2022-01-01 13:38:12 +00:00
|
|
|
# Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
|
2021-06-01 12:20:20 +00:00
|
|
|
|
2018-09-19 13:54:49 +00:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
RSpec.describe 'Calendars', type: :request do
|
|
|
|
|
2020-06-19 09:17:18 +00:00
|
|
|
let(:admin) do
|
|
|
|
create(:admin)
|
2018-09-19 13:54:49 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
describe 'request handling' do
|
|
|
|
|
|
|
|
it 'does calendar index with nobody' do
|
|
|
|
get '/api/v1/calendars', as: :json
|
2021-02-04 08:28:41 +00:00
|
|
|
expect(response).to have_http_status(:forbidden)
|
2018-09-19 13:54:49 +00:00
|
|
|
|
|
|
|
expect(json_response).to be_a_kind_of(Hash)
|
2021-02-04 08:28:41 +00:00
|
|
|
expect(json_response['error']).to eq('Authentication required')
|
2018-09-19 13:54:49 +00:00
|
|
|
|
|
|
|
get '/api/v1/calendars_init', as: :json
|
2021-02-04 08:28:41 +00:00
|
|
|
expect(response).to have_http_status(:forbidden)
|
2018-09-19 13:54:49 +00:00
|
|
|
|
|
|
|
expect(json_response).to be_a_kind_of(Hash)
|
2021-02-04 08:28:41 +00:00
|
|
|
expect(json_response['error']).to eq('Authentication required')
|
2019-02-10 11:01:38 +00:00
|
|
|
|
|
|
|
get '/api/v1/calendars/timezones', as: :json
|
2021-02-04 08:28:41 +00:00
|
|
|
expect(response).to have_http_status(:forbidden)
|
2019-02-10 11:01:38 +00:00
|
|
|
|
|
|
|
expect(json_response).to be_a_kind_of(Hash)
|
2021-02-04 08:28:41 +00:00
|
|
|
expect(json_response['error']).to eq('Authentication required')
|
2018-09-19 13:54:49 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'does calendar index with admin' do
|
2020-06-19 09:17:18 +00:00
|
|
|
authenticated_as(admin)
|
2018-09-19 13:54:49 +00:00
|
|
|
get '/api/v1/calendars', as: :json
|
2019-04-15 01:41:17 +00:00
|
|
|
expect(response).to have_http_status(:ok)
|
2018-09-19 13:54:49 +00:00
|
|
|
expect(json_response).to be_a_kind_of(Array)
|
|
|
|
expect(json_response).to be_truthy
|
|
|
|
expect(json_response.count).to eq(1)
|
|
|
|
|
|
|
|
get '/api/v1/calendars?expand=true', as: :json
|
2019-04-15 01:41:17 +00:00
|
|
|
expect(response).to have_http_status(:ok)
|
2018-09-19 13:54:49 +00:00
|
|
|
expect(json_response).to be_a_kind_of(Array)
|
|
|
|
expect(json_response).to be_truthy
|
|
|
|
expect(json_response.count).to eq(1)
|
|
|
|
|
|
|
|
get '/api/v1/calendars?full=true', as: :json
|
2019-04-15 01:41:17 +00:00
|
|
|
expect(response).to have_http_status(:ok)
|
2018-09-19 13:54:49 +00:00
|
|
|
expect(json_response).to be_a_kind_of(Hash)
|
|
|
|
expect(json_response).to be_truthy
|
|
|
|
expect(json_response['record_ids']).to be_truthy
|
|
|
|
expect(json_response['record_ids'].count).to eq(1)
|
|
|
|
expect(json_response['assets']).to be_truthy
|
|
|
|
expect(json_response['assets']).to be_present
|
|
|
|
|
|
|
|
# index
|
|
|
|
get '/api/v1/calendars_init', as: :json
|
2019-04-15 01:41:17 +00:00
|
|
|
expect(response).to have_http_status(:ok)
|
2018-09-19 13:54:49 +00:00
|
|
|
expect(json_response).to be_a_kind_of(Hash)
|
|
|
|
expect(json_response['record_ids']).to be_truthy
|
|
|
|
expect(json_response['ical_feeds']).to be_truthy
|
2021-05-05 15:35:38 +00:00
|
|
|
expect(json_response['ical_feeds']['https://www.google.com/calendar/ical/da.danish%23holiday%40group.v.calendar.google.com/public/basic.ics']).to eq('Denmark')
|
|
|
|
expect(json_response['ical_feeds']['https://www.google.com/calendar/ical/de.austrian%23holiday%40group.v.calendar.google.com/public/basic.ics']).to eq('Austria')
|
2018-09-19 13:54:49 +00:00
|
|
|
expect(json_response['timezones']).to be_truthy
|
|
|
|
expect(json_response['timezones']['Africa/Johannesburg']).to eq(2)
|
2018-11-05 05:03:04 +00:00
|
|
|
expect(json_response['timezones']['America/Sitka']).to be_between(-9, -8)
|
|
|
|
expect(json_response['timezones']['Europe/Berlin']).to be_between(1, 2)
|
2018-09-19 13:54:49 +00:00
|
|
|
expect(json_response['assets']).to be_truthy
|
2019-02-10 11:01:38 +00:00
|
|
|
|
|
|
|
# timezones
|
|
|
|
get '/api/v1/calendars/timezones', as: :json
|
2019-04-15 01:41:17 +00:00
|
|
|
expect(response).to have_http_status(:ok)
|
2019-02-10 11:01:38 +00:00
|
|
|
expect(json_response).to be_a_kind_of(Hash)
|
|
|
|
expect(json_response['timezones']).to be_a_kind_of(Hash)
|
|
|
|
expect(json_response['timezones']['America/New_York']).to be_truthy
|
2018-09-19 13:54:49 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-11-10 14:29:31 +00:00
|
|
|
describe 'Removing calendars via UI and API does not check for references #3845', authenticated_as: -> { user } do
|
|
|
|
let(:calendar) { create(:calendar) }
|
|
|
|
let(:sla) { create(:sla, calendar: calendar) }
|
|
|
|
let(:user) { create(:admin) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
sla
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does return reference error on delete if related objects exist' do
|
|
|
|
delete "/api/v1/calendars/#{calendar.id}", params: {}, as: :json
|
|
|
|
expect(json_response['error']).to eq("Can't delete, object has references.")
|
|
|
|
end
|
|
|
|
end
|
2018-09-19 13:54:49 +00:00
|
|
|
end
|