Skip to content

Commit

Permalink
[Internal] Add route for widget testing (chatwoot#199)
Browse files Browse the repository at this point in the history
  • Loading branch information
pranavrajs authored and sojan-official committed Nov 1, 2019
1 parent f3fc542 commit 5cc3543
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ group :development, :test do
gem 'faker'
gem 'listen'
gem 'pry-rails'
gem 'rspec-rails', '~> 3.8'
gem 'rspec-rails', git: 'https://github.com/rspec/rspec-rails', tag: 'v4.0.0.beta3'
gem 'rubocop', '~> 0.73.0', require: false
gem 'rubocop-performance', require: false
gem 'rubocop-rails', require: false
Expand Down
24 changes: 15 additions & 9 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,20 @@ GIT
responders
warden (~> 1.2.3)

GIT
remote: https://github.com/rspec/rspec-rails
revision: bfa37ce6d6ab80257c48e407042406007c7cb724
tag: v4.0.0.beta3
specs:
rspec-rails (4.0.0.beta3)
actionpack (>= 4.2)
activesupport (>= 4.2)
railties (>= 4.2)
rspec-core (~> 3.8)
rspec-expectations (~> 3.8)
rspec-mocks (~> 3.8)
rspec-support (~> 3.8)

GEM
remote: https://rubygems.org/
specs:
Expand Down Expand Up @@ -332,14 +346,6 @@ GEM
rspec-mocks (3.9.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.9.0)
rspec-rails (3.9.0)
actionpack (>= 3.0)
activesupport (>= 3.0)
railties (>= 3.0)
rspec-core (~> 3.9.0)
rspec-expectations (~> 3.9.0)
rspec-mocks (~> 3.9.0)
rspec-support (~> 3.9.0)
rspec-support (3.9.0)
rubocop (0.73.0)
jaro_winkler (~> 1.5.1)
Expand Down Expand Up @@ -478,7 +484,7 @@ DEPENDENCIES
redis-namespace
redis-rack-cache
responders
rspec-rails (~> 3.8)
rspec-rails!
rubocop (~> 0.73.0)
rubocop-performance
rubocop-rails
Expand Down
13 changes: 13 additions & 0 deletions app/controllers/widget_tests_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class WidgetTestsController < ActionController::Base
before_action :set_web_widget

def index
render
end

private

def set_web_widget
@web_widget = Channel::WebWidget.first
end
end
14 changes: 14 additions & 0 deletions app/views/widget_tests/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<script>
(function(d,t) {
var BASE_URL = '';
var g=d.createElement(t),s=d.getElementsByTagName(t)[0];
g.src= BASE_URL + "/packs/js/sdk.js";
s.parentNode.insertBefore(g,s);
g.onload=function(){
window.chatwootSDK.run({
websiteToken: '<%= @web_widget.website_token %>',
baseUrl: BASE_URL
})
}
})(document,"script");
</script>
3 changes: 3 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,7 @@

mount Facebook::Messenger::Server, at: 'bot'
post '/webhooks/telegram/:account_id/:inbox_id' => 'home#telegram'

# Routes for testing
resources :widget_tests, only: [:index] unless Rails.env.production?
end
File renamed without changes.
12 changes: 12 additions & 0 deletions spec/controllers/widget_tests_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
require 'rails_helper'

describe WidgetTestsController, type: :controller do
let(:channel_widget) { create(:channel_widget) }

describe '#index' do
it 'renders the page correctly' do
get :index
expect(response.status).to eq 200
end
end
end

0 comments on commit 5cc3543

Please sign in to comment.