diff --git a/.github/532038E6-0893-447F-86CB-973C499C0613.jpeg b/.github/532038E6-0893-447F-86CB-973C499C0613.jpeg new file mode 100644 index 0000000..f7c02e8 Binary files /dev/null and b/.github/532038E6-0893-447F-86CB-973C499C0613.jpeg differ diff --git a/README.md b/README.md index bc844c2..cb2f569 100644 --- a/README.md +++ b/README.md @@ -716,6 +716,124 @@ Response: 422 Unprocessable Entity "error": "Phone number must be in the format '555-555-5555'" } ``` +### User Dashboard + +Get login credentials:
+`Refer to Companies "Get login credentials" above` + +**Make sure to not only create/login a user, but to have that user also create a Company/Job Application/Contact for your Postman scripts. Refer to above endpoints to do so and make sure that user is the one creating the other resources** + +#### Get Dashboard +Request: + +``` +GET /api/v1/users/:user_id/dashboard + +Authorization: Bearer Token - put in token for user +``` +Successful Response: + +``` +{ + "data": { + "id": "5", + "type": "dashboard", + "attributes": { + "id": 5, + "name": "Danny DeVito", + "email": "danny_de@email.com", + "dashboard": { + "weekly_summary": { + "job_applications": [ + { + "id": 1, + "position_title": "Jr. CTO", + "date_applied": "2024-10-31", + "status": 1, + "notes": "Fingers crossed!", + "job_description": "Looking for Turing grad/jr dev to be CTO", + "application_url": "www.example.com", + "contact_information": "boss@example.com", + "created_at": "2024-12-14T17:20:41.979Z", + "updated_at": "2024-12-14T17:20:41.979Z", + "company_id": 1, + "user_id": 5 + }, + { + "id": 2, + "position_title": " CTO", + "date_applied": "2024-10-31", + "status": 2, + "notes": "Fingers crossed!", + "job_description": "Looking for Turing grad/jr dev to be CTO", + "application_url": "www.testexample.com", + "contact_information": "boss1@example.com", + "created_at": "2024-12-14T17:37:28.465Z", + "updated_at": "2024-12-14T17:37:28.465Z", + "company_id": 2, + "user_id": 5 + } + ], + "contacts": [ + { + "id": 1, + "first_name": "Jonny", + "last_name": "Smith", + "email": "jonny@gmail.com", + "phone_number": "555-785-5555", + "notes": "Good contact for XYZ", + "created_at": "2024-12-14T17:55:21.875Z", + "updated_at": "2024-12-14T17:55:21.875Z", + "user_id": 5, + "company_id": 1 + }, + { + "id": 2, + "first_name": "Josnny", + "last_name": "Smsith", + "email": "jonny@gmail.com", + "phone_number": "555-785-5555", + "notes": "Good contact for XYZ", + "created_at": "2024-12-15T01:57:14.557Z", + "updated_at": "2024-12-15T01:57:14.557Z", + "user_id": 5, + "company_id": 1 + } + ], + "companies": [ + { + "id": 1, + "user_id": 5, + "name": "New Company", + "website": "www.company.com", + "street_address": "123 Main St", + "city": "New York", + "state": "NY", + "zip_code": "10001", + "notes": "This is a new company.", + "created_at": "2024-12-14T17:20:10.909Z", + "updated_at": "2024-12-14T17:20:10.909Z" + }, + { + "id": 2, + "user_id": 5, + "name": "New Company1", + "website": "www.company1.com", + "street_address": "1231 Main St", + "city": "New York", + "state": "NY", + "zip_code": "10001", + "notes": "This is a new company1.", + "created_at": "2024-12-14T17:37:24.153Z", + "updated_at": "2024-12-14T17:37:24.153Z" + } + ] + } + } + } + } +} +``` # Authentication, User Roles, and Authorization diff --git a/app/controllers/api/v1/contacts_controller.rb b/app/controllers/api/v1/contacts_controller.rb index 38fe356..9b7bcc3 100644 --- a/app/controllers/api/v1/contacts_controller.rb +++ b/app/controllers/api/v1/contacts_controller.rb @@ -4,6 +4,7 @@ class ContactsController < ApplicationController before_action :authenticate_user def index + authorize Contact contacts = @current_user.contacts if contacts.empty? render json: { data: [], message: "No contacts found" }, status: :ok @@ -13,6 +14,7 @@ def index end def create + authorize Contact contact = @current_user.contacts.new(contact_params) if contact.save render json: ContactsSerializer.new(contact), status: :created diff --git a/app/controllers/api/v1/dashboards_controller.rb b/app/controllers/api/v1/dashboards_controller.rb new file mode 100644 index 0000000..0457d53 --- /dev/null +++ b/app/controllers/api/v1/dashboards_controller.rb @@ -0,0 +1,9 @@ +class Api::V1::DashboardsController < ApplicationController + before_action :authenticate_user + + def show + user = current_user + authorize user + render json: DashboardSerializer.new(user), status: :ok + end +end diff --git a/app/controllers/api/v1/job_applications_controller.rb b/app/controllers/api/v1/job_applications_controller.rb index 2790aec..04a0b55 100644 --- a/app/controllers/api/v1/job_applications_controller.rb +++ b/app/controllers/api/v1/job_applications_controller.rb @@ -2,7 +2,7 @@ class Api::V1::JobApplicationsController < ApplicationController before_action :authenticate_user def create - user = User.find(params[:user_id]) + user = authorize User.find(params[:user_id]) job_application = user.job_applications.build(job_application_params) @@ -34,9 +34,11 @@ def show def index - job_applications = @current_user.job_applications + authorize JobApplication + job_applications = policy_scope(JobApplication) render json: JobApplicationSerializer.new(job_applications), status: :ok end + private def job_application_params diff --git a/app/controllers/api/v1/users/job_applications_controller.rb b/app/controllers/api/v1/users/job_applications_controller.rb deleted file mode 100644 index c7ac3f5..0000000 --- a/app/controllers/api/v1/users/job_applications_controller.rb +++ /dev/null @@ -1,8 +0,0 @@ -class Api::V1::Users::JobApplicationsController < ApplicationController - before_action :authenticate_user - - def index - job_applications = @current_user.job_applications - render json: JobApplicationSerializer.new(job_applications), status: :ok - end -end \ No newline at end of file diff --git a/app/controllers/api/v1/users_controller.rb b/app/controllers/api/v1/users_controller.rb index 1910cc6..d4391fb 100644 --- a/app/controllers/api/v1/users_controller.rb +++ b/app/controllers/api/v1/users_controller.rb @@ -1,9 +1,11 @@ module Api module V1 class UsersController < ApplicationController + def create - authorize User user = User.new(user_params) + authorize user + if user.save render json: UserSerializer.new(user), status: :created else @@ -19,7 +21,6 @@ def index def show @user = authorize User.find(params[:id]) - render json: UserSerializer.new(User.find(params[:id])) end diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index e123478..6c57762 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -2,7 +2,7 @@ class ApplicationController < ActionController::API include Pundit::Authorization after_action :verify_authorized - # temporary current_user testing stub until we add in authentication + def current_user @current_user ||= self.authenticate_user end diff --git a/app/models/company.rb b/app/models/company.rb index 79927bd..12f5d72 100644 --- a/app/models/company.rb +++ b/app/models/company.rb @@ -1,6 +1,9 @@ class Company < ApplicationRecord rolify strict: true belongs_to :user + has_many :contacts + has_many :job_applications + validates :name, presence: true validates :website, presence: true validates :street_address, presence: true diff --git a/app/models/user.rb b/app/models/user.rb index 065306f..52db957 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -3,6 +3,7 @@ class User < ApplicationRecord has_many :companies, dependent: :destroy has_many :job_applications, dependent: :destroy + has_many :contacts, dependent: :destroy validates :name, presence: true validates :email, presence: true, uniqueness: true diff --git a/app/policies/contact_policy.rb b/app/policies/contact_policy.rb index e36186a..7001753 100644 --- a/app/policies/contact_policy.rb +++ b/app/policies/contact_policy.rb @@ -1,14 +1,23 @@ class ContactPolicy < ApplicationPolicy - # NOTE: Up to Pundit v2.3.1, the inheritance was declared as - # `Scope < Scope` rather than `Scope < ApplicationPolicy::Scope`. - # In most cases the behavior will be identical, but if updating existing - # code, beware of possible changes to the ancestors: - # https://gist.github.com/Burgestrand/4b4bc22f31c8a95c425fc0e30d7ef1f5 + def index? + admin? || user.present? + end + + def create? + admin? || user.present? + end + class Scope < ApplicationPolicy::Scope - # NOTE: Be explicit about which records you allow access to! - # def resolve - # scope.all - # end + + def resolve + if admin? + scope.all + elsif user? + scope.where(user: user) + else + scope.none + end + end end end diff --git a/app/policies/dashboard_policy.rb b/app/policies/dashboard_policy.rb new file mode 100644 index 0000000..307179b --- /dev/null +++ b/app/policies/dashboard_policy.rb @@ -0,0 +1,17 @@ +class DashboardPolicy < ApplicationPolicy + + def show? + user == record + end + + class Scope < ApplicationPolicy::Scope + + # def resolve + # if user? + # scope.all + # else + # scope.none + # end + # end + end +end \ No newline at end of file diff --git a/app/policies/job_application_policy.rb b/app/policies/job_application_policy.rb new file mode 100644 index 0000000..7494865 --- /dev/null +++ b/app/policies/job_application_policy.rb @@ -0,0 +1,25 @@ +class JobApplicationPolicy < ApplicationPolicy + + def index? + user.present? + end + + def create? + record.user_id == user.id + end + + def show? + record.user_id == user.id + end + + class Scope < ApplicationPolicy::Scope + + def resolve + if user? + scope.where(user_id: user.id) + else + scope.none + end + end + end +end diff --git a/app/policies/job_policy.rb b/app/policies/job_policy.rb deleted file mode 100644 index 5437e3b..0000000 --- a/app/policies/job_policy.rb +++ /dev/null @@ -1,22 +0,0 @@ -class JobPolicy < ApplicationPolicy - # NOTE: Up to Pundit v2.3.1, the inheritance was declared as - # `Scope < Scope` rather than `Scope < ApplicationPolicy::Scope`. - # In most cases the behavior will be identical, but if updating existing - # code, beware of possible changes to the ancestors: - # https://gist.github.com/Burgestrand/4b4bc22f31c8a95c425fc0e30d7ef1f5 - - def index? - admin? || user == record - end - - def show? - admin? || user == record - end - - class Scope < ApplicationPolicy::Scope - # NOTE: Be explicit about which records you allow access to! - def resolve - scope.all - end - end -end diff --git a/app/policies/user_policy.rb b/app/policies/user_policy.rb index 07d129b..0a6336e 100644 --- a/app/policies/user_policy.rb +++ b/app/policies/user_policy.rb @@ -30,7 +30,7 @@ def resolve #resolve determines which records a user is allowed to access if admin? #method inherited from ApplicationPolicy to check role of current user(:admin) scope.all elsif user?#method inherited from ApplicationPolicy to check role of current user(:user) - scope.where(id: user.id) + scope.where(id: user.id) || scope.where(user_id: user.id) else scope.none end diff --git a/app/serializers/dashboard_serializer.rb b/app/serializers/dashboard_serializer.rb new file mode 100644 index 0000000..6d2d4ea --- /dev/null +++ b/app/serializers/dashboard_serializer.rb @@ -0,0 +1,14 @@ +class DashboardSerializer + include JSONAPI::Serializer + attributes :id, :name, :email + + attribute :dashboard do |user| + { + weekly_summary: { + job_applications: user.job_applications, + contacts: user.contacts, + companies: user.companies + } + } + end +end diff --git a/config/routes.rb b/config/routes.rb index d1f833e..c748e5b 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -14,7 +14,7 @@ resources :job_applications, only: [:create, :index, :show] resources :companies, only: [:create, :index] resources :contacts, only: [:create, :index] - + resource :dashboard, only: :show end resources :sessions, only: :create diff --git a/spec/policies/company_policy_spec.rb b/spec/policies/company_policy_spec.rb index bf6cfd9..8866e99 100644 --- a/spec/policies/company_policy_spec.rb +++ b/spec/policies/company_policy_spec.rb @@ -48,6 +48,13 @@ end end + permissions :index? do + it "allows an admin or a user to view all the companies" do + expect(subject).to permit(user, Company.new) + expect(subject).to permit(admin, Company.new) + end + end + permissions ".scope" do let(:scope) { Pundit.policy_scope!(current_user, Company) } diff --git a/spec/policies/contact_policy_spec.rb b/spec/policies/contact_policy_spec.rb index 76a2376..22bf29e 100644 --- a/spec/policies/contact_policy_spec.rb +++ b/spec/policies/contact_policy_spec.rb @@ -1,27 +1,59 @@ require 'rails_helper' RSpec.describe ContactPolicy, type: :policy do - let(:user) { User.new } - subject { described_class } - permissions ".scope" do - pending "add some examples to (or delete) #{__FILE__}" + let(:user) { User.create!(name: "user" , email: "user@email.com", password: "123") } + let(:other_user) { User.create!(name: "other_user" , email: "other_user@email.com", password: "234") } + let(:admin) { User.create!(name: "admin" , email: "admin@email.com", password: "456") } + let(:admin_contact) { Contact.create!(user: admin, first_name: "John", last_name: "Smith") } + let(:user_contact) { Contact.create!(user: user, first_name: "Johno", last_name: "Smitho") } + let(:scope) { Pundit.policy_scope!(current_user, Contact) } + + before(:each) do + admin.set_role(:admin) end - permissions :show? do - pending "add some examples to (or delete) #{__FILE__}" + permissions :index? do + it "allows admin or any logged in user to view all contacts" do + expect(subject).to permit(user, Contact.all) + expect(subject).to permit(admin, Contact.all) + expect(subject).not_to permit(nil, Contact.all) + end end permissions :create? do - pending "add some examples to (or delete) #{__FILE__}" + it "allows admin or any logged in user to create a contact" do + expect(subject).to permit(user, Contact.all) + expect(subject).to permit(admin, Contact.all) + expect(subject).not_to permit(nil, Contact.all) + end end - permissions :update? do - pending "add some examples to (or delete) #{__FILE__}" - end + permissions '.scope' do + context "when user is an :admin" do + let(:current_user) { admin } + + it "returns all contacts for an admin" do + expect(scope).to include(admin_contact, user_contact) + end + end + + context "when user is a :user" do + let(:current_user) { user } + + it "returns only a user's contacts for THAT user" do + expect(scope).to include(user_contact) + expect(scope).not_to include(admin_contact) + end + end + + context "no user" do + let(:current_user) { nil } - permissions :destroy? do - pending "add some examples to (or delete) #{__FILE__}" + it "returns nothing" do + expect(scope).to be_empty + end + end end end diff --git a/spec/policies/dashboard_policy_spec.rb b/spec/policies/dashboard_policy_spec.rb new file mode 100644 index 0000000..e233632 --- /dev/null +++ b/spec/policies/dashboard_policy_spec.rb @@ -0,0 +1,15 @@ +require 'rails_helper' + +RSpec.describe DashboardPolicy, type: :policy do + subject { described_class } + + let(:user) { User.create!(name: "user" , email: "user@email.com", password: "123") } + let(:other_user) { User.create!(name: "other_user" , email: "other_user@email.com", password: "234") } + + permissions :show? do + it "allows a user to view only their own dashboard" do + expect(subject).to permit(user, user) + expect(subject).not_to permit(user, other_user) + end + end +end \ No newline at end of file diff --git a/spec/policies/job_application_policy_spec.rb b/spec/policies/job_application_policy_spec.rb new file mode 100644 index 0000000..fa8afc2 --- /dev/null +++ b/spec/policies/job_application_policy_spec.rb @@ -0,0 +1,96 @@ +require 'rails_helper' + +RSpec.describe JobApplicationPolicy, type: :policy do + subject { described_class } + + let(:user) { User.create!(name: "user" , email: "user@email.com", password: "123") } + let(:other_user) { User.create!(name: "other_user" , email: "other_user@email.com", password: "234") } + let(:admin) { User.create!(name: "admin" , email: "admin@email.com", password: "456") } + + let(:company_1) { Company.create!( + name: 'Tech Innovators', website: 'https://techinnovators.com', + street_address: '123 Innovation Way', city: 'San Francisco', + state: 'CA', zip_code: '94107', + notes: 'Reached out on LinkedIn, awaiting response.', user_id: admin.id) } + + let(:company_2) { Company.create!( + name: 'Future Designs LLC', website: 'https://futuredesigns.com', + street_address: '456 Future Blvd', city: 'Austin', + state: 'TX', zip_code: '73301', + notes: 'Submitted application for the UI Designer role.', user_id: user.id) } + + let(:company_3) { Company.create!( + name: 'Creative Solutions Inc.', website: 'https://creativesolutions.com', + street_address: '789 Creative Street', city: 'Seattle', + state: 'WA', zip_code: '98101', + notes: 'Follow up scheduled for next week.', user_id: other_user.id)} + + let(:job_app_admin) { JobApplication.create!( + position_title: "Jr. CTO", date_applied: "2024-10-31", + status: 1, notes: "Fingers crossed!", + job_description: "Looking for Turing grad/jr dev to be CTO", + application_url: "www.example.com", + contact_information: "boss@example.com", + company_id: company_1.id, user_id: admin.id) } + + let(:job_app_user) { JobApplication.create!( + position_title: "UI Designer", date_applied: "2024-09-15", + status: 0, notes: "Submitted portfolio and waiting for feedback.", + job_description: "Designing innovative and user-friendly interfaces.", + application_url: "https://futuredesigns.com/jobs/ui-designer", + contact_information: "hr@futuredesigns.com", + company_id: company_2.id, user_id: user.id) } + + let(:job_app_other_user) { JobApplication.create!( + position_title: "Backend Developer", date_applied: "2024-08-20", + status: 2, notes: "Had a technical interview, awaiting decision.", + job_description: "Developing RESTful APIs and optimizing server performance.", + application_url: "https://creativesolutions.com/careers/backend-developer", + contact_information: "techlead@creativesolutions.com", + company_id: company_3.id, user_id: other_user.id) } + + let(:scope) { Pundit.policy_scope!(current_user, JobApplication) } + + before(:each) do + admin.set_role(:admin) + end + + permissions :index? do + it "allows a user to view all job apps when logged in" do + expect(subject).to permit(user, JobApplication.all) + end + end + + permissions :create? do + it "allows any user to create their own job app" do + expect(subject).to permit(user, job_app_user) + expect(subject).to permit(admin, job_app_admin) + end + end + + permissions :show? do + it "allows a user to view a single one of their job apps" do + expect(subject).to permit(user, job_app_user) + expect(subject).not_to permit(user, job_app_admin) + end + end + + permissions '.scope' do + context "when user is a :user" do + let(:current_user) { user } + + it "will only allow a user to view a job app related to their user id" do + expect(scope).to include(job_app_user) + expect(scope).not_to include(job_app_other_user) + end + end + + context "no user" do + let(:current_user) { nil } + + it "returns nothing" do + expect(scope).to be_empty + end + end + end +end diff --git a/spec/policies/job_policy_spec.rb b/spec/policies/job_policy_spec.rb deleted file mode 100644 index 3c85a53..0000000 --- a/spec/policies/job_policy_spec.rb +++ /dev/null @@ -1,27 +0,0 @@ -require 'rails_helper' - -RSpec.describe JobPolicy, type: :policy do - let(:user) { User.new } - - subject { described_class } - - permissions ".scope" do - pending "add some examples to (or delete) #{__FILE__}" - end - - permissions :show? do - pending "add some examples to (or delete) #{__FILE__}" - end - - permissions :create? do - pending "add some examples to (or delete) #{__FILE__}" - end - - permissions :update? do - pending "add some examples to (or delete) #{__FILE__}" - end - - permissions :destroy? do - pending "add some examples to (or delete) #{__FILE__}" - end -end diff --git a/spec/policies/user_policy_spec.rb b/spec/policies/user_policy_spec.rb index 51bc302..548866e 100644 --- a/spec/policies/user_policy_spec.rb +++ b/spec/policies/user_policy_spec.rb @@ -74,6 +74,14 @@ expect(scope).not_to match_array(User.all) end end + + context "no user" do + let(:current_user) { nil } + + it "returns nothing" do + expect(scope).to be_empty + end + end end end diff --git a/spec/requests/api/v1/dashboard/dashboards_spec.rb b/spec/requests/api/v1/dashboard/dashboards_spec.rb new file mode 100644 index 0000000..b4cc7e2 --- /dev/null +++ b/spec/requests/api/v1/dashboard/dashboards_spec.rb @@ -0,0 +1,88 @@ +require 'rails_helper' + +RSpec.describe "DashboardsController", type: :request do + describe "GET #show" do + + let(:user) { User.create!( + name: "Testy Tim", + email: "testytim420@email.com", + password: "12345") } + + let(:test_company) { Company.find_or_create_by!( + user_id: user.id, + name: "testCO", + website: "testcompany.com", + street_address: "10 Amphitheatre Parkway", + city: "Mon View", state: "CO", + zip_code: "88888", notes: "Searchy engine")} + + let(:job_application1) { JobApplication.create!( + position_title: "Jr. CTO", + date_applied: "2024-10-31", + status: 1, + notes: "Fingers crossed!", + job_description: "Looking for Turing grad/jr dev to be CTO", + application_url: "www.example1.com", + contact_information: "boss@example.com", + company_id: test_company.id, + user_id: user.id) } + + let(:job_application2) {JobApplication.create!( + position_title: "Frontend Developer", + date_applied: "2024-11-01", + status: 0, + notes: "Excited about this opportunity!", + job_description: "Frontend Developer role with React expertise", + application_url: "www.frontend.com", + contact_information: "hiring@example.com", + company_id: test_company.id, + user_id: user.id) } + + let(:contact_params) { Contact.create!( + first_name: "Josnny", + last_name: "Smsith", + company_id: test_company.id, + email: "jonny@gmail.com", + phone_number: "555-785-5555", + notes: "Good contact for XYZ", + user_id: user.id) } + + before(:each) do + post "/api/v1/sessions", params: { email: user.email, password: user.password }, as: :json + expect(response).to have_http_status(:ok) + @token = JSON.parse(response.body)["token"] + + post "/api/v1/users/#{user.id}/companies", params: :test_company, + headers: { "Authorization" => "Bearer #{@token}" }, as: :json + post "/api/v1/users/#{user.id}/job_applications", params: job_application1, + headers: { "Authorization" => "Bearer #{@token}" }, as: :json + post "/api/v1/users/#{user.id}/job_applications", params: job_application2, + headers: { "Authorization" => "Bearer #{@token}" }, as: :json + post "/api/v1/users/#{user.id}/contacts", params: contact_params, + headers: { "Authorization" => "Bearer #{@token}" }, as: :json + end + + it "will display a user's dashboard and have correct attributes" do + get "/api/v1/users/#{user.id}/dashboard", + headers: { "Authorization" => "Bearer #{@token}" },as: :json + + expect(response).to have_http_status(:ok) + + json = JSON.parse(response.body, symbolize_names: true)[:data] + + expect(json[:id]).to eq(user.id.to_s) + expect(json[:type]).to eq("dashboard") + expect(json[:attributes][:name]).to eq("Testy Tim") + expect(json[:attributes][:email]).to eq("testytim420@email.com") + + dashboard_summary = json[:attributes][:dashboard][:weekly_summary] + + expect(dashboard_summary[:job_applications].count).to eq(2) + expect(dashboard_summary[:job_applications].first[:position_title]).to eq("Jr. CTO") + expect(dashboard_summary[:job_applications].last[:position_title]).to eq("Frontend Developer") + expect(dashboard_summary[:companies].first[:name]).to eq("testCO") + expect(dashboard_summary[:companies].first[:website]).to eq("testcompany.com") + expect(dashboard_summary[:contacts].count).to eq(1) + end + end +end diff --git a/spec/requests/api/v1/job_applications/job_application_create_spec.rb b/spec/requests/api/v1/job_applications/job_application_create_spec.rb index 292c462..7a9b1f5 100644 --- a/spec/requests/api/v1/job_applications/job_application_create_spec.rb +++ b/spec/requests/api/v1/job_applications/job_application_create_spec.rb @@ -1,6 +1,6 @@ require "rails_helper" -RSpec.describe "Job Application #create", type: :request do +RSpec.describe "Job Application #create & #index", type: :request do before(:each) do @user = User.create!(name: "Dolly Parton", email: "dollyP123@email.com", password: "Jolene123") @@ -16,7 +16,7 @@ status: 1, notes: "Fingers crossed!", job_description: "Looking for Turing grad/jr dev to be CTO", - application_url: "www.example.com", + application_url: "www.example1.com", contact_information: "boss@example.com", company: @google, user: @user @@ -51,7 +51,7 @@ } end - context "happy path" do + context "#Create happy path" do it "Returns expected fields" do post "/api/v1/users/#{@user.id}/job_applications", params: { job_application: job_application_params }, @@ -76,7 +76,7 @@ end end - context "sad path" do + context "#Create sad path" do it "Returns error serializer if params are missing attribute" do post "/api/v1/users/#{@user.id}/job_applications", params: { @@ -124,7 +124,7 @@ end end - context "happy path" do + context "#Index happy path" do it "returns all job applications for the logged-in user" do get "/api/v1/users/#{@user.id}/job_applications", headers: { "Authorization" => "Bearer #{@token}" }, @@ -149,7 +149,7 @@ end end - context "sad path" do + context "#Index sad path" do it "returns a 401 error if the user is not authenticated" do get "/api/v1/users/#{@user.id}/job_applications", as: :json diff --git a/spec/requests/api/v1/users/create_spec.rb b/spec/requests/api/v1/users/create_spec.rb index 8c73de4..6838e19 100644 --- a/spec/requests/api/v1/users/create_spec.rb +++ b/spec/requests/api/v1/users/create_spec.rb @@ -1,7 +1,7 @@ require "rails_helper" -RSpec.describe "Users Create", type: :request do - describe "Create User Endpoint" do +RSpec.describe "Users #Create", type: :request do + describe "endpoints" do let(:user_params) do { name: "Me", @@ -14,7 +14,7 @@ context "request is valid" do it "returns 201 Created and provides expected fields" do post api_v1_users_path, params: user_params, as: :json - + expect(response).to have_http_status(:created) json = JSON.parse(response.body, symbolize_names: true) expect(json[:data][:type]).to eq("user")