diff options
| author | Robert | 2017-07-17 15:34:33 +0200 |
|---|---|---|
| committer | Robert | 2017-07-19 08:40:03 +0200 |
| commit | 0c69d141911a1f8e55c50d521691506ba7f32ac0 (patch) | |
| tree | ff6f6586c6a24d0e4fc56683da3ab139178fdb0e /spec/requests | |
| parent | eac2dc45fdf6c7dbaa413396ea513b1642b32c1c (diff) | |
| download | chouette-core-0c69d141911a1f8e55c50d521691506ba7f32ac0.tar.bz2 | |
Refs: #3506@16h Request Spec for NetexImport API and implementation
- Carrier Wave Upload with `fixture_file_upload`
- Request specs to .json
- Implementation
- API token setup
- Refuted experiments with controller specs
Diffstat (limited to 'spec/requests')
| -rw-r--r-- | spec/requests/api/v1/netex_import_spec.rb | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/spec/requests/api/v1/netex_import_spec.rb b/spec/requests/api/v1/netex_import_spec.rb new file mode 100644 index 000000000..b7a5c94ee --- /dev/null +++ b/spec/requests/api/v1/netex_import_spec.rb @@ -0,0 +1,71 @@ +RSpec.describe "NetexImport", type: :request do + + describe 'POST netex_imports' do + + let( :referential ){ create :referential } + + let( :file_path ){'spec/fixtures/neptune.zip'} + let( :file ){ fixture_file_upload( file_path ) } + + let( :post_request ) do + -> do + post "/api/v1/netex_imports.json", + attributes, + authorization + end + end + + let( :attributes ){ { + netex_import: { + name: 'hello world', + file: file, + referential_id: referential.id} + } } + + context 'with correct credentials and correct request' do + let( :authorization ){ authorization_token_header( get_api_key.token ) } + + + it 'succeeds' do + post_request.() + expect( response ).to be_success + expect( JSON.parse(response.body) ).to eq({'id' => NetexImport.last.id, 'type' => 'NetexImport'}) + end + + it 'creates a NetexImport object in the DB' do + expect(&post_request).to change{NetexImport.count}.by(1) + end + end + + context 'with incorrect credentials and correct request' do + let( :authorization ){ authorization_token_header( "#{referential.id}-incorrect_token") } + + it 'succeeds not' do + post_request.() + expect( response.status ).to eq(401) + end + + it 'does not create an Import object' do + expect(&post_request).not_to change{Import.count} + end + end + + context 'with correct credentials and incorrect request' do + let( :authorization ){ authorization_token_header( get_api_key.token ) } + let( :attributes ){ { + netex_import: { + referential_id: referential.id} + } } + + it 'succeeds not' do + post_request.() + expect( response.status ).to eq(406) + expect( json_response_body['errors']['file'] ).not_to be_empty + end + + it 'does not create an Import object' do + expect(&post_request).not_to change{Import.count} + end + end + end +end |
