|
|
@ -234,6 +234,17 @@ describe('[Users]', function() { |
|
|
|
}) |
|
|
|
}) |
|
|
|
.end(resolve); |
|
|
|
.end(resolve); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
const updatePermission = (permission, roles) => new Promise((resolve) => { |
|
|
|
|
|
|
|
request.post(api('permissions.update')) |
|
|
|
|
|
|
|
.set(credentials) |
|
|
|
|
|
|
|
.send({ permissions: [{ _id: permission, roles }] }) |
|
|
|
|
|
|
|
.expect('Content-Type', 'application/json') |
|
|
|
|
|
|
|
.expect(200) |
|
|
|
|
|
|
|
.expect((res) => { |
|
|
|
|
|
|
|
expect(res.body).to.have.property('success', true); |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
.end(resolve); |
|
|
|
|
|
|
|
}); |
|
|
|
before((done) => { |
|
|
|
before((done) => { |
|
|
|
updateSetting('Accounts_AllowUserProfileChange', true) |
|
|
|
updateSetting('Accounts_AllowUserProfileChange', true) |
|
|
|
.then(() => updateSetting('Accounts_AllowUsernameChange', true)) |
|
|
|
.then(() => updateSetting('Accounts_AllowUsernameChange', true)) |
|
|
@ -315,103 +326,223 @@ describe('[Users]', function() { |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('should return an error when trying update username and it is not allowed', (done) => { |
|
|
|
it('should return an error when trying update username and it is not allowed', (done) => { |
|
|
|
updateSetting('Accounts_AllowUsernameChange', false) |
|
|
|
updatePermission('edit-other-user-info', ['user']).then(() => { |
|
|
|
.then(() => { |
|
|
|
updateSetting('Accounts_AllowUsernameChange', false) |
|
|
|
request.post(api('users.update')) |
|
|
|
.then(() => { |
|
|
|
.set(credentials) |
|
|
|
request.post(api('users.update')) |
|
|
|
.send({ |
|
|
|
.set(credentials) |
|
|
|
userId: targetUser._id, |
|
|
|
.send({ |
|
|
|
data: { |
|
|
|
userId: targetUser._id, |
|
|
|
username: 'fake.name', |
|
|
|
data: { |
|
|
|
}, |
|
|
|
username: 'fake.name', |
|
|
|
}) |
|
|
|
}, |
|
|
|
.expect('Content-Type', 'application/json') |
|
|
|
}) |
|
|
|
.expect(400) |
|
|
|
.expect('Content-Type', 'application/json') |
|
|
|
.expect((res) => { |
|
|
|
.expect(400) |
|
|
|
expect(res.body).to.have.property('success', false); |
|
|
|
.expect((res) => { |
|
|
|
}) |
|
|
|
expect(res.body).to.have.property('success', false); |
|
|
|
.end(done); |
|
|
|
}) |
|
|
|
}); |
|
|
|
.end(done); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it('should update the user name when the required permission is applied', (done) => { |
|
|
|
|
|
|
|
updatePermission('edit-other-user-info', ['admin']).then(() => { |
|
|
|
|
|
|
|
updateSetting('Accounts_AllowUsernameChange', false) |
|
|
|
|
|
|
|
.then(() => { |
|
|
|
|
|
|
|
request.post(api('users.update')) |
|
|
|
|
|
|
|
.set(credentials) |
|
|
|
|
|
|
|
.send({ |
|
|
|
|
|
|
|
userId: targetUser._id, |
|
|
|
|
|
|
|
data: { |
|
|
|
|
|
|
|
username: 'fake.name', |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
.expect('Content-Type', 'application/json') |
|
|
|
|
|
|
|
.expect(200) |
|
|
|
|
|
|
|
.expect((res) => { |
|
|
|
|
|
|
|
expect(res.body).to.have.property('success', true); |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
.end(done); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('should return an error when trying update user real name and it is not allowed', (done) => { |
|
|
|
it('should return an error when trying update user real name and it is not allowed', (done) => { |
|
|
|
updateSetting('Accounts_AllowRealNameChange', false) |
|
|
|
updatePermission('edit-other-user-info', ['user']).then(() => { |
|
|
|
.then(() => { |
|
|
|
updateSetting('Accounts_AllowRealNameChange', false) |
|
|
|
request.post(api('users.update')) |
|
|
|
.then(() => { |
|
|
|
.set(credentials) |
|
|
|
request.post(api('users.update')) |
|
|
|
.send({ |
|
|
|
.set(credentials) |
|
|
|
userId: targetUser._id, |
|
|
|
.send({ |
|
|
|
data: { |
|
|
|
userId: targetUser._id, |
|
|
|
name: 'Fake name', |
|
|
|
data: { |
|
|
|
}, |
|
|
|
name: 'Fake name', |
|
|
|
}) |
|
|
|
}, |
|
|
|
.expect('Content-Type', 'application/json') |
|
|
|
}) |
|
|
|
.expect(400) |
|
|
|
.expect('Content-Type', 'application/json') |
|
|
|
.expect((res) => { |
|
|
|
.expect(400) |
|
|
|
expect(res.body).to.have.property('success', false); |
|
|
|
.expect((res) => { |
|
|
|
}) |
|
|
|
expect(res.body).to.have.property('success', false); |
|
|
|
.end(done); |
|
|
|
}) |
|
|
|
}); |
|
|
|
.end(done); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it('should update user real name when the required permission is applied', (done) => { |
|
|
|
|
|
|
|
updatePermission('edit-other-user-info', ['admin']).then(() => { |
|
|
|
|
|
|
|
updateSetting('Accounts_AllowRealNameChange', false) |
|
|
|
|
|
|
|
.then(() => { |
|
|
|
|
|
|
|
request.post(api('users.update')) |
|
|
|
|
|
|
|
.set(credentials) |
|
|
|
|
|
|
|
.send({ |
|
|
|
|
|
|
|
userId: targetUser._id, |
|
|
|
|
|
|
|
data: { |
|
|
|
|
|
|
|
name: 'Fake name', |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
.expect('Content-Type', 'application/json') |
|
|
|
|
|
|
|
.expect(200) |
|
|
|
|
|
|
|
.expect((res) => { |
|
|
|
|
|
|
|
expect(res.body).to.have.property('success', true); |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
.end(done); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('should return an error when trying update user email and it is not allowed', (done) => { |
|
|
|
it('should return an error when trying update user email and it is not allowed', (done) => { |
|
|
|
updateSetting('Accounts_AllowEmailChange', false) |
|
|
|
updatePermission('edit-other-user-info', ['user']).then(() => { |
|
|
|
.then(() => { |
|
|
|
updateSetting('Accounts_AllowEmailChange', false) |
|
|
|
request.post(api('users.update')) |
|
|
|
.then(() => { |
|
|
|
.set(credentials) |
|
|
|
request.post(api('users.update')) |
|
|
|
.send({ |
|
|
|
.set(credentials) |
|
|
|
userId: targetUser._id, |
|
|
|
.send({ |
|
|
|
data: { |
|
|
|
userId: targetUser._id, |
|
|
|
email: 'itsnotworking@email.com', |
|
|
|
data: { |
|
|
|
}, |
|
|
|
email: 'itsnotworking@email.com', |
|
|
|
}) |
|
|
|
}, |
|
|
|
.expect('Content-Type', 'application/json') |
|
|
|
}) |
|
|
|
.expect(400) |
|
|
|
.expect('Content-Type', 'application/json') |
|
|
|
.expect((res) => { |
|
|
|
.expect(400) |
|
|
|
expect(res.body).to.have.property('success', false); |
|
|
|
.expect((res) => { |
|
|
|
}) |
|
|
|
expect(res.body).to.have.property('success', false); |
|
|
|
.end(done); |
|
|
|
}) |
|
|
|
}); |
|
|
|
.end(done); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it('should update user email when the required permission is applied', (done) => { |
|
|
|
|
|
|
|
updatePermission('edit-other-user-info', ['admin']).then(() => { |
|
|
|
|
|
|
|
updateSetting('Accounts_AllowEmailChange', false) |
|
|
|
|
|
|
|
.then(() => { |
|
|
|
|
|
|
|
request.post(api('users.update')) |
|
|
|
|
|
|
|
.set(credentials) |
|
|
|
|
|
|
|
.send({ |
|
|
|
|
|
|
|
userId: targetUser._id, |
|
|
|
|
|
|
|
data: { |
|
|
|
|
|
|
|
email: apiEmail, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
.expect('Content-Type', 'application/json') |
|
|
|
|
|
|
|
.expect(200) |
|
|
|
|
|
|
|
.expect((res) => { |
|
|
|
|
|
|
|
expect(res.body).to.have.property('success', true); |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
.end(done); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('should return an error when trying update user password and it is not allowed', (done) => { |
|
|
|
it('should return an error when trying update user password and it is not allowed', (done) => { |
|
|
|
updateSetting('Accounts_AllowPasswordChange', false) |
|
|
|
updatePermission('edit-other-user-password', ['user']).then(() => { |
|
|
|
.then(() => { |
|
|
|
updateSetting('Accounts_AllowPasswordChange', false) |
|
|
|
request.post(api('users.update')) |
|
|
|
.then(() => { |
|
|
|
.set(credentials) |
|
|
|
request.post(api('users.update')) |
|
|
|
.send({ |
|
|
|
.set(credentials) |
|
|
|
userId: targetUser._id, |
|
|
|
.send({ |
|
|
|
data: { |
|
|
|
userId: targetUser._id, |
|
|
|
password: 'itsnotworking', |
|
|
|
data: { |
|
|
|
}, |
|
|
|
password: 'itsnotworking', |
|
|
|
}) |
|
|
|
}, |
|
|
|
.expect('Content-Type', 'application/json') |
|
|
|
}) |
|
|
|
.expect(400) |
|
|
|
.expect('Content-Type', 'application/json') |
|
|
|
.expect((res) => { |
|
|
|
.expect(400) |
|
|
|
expect(res.body).to.have.property('success', false); |
|
|
|
.expect((res) => { |
|
|
|
}) |
|
|
|
expect(res.body).to.have.property('success', false); |
|
|
|
.end(done); |
|
|
|
}) |
|
|
|
}); |
|
|
|
.end(done); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it('should update user password when the required permission is applied', (done) => { |
|
|
|
|
|
|
|
updatePermission('edit-other-user-password', ['admin']).then(() => { |
|
|
|
|
|
|
|
updateSetting('Accounts_AllowPasswordChange', false) |
|
|
|
|
|
|
|
.then(() => { |
|
|
|
|
|
|
|
request.post(api('users.update')) |
|
|
|
|
|
|
|
.set(credentials) |
|
|
|
|
|
|
|
.send({ |
|
|
|
|
|
|
|
userId: targetUser._id, |
|
|
|
|
|
|
|
data: { |
|
|
|
|
|
|
|
password: 'itsnotworking', |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
.expect('Content-Type', 'application/json') |
|
|
|
|
|
|
|
.expect(200) |
|
|
|
|
|
|
|
.expect((res) => { |
|
|
|
|
|
|
|
expect(res.body).to.have.property('success', true); |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
.end(done); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('should return an error when trying update profile and it is not allowed', (done) => { |
|
|
|
it('should return an error when trying update profile and it is not allowed', (done) => { |
|
|
|
updateSetting('Accounts_AllowUserProfileChange', false) |
|
|
|
updatePermission('edit-other-user-info', ['user']).then(() => { |
|
|
|
.then(() => { |
|
|
|
updateSetting('Accounts_AllowUserProfileChange', false) |
|
|
|
request.post(api('users.update')) |
|
|
|
.then(() => { |
|
|
|
.set(credentials) |
|
|
|
request.post(api('users.update')) |
|
|
|
.send({ |
|
|
|
.set(credentials) |
|
|
|
userId: targetUser._id, |
|
|
|
.send({ |
|
|
|
data: { |
|
|
|
userId: targetUser._id, |
|
|
|
verified: true, |
|
|
|
data: { |
|
|
|
}, |
|
|
|
verified: true, |
|
|
|
}) |
|
|
|
}, |
|
|
|
.expect('Content-Type', 'application/json') |
|
|
|
}) |
|
|
|
.expect(400) |
|
|
|
.expect('Content-Type', 'application/json') |
|
|
|
.expect((res) => { |
|
|
|
.expect(400) |
|
|
|
expect(res.body).to.have.property('success', false); |
|
|
|
.expect((res) => { |
|
|
|
}) |
|
|
|
expect(res.body).to.have.property('success', false); |
|
|
|
.end(done); |
|
|
|
}) |
|
|
|
}); |
|
|
|
.end(done); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it('should update profile when the required permission is applied', (done) => { |
|
|
|
|
|
|
|
updatePermission('edit-other-user-info', ['admin']).then(() => { |
|
|
|
|
|
|
|
updateSetting('Accounts_AllowUserProfileChange', false) |
|
|
|
|
|
|
|
.then(() => { |
|
|
|
|
|
|
|
request.post(api('users.update')) |
|
|
|
|
|
|
|
.set(credentials) |
|
|
|
|
|
|
|
.send({ |
|
|
|
|
|
|
|
userId: targetUser._id, |
|
|
|
|
|
|
|
data: { |
|
|
|
|
|
|
|
verified: true, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
.expect('Content-Type', 'application/json') |
|
|
|
|
|
|
|
.expect(200) |
|
|
|
|
|
|
|
.expect((res) => { |
|
|
|
|
|
|
|
expect(res.body).to.have.property('success', true); |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
.end(done); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|