<commit_before>/**
 * Copyright (c) 2016, salesforce.com, inc.
 * All rights reserved.
 * Licensed under the BSD 3-Clause license.
 * For full license text, see LICENSE.txt file in the repo root or
 * https://opensource.org/licenses/BSD-3-Clause
 */

/**
 * tests/db/model/aspect/find.js
 */
'use strict'; // eslint-disable-line strict
const expect = require('chai').expect;
const tu = require('../../../testUtils');
const u = require('./utils');
const Aspect = tu.db.Aspect;

describe('tests/db/model/aspect/find.js >', () => {
  before((done) => {
    u.createMedium()
    .then(() => {
      Aspect.create({
        name: 'luke',
        timeout: '1s',
        isPublished: true,
        tags: ['jedi', 'boring'],
      });
      Aspect.create({
        name: 'leia',
        timeout: '1m',
        isPublished: true,
        tags: ['princess', 'jedi'],
      });
    })
    .then(() => done())
    .catch(done);
  });

  after(u.forceDelete);

  describe('find by name >', () => {
    it('find by name, found', (done) => {
      Aspect.findOne({ where: { name: u.name } })
      .then((o) => {
        if (o === null) {
          done(new Error('expecting record to be found'));
        } else {
          done();
        }
      })
      .catch(done);
    });

    it('find by name, not found', (done) => {
      Aspect.findOne({ where: { name: 'x' } })
      .then((o) => {
        if (o === null) {
          done();
        } else {
          done(new Error('expecting record to not be found'));
        }
      })
      .catch(done);
    });
  });

  it('find by tag, found', (done) => {
    Aspect.findAll({
      where: { tags: { $contains: ['jedi'] } },
    })
    .then((o) => {
      if (o.length !== 2) {
        done(new Error('expecting two aspects'));
      }
    })
    .then(() => Aspect.findAll({
      where: { tags: { $contains: ['boring'] } },
    }))
    .then((o) => {
      if (o.length !== 1) {
        done(new Error('expecting one aspect'));
      }
    })
    .then(() => Aspect.findAll({
      where: { tags: { $contains: ['father'] } },
    }))
    .then((o) => {
      if (tu.gotArrayWithExpectedLength(o, 0)) {
        done();
      } else {
        done(new Error('expecting zero aspects'));
      }<commit_msg>fix aspect find flapper (#861)<commit_after>/**
 * Copyright (c) 2016, salesforce.com, inc.
 * All rights reserved.
 * Licensed under the BSD 3-Clause license.
 * For full license text, see LICENSE.txt file in the repo root or
 * https://opensource.org/licenses/BSD-3-Clause
 */

/**
 * tests/db/model/aspect/find.js
 */
'use strict'; // eslint-disable-line strict
const expect = require('chai').expect;
const tu = require('../../../testUtils');
const u = require('./utils');
const Aspect = tu.db.Aspect;

describe('tests/db/model/aspect/find.js >', () => {
  before((done) => {
    u.createMedium()
    .then(() => {
      Aspect.create({
        name: 'luke',
        timeout: '1s',
        isPublished: true,
        tags: ['jedi', 'boring'],
      });
      Aspect.create({
        name: 'leia',
        timeout: '1m',
        isPublished: true,
        tags: ['princess', 'jedi'],
      });
    })
    .then(() => done())
    .catch(done);
  });

  after(u.forceDelete);

  describe('find by name >', () => {
    it('find by name, found', (done) => {
      Aspect.findOne({ where: { name: u.name } })
      .then((o) => {
        if (o === null) {
          done(new Error('expecting record to be found'));
        } else {
          done();
        }
      })
      .catch(done);
    });

    it('find by name, not found', (done) => {
      Aspect.findOne({ where: { name: 'x' } })
      .then((o) => {
        if (o === null) {
          done();
        } else {
          done(new Error('expecting record to not be found'));
        }
      })
      .catch(done);
    });
  });

  it('find by tag, found', (done) => {
    Aspect.findAll({
      where: { tags: { $contains: ['jedi'] } },
    })
    .then((o) => {
      if (o.length !== 2) {
        return done(new Error('expecting two aspects'));
      }
    })
    .then(() => Aspect.findAll({
      where: { tags: { $contains: ['boring'] } },
    }))
    .then((o) => {
      if (o.length !== 1) {
        return done(new Error('expecting one aspect'));
      }
    })
    .then(() => Aspect.findAll({
      where: { tags: { $contains: ['father'] } },
    }))
    .then((o) => {
      if (tu.gotArrayWithExpectedLength(o, 0)) {
        return done();
      } else {
        return done(new Error('expecting zero aspects'));
      }
{'fraction_non_alphanumeric': 0.2051112579863406, 'fraction_numerical': 0.0055078211059704785, 'mean_word_length': 1.977049180327869, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 37, 'https://': 2, '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': '5083459', 'n_tokens_mistral': 1540, 'n_tokens_neox': 1497, 'n_words': 348}