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

66 lines
2.2 KiB
JavaScript
Raw Normal View History

const app = require(`${servicesDir}/client/server/server`);
const restoreFixtures = require(`${servicesDir}/db/testing_fixtures`);
describe('Client Create', () => {
let sqlStatements = {deletes: `
2018-03-21 11:57:23 +00:00
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);
});
afterAll(() => {
restoreFixtures(sqlStatements);
});
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');
}
});
});