2012-09-20 10:44:44 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2014-04-11 15:45:56 -04:00
|
|
|
describe API::API, api: true do
|
2012-09-20 10:44:44 -04:00
|
|
|
include ApiHelpers
|
|
|
|
|
2012-11-05 22:31:55 -05:00
|
|
|
let(:user) { create(:user) }
|
2012-09-20 10:44:44 -04:00
|
|
|
|
|
|
|
describe "POST /session" do
|
|
|
|
context "when valid password" do
|
|
|
|
it "should return private token" do
|
2013-11-25 15:33:04 -05:00
|
|
|
post api("/session"), email: user.email, password: '12345678'
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(response.status).to eq(201)
|
2012-09-20 10:44:44 -04:00
|
|
|
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(json_response['email']).to eq(user.email)
|
|
|
|
expect(json_response['private_token']).to eq(user.private_token)
|
|
|
|
expect(json_response['is_admin']).to eq(user.is_admin?)
|
|
|
|
expect(json_response['can_create_project']).to eq(user.can_create_project?)
|
|
|
|
expect(json_response['can_create_group']).to eq(user.can_create_group?)
|
2012-09-20 10:44:44 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-10-22 11:29:26 -04:00
|
|
|
context 'when email has case-typo and password is valid' do
|
|
|
|
it 'should return private token' do
|
|
|
|
post api('/session'), email: user.email.upcase, password: '12345678'
|
|
|
|
expect(response.status).to eq 201
|
|
|
|
|
|
|
|
expect(json_response['email']).to eq user.email
|
|
|
|
expect(json_response['private_token']).to eq user.private_token
|
|
|
|
expect(json_response['is_admin']).to eq user.is_admin?
|
|
|
|
expect(json_response['can_create_project']).to eq user.can_create_project?
|
|
|
|
expect(json_response['can_create_group']).to eq user.can_create_group?
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when login has case-typo and password is valid' do
|
|
|
|
it 'should return private token' do
|
|
|
|
post api('/session'), login: user.username.upcase, password: '12345678'
|
|
|
|
expect(response.status).to eq 201
|
|
|
|
|
|
|
|
expect(json_response['email']).to eq user.email
|
|
|
|
expect(json_response['private_token']).to eq user.private_token
|
|
|
|
expect(json_response['is_admin']).to eq user.is_admin?
|
|
|
|
expect(json_response['can_create_project']).to eq user.can_create_project?
|
|
|
|
expect(json_response['can_create_group']).to eq user.can_create_group?
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-09-20 10:44:44 -04:00
|
|
|
context "when invalid password" do
|
|
|
|
it "should return authentication error" do
|
|
|
|
post api("/session"), email: user.email, password: '123'
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(response.status).to eq(401)
|
2012-09-20 10:44:44 -04:00
|
|
|
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(json_response['email']).to be_nil
|
|
|
|
expect(json_response['private_token']).to be_nil
|
2012-09-20 10:44:44 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when empty password" do
|
|
|
|
it "should return authentication error" do
|
|
|
|
post api("/session"), email: user.email
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(response.status).to eq(401)
|
2012-09-20 10:44:44 -04:00
|
|
|
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(json_response['email']).to be_nil
|
|
|
|
expect(json_response['private_token']).to be_nil
|
2012-09-20 10:44:44 -04:00
|
|
|
end
|
|
|
|
end
|
2013-02-27 06:58:06 -05:00
|
|
|
|
|
|
|
context "when empty name" do
|
|
|
|
it "should return authentication error" do
|
|
|
|
post api("/session"), password: user.password
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(response.status).to eq(401)
|
2013-02-27 06:58:06 -05:00
|
|
|
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(json_response['email']).to be_nil
|
|
|
|
expect(json_response['private_token']).to be_nil
|
2013-02-27 06:58:06 -05:00
|
|
|
end
|
|
|
|
end
|
2012-09-20 10:44:44 -04:00
|
|
|
end
|
|
|
|
end
|