Sha256: 22571519c75cbe3495cc244b15f6550b1f5454d9dc746446ace4eeea32e40508
Contents?: true
Size: 1.48 KB
Versions: 14
Compression:
Stored size: 1.48 KB
Contents
require 'rails_helper' module Ctws RSpec.describe 'Ctws::Authentication', type: :request do # Authentication test suite describe 'POST ctws/v1/login' do # create test user let!(:ctws_user) { create(:ctws_user) } # set headers for authorization let(:headers) { valid_headers.except('Authorization') } # set test valid and invalid credentials let(:valid_credentials) do { email: ctws_user.email, password: ctws_user.password }.to_json end let(:invalid_credentials) do { email: Faker::Internet.email, password: Faker::Internet.password }.to_json end # set request.headers to our custom headers # before { allow(request).to receive(:headers).and_return(headers) } # returns auth token when request is valid context 'When request is valid' do before { post '/ctws/v1/login', params: valid_credentials, headers: headers } it 'returns an authentication token' do expect(json["data"]["attributes"]["auth_token"]).not_to be_nil end end # returns failure message when request is invalid context 'When request is invalid' do before { post '/ctws/v1/login', params: invalid_credentials, headers: headers } it 'returns a failure message' do expect(json["errors"]["message"]).to match(/Invalid credentials/) end end end end end
Version data entries
14 entries across 14 versions & 1 rubygems