Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor/job application application url uniqueness #34

Merged
merged 6 commits into from
Dec 9, 2024

Conversation

kylomite
Copy link
Collaborator

@kylomite kylomite commented Dec 8, 2024

Type of Change

  • refactor πŸ§‘β€πŸ’»
  • testing πŸ§ͺ

Description

  • Add validation for job application uniqueness by checking application_url field in job application model
  • Add unit and integration test for uniqueness in job application model spec, and job application create spec respectively

Motivation and Context

  • This change will prevent users from saving duplicates of the same job application to their profile. It also ensure 2 distinct users can save the same application to their profiles without error
  • closes refactor Job Application application_urlΒ #31

Related Tickets

Added Test?

  • Yes 🫑
    • Unit test: job_application_spec.rb
    • Controller test: job_application_create_spec.rb
  • No πŸ™…
  • All previous tests still pass πŸ₯³

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.

Copy link
Collaborator

@jchirch jchirch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code looks good, thank you for picking up this validation and testing. Updated documentation looks good as well.

@@ -44,6 +44,20 @@
expect(jobApp[:data][:attributes][:contact_information]).to eq(job_application_params[:contact_information])
expect(jobApp[:data][:attributes][:company_id]).to eq(job_application_params[:company_id])
end
it "Allows 2 unique users to create job applications with the same URL" do
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an excellent test to include, not only does it test the flexibility of the validation, but this functionality is necessary for the foundation of this application.

Comment on lines +110 to +125
it "returns a error message if a user tries to create multiple job applications with the same URL" do
post "/api/v1/users/#{@user.id}/job_applications",
params: { job_application: job_application_params }
expect(response).to be_successful
expect(response.status).to eq(200)

post "/api/v1/users/#{@user.id}/job_applications",
params: { job_application: job_application_params }
expect(response).to_not be_successful
expect(response.status).to eq(400)

json = JSON.parse(response.body, symbolize_names: true)

expect(json[:message]).to eq("Application url already exists for the user, try making a new application with a new URL.")
expect(json[:status]).to eq(400)
end
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like that you added and tested this functionality, verifying that a user cannot make multiple entries of the same job application. This is a excellent enhancement for maintaining clean and accurate data being stored in the database. From a user perspective, I would appreciate this functionality, as I could be creating a new job application online, yet have the wrong URL in my clipboard, and this error message would prove very helpful in understanding.

Comment on lines +44 to +46
it "validates uniqueness of job application for a given user" do
expect(subject).to validate_uniqueness_of(:application_url).scoped_to(:user_id).with_message("already exists for the user, try making a new application with a new URL.")
end
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A lot goes into testing the validity scoped to a user. I appreciate the clean, one-line test, and a very user-friendly error message. Excellent work.

@reneemes reneemes merged commit 32ef579 into main Dec 9, 2024
@@ -6,7 +6,7 @@ class JobApplication < ApplicationRecord
validates :date_applied, presence: true
validates :status, presence: true
validates :job_description, presence: true
validates :application_url, presence: true
validates :application_url, presence: true, uniqueness: { scope: :user_id, message: "already exists for the user, try making a new application with a new URL." }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work adding this particular validation. Now we can ensure that every application record is unique per user while allowing other users to have the same url. This will help maintain data integrity and avoid duplicate entries for the same job application.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

refactor Job Application application_url
4 participants