2016-08-10 03:55:12 +02:00
|
|
|
describe '/user/edit-email' do
|
|
|
|
|
2021-11-05 21:06:08 +01:00
|
|
|
Scripts.logout()
|
2016-08-10 03:55:12 +02:00
|
|
|
result = request('/user/login', {
|
|
|
|
email: 'steve@jobs.com',
|
2019-02-14 23:43:22 +01:00
|
|
|
password: 'custompassword'
|
2016-08-10 03:55:12 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
$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
|
2016-08-10 04:54:39 +02:00
|
|
|
})
|
2016-08-10 03:55:12 +02:00
|
|
|
(result['status']).should.equal('fail')
|
2016-10-04 23:42:47 +02:00
|
|
|
(result['message']).should.equal('INVALID_EMAIL')
|
2016-08-10 03:55:12 +02:00
|
|
|
|
|
|
|
result = request('/user/edit-email', {
|
|
|
|
newEmail: 'newemailjobs.com',
|
|
|
|
csrf_userid: $csrf_userid,
|
|
|
|
csrf_token: $csrf_token
|
2016-08-10 04:54:39 +02:00
|
|
|
})
|
2016-08-10 03:55:12 +02:00
|
|
|
(result['status']).should.equal('fail')
|
2016-10-04 23:42:47 +02:00
|
|
|
(result['message']).should.equal('INVALID_EMAIL')
|
2016-08-10 03:55:12 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should change email' do
|
|
|
|
result = request('/user/edit-email', {
|
|
|
|
newEmail: 'newemail@jobs.com',
|
|
|
|
csrf_userid: $csrf_userid,
|
|
|
|
csrf_token: $csrf_token
|
2016-08-10 04:54:39 +02:00
|
|
|
})
|
2016-08-10 03:55:12 +02:00
|
|
|
(result['status']).should.equal('success')
|
2019-02-14 23:43:22 +01:00
|
|
|
|
|
|
|
result = request('/user/edit-email', {
|
|
|
|
newEmail: 'steve@jobs.com',
|
|
|
|
csrf_userid: $csrf_userid,
|
|
|
|
csrf_token: $csrf_token
|
|
|
|
})
|
2016-08-10 03:55:12 +02:00
|
|
|
end
|
2021-12-28 04:26:55 +01:00
|
|
|
|
|
|
|
|
|
|
|
it 'should success if email selected is used by himself' do
|
|
|
|
|
|
|
|
Scripts.logout()
|
|
|
|
|
|
|
|
Scripts.createUser('miare@os4.com','sellamamarlos', 'maria')
|
|
|
|
|
|
|
|
result = request('/user/login', {
|
|
|
|
email: 'miare@os4.com',
|
|
|
|
password: 'sellamamarlos'
|
|
|
|
})
|
|
|
|
|
|
|
|
(result['status']).should.equal('success')
|
|
|
|
|
|
|
|
$csrf_userid = result['data']['userId']
|
|
|
|
$csrf_token = result['data']['token']
|
|
|
|
|
|
|
|
row = $database.getRow('user', 'miare@os4.com', 'email')
|
|
|
|
|
|
|
|
result = request('/user/edit-email', {
|
|
|
|
newEmail: row['email'],
|
|
|
|
csrf_userid: $csrf_userid,
|
|
|
|
csrf_token: $csrf_token
|
|
|
|
})
|
|
|
|
|
|
|
|
(result['status']).should.equal('success')
|
|
|
|
|
|
|
|
row = $database.getRow('user', 'miare@os4.com', 'email')
|
|
|
|
|
|
|
|
(row['email']).should.equal('miare@os4.com')
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should fail if email selected is already used' do
|
|
|
|
|
|
|
|
staffRow = $database.getRow('staff', 1, 'id')
|
|
|
|
userRow = $database.getRow('user', 1, 'id')
|
|
|
|
|
|
|
|
result = request('/user/edit-email', {
|
|
|
|
newEmail: staffRow['email'],
|
|
|
|
csrf_userid: $csrf_userid,
|
|
|
|
csrf_token: $csrf_token
|
|
|
|
})
|
|
|
|
(result['status']).should.equal('fail')
|
|
|
|
(result['message']).should.equal('INVALID_EMAIL')
|
|
|
|
|
|
|
|
row = $database.getRow('user', 'miare@os4.com', 'email')
|
|
|
|
(row['email']).should.equal('miare@os4.com')
|
|
|
|
|
|
|
|
result = request('/user/edit-email', {
|
|
|
|
newEmail: userRow['email'],
|
|
|
|
csrf_userid: $csrf_userid,
|
|
|
|
csrf_token: $csrf_token
|
|
|
|
})
|
|
|
|
(result['status']).should.equal('fail')
|
|
|
|
(result['message']).should.equal('INVALID_EMAIL')
|
|
|
|
|
|
|
|
row = $database.getRow('user', 'miare@os4.com', 'email')
|
|
|
|
(row['email']).should.equal('miare@os4.com')
|
|
|
|
end
|
2016-08-10 03:55:12 +02:00
|
|
|
end
|