Repository URL to install this package:
|
Version:
2.23.0 ▾
|
require 'spec_helper'
describe JPlatform::SessionsController, :type => :controller do
describe "GET 'create'" do
describe "General Member" do
before do
OmniAuth.config.mock_auth[:j_auth] = {
credentials: { token: '12345'},
info: { id: '2'}
}
request.env["omniauth.auth"] = OmniAuth.config.mock_auth[:j_auth]
stub_get("/api/v1/users/me.json").to_return(body: fixture("member_without_project.json"), headers: {content_type: "application/json; charset=utf-8"})
end
it "creates users login session data properly" do
session[:last_seen] = nil
get :create, use_route: :auth_callback_path
expect(controller.session[:user_id]).to eq("2")
expect(controller.session[:last_seen]).not_to be_nil
end
it "redirects user to the user profile page if Oauth origin url is not set" do
get :create, use_route: :auth_callback_path
expect(response).to redirect_to "/"
end
it "redirects user to the Oauth origin url if it is set" do
return_to_url = 'http://www.test.com/test/test?=test123'
@request.env['omniauth.origin'] = return_to_url
get :create, use_route: :auth_callback_path
expect(response).to redirect_to return_to_url
end
end
end
describe "GET 'destroy'" do
include_context "controller setup"
before(:each) do
allow(Typhoeus::Request).to receive(:post)
end
it "clears users login session data" do
expect(controller.session[:user_id]).not_to be_nil
get :destroy, use_route: :logout_path
expect(controller.session[:user_id]).to be_nil
end
it "redirects user to JPlatform with return to url data" do
return_to_url = 'http://www.test.com/test/test?=test123'
@request.env['HTTP_REFERER'] = return_to_url
get :destroy, use_route: :logout_path
expect(response).to redirect_to JPlatform::Default.endpoint + '/logout?return_to=' + Rack::Utils.escape(return_to_url)
end
it "sends post request to revoke access token" do
session[:user_token] = "token"
platform_revoke_path = "#{JPlatform::Default.endpoint}/oauth/revoke"
expect(Typhoeus::Request).to receive(:post).with(platform_revoke_path,
body: { token: "token", token_type: 'access_token', access_token: 'token' })
get :destroy, use_route: :logout_path
end
end
end