Skip to content

Commit

Permalink
Create sessions_controller tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Wineshuga committed Dec 12, 2023
1 parent 2e36afe commit 08cd76a
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions spec/requests/api/sessions_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
require 'swagger_helper'
require 'rails_helper'

RSpec.describe 'Api::SessionsControllers', type: :request do
before do
post '/api/users', params: {
user: {
username: 'user',
email: 'user@example.com',
password: 'password'
}
}
end

describe 'POST /create' do
context 'successful user login' do
it 'logs a user in' do
post '/api/users/sign_in', params: {
user: {
username: 'user',
password: 'password'
}
}

json = JSON.parse(response.body).deep_symbolize_keys
expect(response.status).to eq(200)
expect(json[:message]).to eq('Login successful')
end
end

context 'failed user login' do
it 'returns an error message' do
post '/api/users/sign_in', params: {
user: {
username: 'login_user',
password: 'password'
}
}

json = JSON.parse(response.body).deep_symbolize_keys
expect(response.status).to eq(401)
expect(json[:message]).to eq('Invalid username or password')
end
end
end
end

0 comments on commit 08cd76a

Please sign in to comment.