Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix escape characters of events when dry running #1715

Merged
merged 1 commit into from
Sep 30, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/assets/javascripts/components/utils.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class @Utils
json = $(e.target).find('.payload-editor').val()
json = '{}' if json == ''
try
payload = JSON.parse(json)
payload = JSON.parse(json.replace(/\\\\([n|r|t])/g, "\\$1"))
throw true unless payload.constructor is Object
if Object.keys(payload).length == 0
json = ''
Expand Down
35 changes: 35 additions & 0 deletions spec/features/dry_running_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
require 'rails_helper'

describe "Dry running an Agent", js: true do
let(:formatting_agent) { agents(:bob_formatting_agent) }
let(:user) { users(:bob) }
let(:emitter) { agents(:bob_weather_agent) }

before(:each) do
login_as(user)
end

def open_dry_run_modal(agent)
visit edit_agent_path(agent)
click_on("Dry Run")
expect(page).to have_text('Event to send')
end

context 'successful dry runs' do
it 'sends escape characters correctly to the backend' do
emitter.events << Event.new(payload: {data: "Line 1\nLine 2\nLine 3"})
formatting_agent.sources << emitter
formatting_agent.options.merge!('instructions' => {'data' => "{{data | newline_to_br | strip_newlines | split: '<br />' | join: ','}}"})
formatting_agent.save!

open_dry_run_modal(formatting_agent)
find('.dry-run-event-sample').click
within(:css, '.modal .builder') do
expect(page).to have_text('Line 1\nLine 2\nLine 3')
end
click_on("Dry Run")
expect(page).to have_text('Line 1,Line 2,Line 3')
expect(page).to have_selector(:css, 'li[role="presentation"].active a[href="#tabEvents"]')
end
end
end
8 changes: 8 additions & 0 deletions spec/fixtures/agents.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@ bob_weather_agent:
keep_events_for: <%= 45.days %>
options: <%= { :location => 94102, :lat => 37.779329, :lng => -122.41915, :api_key => 'test' }.to_json.inspect %>

bob_formatting_agent:
type: Agents::EventFormattingAgent
user: bob
name: "Formatting Agent"
guid: <%= SecureRandom.hex %>
keep_events_for: <%= 45.days %>
options: <%= { instructions: {}, mode: 'clean' }.to_json.inspect %>

jane_weather_agent:
type: Agents::WeatherAgent
user: jane
Expand Down
2 changes: 1 addition & 1 deletion spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
require 'rr'
require 'webmock/rspec'

WebMock.disable_net_connect!
WebMock.disable_net_connect!(allow_localhost: true)

# Requires supporting ruby files with custom matchers and macros, etc,
# in spec/support/ and its subdirectories.
Expand Down