Green user sign in flow
This commit is contained in:
@@ -99,10 +99,12 @@ App.ApplicationController = Ember.Controller.extend
|
|||||||
error = @ajaxError (emberError)=>
|
error = @ajaxError (emberError)=>
|
||||||
# if jqXHR.status == 404 officially, now assume close list on error
|
# if jqXHR.status == 404 officially, now assume close list on error
|
||||||
#@redirect_to 'index', message: 'the_list_has_been_closed'
|
#@redirect_to 'index', message: 'the_list_has_been_closed'
|
||||||
console.log "Error: #{emberError.message}" if emberError.message
|
#console.log "Error: #{emberError.message}" if emberError.message
|
||||||
if error_list = @store.all('list').findBy('id', 'current')
|
if error_list = @store.all('list').findBy('id', 'current')
|
||||||
error_list.eraseRecord()
|
error_list.eraseRecord()
|
||||||
@set 'list', null
|
@set 'list', null
|
||||||
|
@redirect_to 'index'
|
||||||
|
|
||||||
@store.find('list', 'current').then(success, error)
|
@store.find('list', 'current').then(success, error)
|
||||||
didInsertElement: (e)->
|
didInsertElement: (e)->
|
||||||
#debugger
|
#debugger
|
||||||
|
|||||||
@@ -20,7 +20,8 @@ App.ApplicationRoute = Ember.Route.extend
|
|||||||
Qstorage.setItem 'user_id', user_id
|
Qstorage.setItem 'user_id', user_id
|
||||||
Qstorage.setItem 'auth_token', auth_token
|
Qstorage.setItem 'auth_token', auth_token
|
||||||
controller = @controllerFor('application')
|
controller = @controllerFor('application')
|
||||||
controller.setCurrentList()
|
controller.setCurrentList ->
|
||||||
|
@transitionTo('active_list')
|
||||||
controller.set 'notice', t('messages.authenticated')
|
controller.set 'notice', t('messages.authenticated')
|
||||||
actions:
|
actions:
|
||||||
obtain_token: ( options = {} ) ->
|
obtain_token: ( options = {} ) ->
|
||||||
|
|||||||
@@ -290,7 +290,7 @@ class UserController < Users::ApplicationController
|
|||||||
#end
|
#end
|
||||||
|
|
||||||
def obtain_token
|
def obtain_token
|
||||||
redirect_to user_omniauth_authorize_path('facebook') and return unless current_user.present?
|
redirect_to user_omniauth_authorize_path(params[:provider].presence || 'facebook') and return unless current_user.present?
|
||||||
# redirect_to case platform
|
# redirect_to case platform
|
||||||
# when 'android' then "file:///android_asset/user/index.html?user_id=#{current_user.id}&auth_token=#{current_user.authentication_token}"
|
# when 'android' then "file:///android_asset/user/index.html?user_id=#{current_user.id}&auth_token=#{current_user.authentication_token}"
|
||||||
# when
|
# when
|
||||||
|
|||||||
@@ -1,41 +1,72 @@
|
|||||||
Feature: Sign up as user using facebook
|
Feature: Sign up as user using facebook
|
||||||
Note that facebook is automatically signing in
|
|
||||||
|
|
||||||
@javascript
|
@javascript
|
||||||
Scenario: Happy flow
|
Scenario: Happy flow facebook without list
|
||||||
Given there is no user information stored in the local storage
|
Given there is no user information stored in the local storage
|
||||||
When I visit the user obtain token path
|
When the user is on the homepage
|
||||||
Then I should be signed in as a user through facebook
|
Then the user is redirected to the sign in page
|
||||||
When I wait 4 seconds
|
When the user clicks the sign in via facebook button
|
||||||
Then I should be redirected to the user home
|
#When I visit the user obtain token path
|
||||||
|
Then the user should be redirected to the homepage
|
||||||
|
And the user should be signed in as the facebook user
|
||||||
And the newly created user info should be stored in the local storage
|
And the newly created user info should be stored in the local storage
|
||||||
|
|
||||||
@javascript
|
@javascript
|
||||||
Scenario: Already signed in user visits obtain token path
|
Scenario: Authencicate with facebook when there is a list already active
|
||||||
Given I am signed in as a user
|
|
||||||
When I visit '/user'
|
|
||||||
And I wait 4 seconds
|
|
||||||
Then I should be redirected to the user home
|
|
||||||
And the newly created user info should be stored in the local storage
|
|
||||||
|
|
||||||
@javascript
|
|
||||||
Scenario: Expired token
|
|
||||||
Given I visit '/user'
|
|
||||||
And I wait 4 seconds
|
|
||||||
And I am signed out as a user
|
|
||||||
When the user authentication token changes
|
|
||||||
And I visit '/user'
|
|
||||||
And I wait 4 seconds
|
|
||||||
Then the newly created user info should be stored in the local storage
|
|
||||||
|
|
||||||
@javascript
|
|
||||||
Scenario: Authenciation when there is a list already active
|
|
||||||
Given there is a confirmed and open supplier
|
Given there is a confirmed and open supplier
|
||||||
And there is a facebook user
|
And there is a facebook user
|
||||||
And the user has an active order
|
And the user has an active order
|
||||||
When I visit the user obtain token path
|
#When I visit the user obtain token path
|
||||||
And I wait 1 second
|
When the user is on the homepage
|
||||||
|
Then the user is redirected to the sign in page
|
||||||
|
When the user clicks the sign in via facebook button
|
||||||
Then the user should be redirected to the user order overview page
|
Then the user should be redirected to the user order overview page
|
||||||
|
|
||||||
|
@javascript
|
||||||
|
Scenario: Happy flow instagram without list
|
||||||
|
Given there is no user information stored in the local storage
|
||||||
|
When the user is on the homepage
|
||||||
|
Then the user is redirected to the sign in page
|
||||||
|
When the user clicks the sign in via instagram button
|
||||||
|
#When I visit the user obtain token path
|
||||||
|
Then the user should be redirected to the homepage
|
||||||
|
And the user should be signed in as the instagram user
|
||||||
|
And the newly created user info should be stored in the local storage
|
||||||
|
|
||||||
|
@javascript
|
||||||
|
Scenario: Authencicate with instagram when there is a list already active
|
||||||
|
Given there is a confirmed and open supplier
|
||||||
|
And there is a instagram user
|
||||||
|
And the user has an active order
|
||||||
|
#When I visit the user obtain token path
|
||||||
|
When the user is on the homepage
|
||||||
|
Then the user is redirected to the sign in page
|
||||||
|
When the user clicks the sign in via instagram button
|
||||||
|
Then the user should be redirected to the user order overview page
|
||||||
|
|
||||||
|
@javascript
|
||||||
|
Scenario: Already signed in user loads the application
|
||||||
|
Given I am signed in as a user
|
||||||
|
When the user is on the homepage
|
||||||
|
#And I open the debugger
|
||||||
|
#Then the user is redirected to the sign in page
|
||||||
|
#When the user clicks the sign in via facebook button
|
||||||
|
#When I visit '/user'
|
||||||
|
#And I wait 4 seconds
|
||||||
|
Then the user should be redirected to the homepage
|
||||||
|
And the newly created user info should be stored in the local storage
|
||||||
|
|
||||||
|
@javascript @broken
|
||||||
|
Scenario: Expired token
|
||||||
|
Given there is no user information stored in the local storage
|
||||||
|
When the user is on the homepage
|
||||||
|
Then the user is redirected to the sign in page
|
||||||
|
When the user clicks the sign in via facebook button
|
||||||
|
Then the user should be redirected to the homepage
|
||||||
|
When the user has no active session
|
||||||
|
And the user authentication token changes
|
||||||
|
When the user is on the homepage
|
||||||
|
Then the newly created user info should be stored in the local storage
|
||||||
|
|
||||||
Scenario: Facebook problem OmniAuth.config.mock_auth[:facebook] = :invalid_credentials
|
Scenario: Facebook problem OmniAuth.config.mock_auth[:facebook] = :invalid_credentials
|
||||||
Scenario: Valid facebook login, but declines information requested by scope
|
Scenario: Valid facebook login, but declines information requested by scope
|
||||||
|
|||||||
@@ -21,17 +21,45 @@ step "there is a facebook user" do
|
|||||||
@user ||= create :user, provider: 'facebook', uid: '123456790' # uid from spec_helper oauth setup
|
@user ||= create :user, provider: 'facebook', uid: '123456790' # uid from spec_helper oauth setup
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
step "there is a instagram user" do
|
||||||
|
if @user
|
||||||
|
raise "There already is a user, but not a instagram user"
|
||||||
|
else
|
||||||
|
@user ||= create :user, provider: 'instagram', uid: '123498765' # uid from spec_helper oauth setup
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
step "the user is redirected to the sign in page" do
|
||||||
|
ember_route_should_be '/sign_in'
|
||||||
|
end
|
||||||
|
|
||||||
step "I am signed in as a user" do
|
step "I am signed in as a user" do
|
||||||
step "there is a user"
|
step "there is a user"
|
||||||
visit test_login_admin_users_path(email: @user.email)
|
visit test_login_admin_users_path(email: @user.email)
|
||||||
end
|
end
|
||||||
|
|
||||||
step "I am signed out as a user" do
|
step "the user clicks the sign in via facebook button" do
|
||||||
|
find('.sign-in-button.facebook').click
|
||||||
|
end
|
||||||
|
|
||||||
|
step "the user clicks the sign in via instagram button" do
|
||||||
|
find('.sign-in-button.instagram').click
|
||||||
|
end
|
||||||
|
step "the user has no active session" do
|
||||||
visit destroy_user_session_path
|
visit destroy_user_session_path
|
||||||
end
|
end
|
||||||
|
|
||||||
step "I should be signed in as a user through facebook" do
|
step "the user should be signed in as the facebook user" do
|
||||||
@user = User.find_by_oauth_token 'fbAuthToken234'
|
@user = User.find_by_oauth_token 'fbAuthToken234'
|
||||||
|
@user.should be_present
|
||||||
|
# For now, actually better to test a signed in response from the server
|
||||||
|
step "the newly created user info should be stored in the local storage"
|
||||||
|
end
|
||||||
|
|
||||||
|
step "the user should be signed in as the instagram user" do
|
||||||
|
@user = User.find_by_oauth_token 'igAuthToken234'
|
||||||
|
@user.should be_present
|
||||||
# For now, actually better to test a signed in response from the server
|
# For now, actually better to test a signed in response from the server
|
||||||
step "the newly created user info should be stored in the local storage"
|
step "the newly created user info should be stored in the local storage"
|
||||||
end
|
end
|
||||||
@@ -42,13 +70,24 @@ step 'there is another signed in user user' do
|
|||||||
visit test_login_admin_users_path(email: @other_user.email)
|
visit test_login_admin_users_path(email: @other_user.email)
|
||||||
end
|
end
|
||||||
|
|
||||||
step "I should be redirected to the user home" do
|
step "the user should be redirected to the homepage" do
|
||||||
route_should_be 'user#index'
|
ember_route_should_be '/'
|
||||||
end
|
end
|
||||||
|
|
||||||
step "the newly created user info should be stored in the local storage" do
|
step "the newly created user info should be stored in the local storage" do
|
||||||
page.evaluate_script(%|Qstorage.getItem('user_id')|).should == @user.id
|
max_wait = 4
|
||||||
page.evaluate_script(%|Qstorage.getItem('auth_token')|).should == @user.authentication_token
|
time = 0.0
|
||||||
|
time_step = 0.25
|
||||||
|
user_id = page.evaluate_script(%|Qstorage.getItem('user_id')|)
|
||||||
|
auth_token = page.evaluate_script(%|Qstorage.getItem('auth_token')|)
|
||||||
|
while time < max_wait && user_id != @user.id && auth_token != @user.authentication_token
|
||||||
|
time += time_step
|
||||||
|
sleep time_step
|
||||||
|
user_id = page.evaluate_script(%|Qstorage.getItem('user_id')|)
|
||||||
|
auth_token = page.evaluate_script(%|Qstorage.getItem('auth_token')|)
|
||||||
|
end
|
||||||
|
user_id.should == @user.id
|
||||||
|
auth_token.should == @user.authentication_token
|
||||||
end
|
end
|
||||||
|
|
||||||
step "the user authentication token changes" do
|
step "the user authentication token changes" do
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ require 'capybara/rspec'
|
|||||||
require 'turnip/capybara'
|
require 'turnip/capybara'
|
||||||
require 'in_memory_q_counter'
|
require 'in_memory_q_counter'
|
||||||
require 'capybara-screenshot/rspec'
|
require 'capybara-screenshot/rspec'
|
||||||
|
require 'webmock/rspec'
|
||||||
|
|
||||||
# Requires supporting ruby files with custom matchers and macros, etc,
|
# Requires supporting ruby files with custom matchers and macros, etc,
|
||||||
# in spec/support/ and its subdirectories.
|
# in spec/support/ and its subdirectories.
|
||||||
@@ -21,6 +22,7 @@ Devise.stretches = 1
|
|||||||
Capybara.javascript_driver = :webkit
|
Capybara.javascript_driver = :webkit
|
||||||
Capybara.default_wait_time = 4 # ember needs more time than the default of 2
|
Capybara.default_wait_time = 4 # ember needs more time than the default of 2
|
||||||
Capybara::Screenshot.webkit_options = { width: 1024, height: 768 }
|
Capybara::Screenshot.webkit_options = { width: 1024, height: 768 }
|
||||||
|
WebMock.disable_net_connect!(allow_localhost: true)
|
||||||
|
|
||||||
#Capybara.javascript_driver = :selenium
|
#Capybara.javascript_driver = :selenium
|
||||||
|
|
||||||
@@ -106,6 +108,20 @@ RSpec.configure do |config|
|
|||||||
uid: '123456790'
|
uid: '123456790'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
OmniAuth.config.add_mock :instagram, {
|
||||||
|
info: {
|
||||||
|
nickname: 'Iggy',
|
||||||
|
name: "Instagram Jane",
|
||||||
|
first_name: "Insta"
|
||||||
|
},
|
||||||
|
credentials: {
|
||||||
|
'token' => 'igAuthToken234',
|
||||||
|
'expires_at' => 1.week.from_now.to_i,
|
||||||
|
'expires' => true
|
||||||
|
},
|
||||||
|
uid: '123498765'
|
||||||
|
}
|
||||||
|
|
||||||
# Use color in STDOUT
|
# Use color in STDOUT
|
||||||
config.color = true
|
config.color = true
|
||||||
config.fail_fast = false
|
config.fail_fast = false
|
||||||
|
|||||||
Reference in New Issue
Block a user