|
2 | 2 | require 'json' |
3 | 3 |
|
4 | 4 | describe "Stats", type: :request do |
5 | | - |
6 | | - token = JWT.encode({ |
7 | | - id: 1, |
8 | | - |
9 | | - first_name: 'Michael', |
10 | | - last_name: 'Kelso', |
11 | | - team: 'Operations', |
12 | | - rendering_id: '1', |
13 | | - exp: Time.now.to_i + 2.weeks.to_i, |
14 | | - permission_level: 'admin' |
15 | | - }, ForestLiana.auth_secret, 'HS256') |
16 | | - |
17 | | - headers = { |
18 | | - 'Accept' => 'application/json', |
19 | | - 'Content-Type' => 'application/json', |
20 | | - 'Authorization' => "Bearer #{token}" |
21 | | - } |
22 | | - |
| 5 | + let(:rendering_id) { '13' } |
| 6 | + let(:scopes) { {'scopes' => {}, 'team' => {'id' => '1', 'name' => 'Operations'}} } |
23 | 7 | let(:schema) { |
24 | 8 | [ |
25 | 9 | ForestLiana::Model::Collection.new({ |
|
30 | 14 | ] |
31 | 15 | } |
32 | 16 |
|
| 17 | + let(:token) { |
| 18 | + JWT.encode({ |
| 19 | + id: 1, |
| 20 | + |
| 21 | + first_name: 'Michael', |
| 22 | + last_name: 'Kelso', |
| 23 | + team: 'Operations', |
| 24 | + rendering_id: rendering_id, |
| 25 | + exp: Time.now.to_i + 2.weeks.to_i, |
| 26 | + permission_level: 'user' |
| 27 | + }, ForestLiana.auth_secret, 'HS256') |
| 28 | + } |
| 29 | + |
| 30 | + let(:headers) { |
| 31 | + { |
| 32 | + 'Accept' => 'application/json', |
| 33 | + 'Content-Type' => 'application/json', |
| 34 | + 'Authorization' => "Bearer #{token}" |
| 35 | + } |
| 36 | + } |
| 37 | + |
33 | 38 | before do |
34 | 39 | Rails.cache.write('forest.users', {'1' => { 'id' => 1, 'roleId' => 1, 'rendering_id' => '1' }}) |
35 | 40 | Rails.cache.write('forest.has_permission', true) |
36 | | - allow_any_instance_of(ForestLiana::Ability::Fetch) |
| 41 | + allow_any_instance_of(ForestLiana::Ability::Permission) |
37 | 42 | .to receive(:get_permissions) |
38 | 43 | .and_return( |
39 | 44 | { |
|
45 | 50 | "aggregateFieldName" => nil, |
46 | 51 | "sourceCollectionName" => "Owner" |
47 | 52 | }, |
| 53 | + { |
| 54 | + "type" => "Objective", |
| 55 | + "sourceCollectionName" => "Owner", |
| 56 | + "aggregateFieldName" => nil, |
| 57 | + "aggregator" => "Count", |
| 58 | + "objective" => 200, |
| 59 | + "filter" => nil, |
| 60 | + }, |
| 61 | + { |
| 62 | + "type" => "Pie", |
| 63 | + "sourceCollectionName" => "Owner", |
| 64 | + "aggregateFieldName" => nil, |
| 65 | + "groupByFieldName" => "id", |
| 66 | + "aggregator" => "Count", |
| 67 | + "filter" => nil, |
| 68 | + }, |
| 69 | + { |
| 70 | + "type" => "Line", |
| 71 | + "sourceCollectionName" => "Owner", |
| 72 | + "aggregateFieldName" => nil, |
| 73 | + "groupByFieldName" => "hired_at", |
| 74 | + "aggregator" => "Count", |
| 75 | + "timeRange" => "Week", |
| 76 | + "filter" => nil, |
| 77 | + }, |
48 | 78 | { |
49 | 79 | "type" => "Value", |
50 | 80 | "query" => "SELECT COUNT(*) AS value FROM products;" |
|
53 | 83 | } |
54 | 84 | ) |
55 | 85 |
|
56 | | - ForestLiana::ScopeManager.class_variable_set(:@@scopes_cache, { |
57 | | - '1' => { |
58 | | - :fetched_at => Time.now, |
59 | | - :scopes => {} |
60 | | - } |
61 | | - }) |
62 | | - |
| 86 | + ForestLiana::ScopeManager.invalidate_scope_cache(rendering_id) |
| 87 | + allow(ForestLiana::ScopeManager).to receive(:fetch_scopes).and_return(scopes) |
| 88 | + |
63 | 89 | allow(ForestLiana).to receive(:apimap).and_return(schema) |
64 | 90 | allow(ForestLiana::IpWhitelist).to receive(:retrieve) { true } |
65 | 91 | allow(ForestLiana::IpWhitelist).to receive(:is_ip_whitelist_retrieved) { true } |
|
0 commit comments