(Guillermo) add ruby testing for user-edit [skip ci]

This commit is contained in:
AntonyAntonio 2016-08-09 22:55:12 -03:00
parent 54da0699dd
commit 9e778f2c90
5 changed files with 105 additions and 7 deletions

View File

@ -14,5 +14,7 @@ require './user/signup.rb'
require './user/login.rb'
require './user/send-recover-password.rb'
require './user/recover-password.rb'
require './user/edit-password.rb'
require './user/edit-email.rb'
require './ticket/create.rb'
require './ticket/comment.rb'

View File

@ -63,7 +63,7 @@ describe '/ticket/comment/' do
comment = $database.getRow('comment', '1', 'id')
(comment['content']).should.equal('some comment content')
(comment['ticket_id']).should.equal('1')
(comment['author_id']).should.equal('1')
(comment['author_id']).should.equal($csrf_userid)
end
it 'should fail if user is not the author nor owner' do

View File

@ -1,8 +1,9 @@
describe '/ticket/create' do
request('/user/logout')
Scripts.createUser('jonhsnow@os4.com','jonhpass','Jonh Snow')
result = request('/user/login', {
email: 'steve@jobs.com',
password: 'custom'
email: 'jonhsnow@os4.com',
password: 'jonhpass'
})
$csrf_userid = result['data']['userId']
@ -106,9 +107,9 @@ describe '/ticket/create' do
(ticket['unread']).should.equal('0')
(ticket['closed']).should.equal('0')
(ticket['department_id']).should.equal('1')
(ticket['author_id']).should.equal('1')
(ticket['author_id']).should.equal($csrf_userid)
ticket_user_relation = $database.getRow('ticket_user','1','ticket_id')
(ticket_user_relation['user_id']).should.equal('1')
(ticket_user_relation['user_id']).should.equal($csrf_userid)
end
end

39
tests/user/edit-email.rb Normal file
View File

@ -0,0 +1,39 @@
describe '/user/edit-email' do
request('/user/logout')
result = request('/user/login', {
email: 'steve@jobs.com',
password: 'newpassword'
})
$csrf_userid = result['data']['userId']
$csrf_token = result['data']['token']
it 'should fail if new email is incorrect' do
result = request('/user/edit-email', {
newEmail: 'newemail@jobscom',
csrf_userid: $csrf_userid,
csrf_token: $csrf_token
})
(result['status']).should.equal('fail')
(result['message']).should.equal('Invalid email')
result = request('/user/edit-email', {
newEmail: 'newemailjobs.com',
csrf_userid: $csrf_userid,
csrf_token: $csrf_token
})
(result['status']).should.equal('fail')
(result['message']).should.equal('Invalid email')
end
it 'should change email' do
result = request('/user/edit-email', {
newEmail: 'newemail@jobs.com',
csrf_userid: $csrf_userid,
csrf_token: $csrf_token
})
(result['status']).should.equal('success')
end
end

View File

@ -0,0 +1,56 @@
describe '/user/edit-password' do
request('/user/logout')
result = request('/user/login', {
email: 'steve@jobs.com',
password: 'custom'
})
$csrf_userid = result['data']['userId']
$csrf_token = result['data']['token']
it 'should fail if new password is incorrect' do
result = request('/user/edit-password', {
oldPassword: 'custom',
newPassword: 'np',
csrf_userid: $csrf_userid,
csrf_token: $csrf_token
})
(result['status']).should.equal('fail')
(result['message']).should.equal('Invalid password')
long_text = ''
250.times {long_text << 'a'}
result = request('/user/edit-password', {
oldPassword: 'custom',
newPassword: long_text,
csrf_userid: $csrf_userid,
csrf_token: $csrf_token
})
(result['status']).should.equal('fail')
(result['message']).should.equal('Invalid password')
end
it 'should fail if old password is not same than old password ' do
result = request('/user/edit-password',{
oldPassword: 'falsepassword',
newPassword: 'newpassword',
csrf_userid: $csrf_userid,
csrf_token: $csrf_token
})
(result['status']).should.equal('fail')
(result['message']).should.equal('Invalid old password')
end
it 'should change password' do
result = request('/user/edit-password',{
oldPassword: 'custom',
newPassword: 'newpassword',
csrf_userid: $csrf_userid,
csrf_token: $csrf_token
})
(result['status']).should.equal('success')
end
end