|
4 | 4 | describe '#create_index' do |
5 | 5 | context 'without a primary key' do |
6 | 6 | it 'creates an index' do |
7 | | - task = client.create_index('new_index') |
| 7 | + task = client.create_index('books') |
8 | 8 |
|
9 | 9 | expect(task['type']).to eq('indexCreation') |
10 | 10 |
|
11 | 11 | client.wait_for_task(task['taskUid']) |
12 | | - index = client.fetch_index('new_index') |
| 12 | + index = client.fetch_index('books') |
13 | 13 |
|
14 | 14 | expect(index).to be_a(MeiliSearch::Index) |
15 | | - expect(index.uid).to eq('new_index') |
| 15 | + expect(index.uid).to eq('books') |
16 | 16 | expect(index.primary_key).to be_nil |
17 | 17 | end |
18 | 18 |
|
19 | 19 | it 'creates an index synchronously' do |
20 | | - task = client.create_index!('new_index') |
| 20 | + task = client.create_index!('books') |
21 | 21 |
|
22 | 22 | expect(task['type']).to eq('indexCreation') |
23 | 23 | expect(task['status']).to eq('succeeded') |
24 | 24 |
|
25 | | - index = client.fetch_index('new_index') |
| 25 | + index = client.fetch_index('books') |
26 | 26 |
|
27 | 27 | expect(index).to be_a(MeiliSearch::Index) |
28 | | - expect(index.uid).to eq('new_index') |
| 28 | + expect(index.uid).to eq('books') |
29 | 29 | expect(index.primary_key).to be_nil |
30 | 30 | end |
31 | 31 | end |
32 | 32 |
|
33 | 33 | context 'with a primary key' do |
34 | 34 | it 'creates an index' do |
35 | | - task = client.create_index('new_index', primaryKey: 'primary_key') |
| 35 | + task = client.create_index('books', primaryKey: 'reference_code') |
36 | 36 |
|
37 | 37 | expect(task['type']).to eq('indexCreation') |
38 | 38 |
|
39 | 39 | client.wait_for_task(task['taskUid']) |
40 | | - index = client.fetch_index('new_index') |
| 40 | + index = client.fetch_index('books') |
41 | 41 |
|
42 | 42 | expect(index).to be_a(MeiliSearch::Index) |
43 | | - expect(index.uid).to eq('new_index') |
44 | | - expect(index.primary_key).to eq('primary_key') |
45 | | - expect(index.fetch_primary_key).to eq('primary_key') |
| 43 | + expect(index.uid).to eq('books') |
| 44 | + expect(index.primary_key).to eq('reference_code') |
| 45 | + expect(index.fetch_primary_key).to eq('reference_code') |
46 | 46 | end |
47 | 47 |
|
48 | 48 | it 'creates an index synchronously' do |
49 | | - task = client.create_index!('new_index', primaryKey: 'primary_key') |
| 49 | + task = client.create_index!('books', primaryKey: 'reference_code') |
50 | 50 |
|
51 | 51 | expect(task['type']).to eq('indexCreation') |
52 | 52 | expect(task['status']).to eq('succeeded') |
53 | 53 |
|
54 | | - index = client.fetch_index('new_index') |
| 54 | + index = client.fetch_index('books') |
55 | 55 |
|
56 | 56 | expect(index).to be_a(MeiliSearch::Index) |
57 | | - expect(index.uid).to eq('new_index') |
58 | | - expect(index.primary_key).to eq('primary_key') |
59 | | - expect(index.fetch_primary_key).to eq('primary_key') |
| 57 | + expect(index.uid).to eq('books') |
| 58 | + expect(index.primary_key).to eq('reference_code') |
| 59 | + expect(index.fetch_primary_key).to eq('reference_code') |
60 | 60 | end |
61 | 61 |
|
62 | 62 | context 'when primary key option in snake_case' do |
63 | 63 | it 'creates an index' do |
64 | | - task = client.create_index('new_index', primary_key: 'primary_key') |
| 64 | + task = client.create_index('books', primary_key: 'reference_code') |
65 | 65 | expect(task['type']).to eq('indexCreation') |
66 | 66 | client.wait_for_task(task['taskUid']) |
67 | 67 |
|
68 | | - index = client.fetch_index('new_index') |
| 68 | + index = client.fetch_index('books') |
69 | 69 | expect(index).to be_a(MeiliSearch::Index) |
70 | | - expect(index.uid).to eq('new_index') |
71 | | - expect(index.primary_key).to eq('primary_key') |
72 | | - expect(index.fetch_primary_key).to eq('primary_key') |
| 70 | + expect(index.uid).to eq('books') |
| 71 | + expect(index.primary_key).to eq('reference_code') |
| 72 | + expect(index.fetch_primary_key).to eq('reference_code') |
73 | 73 | end |
74 | 74 | end |
75 | 75 |
|
76 | 76 | context 'when uid is provided as an option' do |
77 | 77 | it 'ignores the uid option' do |
78 | 78 | task = client.create_index( |
79 | | - 'new_index', |
80 | | - primaryKey: 'primary_key', |
81 | | - uid: 'not_primary_key' |
| 79 | + 'books', |
| 80 | + primaryKey: 'reference_code', |
| 81 | + uid: 'publications' |
82 | 82 | ) |
83 | 83 |
|
84 | 84 | expect(task['type']).to eq('indexCreation') |
85 | 85 |
|
86 | 86 | client.wait_for_task(task['taskUid']) |
87 | | - index = client.fetch_index('new_index') |
| 87 | + index = client.fetch_index('books') |
88 | 88 |
|
89 | 89 | expect(index).to be_a(MeiliSearch::Index) |
90 | | - expect(index.uid).to eq('new_index') |
91 | | - expect(index.primary_key).to eq('primary_key') |
92 | | - expect(index.fetch_primary_key).to eq('primary_key') |
| 90 | + expect(index.uid).to eq('books') |
| 91 | + expect(index.primary_key).to eq('reference_code') |
| 92 | + expect(index.fetch_primary_key).to eq('reference_code') |
93 | 93 | end |
94 | 94 | end |
95 | 95 | end |
96 | 96 |
|
97 | 97 | context 'when an index with a given uid already exists' do |
98 | 98 | it 'returns a failing task' do |
99 | | - initial_task = client.create_index!('existing_index') |
100 | | - last_task = client.create_index!('existing_index') |
| 99 | + initial_task = client.create_index!('books') |
| 100 | + last_task = client.create_index!('books') |
101 | 101 |
|
102 | 102 | expect(initial_task['type']).to eq('indexCreation') |
103 | 103 | expect(last_task['type']).to eq('indexCreation') |
|
110 | 110 | context 'when the uid format is invalid' do |
111 | 111 | it 'raises an error' do |
112 | 112 | expect do |
113 | | - client.create_index('two words') |
| 113 | + client.create_index('ancient books') |
114 | 114 | end.to raise_meilisearch_api_error_with(400, 'invalid_index_uid', 'invalid_request') |
115 | 115 | end |
116 | 116 | end |
117 | 117 | end |
118 | 118 |
|
119 | 119 | describe '#indexes' do |
120 | 120 | it 'returns MeiliSearch::Index objects' do |
121 | | - client.create_index!('index') |
| 121 | + client.create_index!('books') |
122 | 122 |
|
123 | 123 | index = client.indexes['results'].first |
124 | 124 |
|
125 | 125 | expect(index).to be_a(MeiliSearch::Index) |
126 | 126 | end |
127 | 127 |
|
128 | 128 | it 'gets a list of indexes' do |
129 | | - ['first_index', 'second_index', 'third_index'].each { |name| client.create_index!(name) } |
| 129 | + ['books', 'colors', 'artists'].each { |name| client.create_index!(name) } |
130 | 130 |
|
131 | 131 | indexes = client.indexes['results'] |
132 | 132 |
|
133 | 133 | expect(indexes).to be_a(Array) |
134 | 134 | expect(indexes.length).to eq(3) |
135 | 135 | uids = indexes.map(&:uid) |
136 | | - expect(uids).to contain_exactly('first_index', 'second_index', 'third_index') |
| 136 | + expect(uids).to contain_exactly('books', 'colors', 'artists') |
137 | 137 | end |
138 | 138 |
|
139 | 139 | it 'paginates indexes list with limit and offset' do |
140 | | - ['first_index', 'second_index', 'third_index'].each { |name| client.create_index!(name) } |
| 140 | + ['books', 'colors', 'artists'].each { |name| client.create_index!(name) } |
141 | 141 |
|
142 | 142 | indexes = client.indexes(limit: 1, offset: 2) |
143 | 143 |
|
144 | 144 | expect(indexes['results']).to be_a(Array) |
145 | 145 | expect(indexes['total']).to eq(3) |
146 | 146 | expect(indexes['limit']).to eq(1) |
147 | 147 | expect(indexes['offset']).to eq(2) |
148 | | - expect(indexes['results'].map(&:uid)).to eq(['third_index']) |
| 148 | + expect(indexes['results'].map(&:uid)).to eq(['colors']) |
149 | 149 | end |
150 | 150 | end |
151 | 151 |
|
|
160 | 160 | end |
161 | 161 |
|
162 | 162 | it 'gets a list of raw indexes' do |
163 | | - ['first_index', 'second_index', 'third_index'].each { |name| client.create_index!(name) } |
| 163 | + ['books', 'colors', 'artists'].each { |name| client.create_index!(name) } |
164 | 164 |
|
165 | 165 | indexes = client.raw_indexes['results'] |
166 | 166 |
|
167 | 167 | expect(indexes).to be_a(Array) |
168 | 168 | expect(indexes.length).to eq(3) |
169 | 169 | uids = indexes.map { |elem| elem['uid'] } |
170 | | - expect(uids).to contain_exactly('first_index', 'second_index', 'third_index') |
| 170 | + expect(uids).to contain_exactly('books', 'colors', 'artists') |
171 | 171 | end |
172 | 172 | end |
173 | 173 |
|
174 | 174 | describe '#fetch_index' do |
175 | 175 | it 'fetches index by uid' do |
176 | | - client.create_index!('new_index', primaryKey: 'primary_key') |
| 176 | + client.create_index!('books', primaryKey: 'reference_code') |
177 | 177 |
|
178 | | - fetched_index = client.fetch_index('new_index') |
| 178 | + fetched_index = client.fetch_index('books') |
179 | 179 |
|
180 | 180 | expect(fetched_index).to be_a(MeiliSearch::Index) |
181 | | - expect(fetched_index.uid).to eq('new_index') |
182 | | - expect(fetched_index.primary_key).to eq('primary_key') |
183 | | - expect(fetched_index.fetch_primary_key).to eq('primary_key') |
| 181 | + expect(fetched_index.uid).to eq('books') |
| 182 | + expect(fetched_index.primary_key).to eq('reference_code') |
| 183 | + expect(fetched_index.fetch_primary_key).to eq('reference_code') |
184 | 184 | end |
185 | 185 | end |
186 | 186 |
|
187 | 187 | describe '#fetch_raw_index' do |
188 | 188 | it 'fetch a specific index raw Hash response based on uid' do |
189 | | - client.create_index!('specific_index_fetch_raw', primaryKey: 'primary_key') |
190 | | - index = client.fetch_index('specific_index_fetch_raw') |
| 189 | + client.create_index!('books', primaryKey: 'reference_code') |
| 190 | + index = client.fetch_index('books') |
191 | 191 | raw_response = index.fetch_raw_info |
192 | 192 |
|
193 | 193 | expect(raw_response).to be_a(Hash) |
194 | | - expect(raw_response['uid']).to eq('specific_index_fetch_raw') |
195 | | - expect(raw_response['primaryKey']).to eq('primary_key') |
| 194 | + expect(raw_response['uid']).to eq('books') |
| 195 | + expect(raw_response['primaryKey']).to eq('reference_code') |
196 | 196 | expect(Time.parse(raw_response['createdAt'])).to be_a(Time) |
197 | 197 | expect(Time.parse(raw_response['createdAt'])).to be_within(60).of(Time.now) |
198 | 198 | expect(Time.parse(raw_response['updatedAt'])).to be_a(Time) |
|
202 | 202 |
|
203 | 203 | describe '#index' do |
204 | 204 | it 'returns an index object with the provided uid' do |
205 | | - client.create_index!('existing_index', primaryKey: 'primary_key') |
| 205 | + client.create_index!('books', primaryKey: 'reference_code') |
206 | 206 | # this index is in memory, without metadata from server |
207 | | - index = client.index('existing_index') |
| 207 | + index = client.index('books') |
208 | 208 |
|
209 | 209 | expect(index).to be_a(MeiliSearch::Index) |
210 | | - expect(index.uid).to eq('existing_index') |
| 210 | + expect(index.uid).to eq('books') |
211 | 211 | expect(index.primary_key).to be_nil |
212 | 212 |
|
213 | 213 | # fetch primary key metadata from server |
214 | | - expect(index.fetch_primary_key).to eq('primary_key') |
215 | | - expect(index.primary_key).to eq('primary_key') |
| 214 | + expect(index.fetch_primary_key).to eq('reference_code') |
| 215 | + expect(index.primary_key).to eq('reference_code') |
216 | 216 | end |
217 | 217 | end |
218 | 218 |
|
219 | 219 | describe '#delete_index' do |
220 | 220 | context 'when the index exists' do |
221 | 221 | it 'deletes the index' do |
222 | | - client.create_index!('existing_index') |
223 | | - task = client.delete_index('existing_index') |
| 222 | + client.create_index!('books') |
| 223 | + task = client.delete_index('books') |
224 | 224 |
|
225 | 225 | expect(task['type']).to eq('indexDeletion') |
226 | 226 |
|
227 | 227 | achieved_task = client.wait_for_task(task['taskUid']) |
228 | 228 |
|
229 | 229 | expect(achieved_task['status']).to eq('succeeded') |
230 | | - expect { client.fetch_index('existing_index') }.to raise_index_not_found_meilisearch_api_error |
| 230 | + expect { client.fetch_index('books') }.to raise_index_not_found_meilisearch_api_error |
231 | 231 | end |
232 | 232 | end |
233 | 233 |
|
234 | 234 | context 'when the index does not exist' do |
235 | 235 | it 'raises an index not found error' do |
236 | | - expect { client.fetch_index('index_does_not_exist') }.to raise_index_not_found_meilisearch_api_error |
| 236 | + expect { client.fetch_index('books') }.to raise_index_not_found_meilisearch_api_error |
237 | 237 | end |
238 | 238 | end |
239 | 239 | end |
|
0 commit comments