Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'rails_helper'
- RSpec.describe Customers::Api::V1::SessionsController, type: :controller do
- describe "POST #create" do
- before(:each) do
- @user = create(:customer_user, password: '12345678')
- end
- context "when the credentials are correct" do
- before(:each) do
- credentials = { email: @user.email, password: "12345678" }
- post :create, user: credentials
- end
- it "returns the user record corresponding to the given credentials" do
- @user.reload
- expect(JSON.parse(response.body)['user']['authentication_token']).to eq @user.authentication_token
- end
- it { should respond_with 200 }
- end
- context "when the credentials are incorrect" do
- before(:each) do
- credentials = { email: @user.email, password: "invalidpassword" }
- post :create, user: credentials
- end
- it "returns a json with an error" do
- expect(JSON.parse(response.body)['errors']).to eq "Correo o contraseña inválidos"
- end
- it { should respond_with 422 }
- end
- end
- describe 'DELETE #destroy' do
- before(:each) do
- @user = create(:user, authentication_token: 'token')
- @user.devices.create(fcm_id: 'token111')
- delete :destroy, id: @user.authentication_token, fcm_id: 'token111'
- end
- it 'changes user token' do
- expect(@user.reload.authentication_token).not_to eq('token')
- end
- it 'resets device' do
- expect(@user.reload.devices).to be_empty
- end
- it { should respond_with 204 }
- end
- end
Add Comment
Please, Sign In to add comment