|
| 1 | +import { searchClient, dataset, Movies } from './assets/utils' |
| 2 | + |
| 3 | +describe('Instant MeiliSearch Browser test', () => { |
| 4 | + beforeAll(async () => { |
| 5 | + try { |
| 6 | + await searchClient.MeiliSearchClient.deleteIndex('movies') |
| 7 | + } catch (e) { |
| 8 | + // movies does not exist |
| 9 | + } |
| 10 | + const moviesUpdate = await searchClient.MeiliSearchClient.index( |
| 11 | + 'movies' |
| 12 | + ).addDocuments(dataset) |
| 13 | + await searchClient.MeiliSearchClient.index('movies').waitForPendingUpdate( |
| 14 | + moviesUpdate.updateId |
| 15 | + ) |
| 16 | + }) |
| 17 | + |
| 18 | + test('Test multiple filters', async () => { |
| 19 | + const response = await searchClient.search([ |
| 20 | + { |
| 21 | + indexName: 'movies', |
| 22 | + params: { |
| 23 | + filters: |
| 24 | + 'title = "Four Rooms" OR title = "Ariel" AND release_date > 593395200', |
| 25 | + query: '', |
| 26 | + }, |
| 27 | + }, |
| 28 | + ]) |
| 29 | + |
| 30 | + const hit = <Movies>response.results[0].hits[0] |
| 31 | + expect(hit.title).toEqual('Four Rooms') |
| 32 | + }) |
| 33 | + |
| 34 | + test('Test empty', async () => { |
| 35 | + const response = await searchClient.search([ |
| 36 | + { |
| 37 | + indexName: 'movies', |
| 38 | + params: { |
| 39 | + filters: '', |
| 40 | + query: '', |
| 41 | + }, |
| 42 | + }, |
| 43 | + ]) |
| 44 | + |
| 45 | + const hit = <Movies>response.results[0].hits[0] |
| 46 | + expect(hit.title).toEqual('Ariel') |
| 47 | + }) |
| 48 | + |
| 49 | + test('Test multiple filters', async () => { |
| 50 | + const response = await searchClient.search([ |
| 51 | + { |
| 52 | + indexName: 'movies', |
| 53 | + params: { |
| 54 | + filters: 'title = "Four Rooms" OR title = "Ariel"', |
| 55 | + numericFilters: ['release_date > 593395200'], |
| 56 | + query: '', |
| 57 | + }, |
| 58 | + }, |
| 59 | + ]) |
| 60 | + |
| 61 | + const hit = <Movies>response.results[0].hits[0] |
| 62 | + expect(hit.title).toEqual('Four Rooms') |
| 63 | + }) |
| 64 | + |
| 65 | + test('Only numeric filters', async () => { |
| 66 | + const response = await searchClient.search([ |
| 67 | + { |
| 68 | + indexName: 'movies', |
| 69 | + params: { |
| 70 | + filters: 'title = "Four Rooms" OR title = "Ariel"', |
| 71 | + numericFilters: ['release_date > 593395200'], |
| 72 | + query: '', |
| 73 | + }, |
| 74 | + }, |
| 75 | + ]) |
| 76 | + |
| 77 | + const hit = <Movies>response.results[0].hits[0] |
| 78 | + expect(hit.title).toEqual('Four Rooms') |
| 79 | + }) |
| 80 | +}) |
0 commit comments