Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7858061

Browse files
author
Peter Bengtsson
authored
test api search in non-English (#33786)
1 parent d7950bb commit 7858061

3 files changed

Lines changed: 43 additions & 3 deletions

File tree

.github/workflows/test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ jobs:
5151
- name: Install a local Elasticsearch for testing
5252
# For the sake of saving time, only run this step if the test-group
5353
# is one that will run tests against an Elasticsearch on localhost.
54-
if: ${{ matrix.test-group == 'content' }}
54+
if: ${{ matrix.test-group == 'content' || matrix.test-group == 'translations' }}
5555
uses: getong/elasticsearch-action@95b501ab0c83dee0aac7c39b7cea3723bef14954
5656
with:
5757
# Make sure this matches production and `sync-search-pr.yml`
@@ -222,7 +222,7 @@ jobs:
222222
- name: Index fixtures into the local Elasticsearch
223223
# For the sake of saving time, only run this step if the test-group
224224
# is one that will run tests against an Elasticsearch on localhost.
225-
if: ${{ matrix.test-group == 'content' }}
225+
if: ${{ matrix.test-group == 'content' || matrix.test-group == 'translations' }}
226226
run: npm run index-test-fixtures
227227

228228
- name: Run tests

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ coverage/
1414
.next
1515
.eslintcache
1616
*.tsbuildinfo
17-
translations/
1817

1918
# blc: broken link checker
2019
blc_output.log

tests/translations/api-search.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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

Comments
 (0)