2018-02-02 15:24:22 +00:00
|
|
|
const app = require('../../../../../client/server/server');
|
2018-01-31 11:02:35 +00:00
|
|
|
const catchErrors = require('../../../../../../services/utils/jasmineHelpers').catchErrors;
|
|
|
|
const restoreFixtures = require('../../../../../../services/db/testing_fixtures');
|
2018-01-16 20:39:40 +00:00
|
|
|
|
2018-01-23 08:32:19 +00:00
|
|
|
describe('Client Create', () => {
|
2018-03-08 11:23:51 +00:00
|
|
|
let sqlStatements = {deletes: `
|
|
|
|
DELETE FROM vn.address WHERE nickname = "Wade";
|
|
|
|
DELETE FROM vn.client WHERE name = "Wade";
|
|
|
|
DELETE FROM account.user WHERE name = "Deadpool";
|
|
|
|
`, inserts: ``, updates: ``};
|
|
|
|
|
|
|
|
beforeAll(() => {
|
|
|
|
restoreFixtures(sqlStatements);
|
2018-01-16 20:39:40 +00:00
|
|
|
});
|
|
|
|
|
2018-03-08 11:23:51 +00:00
|
|
|
afterAll(() => {
|
|
|
|
restoreFixtures(sqlStatements);
|
2018-01-24 07:09:39 +00:00
|
|
|
});
|
|
|
|
|
2018-01-17 11:46:26 +00:00
|
|
|
let newAccountData = {
|
2018-01-23 08:32:19 +00:00
|
|
|
active: true,
|
2018-01-17 11:46:26 +00:00
|
|
|
name: 'Wade',
|
|
|
|
userName: 'Deadpool',
|
|
|
|
email: 'Deadpool@marvel.com',
|
2018-02-27 11:56:03 +00:00
|
|
|
fi: '16195279J',
|
2018-01-23 08:32:19 +00:00
|
|
|
socialName: 'Deadpool Marvel',
|
|
|
|
salesPersonFk: 1
|
2017-09-20 12:01:33 +00:00
|
|
|
};
|
2017-09-10 18:04:22 +00:00
|
|
|
|
2018-01-17 11:46:26 +00:00
|
|
|
it('should find Charles Xavier', done => {
|
2018-01-16 20:39:40 +00:00
|
|
|
app.models.Account.findOne({where: {name: 'CharlesXavier'}})
|
2018-02-02 15:24:22 +00:00
|
|
|
.then(account => {
|
|
|
|
expect(account.name).toEqual('CharlesXavier');
|
|
|
|
done();
|
|
|
|
});
|
2018-01-16 20:39:40 +00:00
|
|
|
});
|
|
|
|
|
2018-02-02 15:24:22 +00:00
|
|
|
it(`should not find Deadpool as he's not created yet`, done => {
|
2018-01-17 11:46:26 +00:00
|
|
|
app.models.Account.findOne({where: {name: newAccountData.userName}})
|
2018-02-02 15:24:22 +00:00
|
|
|
.then(account => {
|
|
|
|
expect(account).toEqual(null);
|
|
|
|
app.models.Client.findOne({where: {name: newAccountData.name}})
|
|
|
|
.then(client => {
|
|
|
|
expect(client).toEqual(null);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
})
|
|
|
|
.catch(catchErrors(done));
|
2018-01-17 11:46:26 +00:00
|
|
|
});
|
|
|
|
|
2018-03-12 12:09:52 +00:00
|
|
|
it('should not be able to create a user if exists', async() => {
|
|
|
|
let client = await app.models.Client.findOne({where: {name: 'Charles Xavier'}});
|
|
|
|
let account = await app.models.Account.findOne({where: {id: client.id}});
|
2018-01-17 11:46:26 +00:00
|
|
|
|
2018-03-12 12:09:52 +00:00
|
|
|
let formerAccountData = {
|
|
|
|
name: client.name,
|
|
|
|
userName: account.name,
|
|
|
|
email: client.email,
|
|
|
|
fi: client.fi,
|
|
|
|
socialName: client.socialName
|
|
|
|
};
|
|
|
|
|
|
|
|
try {
|
|
|
|
let client = await app.models.Client.createWithUser(formerAccountData);
|
|
|
|
|
|
|
|
expect(client).toBeNull();
|
|
|
|
} catch (err) {
|
|
|
|
expect(err.details.codes.name[0]).toEqual('uniqueness');
|
|
|
|
}
|
2017-09-20 12:01:33 +00:00
|
|
|
});
|
2018-01-17 11:46:26 +00:00
|
|
|
|
2018-03-12 12:09:52 +00:00
|
|
|
it('should create a new account', async() => {
|
|
|
|
let client = await app.models.Client.createWithUser(newAccountData);
|
|
|
|
let account = await app.models.Account.findOne({where: {name: newAccountData.userName}});
|
|
|
|
|
|
|
|
expect(account.name).toEqual(newAccountData.userName);
|
|
|
|
|
|
|
|
client = await app.models.Client.findOne({where: {name: newAccountData.name}});
|
|
|
|
|
|
|
|
expect(client.id).toEqual(account.id);
|
|
|
|
expect(client.name).toEqual(newAccountData.name);
|
|
|
|
expect(client.email).toEqual(newAccountData.email);
|
|
|
|
expect(client.fi).toEqual(newAccountData.fi);
|
|
|
|
expect(client.socialName).toEqual(newAccountData.socialName);
|
2018-01-23 08:32:19 +00:00
|
|
|
});
|
2017-09-20 12:01:33 +00:00
|
|
|
});
|