diff options
Diffstat (limited to 'spec')
7 files changed, 221 insertions, 2 deletions
diff --git a/spec/controllers/autocomplete_purchase_windows_controller_spec.rb b/spec/controllers/autocomplete_purchase_windows_controller_spec.rb new file mode 100644 index 000000000..cea600ea8 --- /dev/null +++ b/spec/controllers/autocomplete_purchase_windows_controller_spec.rb @@ -0,0 +1,33 @@ +require 'rails_helper' + +RSpec.describe AutocompletePurchaseWindowsController, type: :controller do + login_user + + let(:referential) { Referential.first } + let!(:window) { create :purchase_window, referential: referential, name: 'écolà militaire' } + + describe 'GET #index' do + it 'should be unauthorized' do + expect { get(:index, referential_id: referential.id) }.to raise_error(FeatureChecker::NotAuthorizedError) + end + + with_feature "purchase_windows" do + let(:request){ get(:index, referential_id: referential.id) } + before do + request + end + + it 'should be successful' do + expect(response).to be_success + end + + context 'search by name' do + let(:request){ get :index, referential_id: referential.id, q: {name_or_objectid_cont_any: 'écolà'}, :format => :json } + it 'should be successful' do + expect(response).to be_success + expect(assigns(:purchase_windows)).to eq([window]) + end + end + end + end +end diff --git a/spec/controllers/vehicle_journeys_controller_spec.rb b/spec/controllers/vehicle_journeys_controller_spec.rb index c9356fffa..416450c21 100644 --- a/spec/controllers/vehicle_journeys_controller_spec.rb +++ b/spec/controllers/vehicle_journeys_controller_spec.rb @@ -10,6 +10,7 @@ RSpec.describe VehicleJourneysController, :type => :controller do before do allow(controller).to receive(:pundit_user).and_return(user_context) + allow(controller).to receive(:current_organisation).and_return(@user.organisation) end it 'computes them correctly if not authorized' do diff --git a/spec/db/schema_spec.rb b/spec/db/schema_spec.rb index 585636124..a7fe0a162 100644 --- a/spec/db/schema_spec.rb +++ b/spec/db/schema_spec.rb @@ -44,6 +44,6 @@ Diff: #{diff} def diff RSpec::Support::Differ.new( color: RSpec::Matchers.configuration.color? - ).diff_as_string(@expected, @original) + ).diff_as_string(@original, @expected) end end diff --git a/spec/javascript/vehicle_journeys/actions_spec.js b/spec/javascript/vehicle_journeys/actions_spec.js index 789507482..3af19ebc3 100644 --- a/spec/javascript/vehicle_journeys/actions_spec.js +++ b/spec/javascript/vehicle_journeys/actions_spec.js @@ -209,6 +209,13 @@ describe('when clicking on edit notes modal', () => { expect(actions.openNotesEditModal(vehicleJourney)).toEqual(expectedAction) }) }) + + // ___ ___ ___ _____ _ _ ___ _____ ___ ___ + // | __/ _ \ / _ \_ _| \| |/ _ \_ _| __/ __| + // | _| (_) | (_) || | | .` | (_) || | | _|\__ \ + // |_| \___/ \___/ |_| |_|\_|\___/ |_| |___|___/ + // + describe('when clicking on a footnote button inside footnote modal', () => { it('should create an action to toggle this footnote', () => { const footnote = {}, isShown = true @@ -230,6 +237,13 @@ describe('when clicking on validate button inside footnote modal', () => { expect(actions.editVehicleJourneyNotes(footnotes)).toEqual(expectedAction) }) }) + + // _____ ___ __ __ ___ _____ _ ___ _ ___ ___ + // |_ _|_ _| \/ | __|_ _/_\ | _ ) | | __/ __| + // | | | || |\/| | _| | |/ _ \| _ \ |__| _|\__ \ + // |_| |___|_| |_|___| |_/_/ \_\___/____|___|___/ + // + describe('when clicking on calendar button in toolbox', () => { it('should create an action to open calendar modal', () => { const vehicleJourneys = [] @@ -288,6 +302,83 @@ describe('when using select2 to pick a timetable', () => { expect(actions.selectTTCalendarsModal(selectedTT)).toEqual(expectedAction) }) }) + + // ___ _ _ ___ ___ _ _ _ ___ ___ + // | _ \ | | | _ \/ __| || | /_\ / __| __| + // | _/ |_| | / (__| __ |/ _ \\__ \ _| + // |_| \___/|_|_\\___|_||_/_/_\_\___/___|__ + // \ \ / /_ _| \| | \ / _ \ \ / / __| + // \ \/\/ / | || .` | |) | (_) \ \/\/ /\__ \ + // \_/\_/ |___|_|\_|___/ \___/ \_/\_/ |___/ + // + +describe('when clicking on purchase window button in toolbox', () => { + it('should create an action to open purchase window modal', () => { + const vehicleJourneys = [] + const expectedAction = { + type: 'EDIT_PURCHASE_WINDOWS_VEHICLEJOURNEY_MODAL', + vehicleJourneys + } + expect(actions.openPurchaseWindowsEditModal(vehicleJourneys)).toEqual(expectedAction) + }) +}) +describe('when clicking on delete button next to a purchase window inside modal', () => { + it('should create an action to delete purchase window from selected vehicle journeys', () => { + const purchaseWindow = {} + const expectedAction = { + type: 'DELETE_PURCHASE_WINDOW_MODAL', + purchaseWindow + } + expect(actions.deletePurchaseWindowsModal(purchaseWindow)).toEqual(expectedAction) + }) +}) +describe('when clicking on validate button inside purchase windows modal', () => { + it('should create an action to update vj purchase windows', () => { + const vehicleJourneys = [] + const purchase_windows = [] + const expectedAction = { + type: 'EDIT_VEHICLEJOURNEYS_PURCHASE_WINDOWS', + vehicleJourneys, + purchase_windows + } + expect(actions.editVehicleJourneyPurchaseWindows(vehicleJourneys, purchase_windows)).toEqual(expectedAction) + }) +}) +describe('when clicking on add button inside purchase windows modal', () => { + it('should create an action to add the selected purchase window to preselected vjs', () => { + const expectedAction = { + type: 'ADD_SELECTED_PURCHASE_WINDOW', + } + expect(actions.addSelectedPurchaseWindow()).toEqual(expectedAction) + }) +}) +describe('when using select2 to pick a purchase window', () => { + it('should create an action to select a purchase window inside modal', () => { + let selectedTT = { + id: 1, + objectid: 2, + name: 'test', + color: 'color', + } + const expectedAction = { + type: 'SELECT_PURCHASE_WINDOW_MODAL', + selectedItem:{ + id: selectedTT.id, + objectid: selectedTT.objectid, + name: selectedTT.name, + color: "color" + } + } + expect(actions.selectPurchaseWindowsModal(selectedTT)).toEqual(expectedAction) + }) +}) + + // ___ ___ _ _____ ___ ___ ___ + // | __|_ _| ||_ _| __| _ \/ __| + // | _| | || |__| | | _|| /\__ \ + // |_| |___|____|_| |___|_|_\|___/ + // + describe('when clicking on reset button inside query filters', () => { it('should create an action to reset the query filters', () => { const expectedAction = { diff --git a/spec/javascript/vehicle_journeys/reducers/modal_spec.js b/spec/javascript/vehicle_journeys/reducers/modal_spec.js index 69de9168b..ea8a002d2 100644 --- a/spec/javascript/vehicle_journeys/reducers/modal_spec.js +++ b/spec/javascript/vehicle_journeys/reducers/modal_spec.js @@ -91,6 +91,12 @@ describe('modal reducer', () => { ).toEqual(newState) }) + // _____ ___ __ __ ___ _____ _ ___ _ ___ ___ + // |_ _|_ _| \/ | __|_ _/_\ | _ ) | | __/ __| + // | | | || |\/| | _| | |/ _ \| _ \ |__| _|\__ \ + // |_| |___|_| |_|___| |_/_/ \_\___/____|___|___/ + // + it('should handle EDIT_CALENDARS_VEHICLEJOURNEY_MODAL', () => { let vehicleJourneys = [] let modalPropsResult = { @@ -158,6 +164,82 @@ describe('modal reducer', () => { ).toEqual(newState) }) + // ___ _ _ ___ ___ _ _ _ ___ ___ + // | _ \ | | | _ \/ __| || | /_\ / __| __| + // | _/ |_| | / (__| __ |/ _ \\__ \ _| + // |_| \___/|_|_\\___|_||_/_/_\_\___/___|__ + // \ \ / /_ _| \| | \ / _ \ \ / / __| + // \ \/\/ / | || .` | |) | (_) \ \/\/ /\__ \ + // \_/\_/ |___|_|\_|___/ \___/ \_/\_/ |___/ + // + + it('should handle EDIT_PURCHASE_WINDOWS_VEHICLEJOURNEY_MODAL', () => { + let vehicleJourneys = [] + let modalPropsResult = { + vehicleJourneys: [], + purchase_windows: [] + } + expect( + modalReducer(state, { + type: 'EDIT_PURCHASE_WINDOWS_VEHICLEJOURNEY_MODAL', + vehicleJourneys + }) + ).toEqual(Object.assign({}, state, {type: 'purchase_windows_edit', modalProps: modalPropsResult})) + }) + + it('should handle SELECT_PURCHASE_WINDOW_MODAL', () => { + let newModalProps = {selectedPurchaseWindow : {id: 1}} + expect( + modalReducer(state, { + type: 'SELECT_PURCHASE_WINDOW_MODAL', + selectedItem: {id: 1} + }) + ).toEqual(Object.assign({}, state, {modalProps: newModalProps})) + }) + + it('should handle ADD_SELECTED_PURCHASE_WINDOW', () => { + let fakeWindows = [{'test': 'test'}, {'test 2': 'test 2'}] + let newWindows = [{'test': 'test'}, {'test 2': 'test 2'}, {'add': 'add'}] + let fakeVehicleJourneys= [{purchase_windows: fakeWindows}, {purchase_windows: newWindows}] + state.modalProps.vehicleJourneys = fakeVehicleJourneys + state.modalProps.purchase_windows = fakeWindows + state.modalProps.selectedPurchaseWindow = {'add': 'add'} + let newState = { + type: '', + modalProps:{ + vehicleJourneys: fakeVehicleJourneys, + purchase_windows: [{'test': 'test'},{'test 2': 'test 2'},{'add': 'add'}], + selectedPurchaseWindow: {'add': 'add'} + }, + confirmModal: {} + } + expect( + modalReducer(state, { + type: 'ADD_SELECTED_PURCHASE_WINDOW', + }) + ).toEqual(newState) + }) + + it('should handle DELETE_PURCHASE_WINDOW_MODAL', () => { + let deletableWindow = {'delete': 'delete'} + let fakeWindows = [{'test': 'test'}, {'test 2': 'test 2'}, deletableWindow] + let newWindows = [{'test': 'test'}, {'test 2': 'test 2'}] + let fakeVehicleJourneys= [{purchase_windows: fakeWindows}, {purchase_windows: newWindows}] + state.modalProps = Object.assign({}, state.modalProps,{vehicleJourneys : fakeVehicleJourneys, purchase_windows: fakeWindows }) + let newState = { + // for the sake of the test, no need to specify the type + type: '', + modalProps:{vehicleJourneys: [{purchase_windows: newWindows},{purchase_windows: newWindows}], purchase_windows: newWindows}, + confirmModal: {} + } + expect( + modalReducer(state, { + type: 'DELETE_PURCHASE_WINDOW_MODAL', + purchaseWindow: deletableWindow + }) + ).toEqual(newState) + }) + it('should handle SELECT_CP_EDIT_MODAL', () => { let newModalProps = {selectedCompany : {name: 'ALBATRANS'}} expect( diff --git a/spec/javascript/vehicle_journeys/reducers/vehicleJourneys_spec.js b/spec/javascript/vehicle_journeys/reducers/vehicleJourneys_spec.js index 1c2cc1577..c834de1f6 100644 --- a/spec/javascript/vehicle_journeys/reducers/vehicleJourneys_spec.js +++ b/spec/javascript/vehicle_journeys/reducers/vehicleJourneys_spec.js @@ -254,7 +254,6 @@ describe('vehicleJourneys reducer', () => { ).toEqual([newVJ, state[1]]) }) - it('should handle EDIT_VEHICLEJOURNEYS_TIMETABLES', () => { let newState = JSON.parse(JSON.stringify(state)) newState[0].time_tables = [fakeTimeTables[0]] @@ -266,4 +265,16 @@ describe('vehicleJourneys reducer', () => { }) ).toEqual(newState) }) + + it('should handle EDIT_VEHICLEJOURNEYS_PURCHASE_WINDOWS', () => { + let newState = JSON.parse(JSON.stringify(state)) + newState[0].purchase_windows = [fakeTimeTables[0]] + expect( + vjReducer(state, { + type: 'EDIT_VEHICLEJOURNEYS_PURCHASE_WINDOWS', + vehicleJourneys: state, + purchase_windows: [fakeTimeTables[0]] + }) + ).toEqual(newState) + }) }) diff --git a/spec/models/chouette/vehicle_journey_spec.rb b/spec/models/chouette/vehicle_journey_spec.rb index ac9b21ceb..60ab2b818 100644 --- a/spec/models/chouette/vehicle_journey_spec.rb +++ b/spec/models/chouette/vehicle_journey_spec.rb @@ -2,6 +2,7 @@ require 'spec_helper' describe Chouette::VehicleJourney, :type => :model do it { is_expected.to be_versioned } + it { should have_and_belong_to_many(:purchase_windows) } it "must be valid with an at-stop day offset of 1" do vehicle_journey = create( |
