2018-05-09 12:37:14 -07:00
|
|
|
import { module, test } from 'qunit';
|
2018-05-14 23:47:00 -07:00
|
|
|
import { startMirage } from 'wherehows-web/initializers/ember-cli-mirage';
|
|
|
|
import datasetsCreateSearchEntries from 'wherehows-web/utils/datasets/create-search-entries';
|
2018-05-09 12:37:14 -07:00
|
|
|
import { testSchemaA } from 'wherehows-web/mirage/data/schema';
|
|
|
|
|
2018-05-10 23:10:49 -07:00
|
|
|
module('Unit | Utility | datasets/create search entries', {
|
2018-05-09 12:37:14 -07:00
|
|
|
beforeEach() {
|
2018-05-14 23:47:00 -07:00
|
|
|
this.server = startMirage();
|
2018-05-09 12:37:14 -07:00
|
|
|
},
|
|
|
|
afterEach() {
|
2018-05-14 23:47:00 -07:00
|
|
|
this.server.shutdown();
|
2018-05-09 12:37:14 -07:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
test('it works base case', function(assert) {
|
2018-05-14 23:47:00 -07:00
|
|
|
const { server } = this;
|
|
|
|
const dataset = server.create('dataset', 'forUnitTests');
|
2018-05-09 12:37:14 -07:00
|
|
|
|
2018-05-14 23:47:00 -07:00
|
|
|
const result = datasetsCreateSearchEntries([]);
|
2018-05-09 12:37:14 -07:00
|
|
|
assert.ok(!result, 'Returns without error for nothing case');
|
|
|
|
|
2018-05-14 23:47:00 -07:00
|
|
|
datasetsCreateSearchEntries([dataset]);
|
2018-05-09 12:37:14 -07:00
|
|
|
assert.equal(dataset.id, 0, 'Sanity check: Created model successfully');
|
|
|
|
assert.equal(dataset.schema, testSchemaA.slice(0, 499), 'Partial schema from beginning if no keyword found');
|
|
|
|
});
|
|
|
|
|
|
|
|
test('it works for keyword cases', function(assert) {
|
2018-05-14 23:47:00 -07:00
|
|
|
const { server } = this;
|
|
|
|
const dataset = server.create('dataset', 'forUnitTests');
|
2018-05-09 12:37:14 -07:00
|
|
|
|
2018-05-14 23:47:00 -07:00
|
|
|
datasetsCreateSearchEntries([dataset], 'Rebel');
|
2018-05-09 12:37:14 -07:00
|
|
|
assert.equal(dataset.id, 0, 'Sanity check: Created model successfully again');
|
|
|
|
assert.equal(dataset.schema, testSchemaA.slice(29, 529), 'Partial schema starts from keyword index');
|
|
|
|
});
|