Merge branch 'master' into Recover-Password

Conflicts:
	server/models/ERRORS.php
This commit is contained in:
AntonyAntonio 2016-07-25 11:00:43 -03:00
commit 1f39e4d845
4 changed files with 95 additions and 4 deletions

View File

@ -1,5 +1,7 @@
<?php
use Respect\Validation\Validator as DataValidator;
class SignUpController extends Controller {
const PATH = '/signup';
@ -9,7 +11,20 @@ class SignUpController extends Controller {
public function validations() {
return [
'permission' => 'any',
'requestData' => []
'requestData' => [
'name' => [
'validation' => DataValidator::length(2, 55)->alpha(),
'error' => ERRORS::INVALID_NAME
],
'email' => [
'validation' => DataValidator::email(),
'error' => ERRORS::INVALID_EMAIL
],
'password' => [
'validation' => DataValidator::length(5, 200),
'error' => ERRORS::INVALID_PASSWORD
]
]
];
}

View File

@ -3,8 +3,6 @@ class ERRORS {
const INVALID_CREDENTIALS = 'User or password is not defined';
const SESSION_EXISTS = 'User is already logged in';
const NO_PERMISSION = 'You have no permission to access';
const INVALID_EMAIL = 'Invalid email';
const INVALID_TITLE = 'Invalid title';
const INVALID_CONTENT = 'Invalid content';
const INVALID_PASSWORD = 'Invalid password';
}

View File

@ -1,6 +1,7 @@
class Scripts
def self.createUser(email = 'steve@jobs.com', password = 'custompassword')
def self.createUser(email = 'steve@jobs.com', password = 'custompassword', name = 'steve jobs')
response = request('/user/signup', {
'name' => name,
'email' => email,
'password' => password
})

View File

@ -1,6 +1,7 @@
describe '/user/signup' do
it 'should create user in database' do
response = request('/user/signup', {
'name' => 'Steve Jobs',
'email' => 'steve@jobs.com',
'password' => 'custom'
})
@ -9,4 +10,80 @@ describe '/user/signup' do
(userRow['email']).should.equal('steve@jobs.com')
end
it 'should fail if name is invalid' do
long_text = ''
100.times {long_text << 'a'}
result = request('/user/signup', {
name: 't',
email: 'tyrion@outlook.com',
password: 'Lannister'
})
(result['status']).should.equal('fail')
(result['message']).should.equal('Invalid name')
result = request('/user/signup', {
name: long_text,
email: 'tyrion@outlook.com',
password: 'Lannister'
})
(result['status']).should.equal('fail')
(result['message']).should.equal('Invalid name')
result = request('/user/signup', {
name: 'tyri0n',
email: 'tyrion@outlook.com',
password: 'Lannister'
})
(result['status']).should.equal('fail')
(result['message']).should.equal('Invalid name')
end
it 'should fail if email is invalid' do
result = request('/user/signup', {
name: 'tyrion',
email: 'tyrionoutlook.com',
password: 'Lannister'
})
(result['status']).should.equal('fail')
(result['message']).should.equal('Invalid email')
result = request('/user/signup', {
name: 'tyrion',
email: 'tyrion@outlookcom',
password: 'Lannister'
})
(result['status']).should.equal('fail')
(result['message']).should.equal('Invalid email')
end
it 'should fail if password is invalid' do
result = request('/user/signup', {
name: 'tyrion',
email: 'tyrion@outlook.com',
password: 'Lann'
})
(result['status']).should.equal('fail')
(result['message']).should.equal('Invalid password')
long_text = ''
250.times {long_text << 'a'}
result = request('/user/signup', {
name: 'tyrion',
email: 'tyrion@outlook.com',
password: long_text
})
(result['status']).should.equal('fail')
(result['message']).should.equal('Invalid password')
end
end