Skip to content

Commit

Permalink
Feature/transition to usajobs api (#159)
Browse files Browse the repository at this point in the history
* update search-gov to point to usajobs

* remove highlighting for jobs

* exception error refactor

* highlighting_disabled not being used

* update connection to usajobs

* post-process jobs results

* update helper specs

* squashme: use single quotes

* refacter location name

* cleanup

* fix indents, update key, remove debug

* place adapter back in

* remove headers[:accept] not being used anywhere

* fix test cases

* remove debug statement

* typo  and debug statement

* use geoip_info

* changes made to get rspec working

* changes made to job_openings to use the fixture json hash

* cleanup code

* changes made to rspec to add correct mapping for test

* add keyword instead of query

* update test to use job instead of foo

* reset cossettes

* update vcr cassettes

* fix specs

* remove put

* remove logger debug

* pass Keyword instead of query in jobs spec

* hide secrets from vcr cassettes

* require results keyword arg in post processor

* pass correct rate interval codes to jobs helper

* remove TODO

* add location_name method to GeoIP::City objects

* add location_name method to GeoIP::City

* misc vcr cassettes

* fix intermittent test failure

* add basic jobs search spec

* remove "is usajob?" view & helper conditionals

* update readme to have new phantomjs instructions

* - fix nil rate interval code
- add cucumber test for salary format

* fix missing application deadline

* remove neogov specs
- remove unused neogov case in jobs helper

* remove extra line break

* get host from config file
  • Loading branch information
peggles2 authored Nov 15, 2018
1 parent d4f1323 commit 28cf52f
Show file tree
Hide file tree
Showing 29 changed files with 6,616 additions and 247 deletions.
4 changes: 3 additions & 1 deletion README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,9 @@ Download and install PhantomJS:

It can also be installed with Homebrew on a Mac.

$ brew install homebrew/versions/phantomjs198
$ brew tap homebrew/cask

$ brew cask install phantomjs

If you see ```Error: The `brew link` step did not complete successfully``` when installing phantomjs,

Expand Down
36 changes: 13 additions & 23 deletions app/helpers/jobs_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ def format_salary(job)
min_str = number_to_currency(job.minimum)
max_str = number_to_currency(job.maximum)
case job.rate_interval_code
when 'PA', 'PH'
period = job.rate_interval_code == 'PA' ? 'yr' : 'hr'
when 'Per Year', 'Per Hour'
period = job.rate_interval_code == 'Per Year' ? 'yr' : 'hr'
plus = max > job.minimum ? '+' : ''
"#{min_str}#{plus}/#{period}"
when 'WC'
when 'Without Compensation'
nil
else
with_max = max > job.minimum ? "-#{max_str} " : ' '
"#{min_str}#{with_max}#{Jobs::RATE_INTERVALS[job.rate_interval_code.to_sym]}"
"#{min_str}#{with_max}#{job.rate_interval_code}"
end
end

Expand All @@ -51,9 +51,9 @@ def usajobs_logo
end
end

def jobs_content_heading_css_classes(is_usajobs_listing)
def jobs_content_heading_css_classes
css_classes = 'content-heading'
css_classes << ' usajobs' if is_usajobs_listing
css_classes << ' usajobs'
css_classes
end

Expand All @@ -74,39 +74,29 @@ def legacy_link_to_more_jobs(search)

def more_jobs_title_and_url(search)
if search.affiliate.has_organization_codes?
more_agency_jobs_title_and_url search.affiliate.agency, search.jobs.first.id
more_agency_jobs_title_and_url search.affiliate.agency
else
more_federal_jobs_title_and_url
end
end

def more_agency_jobs_title_and_url(agency, job_id)
def more_agency_jobs_title_and_url(agency)
title = "#{t :'searches.more_agency_job_openings', agency: agency.abbreviation || agency.name}"
title << " #{t :'searches.on_usajobs'}" if job_listed_on_usajobs?(job_id)
title << " #{t :'searches.on_usajobs'}"

url = url_for_more_agency_jobs agency, job_id
url = url_for_more_agency_jobs agency
[title, url]
end

def job_listed_on_usajobs?(job_id)
job_id =~ /^usajobs/
end

def more_federal_jobs_title_and_url
title = t :'searches.more_federal_job_openings'
url = 'https://www.usajobs.gov/Search/Results?hp=public'
[title, url]
end

def url_for_more_agency_jobs(agency, job_id)
case job_id
when /^usajobs/
organization_codes = agency.joined_organization_codes('&a=')
"https://www.usajobs.gov/Search/Results?a=#{organization_codes}&hp=public"
when /^ng:/
ng_agency = job_id.split(':')[1]
"http://agency.governmentjobs.com/#{ng_agency}/default.cfm"
end
def url_for_more_agency_jobs(agency)
organization_codes = agency.joined_organization_codes('&a=')
"https://www.usajobs.gov/Search/Results?a=#{organization_codes}&hp=public"
end

def job_openings_header(agency)
Expand Down
31 changes: 8 additions & 23 deletions app/models/govbox_set.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ class GovboxSet
def initialize(query, affiliate, geoip_info, options = {})
@query, @affiliate, @geoip_info = query, affiliate, geoip_info
@highlighting_options = options.slice(:highlighting, :pre_tags, :post_tags)

@base_search_options = @highlighting_options.merge(
language: @affiliate.indexing_locale,
q: @query)
Expand Down Expand Up @@ -105,31 +104,20 @@ def init_news_items

def init_jobs
if @affiliate.jobs_enabled?
@jobs = Jobs.search build_jobs_search_options
if @jobs.present?
translate_jobs_highlights unless highlighting_disabled?
job_results = Jobs.search(build_jobs_search_options)&.search_result&.search_result_items
if job_results.present?
@jobs = JobResultsPostProcessor.new(results: job_results)&.post_processed_results
@modules << 'JOBS'
end
end
end

def build_jobs_search_options
jobs_options = { query: @query, size: 10 }
jobs_options[:hl] = 1 unless highlighting_disabled?
org_tags_hash = @affiliate.has_organization_codes? ? { organization_ids: @affiliate.agency.joined_organization_codes(',') } : { tags: 'federal' }
jobs_options.merge!(org_tags_hash)
jobs_options.merge!(lat_lon: [@geoip_info.latitude, @geoip_info.longitude].join(',')) if @geoip_info.present?
jobs_options
end

def translate_jobs_highlights
pre_tag = (@highlighting_options[:pre_tags] || DEFAULT_JOB_HIGHLIGHTING_OPTIONS[:pre_tags]).first
post_tag = (@highlighting_options[:post_tags] || DEFAULT_JOB_HIGHLIGHTING_OPTIONS[:post_tags]).first
@jobs.each do |job_opening|
job_opening.position_title = job_opening.position_title.
gsub(/<em>/, pre_tag).
gsub(/<\/em>/, post_tag)
end
jobs_options = { Keyword: @query, ResultsPerPage: 10 }
org_hash = { Organization: @affiliate.agency&.joined_organization_codes }
jobs_options.merge!(org_hash)
jobs_options.merge!(LocationName: @geoip_info&.location_name)
jobs_options.compact
end

def init_federal_register_documents
Expand Down Expand Up @@ -170,7 +158,4 @@ def elastic_results_exist?(elastic_results)
elastic_results.present? && elastic_results.total > 0
end

def highlighting_disabled?
@highlighting_options[:highlighting] === false
end
end
18 changes: 18 additions & 0 deletions app/models/job_results_post_processor.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class JobResultsPostProcessor
attr_reader :results

def initialize(results:)
@results = results.map(&:matched_object_descriptor)
end

def post_processed_results
results.each do |result|
result.id = result.position_id
result.url = result.position_uri
result.locations = result.position_location.map(&:location_name)
result.minimum = result.position_remuneration.first.minimum_range.to_f
result.maximum = result.position_remuneration.first.maximum_range.to_f
result.rate_interval_code = result.position_remuneration.first.rate_interval_code
end
end
end
2 changes: 1 addition & 1 deletion app/views/searches/_job.mobile.haml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
.job-organization= job.organization_name
.job-locations-money
= locations_and_salary(job)
.job-dates= job_application_deadline(job.end_date)
.job-dates= job_application_deadline(job.application_close_date)
5 changes: 2 additions & 3 deletions app/views/searches/_jobs.mobile.haml
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
#jobs.search.collapsible.collapsed.focus-on-next-sibling{ tabindex: -1 }
.content-block-item.content-block-item-header
- is_usajobs_listing = job_listed_on_usajobs? search.jobs.first.id

= usajobs_logo if is_usajobs_listing
%h3{ class: jobs_content_heading_css_classes(is_usajobs_listing) }
= usajobs_logo
%h3{ class: jobs_content_heading_css_classes }
= job_openings_header(search.affiliate.agency)

- search.jobs.each_with_index do |job, index|
Expand Down
2 changes: 1 addition & 1 deletion app/views/shared/_jobs_gov_box.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
- if search.affiliate.should_show_job_organization_name?
.job-organization= job.organization_name
.job-locations-money= locations_and_salary(job)
.job-dates= job_application_deadline(job.end_date)
.job-dates= job_application_deadline(job.application_close_date)

.more-jobs= legacy_link_to_more_jobs(search)
1 change: 1 addition & 0 deletions config/initializers/extensions/geoip.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require 'geoip_extensions'
9 changes: 7 additions & 2 deletions config/secrets.yml.dev
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ airbrake_secrets: &AIRBRAKE_SECRETS
project_id: 12345
project_key: PUT_YOUR_PROJECT_KEY_HERE

jobs_secrets: &JOBS_SECRETS
user_agent: your_email
authorization_key: your_usajobs_api_key

newrelic_secrets: &NEWRELIC_SECRETS
license_key: newreliclicensekeygoeshere

Expand Down Expand Up @@ -65,8 +69,9 @@ dev_settings: &DEV_SETTINGS
writers:
- localhost
jobs:
host: 'https://jobs.search.gov'
endpoint: '/jobs/search.json'
<<: *JOBS_SECRETS
host: 'https://data.usajobs.gov'
endpoint: '/api/search'
adapter: :net_http_persistent
newrelic:
<<: *NEWRELIC_SECRETS
Expand Down
2 changes: 2 additions & 0 deletions features/mobile_searches.feature
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,8 @@ Feature: Searches using mobile device
And I press "Search"
Then I should see "Federal Job Openings"
And I should see 10 job postings
And I should see an annual salary
And I should see an application deadline
And I should see an image link to "USAJobs.gov" with url for "https://www.usajobs.gov/"
And I should see a link to "More federal job openings on USAJobs.gov" with url for "https://www.usajobs.gov/Search/Results?hp=public"

Expand Down
14 changes: 11 additions & 3 deletions features/step_definitions/job_steps.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
Then /^I should see (\d+) job postings?$/ do |num_results|
html = Nokogiri::HTML(page.body)
job_postings = html.search('.content-block-item.job.result')
job_postings.size == num_results.to_i
page.should have_selector('.content-block-item.job.result')
end

Then /I should see an annual salary/ do
annual_salary_regex = /\$\d{2,3},\d{3}\.\d{2}\+\/yr/
page.should have_selector('.job-locations-money', text: annual_salary_regex)
end

Then /I should see an application deadline/ do
deadline_regex = /Apply by [[:alpha:]]+ \d{1,2}, \d{4}/
page.should have_selector('.job-dates', text: deadline_regex)
end
Loading

0 comments on commit 28cf52f

Please sign in to comment.