master
1require "rails_helper"
2
3describe Api::V1::LoginsController do
4 render_views
5
6 context "when logging in with proper credentials" do
7 let(:user) { create(:user) }
8
9 it "returns the auth token" do
10 post :create, params: { email: user.email, password: 'password' }, xhr: true
11 expected_json = { auth_token: user.authentication_token }.to_json
12 expect(response.body).to eql(expected_json)
13 end
14 end
15
16 context "when logging in with invalid credentials" do
17 let(:user) { create(:user) }
18
19 before do
20 post :create, params: { email: user.email, password: user.password.reverse }, xhr: true
21 end
22
23 it "returns an empty auth token" do
24 expect(response.body).to eql({ auth_token: "" }.to_json)
25 end
26 end
27end