From 0c69d141911a1f8e55c50d521691506ba7f32ac0 Mon Sep 17 00:00:00 2001 From: Robert Date: Mon, 17 Jul 2017 15:34:33 +0200 Subject: 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 --- spec/requests/api/v1/netex_import_spec.rb | 71 +++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 spec/requests/api/v1/netex_import_spec.rb (limited to 'spec/requests') 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 -- cgit v1.2.3