Green user sign in flow
This commit is contained in:
@@ -99,10 +99,12 @@ App.ApplicationController = Ember.Controller.extend
|
||||
error = @ajaxError (emberError)=>
|
||||
# if jqXHR.status == 404 officially, now assume close list on error
|
||||
#@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')
|
||||
error_list.eraseRecord()
|
||||
@set 'list', null
|
||||
@redirect_to 'index'
|
||||
|
||||
@store.find('list', 'current').then(success, error)
|
||||
didInsertElement: (e)->
|
||||
#debugger
|
||||
|
||||
@@ -20,8 +20,9 @@ App.ApplicationRoute = Ember.Route.extend
|
||||
Qstorage.setItem 'user_id', user_id
|
||||
Qstorage.setItem 'auth_token', auth_token
|
||||
controller = @controllerFor('application')
|
||||
controller.setCurrentList()
|
||||
controller.set 'notice', t('messages.authenticated')
|
||||
controller.setCurrentList ->
|
||||
@transitionTo('active_list')
|
||||
controller.set 'notice', t('messages.authenticated')
|
||||
actions:
|
||||
obtain_token: ( options = {} ) ->
|
||||
provider = options.provider || 'facebook'
|
||||
|
||||
@@ -290,7 +290,7 @@ class UserController < Users::ApplicationController
|
||||
#end
|
||||
|
||||
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
|
||||
# when 'android' then "file:///android_asset/user/index.html?user_id=#{current_user.id}&auth_token=#{current_user.authentication_token}"
|
||||
# when
|
||||
|
||||
@@ -1,41 +1,72 @@
|
||||
Feature: Sign up as user using facebook
|
||||
Note that facebook is automatically signing in
|
||||
|
||||
@javascript
|
||||
Scenario: Happy flow
|
||||
Scenario: Happy flow facebook without list
|
||||
Given there is no user information stored in the local storage
|
||||
When I visit the user obtain token path
|
||||
Then I should be signed in as a user through facebook
|
||||
When I wait 4 seconds
|
||||
Then I should be redirected to the user home
|
||||
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
|
||||
#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
|
||||
|
||||
@javascript
|
||||
Scenario: Already signed in user visits obtain token path
|
||||
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
|
||||
Scenario: Authencicate with facebook when there is a list already active
|
||||
Given there is a confirmed and open supplier
|
||||
And there is a facebook user
|
||||
And the user has an active order
|
||||
When I visit the user obtain token path
|
||||
And I wait 1 second
|
||||
#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 facebook button
|
||||
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: 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
|
||||
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 "there is a user"
|
||||
visit test_login_admin_users_path(email: @user.email)
|
||||
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
|
||||
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.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
|
||||
step "the newly created user info should be stored in the local storage"
|
||||
end
|
||||
@@ -42,13 +70,24 @@ step 'there is another signed in user user' do
|
||||
visit test_login_admin_users_path(email: @other_user.email)
|
||||
end
|
||||
|
||||
step "I should be redirected to the user home" do
|
||||
route_should_be 'user#index'
|
||||
step "the user should be redirected to the homepage" do
|
||||
ember_route_should_be '/'
|
||||
end
|
||||
|
||||
step "the newly created user info should be stored in the local storage" do
|
||||
page.evaluate_script(%|Qstorage.getItem('user_id')|).should == @user.id
|
||||
page.evaluate_script(%|Qstorage.getItem('auth_token')|).should == @user.authentication_token
|
||||
max_wait = 4
|
||||
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
|
||||
|
||||
step "the user authentication token changes" do
|
||||
|
||||
@@ -9,6 +9,7 @@ require 'capybara/rspec'
|
||||
require 'turnip/capybara'
|
||||
require 'in_memory_q_counter'
|
||||
require 'capybara-screenshot/rspec'
|
||||
require 'webmock/rspec'
|
||||
|
||||
# Requires supporting ruby files with custom matchers and macros, etc,
|
||||
# in spec/support/ and its subdirectories.
|
||||
@@ -21,6 +22,7 @@ Devise.stretches = 1
|
||||
Capybara.javascript_driver = :webkit
|
||||
Capybara.default_wait_time = 4 # ember needs more time than the default of 2
|
||||
Capybara::Screenshot.webkit_options = { width: 1024, height: 768 }
|
||||
WebMock.disable_net_connect!(allow_localhost: true)
|
||||
|
||||
#Capybara.javascript_driver = :selenium
|
||||
|
||||
@@ -106,6 +108,20 @@ RSpec.configure do |config|
|
||||
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
|
||||
config.color = true
|
||||
config.fail_fast = false
|
||||
|
||||
Reference in New Issue
Block a user