# frozen_string_literal: true

require 'rails_helper'

RSpec.describe Api::ProfilesController, type: :controller do
  let(:current_user) { create(:user) }

  describe '#show' do
    it 'responds with profile info for the current user' do
      sign_in_to_api(current_user)

      get :show

      expect(response).to be_successful
      expect(response_body_data).to include('id' => current_user.to_param, 'type' => 'user')
      expect(response_body_data_attributes).to include('email' => current_user.email)
    end
  end

  private

  def response_body_data
    JSON.parse(response.body).dig('data')
  end

  def response_body_data_attributes
    response_body_data.dig('attributes')
  end
end
