|
1 | 1 | require 'rails_helper'
|
2 | 2 |
|
3 |
| -describe 'Requesting Tree index', :type => :request do |
4 |
| - before do |
| 3 | +describe 'Requesting Tree resources', :type => :request do |
| 4 | + before(:each) do |
| 5 | + user = User.create(name: 'Michel') |
| 6 | + tree = Tree.create(name: 'Lemon Tree', owner: user, cutter: user) |
| 7 | + end |
| 8 | + |
| 9 | + after(:each) do |
| 10 | + User.destroy_all |
| 11 | + Tree.destroy_all |
| 12 | + end |
| 13 | + |
| 14 | + before(:each) do |
5 | 15 | allow(ForestLiana::IpWhitelist).to receive(:retrieve) { true }
|
6 | 16 | allow(ForestLiana::IpWhitelist).to receive(:is_ip_whitelist_retrieved) { true }
|
7 | 17 | allow(ForestLiana::IpWhitelist).to receive(:is_ip_valid) { true }
|
8 | 18 |
|
9 | 19 | allow_any_instance_of(ForestLiana::PermissionsChecker).to receive(:is_authorized?) { true }
|
10 | 20 | end
|
11 | 21 |
|
12 |
| - it 'should route /:collection to resource#index' do |
13 |
| - headers = { |
14 |
| - 'Accept' => 'application/json', |
15 |
| - 'Content-Type' => 'application/json', |
16 |
| - 'Authorization' => 'Bearer eyJhbGciOiJIUzI1NiJ9.eyJleHAiOiIxODQ5ODc4ODYzIiwiZGF0YSI6eyJpZCI6IjM4IiwidHlwZSI6InVzZXJzIiwiZGF0YSI6eyJlbWFpbCI6Im1pY2hhZWwua2Vsc29AdGhhdDcwLnNob3ciLCJmaXJzdF9uYW1lIjoiTWljaGFlbCIsImxhc3RfbmFtZSI6IktlbHNvIiwidGVhbXMiOiJPcGVyYXRpb25zIn0sInJlbGF0aW9uc2hpcHMiOnsicmVuZGVyaW5ncyI6eyJkYXRhIjpbeyJ0eXBlIjoicmVuZGVyaW5ncyIsImlkIjoxNn1dfX19fQ.U4Mxi0tq0Ce7y5FRXP47McNPRPhUx37LznQ5E3mJIp4' |
17 |
| - } |
| 22 | + headers = { |
| 23 | + 'Accept' => 'application/json', |
| 24 | + 'Content-Type' => 'application/json', |
| 25 | + 'Authorization' => 'Bearer eyJhbGciOiJIUzI1NiJ9.eyJleHAiOiIxODQ5ODc4ODYzIiwiZGF0YSI6eyJpZCI6IjM4IiwidHlwZSI6InVzZXJzIiwiZGF0YSI6eyJlbWFpbCI6Im1pY2hhZWwua2Vsc29AdGhhdDcwLnNob3ciLCJmaXJzdF9uYW1lIjoiTWljaGFlbCIsImxhc3RfbmFtZSI6IktlbHNvIiwidGVhbXMiOiJPcGVyYXRpb25zIn0sInJlbGF0aW9uc2hpcHMiOnsicmVuZGVyaW5ncyI6eyJkYXRhIjpbeyJ0eXBlIjoicmVuZGVyaW5ncyIsImlkIjoxNn1dfX19fQ.U4Mxi0tq0Ce7y5FRXP47McNPRPhUx37LznQ5E3mJIp4' |
| 26 | + } |
| 27 | + |
| 28 | + describe 'index' do |
| 29 | + describe 'without any filter' do |
| 30 | + params = { |
| 31 | + fields: { 'Tree' => 'id,name' }, |
| 32 | + page: { 'number' => '1', 'size' => '10' }, |
| 33 | + searchExtended: '0', |
| 34 | + sort: '-id', |
| 35 | + timezone: 'Europe/Paris' |
| 36 | + } |
| 37 | + |
| 38 | + it 'should respond 200' do |
| 39 | + get '/forest/Tree', params, headers |
| 40 | + expect(response.status).to eq(200) |
| 41 | + end |
| 42 | + |
| 43 | + it 'should respond the tree data' do |
| 44 | + get '/forest/Tree', params, headers |
| 45 | + expect(JSON.parse(response.body)).to eq({ |
| 46 | + "data" => [{ |
| 47 | + "type" => "Tree", |
| 48 | + "id" => "1", |
| 49 | + "attributes" => { |
| 50 | + "id" => 1, |
| 51 | + "name" => "Lemon Tree" |
| 52 | + }, |
| 53 | + "links" => { |
| 54 | + "self" => "/forest/tree/1" |
| 55 | + } |
| 56 | + }], |
| 57 | + "included" => [] |
| 58 | + }) |
| 59 | + end |
| 60 | + end |
| 61 | + |
| 62 | + describe 'with a filter on an association that is not a displayed column' do |
| 63 | + params = { |
| 64 | + fields: { 'Tree' => 'id,name' }, |
| 65 | + filterType: 'and', |
| 66 | + filter: { 'owner:id' => '$present' }, |
| 67 | + page: { 'number' => '1', 'size' => '10' }, |
| 68 | + searchExtended: '0', |
| 69 | + sort: '-id', |
| 70 | + timezone: 'Europe/Paris' |
| 71 | + } |
| 72 | + |
| 73 | + it 'should respond 200' do |
| 74 | + get '/forest/Tree', params, headers |
| 75 | + expect(response.status).to eq(200) |
| 76 | + end |
18 | 77 |
|
19 |
| - get '/forest/Tree', {}, headers |
20 |
| - expect(response.status).to eq(200) |
21 |
| - expect(response.body).to eq("{\"data\":[],\"included\":[]}") |
| 78 | + it 'should respond the tree data' do |
| 79 | + get '/forest/Tree', params, headers |
| 80 | + expect(JSON.parse(response.body)).to eq({ |
| 81 | + "data" => [{ |
| 82 | + "type" => "Tree", |
| 83 | + "id" => "1", |
| 84 | + "attributes" => { |
| 85 | + "id" => 1, |
| 86 | + "name" => "Lemon Tree" |
| 87 | + }, |
| 88 | + "links" => { |
| 89 | + "self" => "/forest/tree/1" |
| 90 | + } |
| 91 | + }], |
| 92 | + "included" => [] |
| 93 | + }) |
| 94 | + end |
| 95 | + end |
22 | 96 | end
|
23 | 97 | end
|
0 commit comments