123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- require 'test_helper'
- require 'rake'
- class ReportsControllerTest < ActionDispatch::IntegrationTest
- setup do
- # set accept header
- @headers = { 'ACCEPT' => 'application/json', 'CONTENT_TYPE' => 'application/json' }
- @year = DateTime.now.utc.year
- @month = DateTime.now.utc.month
- @week = DateTime.now.utc.strftime('%U').to_i
- @day = DateTime.now.utc.day
- roles = Role.where(name: 'Admin')
- groups = Group.all
- UserInfo.current_user_id = 1
- @admin = User.create_or_update(
- login: 'rest-admin',
- firstname: 'Rest',
- lastname: 'Agent',
- email: 'rest-admin@example.com',
- password: 'adminpw',
- active: true,
- roles: roles,
- groups: groups,
- updated_by_id: 1,
- created_by_id: 1
- )
- roles = Role.where(name: 'Customer')
- @customer_without_org = User.create_or_update(
- login: 'rest-customer1@example.com',
- firstname: 'Rest',
- lastname: 'Customer1',
- email: 'rest-customer1@example.com',
- password: 'customer1pw',
- active: true,
- roles: roles,
- updated_by_id: 1,
- created_by_id: 1
- )
- @group1 = Group.create_or_update(
- name: "GroupWithoutPermission-#{rand(9_999_999_999)}",
- active: true,
- updated_by_id: 1,
- created_by_id: 1,
- )
- @ticket1 = Ticket.create!(
- title: 'ticket for report',
- group_id: @group1.id,
- customer_id: @customer_without_org.id,
- state: Ticket::State.lookup(name: 'open'),
- priority: Ticket::Priority.lookup(name: '2 normal'),
- updated_by_id: 1,
- created_by_id: 1,
- )
- Ticket::Article.create!(
- type: Ticket::Article::Type.lookup(name: 'note'),
- sender: Ticket::Article::Sender.lookup(name: 'Customer'),
- from: 'sender',
- subject: 'subject',
- body: 'some body',
- ticket_id: @ticket1.id,
- updated_by_id: 1,
- created_by_id: 1,
- )
- if ENV['ES_URL'].present?
- #fail "ERROR: Need ES_URL - hint ES_URL='http://127.0.0.1:9200'"
- Setting.set('es_url', ENV['ES_URL'])
- # Setting.set('es_url', 'http://127.0.0.1:9200')
- # Setting.set('es_index', 'estest.local_zammad')
- # Setting.set('es_user', 'elasticsearch')
- # Setting.set('es_password', 'zammad')
- if ENV['ES_INDEX_RAND'].present?
- ENV['ES_INDEX'] = "es_index_#{rand(999_999_999)}"
- end
- if ENV['ES_INDEX'].blank?
- raise "ERROR: Need ES_INDEX - hint ES_INDEX='estest.local_zammad'"
- end
- Setting.set('es_index', ENV['ES_INDEX'])
- travel 1.minute
- # drop/create indexes
- Rake::Task.clear
- Zammad::Application.load_tasks
- #Rake::Task["searchindex:drop"].execute
- #Rake::Task["searchindex:create"].execute
- Rake::Task['searchindex:rebuild'].execute
- # execute background jobs
- Scheduler.worker(true)
- sleep 6
- end
- end
- teardown do
- if ENV['ES_URL'].present?
- Rake::Task['searchindex:drop'].execute
- end
- end
- test '01.01 report example - admin access' do
- credentials = ActionController::HttpAuthentication::Basic.encode_credentials('rest-admin@example.com', 'adminpw')
- get "/api/v1/reports/sets?sheet=true;metric=count;year=#{@year};month=#{@month};week=#{@week};day=#{@day};timeRange=year;profile_id=1;downloadBackendSelected=count::created", params: {}, headers: @headers.merge('Authorization' => credentials)
- assert_response(200)
- assert(@response['Content-Disposition'])
- assert_equal('attachment; filename="tickets--all--Created.xls"', @response['Content-Disposition'])
- assert_equal('application/vnd.ms-excel', @response['Content-Type'])
- end
- end
|