|
| 1 | +require 'rails_helper' |
| 2 | + |
| 3 | +describe 'Requesting Owner', :type => :request do |
| 4 | + before(:each) do |
| 5 | + 1.upto(10) do |i| |
| 6 | + Owner.create(name: "Owner #{i}") |
| 7 | + end |
| 8 | + end |
| 9 | + |
| 10 | + after(:each) do |
| 11 | + Owner.destroy_all |
| 12 | + end |
| 13 | + |
| 14 | + before(:each) do |
| 15 | + allow(ForestLiana::IpWhitelist).to receive(:retrieve) { true } |
| 16 | + allow(ForestLiana::IpWhitelist).to receive(:is_ip_whitelist_retrieved) { true } |
| 17 | + allow(ForestLiana::IpWhitelist).to receive(:is_ip_valid) { true } |
| 18 | + |
| 19 | + allow_any_instance_of(ForestLiana::PermissionsChecker).to receive(:is_authorized?) { true } |
| 20 | + |
| 21 | + allow(ForestLiana::ScopeManager).to receive(:fetch_scopes).and_return({}) |
| 22 | + end |
| 23 | + |
| 24 | + token = JWT.encode({ |
| 25 | + id: 38, |
| 26 | + |
| 27 | + first_name: 'Michael', |
| 28 | + last_name: 'Kelso', |
| 29 | + team: 'Operations', |
| 30 | + rendering_id: 16, |
| 31 | + exp: Time.now.to_i + 2.weeks.to_i |
| 32 | + }, ForestLiana.auth_secret, 'HS256') |
| 33 | + |
| 34 | + headers = { |
| 35 | + 'Accept' => 'application/json', |
| 36 | + 'Content-Type' => 'application/json', |
| 37 | + 'Authorization' => "Bearer #{token}" |
| 38 | + } |
| 39 | + describe 'count' do |
| 40 | + params = { |
| 41 | + fields: { 'Owner' => 'id,name' }, |
| 42 | + page: { 'number' => '1', 'size' => '10' }, |
| 43 | + searchExtended: '0', |
| 44 | + sort: '-id', |
| 45 | + timezone: 'Europe/Paris' |
| 46 | + } |
| 47 | + |
| 48 | + it 'should respond 200' do |
| 49 | + get '/forest/Owner/count', params: params, headers: headers |
| 50 | + expect(response.status).to eq(200) |
| 51 | + end |
| 52 | + |
| 53 | + it 'should equal to 10' do |
| 54 | + get '/forest/Owner/count', params: params, headers: headers |
| 55 | + expect(response.status).to eq(200) |
| 56 | + end |
| 57 | + end |
| 58 | + |
| 59 | + describe 'deactivate_count_response' do |
| 60 | + params = { |
| 61 | + fields: { 'Product' => 'id,name' }, |
| 62 | + page: { 'number' => '1', 'size' => '10' }, |
| 63 | + search: 'foo', |
| 64 | + searchExtended: '0', |
| 65 | + sort: '-id', |
| 66 | + timezone: 'Europe/Paris' |
| 67 | + } |
| 68 | + |
| 69 | + it 'should respond 200' do |
| 70 | + get '/forest/Owner/count', params: params, headers: headers |
| 71 | + expect(response.status).to eq(200) |
| 72 | + end |
| 73 | + |
| 74 | + it 'should equal to deactivated response' do |
| 75 | + get '/forest/Owner/count', params: params, headers: headers |
| 76 | + expect(response.body).to eq('{"meta":{"count":"deactivated "}}') |
| 77 | + end |
| 78 | + end |
| 79 | +end |
0 commit comments