Guest User

Untitled

a guest
Jan 16th, 2018
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. require 'rails_helper'
  2.  
  3. RSpec.describe Customers::Api::V1::SessionsController, type: :controller do
  4. describe "POST #create" do
  5. before(:each) do
  6. @user = create(:customer_user, password: '12345678')
  7. end
  8.  
  9. context "when the credentials are correct" do
  10. before(:each) do
  11. credentials = { email: @user.email, password: "12345678" }
  12. post :create, user: credentials
  13. end
  14.  
  15. it "returns the user record corresponding to the given credentials" do
  16. @user.reload
  17. expect(JSON.parse(response.body)['user']['authentication_token']).to eq @user.authentication_token
  18. end
  19. it { should respond_with 200 }
  20. end
  21.  
  22. context "when the credentials are incorrect" do
  23. before(:each) do
  24. credentials = { email: @user.email, password: "invalidpassword" }
  25. post :create, user: credentials
  26. end
  27.  
  28. it "returns a json with an error" do
  29. expect(JSON.parse(response.body)['errors']).to eq "Correo o contraseña inválidos"
  30. end
  31.  
  32. it { should respond_with 422 }
  33. end
  34. end
  35.  
  36. describe 'DELETE #destroy' do
  37. before(:each) do
  38. @user = create(:user, authentication_token: 'token')
  39. @user.devices.create(fcm_id: 'token111')
  40. delete :destroy, id: @user.authentication_token, fcm_id: 'token111'
  41. end
  42.  
  43. it 'changes user token' do
  44. expect(@user.reload.authentication_token).not_to eq('token')
  45. end
  46.  
  47. it 'resets device' do
  48. expect(@user.reload.devices).to be_empty
  49. end
  50.  
  51. it { should respond_with 204 }
  52. end
  53. end
Add Comment
Please, Sign In to add comment