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

Version Path
ctws-0.2.3.beta spec/requests/ctws/authentication_spec.rb
ctws-0.2.2.beta spec/requests/ctws/authentication_spec.rb
ctws-0.2.1.beta spec/requests/ctws/authentication_spec.rb
ctws-0.2.0.beta spec/requests/ctws/authentication_spec.rb
ctws-0.1.14.beta spec/requests/ctws/authentication_spec.rb
ctws-0.1.13.alpha spec/requests/ctws/authentication_spec.rb
ctws-0.1.12.alpha spec/requests/ctws/authentication_spec.rb
ctws-0.1.11.alpha spec/requests/ctws/authentication_spec.rb
ctws-0.1.10.alpha spec/requests/ctws/authentication_spec.rb
ctws-0.1.9.alpha spec/requests/ctws/authentication_spec.rb
ctws-0.1.8.alpha spec/requests/ctws/authentication_spec.rb
ctws-0.1.7.alpha spec/requests/ctws/authentication_spec.rb
ctws-0.1.6.alpha spec/requests/ctws/authentication_spec.rb
ctws-0.1.5.alpha spec/requests/ctws/authentication_spec.rb