BigW Consortium Gitlab

session_spec.rb 1.54 KB
Newer Older
1 2
require 'spec_helper'

3
describe API::API, api: true  do
4 5
  include ApiHelpers

6
  let(:user) { create(:user) }
7 8 9 10

  describe "POST /session" do
    context "when valid password" do
      it "should return private token" do
11
        post api("/session"), email: user.email, password: '12345678'
12 13 14 15
        response.status.should == 201

        json_response['email'].should == user.email
        json_response['private_token'].should == user.private_token
16 17 18
        json_response['is_admin'].should == user.is_admin?
        json_response['can_create_project'].should == user.can_create_project?
        json_response['can_create_group'].should == user.can_create_group?
19 20 21 22 23 24
      end
    end

    context "when invalid password" do
      it "should return authentication error" do
        post api("/session"), email: user.email, password: '123'
25
        response.status.should == 401
26 27 28 29 30 31 32 33 34

        json_response['email'].should be_nil
        json_response['private_token'].should be_nil
      end
    end

    context "when empty password" do
      it "should return authentication error" do
        post api("/session"), email: user.email
35
        response.status.should == 401
36 37 38 39 40

        json_response['email'].should be_nil
        json_response['private_token'].should be_nil
      end
    end
41 42 43 44 45 46 47 48 49 50

    context "when empty name" do
      it "should return authentication error" do
        post api("/session"), password: user.password
        response.status.should == 401

        json_response['email'].should be_nil
        json_response['private_token'].should be_nil
      end
    end
51 52
  end
end