<commit_before>import {assert} from 'chai';
import {Wetland} from '../../src/Wetland';
import {Criteria} from '../../src/Criteria/Criteria';
import {Mapping} from '../../src/Mapping';
import {Delivery} from '../resource/entity/postal/Delivery';
import {Address} from '../resource/entity/postal/Address';
import {Order} from '../resource/entity/postal/Order';
import {Tracker} from '../resource/entity/postal/Tracker';
import {User} from '../resource/entity/postal/User';
import {queries} from '../resource/queries';

function getMappings() {
  return {
    a: Mapping.forEntity(Address),
    d: Mapping.forEntity(Delivery),
    o: Mapping.forEntity(Order),
    t: Mapping.forEntity(Tracker),
    u: Mapping.forEntity(User)
  };
}

function getStatement(wetland, table, alias) {
  return wetland.getStore().getConnection()(`${table} as ${alias}`);
}

let wetland = new Wetland({
  entityPath: __dirname + '/../resource/entity/postal',
  stores    : {
    defaultStore: {
      client    : 'mysql',
      connection: {
        user    : 'root',
        host    : '127.0.0.1',
        database: 'wetland_test'
      }
    }
  }
});

describe('Criteria', () => {
  describe('.apply()', () => {
    it('should compose a simple where query', () => {
      let withAlias     = getStatement(wetland, 'delivery', 'd');
      let criteriaAlias = new Criteria(withAlias, Mapping.forEntity(Delivery), getMappings());<commit_msg>test(Criteria): add tests for default host alias<commit_after>import {assert} from 'chai';
import {Wetland} from '../../src/Wetland';
import {Criteria} from '../../src/Criteria/Criteria';
import {Mapping} from '../../src/Mapping';
import {Delivery} from '../resource/entity/postal/Delivery';
import {Address} from '../resource/entity/postal/Address';
import {Order} from '../resource/entity/postal/Order';
import {Tracker} from '../resource/entity/postal/Tracker';
import {User} from '../resource/entity/postal/User';
import {queries} from '../resource/queries';

function getMappings() {
  return {
    a: Mapping.forEntity(Address),
    d: Mapping.forEntity(Delivery),
    o: Mapping.forEntity(Order),
    t: Mapping.forEntity(Tracker),
    u: Mapping.forEntity(User)
  };
}

function getStatement(wetland, table, alias) {
  return wetland.getStore().getConnection()(`${table} as ${alias}`);
}

let wetland = new Wetland({
  entityPath: __dirname + '/../resource/entity/postal',
  stores    : {
    defaultStore: {
      client    : 'mysql',
      connection: {
        user    : 'root',
        host    : '127.0.0.1',
        database: 'wetland_test'
      }
    }
  }
});

describe('Criteria', () => {
  describe('.mapToColumn()', () => {
    it('should apply provided columns to an alias, when set and found.', () => {
      let withAlias = getStatement(wetland, 'delivery', 'd');
      let criteria  = new Criteria(withAlias, Mapping.forEntity(Delivery), getMappings(), 'd');

      let mappedId       = criteria.mapToColumn('id');
      let mappedCreated  = criteria.mapToColumn('created');
      let mappedNonsense = criteria.mapToColumn('nonsense');

      assert.strictEqual(mappedId, 'd.id');
      assert.strictEqual(mappedCreated, 'd.created');
      assert.strictEqual(mappedNonsense, 'nonsense');
    });

    it('should not apply provided columns to an alias, when not set.', () => {
      let withAlias = getStatement(wetland, 'delivery', 'd');
      let criteria  = new Criteria(withAlias, Mapping.forEntity(Delivery), getMappings());

      let mappedId       = criteria.mapToColumn('id');
      let mappedCreated  = criteria.mapToColumn('created');
      let mappedNonsense = criteria.mapToColumn('nonsense');

      assert.strictEqual(mappedId, 'id');
      assert.strictEqual(mappedCreated, 'created');
      assert.strictEqual(mappedNonsense, 'nonsense');
    });
  });

  describe('.apply()', () => {
    it('should compose a simple where query', () => {
      let withAlias     = getStatement(wetland, 'delivery', 'd');
      let criteriaAlias = new Criteria(withAlias, Mapping.forEntity(Delivery), getMappings());
{'fraction_non_alphanumeric': 0.17090012330456228, 'fraction_numerical': 0.002959309494451295, 'mean_word_length': 3.4867256637168142, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '7218698', 'n_tokens_mistral': 1256, 'n_tokens_neox': 1241, 'n_words': 277}