salix/services/loopback/common/methods/client/specs/createWithUser.spec.js

71 lines
2.7 KiB
JavaScript
Raw Normal View History

const app = require(`${servicesDir}/client/server/server`);
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-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-03-21 11:57:23 +00:00
let newAccount = {
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'
};
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-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-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-03-21 11:57:23 +00:00
expect(account.name).toEqual(newAccount.userName);
});
2018-03-21 11:57:23 +00:00
it('should not be able to create a user if exists', async() => {
try {
2018-03-21 11:57:23 +00:00
let client = await app.models.Client.createWithUser(newAccount);
expect(client).toBeNull();
} catch (err) {
expect(err.details.codes.name[0]).toEqual('uniqueness');
}
});
});