|
| 1 | +import { jest, test, expect } from '@jest/globals' |
| 2 | + |
| 3 | +import { describeIfElasticsearchURL } from '../helpers/conditional-runs.js' |
| 4 | +import { get } from '../helpers/e2etest.js' |
| 5 | + |
| 6 | +// This suite only runs if $ELASTICSEARCH_URL is set. |
| 7 | +describeIfElasticsearchURL('search v1 middleware in non-English', () => { |
| 8 | + jest.setTimeout(60 * 1000) |
| 9 | + |
| 10 | + test('basic search in Japanese', async () => { |
| 11 | + const sp = new URLSearchParams() |
| 12 | + // To see why this will work, |
| 13 | + // see tests/content/fixtures/search-indexes/github-docs-dotcom-en-records.json |
| 14 | + // which clearly has a record with the title "Foo" |
| 15 | + sp.set('query', 'foo') |
| 16 | + sp.set('language', 'ja') |
| 17 | + const res = await get('/api/search/v1?' + sp) |
| 18 | + expect(res.statusCode).toBe(200) |
| 19 | + const results = JSON.parse(res.text) |
| 20 | + |
| 21 | + expect(results.meta).toBeTruthy() |
| 22 | + expect(results.meta.found.value).toBeGreaterThanOrEqual(1) |
| 23 | + expect(results.meta.found.relation).toBeTruthy() |
| 24 | + expect(results.meta.page).toBe(1) |
| 25 | + expect(results.meta.size).toBeGreaterThanOrEqual(1) |
| 26 | + expect(results.meta.took.query_msec).toBeGreaterThanOrEqual(0) |
| 27 | + expect(results.meta.took.total_msec).toBeGreaterThanOrEqual(0) |
| 28 | + |
| 29 | + // Might be empty but at least an array |
| 30 | + expect(results.hits).toBeTruthy() |
| 31 | + // The word 'foo' appears in more than 1 document in the fixtures. |
| 32 | + expect(results.hits.length).toBeGreaterThanOrEqual(1) |
| 33 | + // ...but only one has the word "foo" in its title so we can |
| 34 | + // be certain it comes first. |
| 35 | + const hit = results.hits[0] |
| 36 | + // This specifically checks what we expect of version v1 |
| 37 | + expect(hit.url).toBe('/ja/foo') |
| 38 | + expect(hit.title).toBe('フー') |
| 39 | + expect(hit.breadcrumbs).toBe('fooing') |
| 40 | + }) |
| 41 | +}) |
0 commit comments