const app = require(`${servicesDir}/client/server/server`); const restoreFixtures = require(`${servicesDir}/db/testing_fixtures`); describe('Client Create', () => { 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); }); afterAll(() => { restoreFixtures(sqlStatements); }); let newAccount = { userName: 'Deadpool', email: 'Deadpool@marvel.com', fi: '16195279J', name: 'Wade', socialName: 'Deadpool Marvel' }; 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); }); 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); }); it('should find an existing account', async() => { let account = await app.models.Account.findOne({where: {name: newAccount.userName}}); expect(account.name).toEqual(newAccount.userName); }); it('should not be able to create a user if exists', async() => { try { let client = await app.models.Client.createWithUser(newAccount); expect(client).toBeNull(); } catch (err) { expect(err.details.codes.name[0]).toEqual('uniqueness'); } }); });