2019-08-09 10:22:04 +02:00
|
|
|
import User from "model/user";
|
2019-08-12 12:59:32 +02:00
|
|
|
import MockAdapter from "axios-mock-adapter";
|
|
|
|
import Api from "common/api";
|
2019-08-09 10:22:04 +02:00
|
|
|
|
2020-07-02 10:03:00 +02:00
|
|
|
let chai = require("chai/chai");
|
2019-08-13 08:10:12 +02:00
|
|
|
let assert = chai.assert;
|
|
|
|
|
2019-08-09 10:24:20 +02:00
|
|
|
describe("model/user", () => {
|
2019-08-12 12:59:32 +02:00
|
|
|
const mock = new MockAdapter(Api);
|
|
|
|
|
2019-08-09 10:22:04 +02:00
|
|
|
it("should get entity name", () => {
|
2019-11-08 06:53:40 +01:00
|
|
|
const values = {ID: 5, FirstName: "Max", LastName: "Last", Email: "test@test.com", Role: "admin"};
|
2019-08-09 10:22:04 +02:00
|
|
|
const user = new User(values);
|
|
|
|
const result = user.getEntityName();
|
|
|
|
assert.equal(result, "Max Last");
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should get id", () => {
|
2019-11-08 06:53:40 +01:00
|
|
|
const values = {ID: 5, FirstName: "Max", LastName: "Last", Email: "test@test.com", Role: "admin"};
|
2019-08-09 10:22:04 +02:00
|
|
|
const user = new User(values);
|
|
|
|
const result = user.getId();
|
|
|
|
assert.equal(result, 5);
|
|
|
|
});
|
|
|
|
|
2019-08-09 10:24:20 +02:00
|
|
|
it("should get model name", () => {
|
|
|
|
const result = User.getModelName();
|
|
|
|
assert.equal(result, "User");
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should get collection resource", () => {
|
|
|
|
const result = User.getCollectionResource();
|
|
|
|
assert.equal(result, "users");
|
|
|
|
});
|
2019-08-12 12:59:32 +02:00
|
|
|
|
|
|
|
it("should get register form", async() => {
|
|
|
|
mock.onAny("users/52/register").reply(200, "registerForm");
|
2019-11-08 06:53:40 +01:00
|
|
|
const values = {ID: 52, FirstName: "Max"};
|
2019-08-12 12:59:32 +02:00
|
|
|
const user = new User(values);
|
|
|
|
const result = await user.getRegisterForm();
|
|
|
|
assert.equal(result.definition, "registerForm");
|
|
|
|
mock.reset();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should get profile form", async() => {
|
|
|
|
mock.onAny("users/53/profile").reply(200, "profileForm");
|
2019-11-08 06:53:40 +01:00
|
|
|
const values = {ID: 53, FirstName: "Max"};
|
2019-08-12 12:59:32 +02:00
|
|
|
const user = new User(values);
|
|
|
|
const result = await user.getProfileForm();
|
|
|
|
assert.equal(result.definition, "profileForm");
|
|
|
|
mock.reset();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should get change password", async() => {
|
|
|
|
mock.onPut("users/54/password").reply(200, {password: "old", new_password: "new"});
|
2019-11-08 06:53:40 +01:00
|
|
|
const values = {ID: 54, FirstName: "Max", LastName: "Last", Email: "test@test.com", Role: "admin"};
|
2019-08-12 12:59:32 +02:00
|
|
|
const user = new User(values);
|
|
|
|
const result = await user.changePassword("old", "new");
|
|
|
|
assert.equal(result.new_password, "new");
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should save profile", async() => {
|
2019-11-08 06:53:40 +01:00
|
|
|
mock.onPost("users/55/profile").reply(200, {FirstName: "MaxNew", LastName: "LastNew"});
|
|
|
|
const values = {ID: 55, FirstName: "Max", LastName: "Last", Email: "test@test.com", Role: "admin"};
|
2019-08-12 12:59:32 +02:00
|
|
|
const user = new User(values);
|
2019-11-08 06:53:40 +01:00
|
|
|
assert.equal(user.FirstName, "Max");
|
|
|
|
assert.equal(user.LastName, "Last");
|
2019-08-12 12:59:32 +02:00
|
|
|
await user.saveProfile();
|
2019-11-08 06:53:40 +01:00
|
|
|
assert.equal(user.FirstName, "MaxNew");
|
|
|
|
assert.equal(user.LastName, "LastNew");
|
2019-08-12 12:59:32 +02:00
|
|
|
});
|
2019-11-08 06:53:40 +01:00
|
|
|
});
|