const app = require(`${servicesDir}/client/server/server`); describe('Client Create', () => { 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); }); */ 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); }); 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'); } }); });