(Guillermo) add tests for signup validation

This commit is contained in:
AntonyAntonio 2016-07-19 17:39:26 -03:00
parent 5fd68fdc6e
commit 76ecd4ebc3
2 changed files with 77 additions and 1 deletions

View File

@ -1,6 +1,7 @@
class Scripts 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', { response = request('/user/signup', {
'name' => name,
'email' => email, 'email' => email,
'password' => password 'password' => password
}) })

View File

@ -1,6 +1,7 @@
describe '/user/signup' do describe '/user/signup' do
it 'should create user in database' do it 'should create user in database' do
response = request('/user/signup', { response = request('/user/signup', {
'name' => 'Steve Jobs',
'email' => 'steve@jobs.com', 'email' => 'steve@jobs.com',
'password' => 'custom' 'password' => 'custom'
}) })
@ -9,4 +10,78 @@ describe '/user/signup' do
(userRow['email']).should.equal('steve@jobs.com') (userRow['email']).should.equal('steve@jobs.com')
end 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
})
end
end end