<commit_before>var assert = require('assert');
var dbService = require('../model/service');

var currentDate = function(){
  var currentTime = new Date();
  return new Date(currentTime.getFullYear(), currentTime.getMonth(), currentTime.getDate());
};

var createUser1 = function(){
  return dbService.User.build({
    username: "user01",
    password: "<PASSWORD>"
  });
};

var createAccount1 = function(){
  return dbService.Account.build({
    name: "test account 1",
    balance: 0,
    currency: "RUB",
    includeInTotal: true,
    showInList: true
  });
};

var createTransaction1 = function(){
  return dbService.Transaction.build({
    description: "test transaction 1",
    type: "expenseincome",
    date: currentDate(),
    amount: 100
  });
};

var createTransactionComponent1 = function(){
  return dbService.TransactionComponent.build({
    amount: 100
  });
};


describe('Model', function() {
  beforeEach(function(done) {
    return dbService.sequelize.sync({force: true}).then(function(task){
      done();
    });
  });
  
  describe('populate', function () {
    it('should be able to create related entities in sequence', function (done) {
      var user1= createUser1();
      var account1 = createAccount1();
      var transaction1 = createTransaction1();
      var transactionComponent1 = createTransactionComponent1();
      user1.save().then(function(){
         return account1.save();
      }).then(function(){
         return user1.addAccount(account1);
      }).then(function(){
         return transaction1.save();
      }).then(function(){
        return user1.addTransaction(transaction1);
      }).then(function(){
         return transactionComponent1.save();
      }).then(function(){
        return transactionComponent1.setTransaction(transaction1);
      }).then(function(){
        return transactionComponent1.setAccount(account1);
      }).then(function(){
        return dbService.User.findAll({
          include: [dbService.Account, {model: dbService.Transaction, include: [dbService.TransactionComponent]}]
          //include: [{ all: true }]
        });
      }).then(function(users){
        assert.equal(users.length, 1, "check users count")
        var user = users[0];
        assert.equal(user.username, "user01", "check user01 username");
        assert.equal(user.password, "<PASSWORD>", "check user01 password");
        assert.equal(user.Accounts.length, 1, "check accounts count");
        var account = user.Accounts[0];
        assert.equal(account.name, "test account 1", "check account name");
        assert.equal(account.balance, 0, "check account balance");<commit_msg>Fixed indentation.<commit_after>var assert = require('assert');
var dbService = require('../model/service');

var currentDate = function(){
  var currentTime = new Date();
  return new Date(currentTime.getFullYear(), currentTime.getMonth(), currentTime.getDate());
};

var createUser1 = function(){
  return dbService.User.build({
    username: "user01",
    password: "<PASSWORD>"
  });
};

var createAccount1 = function(){
  return dbService.Account.build({
    name: "test account 1",
    balance: 0,
    currency: "RUB",
    includeInTotal: true,
    showInList: true
  });
};

var createTransaction1 = function(){
  return dbService.Transaction.build({
    description: "test transaction 1",
    type: "expenseincome",
    date: currentDate(),
    amount: 100
  });
};

var createTransactionComponent1 = function(){
  return dbService.TransactionComponent.build({
    amount: 100
  });
};


describe('Model', function() {
  beforeEach(function(done) {
    return dbService.sequelize.sync({force: true}).then(function(task){
      done();
    });
  });

  describe('populate', function () {
    it('should be able to create related entities in sequence', function (done) {
      var user1= createUser1();
      var account1 = createAccount1();
      var transaction1 = createTransaction1();
      var transactionComponent1 = createTransactionComponent1();
      user1.save().then(function(){
        return account1.save();
      }).then(function(){
        return user1.addAccount(account1);
      }).then(function(){
        return transaction1.save();
      }).then(function(){
        return user1.addTransaction(transaction1);
      }).then(function(){
        return transactionComponent1.save();
      }).then(function(){
        return transactionComponent1.setTransaction(transaction1);
      }).then(function(){
        return transactionComponent1.setAccount(account1);
      }).then(function(){
        return dbService.User.findAll({
          include: [dbService.Account, {model: dbService.Transaction, include: [dbService.TransactionComponent]}]
          //include: [{ all: true }]
        });
      }).then(function(users){
        assert.equal(users.length, 1, "check users count")
        var user = users[0];
        assert.equal(user.username, "user01", "check user01 username");
        assert.equal(user.password, "<PASSWORD>", "check user01 password");
        assert.equal(user.Accounts.length, 1, "check accounts count");
        var account = user.Accounts[0];
        assert.equal(account.name, "test account 1", "check account name");
        assert.equal(account.balance, 0, "check account balance");
{'fraction_non_alphanumeric': 0.14632757639020688, 'fraction_numerical': 0.017840197380907193, 'mean_word_length': 3.424853064651553, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7006412', 'n_tokens_mistral': 1470, 'n_tokens_neox': 1428, 'n_words': 340}