feat: improve test user.changePassword (#66)

Fixes #53
This commit is contained in:
heafalan
2019-02-01 15:23:01 +01:00
committed by badrAZ
parent e1c6e4347a
commit 4c1581d845
2 changed files with 64 additions and 0 deletions

View File

@@ -1,5 +1,15 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`user .changePassword() : changes the actual user password 1`] = `true`;
exports[`user .changePassword() : changes the actual user password 2`] = `[JsonRpcError: invalid credentials]`;
exports[`user .changePassword() : fails trying to change the password with invalid oldPassword 1`] = `[JsonRpcError: invalid credentials]`;
exports[`user .changePassword() : fails trying to change the password without newPassword 1`] = `[JsonRpcError: invalid parameters]`;
exports[`user .changePassword() : fails trying to change the password without oldPassword 1`] = `[JsonRpcError: invalid parameters]`;
exports[`user .create() : creates a user with permission 1`] = `
Object {
"email": "wayne2@vates.fr",

View File

@@ -64,6 +64,60 @@ describe("user", () => {
});
});
describe(".changePassword() :", () => {
it("changes the actual user password", async () => {
const user = {
email: "wayne7@vates.fr",
password: "batman",
};
const newPassword = "newpwd";
await xo.createUser(user);
await testWithOtherConnection(user, xo =>
expect(
xo.call("user.changePassword", {
oldPassword: user.password,
newPassword,
})
).resolves.toMatchSnapshot()
);
await testConnection({
credentials: {
email: user.email,
password: newPassword,
},
});
await expect(
testConnection({
credentials: user,
})
).rejects.toMatchSnapshot();
});
withData(
{
"fails trying to change the password without newPassword": {
oldPassword: simpleUser.password,
},
"fails trying to change the password without oldPassword": {
newPassword: "newpwd",
},
"fails trying to change the password with invalid oldPassword": {
oldPassword: "falsepwd",
newPassword: "newpwd",
},
},
async data => {
await xo.createUser(simpleUser);
await testWithOtherConnection(simpleUser, xo =>
expect(xo.call("user.changePassword", data)).rejects.toMatchSnapshot()
);
}
);
});
describe(".getAll() :", () => {
it("gets all the users created", async () => {
const userId1 = await xo.createUser({