2016-05-15 01:22:46 +02:00
|
|
|
describe '/user/signup' do
|
|
|
|
it 'should create user in database' do
|
|
|
|
response = request('/user/signup', {
|
2016-08-04 20:18:29 +02:00
|
|
|
:name => 'Steve Jobs',
|
|
|
|
:email => 'steve@jobs.com',
|
|
|
|
:password => 'custom'
|
2016-05-15 01:22:46 +02:00
|
|
|
})
|
|
|
|
|
2016-07-04 02:32:34 +02:00
|
|
|
userRow = $database.getRow('user', response['data']['userId'])
|
2016-05-15 01:22:46 +02:00
|
|
|
|
2016-12-23 05:27:21 +01:00
|
|
|
request('/user/verify', {
|
|
|
|
:email => 'steve@jobs.com',
|
|
|
|
:token => userRow['verification_token']
|
|
|
|
})
|
|
|
|
|
2016-05-15 01:22:46 +02:00
|
|
|
(userRow['email']).should.equal('steve@jobs.com')
|
2016-07-27 05:50:20 +02:00
|
|
|
(userRow['name']).should.equal('Steve Jobs')
|
2016-12-29 21:25:45 +01:00
|
|
|
|
|
|
|
lastLog = $database.getLastRow('log')
|
|
|
|
(lastLog['type']).should.equal('SIGNUP')
|
2016-05-15 01:22:46 +02:00
|
|
|
end
|
2016-07-19 22:39:26 +02:00
|
|
|
|
|
|
|
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')
|
2016-10-04 23:42:47 +02:00
|
|
|
(result['message']).should.equal('INVALID_NAME')
|
2016-07-19 22:39:26 +02:00
|
|
|
|
|
|
|
result = request('/user/signup', {
|
|
|
|
name: long_text,
|
|
|
|
email: 'tyrion@outlook.com',
|
|
|
|
password: 'Lannister'
|
|
|
|
})
|
|
|
|
|
|
|
|
(result['status']).should.equal('fail')
|
2016-10-04 23:42:47 +02:00
|
|
|
(result['message']).should.equal('INVALID_NAME')
|
2016-07-19 22:39:26 +02:00
|
|
|
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')
|
2016-10-04 23:42:47 +02:00
|
|
|
(result['message']).should.equal('INVALID_EMAIL')
|
2016-07-19 22:39:26 +02:00
|
|
|
|
|
|
|
result = request('/user/signup', {
|
|
|
|
name: 'tyrion',
|
|
|
|
email: 'tyrion@outlookcom',
|
|
|
|
password: 'Lannister'
|
|
|
|
})
|
|
|
|
|
|
|
|
(result['status']).should.equal('fail')
|
2016-10-04 23:42:47 +02:00
|
|
|
(result['message']).should.equal('INVALID_EMAIL')
|
2016-07-19 22:39:26 +02:00
|
|
|
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')
|
2016-10-04 23:42:47 +02:00
|
|
|
(result['message']).should.equal('INVALID_PASSWORD')
|
2016-07-19 22:39:26 +02:00
|
|
|
|
|
|
|
long_text = ''
|
|
|
|
250.times {long_text << 'a'}
|
|
|
|
|
|
|
|
result = request('/user/signup', {
|
|
|
|
name: 'tyrion',
|
|
|
|
email: 'tyrion@outlook.com',
|
|
|
|
password: long_text
|
|
|
|
})
|
2016-07-21 20:27:57 +02:00
|
|
|
|
|
|
|
(result['status']).should.equal('fail')
|
2016-10-04 23:42:47 +02:00
|
|
|
(result['message']).should.equal('INVALID_PASSWORD')
|
2016-07-19 22:39:26 +02:00
|
|
|
end
|
|
|
|
|
2016-05-15 01:22:46 +02:00
|
|
|
end
|