mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2024-12-15 00:24:09 +01:00
38 lines
954 B
Ruby
38 lines
954 B
Ruby
|
# frozen_string_literal: true
|
||
|
|
||
|
require 'test_helper'
|
||
|
|
||
|
class AnalyticsTest < ActionDispatch::IntegrationTest
|
||
|
def setup
|
||
|
@admin = User.find_by(username: 'admin')
|
||
|
@jdupond = User.find_by(username: 'jdupond')
|
||
|
end
|
||
|
|
||
|
test 'fetch analytics data' do
|
||
|
login_as(@admin, scope: :user)
|
||
|
|
||
|
get '/api/analytics/data'
|
||
|
|
||
|
# Check response format & status
|
||
|
assert_equal 200, response.status, response.body
|
||
|
assert_equal Mime[:json], response.content_type
|
||
|
|
||
|
# Check the resulting data was created
|
||
|
res = json_response(response.body)
|
||
|
assert_not_nil res[:version]
|
||
|
assert_not_nil res[:members]
|
||
|
assert_not_nil res[:admins]
|
||
|
assert_not_nil res[:managers]
|
||
|
assert_not_nil res[:availabilities]
|
||
|
assert_not_nil res[:reservations]
|
||
|
assert_not_nil res[:orders]
|
||
|
end
|
||
|
|
||
|
test 'non-admin cannot fetch analytics data' do
|
||
|
login_as(@jdupond, scope: :user)
|
||
|
get '/api/analytics/data'
|
||
|
|
||
|
assert_response :forbidden
|
||
|
end
|
||
|
end
|