2018-08-13 11:11:37 +00:00
|
|
|
const app = require(`${servicesDir}/client/server/server`);
|
2018-01-16 20:39:40 +00:00
|
|
|
|
2018-01-23 08:32:19 +00:00
|
|
|
describe('Client Create', () => {
|
2018-09-28 06:43:00 +00:00
|
|
|
const clientName = 'Wade';
|
|
|
|
const AccountName = 'Deadpool';
|
|
|
|
/* beforeAll(async() => {
|
|
|
|
let address = await app.models.Address.findOne({where: {nickname: clientName}});
|
|
|
|
let client = await app.models.Client.findOne({where: {name: clientName}});
|
|
|
|
let account = await app.models.Account.findOne({where: {name: AccountName}});
|
|
|
|
await app.models.Address.destroyById(address.id);
|
|
|
|
await app.models.Client.destroyById(client.id);
|
|
|
|
await app.models.Account.destroyById(account.id);
|
|
|
|
}); */
|
2018-03-08 11:23:51 +00:00
|
|
|
|
2018-09-28 06:43:00 +00:00
|
|
|
afterAll(async() => {
|
|
|
|
let address = await app.models.Address.findOne({where: {nickname: clientName}});
|
|
|
|
let client = await app.models.Client.findOne({where: {name: clientName}});
|
|
|
|
let account = await app.models.Account.findOne({where: {name: AccountName}});
|
|
|
|
await app.models.Address.destroyById(address.id);
|
|
|
|
await app.models.Client.destroyById(client.id);
|
|
|
|
await app.models.Account.destroyById(account.id);
|
2018-01-24 07:09:39 +00:00
|
|
|
});
|
|
|
|
|
2018-03-21 11:57:23 +00:00
|
|
|
let newAccount = {
|
2018-01-17 11:46:26 +00:00
|
|
|
userName: 'Deadpool',
|
|
|
|
email: 'Deadpool@marvel.com',
|
2018-02-27 11:56:03 +00:00
|
|
|
fi: '16195279J',
|
2018-03-21 11:57:23 +00:00
|
|
|
name: 'Wade',
|
|
|
|
socialName: 'Deadpool Marvel'
|
2017-09-20 12:01:33 +00:00
|
|
|
};
|
2017-09-10 18:04:22 +00:00
|
|
|
|
2018-03-21 11:57:23 +00:00
|
|
|
it(`should not find Deadpool as he's not created yet`, async() => {
|
|
|
|
let account = await app.models.Account.findOne({where: {name: newAccount.userName}});
|
|
|
|
let client = await app.models.Client.findOne({where: {name: newAccount.name}});
|
|
|
|
|
|
|
|
expect(account).toEqual(null);
|
|
|
|
expect(client).toEqual(null);
|
2018-01-16 20:39:40 +00:00
|
|
|
});
|
|
|
|
|
2018-03-21 11:57:23 +00:00
|
|
|
it('should create a new account', async() => {
|
|
|
|
let client = await app.models.Client.createWithUser(newAccount);
|
|
|
|
let account = await app.models.Account.findOne({where: {name: newAccount.userName}});
|
|
|
|
|
|
|
|
expect(account.name).toEqual(newAccount.userName);
|
|
|
|
|
|
|
|
client = await app.models.Client.findOne({where: {name: newAccount.name}});
|
|
|
|
|
|
|
|
expect(client.id).toEqual(account.id);
|
|
|
|
expect(client.name).toEqual(newAccount.name);
|
|
|
|
expect(client.email).toEqual(newAccount.email);
|
|
|
|
expect(client.fi).toEqual(newAccount.fi);
|
|
|
|
expect(client.socialName).toEqual(newAccount.socialName);
|
2018-01-17 11:46:26 +00:00
|
|
|
});
|
|
|
|
|
2018-03-21 11:57:23 +00:00
|
|
|
it('should find an existing account', async() => {
|
|
|
|
let account = await app.models.Account.findOne({where: {name: newAccount.userName}});
|
2018-01-17 11:46:26 +00:00
|
|
|
|
2018-03-21 11:57:23 +00:00
|
|
|
expect(account.name).toEqual(newAccount.userName);
|
|
|
|
});
|
2018-03-12 12:09:52 +00:00
|
|
|
|
2018-03-21 11:57:23 +00:00
|
|
|
it('should not be able to create a user if exists', async() => {
|
2018-03-12 12:09:52 +00:00
|
|
|
try {
|
2018-03-21 11:57:23 +00:00
|
|
|
let client = await app.models.Client.createWithUser(newAccount);
|
2018-03-12 12:09:52 +00:00
|
|
|
|
|
|
|
expect(client).toBeNull();
|
|
|
|
} catch (err) {
|
|
|
|
expect(err.details.codes.name[0]).toEqual('uniqueness');
|
|
|
|
}
|
2017-09-20 12:01:33 +00:00
|
|
|
});
|
|
|
|
});
|