2024-08-12 13:17:38 +03:00
|
|
|
import {authenticateSession} from 'ember-simple-auth/test-support';
|
2024-05-08 19:04:05 +03:00
|
|
|
import {describe, it} from 'mocha';
|
|
|
|
import {expect} from 'chai';
|
|
|
|
import {setupMirage} from 'ember-cli-mirage/test-support';
|
|
|
|
import {setupTest} from 'ember-mocha';
|
|
|
|
|
2024-08-12 13:17:38 +03:00
|
|
|
// we have two search providers
|
|
|
|
// - "flex" which uses the flexsearch engine but is limited to english only
|
|
|
|
// - "basic" which uses exact string matches in a less performant way but is language agnostic
|
2024-06-11 18:47:54 +03:00
|
|
|
const suites = [{
|
2024-08-12 13:17:38 +03:00
|
|
|
name: 'Integration: Service: Search (flex)',
|
2024-06-11 18:47:54 +03:00
|
|
|
beforeEach() {
|
2024-08-12 13:17:38 +03:00
|
|
|
// noop - default locale is 'en'
|
|
|
|
},
|
|
|
|
confirmProvider() {
|
|
|
|
const searchService = this.owner.lookup('service:search');
|
|
|
|
expect(searchService.provider.constructor.name, 'provider name').to.equal('SearchProviderFlexService');
|
2024-06-11 18:47:54 +03:00
|
|
|
}
|
|
|
|
}, {
|
2024-08-12 13:17:38 +03:00
|
|
|
name: 'Integration: Service: Search (basic)',
|
2024-06-11 18:47:54 +03:00
|
|
|
beforeEach() {
|
2024-08-12 13:17:38 +03:00
|
|
|
this.server.db.settings.update({key: 'locale'}, {value: 'de'});
|
|
|
|
},
|
|
|
|
confirmProvider() {
|
|
|
|
const settingsService = this.owner.lookup('service:settings');
|
|
|
|
expect(settingsService.locale, 'settings.locale').to.equal('de');
|
|
|
|
const searchService = this.owner.lookup('service:search');
|
|
|
|
expect(searchService.provider.constructor.name, 'provider name').to.equal('SearchProviderBasicService');
|
2024-06-11 18:47:54 +03:00
|
|
|
}
|
|
|
|
}];
|
2024-05-08 19:04:05 +03:00
|
|
|
|
2024-06-11 18:47:54 +03:00
|
|
|
suites.forEach((suite) => {
|
|
|
|
describe(suite.name, function () {
|
|
|
|
const hooks = setupTest();
|
|
|
|
setupMirage(hooks);
|
2024-05-08 19:04:05 +03:00
|
|
|
|
2024-06-11 18:47:54 +03:00
|
|
|
let search;
|
|
|
|
// eslint-disable-next-line no-unused-vars
|
|
|
|
let firstUser, firstPost, secondPost, firstPage, firstTag;
|
2024-05-08 19:04:05 +03:00
|
|
|
|
2024-08-12 13:17:38 +03:00
|
|
|
beforeEach(async function () {
|
|
|
|
this.server.loadFixtures();
|
|
|
|
await authenticateSession();
|
|
|
|
|
2024-06-11 18:47:54 +03:00
|
|
|
suite.beforeEach.bind(this)();
|
|
|
|
|
2024-08-12 13:17:38 +03:00
|
|
|
const settings = this.owner.lookup('service:settings');
|
|
|
|
await settings.fetch();
|
|
|
|
|
2024-06-11 18:47:54 +03:00
|
|
|
search = this.owner.lookup('service:search');
|
|
|
|
|
|
|
|
// populate store with data we'll be searching
|
|
|
|
firstPost = this.server.create('post', {title: 'First post', slug: 'first-post', visibility: 'members', publishedAt: '2024-05-08T16:21:07.000Z'});
|
|
|
|
secondPost = this.server.create('post', {title: 'Second post', slug: 'second-post'});
|
|
|
|
firstPage = this.server.create('page', {title: 'First page', slug: 'first-page'});
|
|
|
|
firstTag = this.server.create('tag', {name: 'First tag', slug: 'first-tag'});
|
|
|
|
});
|
|
|
|
|
2024-08-12 13:17:38 +03:00
|
|
|
it('is using correct provider', async function () {
|
|
|
|
suite.confirmProvider.bind(this)();
|
|
|
|
});
|
|
|
|
|
2024-06-11 18:47:54 +03:00
|
|
|
it('returns urls for search results', async function () {
|
|
|
|
const results = await search.searchTask.perform('first');
|
|
|
|
|
|
|
|
expect(results[0].options[0].url).to.equal('http://localhost:4200/tag/first-tag/');
|
|
|
|
expect(results[1].options[0].url).to.equal('http://localhost:4200/p/post-0/');
|
|
|
|
expect(results[2].options[0].url).to.equal('http://localhost:4200/p/page-0/');
|
|
|
|
});
|
2024-05-08 19:04:05 +03:00
|
|
|
|
2024-06-11 18:47:54 +03:00
|
|
|
it('returns additional post-related fields', async function () {
|
|
|
|
const results = await search.searchTask.perform('post');
|
2024-05-08 19:04:05 +03:00
|
|
|
|
2024-06-11 18:47:54 +03:00
|
|
|
expect(results[0].options[0].visibility).to.equal('members');
|
|
|
|
expect(results[0].options[0].publishedAt).to.equal('2024-05-08T16:21:07.000Z');
|
|
|
|
});
|
2024-05-08 19:04:05 +03:00
|
|
|
});
|
|
|
|
});
|