From 7858061bfd0bab1bdb188a9704579b05a34477d3 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Fri, 6 Jan 2023 17:11:40 +0100 Subject: [PATCH] test api search in non-English (#33786) --- .github/workflows/test.yml | 4 ++-- .gitignore | 1 - tests/translations/api-search.js | 41 ++++++++++++++++++++++++++++++++ 3 files changed, 43 insertions(+), 3 deletions(-) create mode 100644 tests/translations/api-search.js diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 8d20dd7588..2f6f3b897b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -51,7 +51,7 @@ jobs: - name: Install a local Elasticsearch for testing # For the sake of saving time, only run this step if the test-group # is one that will run tests against an Elasticsearch on localhost. - if: ${{ matrix.test-group == 'content' }} + if: ${{ matrix.test-group == 'content' || matrix.test-group == 'translations' }} uses: getong/elasticsearch-action@95b501ab0c83dee0aac7c39b7cea3723bef14954 with: # Make sure this matches production and `sync-search-pr.yml` @@ -222,7 +222,7 @@ jobs: - name: Index fixtures into the local Elasticsearch # For the sake of saving time, only run this step if the test-group # is one that will run tests against an Elasticsearch on localhost. - if: ${{ matrix.test-group == 'content' }} + if: ${{ matrix.test-group == 'content' || matrix.test-group == 'translations' }} run: npm run index-test-fixtures - name: Run tests diff --git a/.gitignore b/.gitignore index 440d93fbab..a11e3bcdda 100644 --- a/.gitignore +++ b/.gitignore @@ -14,7 +14,6 @@ coverage/ .next .eslintcache *.tsbuildinfo -translations/ # blc: broken link checker blc_output.log diff --git a/tests/translations/api-search.js b/tests/translations/api-search.js new file mode 100644 index 0000000000..7d7ec39366 --- /dev/null +++ b/tests/translations/api-search.js @@ -0,0 +1,41 @@ +import { jest, test, expect } from '@jest/globals' + +import { describeIfElasticsearchURL } from '../helpers/conditional-runs.js' +import { get } from '../helpers/e2etest.js' + +// This suite only runs if $ELASTICSEARCH_URL is set. +describeIfElasticsearchURL('search v1 middleware in non-English', () => { + jest.setTimeout(60 * 1000) + + test('basic search in Japanese', async () => { + const sp = new URLSearchParams() + // To see why this will work, + // see tests/content/fixtures/search-indexes/github-docs-dotcom-en-records.json + // which clearly has a record with the title "Foo" + sp.set('query', 'foo') + sp.set('language', 'ja') + const res = await get('/api/search/v1?' + sp) + expect(res.statusCode).toBe(200) + const results = JSON.parse(res.text) + + expect(results.meta).toBeTruthy() + expect(results.meta.found.value).toBeGreaterThanOrEqual(1) + expect(results.meta.found.relation).toBeTruthy() + expect(results.meta.page).toBe(1) + expect(results.meta.size).toBeGreaterThanOrEqual(1) + expect(results.meta.took.query_msec).toBeGreaterThanOrEqual(0) + expect(results.meta.took.total_msec).toBeGreaterThanOrEqual(0) + + // Might be empty but at least an array + expect(results.hits).toBeTruthy() + // The word 'foo' appears in more than 1 document in the fixtures. + expect(results.hits.length).toBeGreaterThanOrEqual(1) + // ...but only one has the word "foo" in its title so we can + // be certain it comes first. + const hit = results.hits[0] + // This specifically checks what we expect of version v1 + expect(hit.url).toBe('/ja/foo') + expect(hit.title).toBe('フー') + expect(hit.breadcrumbs).toBe('fooing') + }) +})