-
Notifications
You must be signed in to change notification settings - Fork 329
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 #739 from guillegiu/master
Custom Validation and Ruby test - Get authors path
- Loading branch information
Showing
5 changed files
with
120 additions
and
16 deletions.
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
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,20 @@ | ||
<?php | ||
|
||
namespace CustomValidations; | ||
|
||
use Respect\Validation\Rules\AbstractRule; | ||
|
||
class ValidAuthorsBlackList extends AbstractRule { | ||
|
||
public function validate($blackList) { | ||
if(is_array(json_decode($blackList))){ | ||
foreach (json_decode($blackList) as $item) { | ||
if(!$item->id || !$item->staff) return false; | ||
if($item->staff != 0 && $item->staff != 1) return false; | ||
if(!is_numeric($item->id)) return false; | ||
} | ||
return true; | ||
} | ||
return false; | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,84 @@ | ||
describe '/ticket/get-authors/' do | ||
|
||
it 'should fail if a user is loged' do | ||
request('/user/logout') | ||
Scripts.login('tyrion@opensupports.com', 'tyrionl') | ||
|
||
result = request('/ticket/get-authors', { | ||
csrf_userid: $csrf_userid, | ||
csrf_token: $csrf_token, | ||
query: 'hello world' | ||
}) | ||
|
||
(result['status']).should.equal('fail') | ||
(result['message']).should.equal('NO_PERMISSION') | ||
|
||
|
||
end | ||
|
||
it 'should fail if blackList is invalid' do | ||
request('/user/logout') | ||
Scripts.login($staff[:email], $staff[:password], true) | ||
Scripts.createUser(email = 'eemilia@jobs.com', password = 'custompassword', name = 'eemilia') | ||
|
||
result = request('/ticket/get-authors', { | ||
csrf_userid: $csrf_userid, | ||
csrf_token: $csrf_token, | ||
query: 'hello world', | ||
blackList: [{'staff':2,'id':2}] | ||
}) | ||
|
||
(result['status']).should.equal('fail') | ||
(result['message']).should.equal('INVALID_BLACK_LIST') | ||
|
||
result = request('/ticket/get-authors', { | ||
csrf_userid: $csrf_userid, | ||
csrf_token: $csrf_token, | ||
query: 'hello world', | ||
blackList: [{'staff':'level two','id':2}] | ||
}) | ||
|
||
(result['status']).should.equal('fail') | ||
(result['message']).should.equal('INVALID_BLACK_LIST') | ||
|
||
result = request('/ticket/get-authors', { | ||
csrf_userid: $csrf_userid, | ||
csrf_token: $csrf_token, | ||
query: 'hello world', | ||
blackList: [{'staff':1,'id':'four'}] | ||
}) | ||
|
||
(result['status']).should.equal('fail') | ||
(result['message']).should.equal('INVALID_BLACK_LIST') | ||
end | ||
|
||
it 'should return the correct authors' do | ||
|
||
result = request('/ticket/get-authors', { | ||
csrf_userid: $csrf_userid, | ||
csrf_token: $csrf_token, | ||
query: 'emilia' | ||
}) | ||
(result['status']).should.equal('success') | ||
(result['data']['authors'].size).should.equal(2) | ||
(result['data']['authors'][0]['name']).should.equal('Emilia Clarke') | ||
(result['data']['authors'][1]['name']).should.equal('eemilia') | ||
|
||
result = request('/ticket/get-authors', { | ||
csrf_userid: $csrf_userid, | ||
csrf_token: $csrf_token, | ||
query: 'emilia', | ||
blackList: '[{"staff":1,"id":1}]' | ||
}) | ||
(result['status']).should.equal('success') | ||
(result['data']['authors'].size).should.equal(1) | ||
(result['data']['authors'][0]['name']).should.equal('eemilia') | ||
|
||
result = request('/ticket/get-authors', { | ||
csrf_userid: $csrf_userid, | ||
csrf_token: $csrf_token, | ||
query: '', | ||
}) | ||
(result['status']).should.equal('success') | ||
end | ||
end |