-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from grnhse/required_multiselect_bug
Fixes a bug in ApplicationService where the required field validator checks for the existence of key[] as sent by Greenhouse, but submission requires you to use key, thus never being able to pass a required multiselect field to an application.
- Loading branch information
Showing
3 changed files
with
218 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,12 @@ public function getTestJobJson() | |
return file_get_contents("$root/../files/test_json/single_job_response.json"); | ||
} | ||
|
||
public function getTestJobJsonWithMultiselect() | ||
{ | ||
$root = realpath(dirname(__FILE__)); | ||
return file_get_contents("$root/../files/test_json/single_job_response_with_multiselect_required.json"); | ||
} | ||
|
||
public function getTestJobJsonNothingRequired() | ||
{ | ||
$root = realpath(dirname(__FILE__)); | ||
|
@@ -77,6 +83,54 @@ public function testValidateRequiredFieldsPass() | |
$this->assertTrue($this->appService->validateRequiredFields($postVars)); | ||
} | ||
|
||
public function testValidateRequiredFieldsWithMultiselect() | ||
{ | ||
$apiStub = $this->getMockBuilder('\Greenhouse\GreenhouseToolsPhp\Services\JobApiService') | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
$apiStub->method('getJob')->willReturn($this->getTestJobJsonWithMultiselect()); | ||
$this->appService->setJobApiService($apiStub); | ||
|
||
$postVars = array( | ||
'id' => '12345', | ||
'first_name' => 'Hiram', | ||
'last_name' => 'Abiff', | ||
'email' => '[email protected]', | ||
'resume_text' => 'Builder', | ||
'cover_letter_text' => 'I built things', | ||
'question_1042159' => 'stuff', | ||
'question_579460' => array(225451, 225452) | ||
); | ||
|
||
$this->assertTrue($this->appService->validateRequiredFields($postVars)); | ||
} | ||
|
||
/** | ||
* Backward compatable version. This is how we checked required fields originally (with the square | ||
* brackets, as returned by the API, but not how we required the request to be submitted. | ||
*/ | ||
public function testValidateRequiredFieldsWithMultiselectLegacy() | ||
{ | ||
$apiStub = $this->getMockBuilder('\Greenhouse\GreenhouseToolsPhp\Services\JobApiService') | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
$apiStub->method('getJob')->willReturn($this->getTestJobJsonWithMultiselect()); | ||
$this->appService->setJobApiService($apiStub); | ||
|
||
$postVars = array( | ||
'id' => '12345', | ||
'first_name' => 'Hiram', | ||
'last_name' => 'Abiff', | ||
'email' => '[email protected]', | ||
'resume_text' => 'Builder', | ||
'cover_letter_text' => 'I built things', | ||
'question_1042159' => 'stuff', | ||
'question_579460[]' => array(225451, 225452) | ||
); | ||
|
||
$this->assertTrue($this->appService->validateRequiredFields($postVars)); | ||
} | ||
|
||
public function testValidateRequiredFieldsFailSingle() | ||
{ | ||
$apiStub = $this->getMockBuilder('\Greenhouse\GreenhouseToolsPhp\Services\JobApiService') | ||
|
140 changes: 140 additions & 0 deletions
140
tests/files/test_json/single_job_response_with_multiselect_required.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
{ | ||
"id": 167538, | ||
"internal_job_id": 187771, | ||
"title": "Controller", | ||
"updated_at": "2016-03-21T15:53:06-04:00", | ||
"location": { | ||
"name": "New York" | ||
}, | ||
"absolute_url": "http://www.greenhouse.io/careers/job?gh_jid=167538", | ||
"metadata": null, | ||
"content": "test", | ||
"departments": [{ | ||
"id": 7219, | ||
"name": "Finance" | ||
}], | ||
"offices": [{ | ||
"id": 13, | ||
"name": "New York", | ||
"location": "Manhattan, NY 10007" | ||
}], | ||
"questions": [{ | ||
"label": "First Name", | ||
"fields": [{ | ||
"name": "first_name", | ||
"type": "input_text" | ||
}], | ||
"required": true | ||
}, { | ||
"label": "Last Name", | ||
"fields": [{ | ||
"name": "last_name", | ||
"type": "input_text" | ||
}], | ||
"required": true | ||
}, { | ||
"label": "Email", | ||
"fields": [{ | ||
"name": "email", | ||
"type": "input_text" | ||
}], | ||
"required": true | ||
}, { | ||
"label": "Phone", | ||
"fields": [{ | ||
"name": "phone", | ||
"type": "input_text" | ||
}], | ||
"required": false | ||
}, { | ||
"label": "Resume", | ||
"fields": [{ | ||
"name": "resume", | ||
"type": "input_file" | ||
}, { | ||
"name": "resume_text", | ||
"type": "textarea" | ||
}], | ||
"required": true | ||
}, { | ||
"label": "Cover Letter", | ||
"fields": [{ | ||
"name": "cover_letter", | ||
"type": "input_file" | ||
}, { | ||
"name": "cover_letter_text", | ||
"type": "textarea" | ||
}], | ||
"required": true | ||
}, { | ||
"label": "LinkedIn Profile", | ||
"fields": [{ | ||
"name": "question_1042159", | ||
"type": "input_text" | ||
}], | ||
"required": true | ||
}, { | ||
"label": "How did you hear about this job?", | ||
"fields": [{ | ||
"name": "question_1042161", | ||
"type": "input_text" | ||
}], | ||
"required": false | ||
}, { | ||
"label": "Are you authorized to work in the United States?", | ||
"fields": [{ | ||
"name": "question_1042162", | ||
"type": "multi_value_single_select", | ||
"values": [{ | ||
"label": "No", | ||
"value": 0 | ||
}, { | ||
"label": "Yes", | ||
"value": 1 | ||
}] | ||
}], | ||
"required": false | ||
}, { | ||
"label": "Will you now or in the future require visa sponsorship?", | ||
"fields": [{ | ||
"name": "question_1042163", | ||
"type": "multi_value_single_select", | ||
"values": [{ | ||
"label": "No", | ||
"value": 0 | ||
}, { | ||
"label": "Yes", | ||
"value": 1 | ||
}] | ||
}], | ||
"required": false | ||
}, { | ||
"label": "Do you have the right to work in the UK?", | ||
"required": true, | ||
"fields": [ | ||
{ | ||
"name": "question_579460[]", | ||
"type": "multi_value_multi_select", | ||
"values": [ | ||
{ | ||
"label": "UK Passport", | ||
"value": 225451 | ||
}, | ||
{ | ||
"label": "EEA Passport", | ||
"value": 225452 | ||
}, | ||
{ | ||
"label": "Other visa", | ||
"value": 225453 | ||
}, | ||
{ | ||
"label": "No", | ||
"value": 225454 | ||
} | ||
] | ||
} | ||
] | ||
}], | ||
"compliance": null | ||
} |