|
| 1 | +require 'rails_helper' |
| 2 | + |
| 3 | +describe JSONAPI::Rails::FilterMediaType do |
| 4 | + let(:app) { ->(_) { [200, {}, ['OK']] } } |
| 5 | + |
| 6 | + context 'when not receiving JSON API Content-Type' do |
| 7 | + it 'passes through' do |
| 8 | + env = { 'CONTENT_TYPE' => 'application/json' } |
| 9 | + |
| 10 | + expect(described_class.new(app).call(env)[0]).to eq(200) |
| 11 | + end |
| 12 | + end |
| 13 | + |
| 14 | + context 'when receiving JSON API Content-Type without media parameters' do |
| 15 | + it 'passes through' do |
| 16 | + env = { 'CONTENT_TYPE' => 'application/vnd.api+json' } |
| 17 | + |
| 18 | + expect(described_class.new(app).call(env)[0]).to eq(200) |
| 19 | + end |
| 20 | + end |
| 21 | + |
| 22 | + context 'when receiving Content-Type with media parameters' do |
| 23 | + it 'fails with 415 Unsupported Media Type' do |
| 24 | + env = { 'CONTENT_TYPE' => 'application/vnd.api+json; charset=utf-8' } |
| 25 | + |
| 26 | + expect(described_class.new(app).call(env)[0]).to eq(415) |
| 27 | + end |
| 28 | + end |
| 29 | + |
| 30 | + context 'when not receiving JSON API in Accept' do |
| 31 | + it 'passes through' do |
| 32 | + env = { 'HTTP_ACCEPT' => 'application/json' } |
| 33 | + |
| 34 | + expect(described_class.new(app).call(env)[0]).to eq(200) |
| 35 | + end |
| 36 | + end |
| 37 | + |
| 38 | + context 'when receiving JSON API in Accept without media parameters' do |
| 39 | + it 'passes through' do |
| 40 | + env = { 'HTTP_ACCEPT' => 'application/vnd.api+json' } |
| 41 | + |
| 42 | + expect(described_class.new(app).call(env)[0]).to eq(200) |
| 43 | + end |
| 44 | + end |
| 45 | + |
| 46 | + context 'when receiving JSON API in Accept without media parameters among others' do |
| 47 | + it 'passes through' do |
| 48 | + env = { 'HTTP_ACCEPT' => 'application/json, application/vnd.api+json' } |
| 49 | + |
| 50 | + expect(described_class.new(app).call(env)[0]).to eq(200) |
| 51 | + end |
| 52 | + end |
| 53 | + |
| 54 | + context 'when receiving JSON API in Accept with media parameters' do |
| 55 | + it 'fails with 406 Not Acceptable' do |
| 56 | + env = { 'HTTP_ACCEPT' => 'application/vnd.api+json; charset=utf-8' } |
| 57 | + |
| 58 | + expect(described_class.new(app).call(env)[0]).to eq(406) |
| 59 | + end |
| 60 | + end |
| 61 | + |
| 62 | + context 'when receiving JSON API in Accept with media parameters among others' do |
| 63 | + it 'fails with 406 Not Acceptable' do |
| 64 | + env = { 'HTTP_ACCEPT' => 'application/json, application/vnd.api+json; charset=utf-8' } |
| 65 | + |
| 66 | + expect(described_class.new(app).call(env)[0]).to eq(406) |
| 67 | + end |
| 68 | + end |
| 69 | +end |
0 commit comments