|
161 | 161 | end |
162 | 162 |
|
163 | 163 | context 'filtering by timestamp' do |
| 164 | + before do |
| 165 | + VCAP::CloudController::Event.plugin :timestamps, update_on_create: false |
| 166 | + end |
| 167 | + |
164 | 168 | let(:timestamp) { (Time.now + 1).utc.iso8601 } |
165 | 169 | let(:timestamp_half_second_later) { (Time.parse(timestamp) + 0.5).utc.iso8601 } |
166 | 170 |
|
| 171 | + after do |
| 172 | + VCAP::CloudController::Event.plugin :timestamps, update_on_create: true |
| 173 | + end |
| 174 | + |
167 | 175 | context 'using less than' do |
168 | 176 | let!(:extra_event) { VCAP::CloudController::Event.make(created_at: Time.now + 100, organization_guid: org.guid) } |
169 | 177 | let!(:half_second_event) { VCAP::CloudController::Event.make(created_at: timestamp_half_second_later, organization_guid: org.guid, type: 'audit.organization.create') } |
|
179 | 187 | end |
180 | 188 | end |
181 | 189 |
|
182 | | - context 'using less than or equal to' do |
183 | | - let!(:extra_event) { VCAP::CloudController::Event.make(created_at: timestamp, organization_guid: org.guid, type: 'audit.organization.create') } |
184 | | - |
185 | | - let(:extra_event_json) do |
186 | | - { |
187 | | - guid: extra_event.guid, |
188 | | - created_at: iso8601, |
189 | | - updated_at: iso8601, |
190 | | - type: 'audit.organization.create', |
191 | | - actor: { |
192 | | - guid: extra_event.actor, |
193 | | - type: extra_event.actor_type, |
194 | | - name: extra_event.actor_name |
195 | | - }, |
196 | | - target: { |
197 | | - guid: extra_event.actee, |
198 | | - type: extra_event.actee_type, |
199 | | - name: extra_event.actee_name |
200 | | - }, |
201 | | - data: {}, |
202 | | - space: nil, |
203 | | - organization: { |
204 | | - guid: org.guid |
205 | | - }, |
206 | | - links: { |
207 | | - self: { |
208 | | - href: "#{link_prefix}/v3/audit_events/#{extra_event.guid}" |
209 | | - } |
210 | | - } |
211 | | - } |
212 | | - end |
213 | | - |
214 | | - let!(:half_second_event) { VCAP::CloudController::Event.make(created_at: timestamp_half_second_later, organization_guid: org.guid, type: 'audit.organization.create') } |
215 | | - |
216 | | - let(:half_second_event_json) do |
217 | | - { |
218 | | - guid: half_second_event.guid, |
219 | | - created_at: iso8601, |
220 | | - updated_at: iso8601, |
221 | | - type: 'audit.organization.create', |
222 | | - actor: { |
223 | | - guid: half_second_event.actor, |
224 | | - type: half_second_event.actor_type, |
225 | | - name: half_second_event.actor_name |
226 | | - }, |
227 | | - target: { |
228 | | - guid: half_second_event.actee, |
229 | | - type: half_second_event.actee_type, |
230 | | - name: half_second_event.actee_name |
231 | | - }, |
232 | | - data: {}, |
233 | | - space: nil, |
234 | | - organization: { |
235 | | - guid: org.guid |
236 | | - }, |
237 | | - links: { |
238 | | - self: { |
239 | | - href: "#{link_prefix}/v3/audit_events/#{half_second_event.guid}" |
240 | | - } |
241 | | - } |
242 | | - } |
243 | | - end |
244 | | - |
245 | | - it 'returns events earlier than the given timestamp' do |
246 | | - get "/v3/audit_events?created_ats[lte]=#{timestamp}", nil, admin_header |
247 | | - |
248 | | - expect( |
249 | | - resources: parsed_response['resources'] |
250 | | - ).to match_json_response( |
251 | | - resources: [unscoped_event_json, space_scoped_event_json, extra_event_json, half_second_event_json] |
252 | | - ) |
253 | | - end |
254 | | - end |
255 | | - |
256 | | - context 'using greater than or equal to' do |
257 | | - let!(:extra_event) { VCAP::CloudController::Event.make(created_at: timestamp, organization_guid: org.guid, type: 'audit.organization.create') } |
258 | | - |
259 | | - let(:extra_event_json) do |
260 | | - { |
261 | | - guid: extra_event.guid, |
262 | | - created_at: iso8601, |
263 | | - updated_at: iso8601, |
264 | | - type: 'audit.organization.create', |
265 | | - actor: { |
266 | | - guid: extra_event.actor, |
267 | | - type: extra_event.actor_type, |
268 | | - name: extra_event.actor_name |
269 | | - }, |
270 | | - target: { |
271 | | - guid: extra_event.actee, |
272 | | - type: extra_event.actee_type, |
273 | | - name: extra_event.actee_name |
274 | | - }, |
275 | | - data: {}, |
276 | | - space: nil, |
277 | | - organization: { |
278 | | - guid: org.guid |
279 | | - }, |
280 | | - links: { |
281 | | - self: { |
282 | | - href: "#{link_prefix}/v3/audit_events/#{extra_event.guid}" |
283 | | - } |
284 | | - } |
285 | | - } |
286 | | - end |
287 | | - |
288 | | - it 'returns events at or after the given timestamp' do |
289 | | - get "/v3/audit_events?created_ats[gte]=#{timestamp}", nil, admin_header |
290 | | - |
291 | | - expect( |
292 | | - resources: parsed_response['resources'] |
293 | | - ).to match_json_response( |
294 | | - resources: [org_scoped_event_json, extra_event_json] |
295 | | - ) |
296 | | - end |
297 | | - end |
298 | | - |
299 | | - context 'using greater than' do |
300 | | - it 'returns events after the given timestamp' do |
301 | | - get "/v3/audit_events?created_ats[gt]=#{timestamp}", nil, admin_header |
302 | | - |
303 | | - expect( |
304 | | - resources: parsed_response['resources'] |
305 | | - ).to match_json_response( |
306 | | - resources: [org_scoped_event_json] |
307 | | - ) |
308 | | - end |
309 | | - end |
310 | | - context 'using greater than or equal to' do |
311 | | - let!(:extra_event) { VCAP::CloudController::Event.make(created_at: timestamp, organization_guid: org.guid, type: 'audit.organization.create') } |
312 | | - |
313 | | - let(:extra_event_json) do |
314 | | - { |
315 | | - guid: extra_event.guid, |
316 | | - created_at: iso8601, |
317 | | - updated_at: iso8601, |
318 | | - type: 'audit.organization.create', |
319 | | - actor: { |
320 | | - guid: extra_event.actor, |
321 | | - type: extra_event.actor_type, |
322 | | - name: extra_event.actor_name |
323 | | - }, |
324 | | - target: { |
325 | | - guid: extra_event.actee, |
326 | | - type: extra_event.actee_type, |
327 | | - name: extra_event.actee_name |
328 | | - }, |
329 | | - data: {}, |
330 | | - space: nil, |
331 | | - organization: { |
332 | | - guid: org.guid |
333 | | - }, |
334 | | - links: { |
335 | | - self: { |
336 | | - href: "#{link_prefix}/v3/audit_events/#{extra_event.guid}" |
337 | | - } |
338 | | - } |
339 | | - } |
340 | | - end |
341 | | - |
342 | | - it 'returns events at or after the given timestamp' do |
343 | | - get "/v3/audit_events?created_ats[gte]=#{timestamp}", nil, admin_header |
344 | | - |
345 | | - expect( |
346 | | - resources: parsed_response['resources'] |
347 | | - ).to match_json_response( |
348 | | - resources: [org_scoped_event_json, extra_event_json] |
349 | | - ) |
350 | | - end |
351 | | - end |
352 | | - |
353 | | - context 'using greater than and less than, together' do |
354 | | - let!(:event_1) { VCAP::CloudController::Event.make(guid: '1', created_at: '2020-05-26T18:47:01Z') } |
355 | | - let!(:event_2) { VCAP::CloudController::Event.make(guid: '2', created_at: '2020-05-26T18:47:02Z') } |
356 | | - let!(:event_3) { VCAP::CloudController::Event.make(guid: '3', created_at: '2020-05-26T18:47:03Z') } |
357 | | - let!(:event_4) { VCAP::CloudController::Event.make(guid: '4', created_at: '2020-05-26T18:47:04Z') } |
358 | | - |
359 | | - let(:event_3_json) do |
360 | | - { |
361 | | - guid: event_3.guid, |
362 | | - created_at: iso8601, |
363 | | - updated_at: iso8601, |
364 | | - type: event_3.type, |
365 | | - actor: { |
366 | | - guid: event_3.actor, |
367 | | - type: event_3.actor_type, |
368 | | - name: event_3.actor_name |
369 | | - }, |
370 | | - target: { |
371 | | - guid: event_3.actee, |
372 | | - type: event_3.actee_type, |
373 | | - name: event_3.actee_name |
374 | | - }, |
375 | | - data: {}, |
376 | | - space: nil, |
377 | | - organization: { |
378 | | - guid: event_3.organization_guid |
379 | | - }, |
380 | | - links: { |
381 | | - self: { |
382 | | - href: "#{link_prefix}/v3/audit_events/#{event_3.guid}" |
383 | | - } |
384 | | - } |
385 | | - } |
386 | | - end |
387 | | - |
388 | | - it 'returns events after the greater-than timestamp but before the less-than timestamp' do |
389 | | - get "/v3/audit_events?created_ats[gt]=#{event_2.created_at.iso8601}&created_ats[lt]=#{event_4.created_at.iso8601}", nil, admin_header |
390 | | - |
391 | | - expect( |
392 | | - resources: parsed_response['resources'] |
393 | | - ).to match_json_response( |
394 | | - resources: [event_3_json] |
395 | | - ) |
396 | | - end |
397 | | - end |
398 | | - |
399 | 190 | context 'using equal' do |
400 | | - let!(:same_time_event) { VCAP::CloudController::Event.make(created_at: timestamp, organization_guid: org.guid, type: 'audit.organization.create') } |
| 191 | + let!(:same_time_event) { VCAP::CloudController::Event.make(updated_at: timestamp, organization_guid: org.guid, type: 'audit.organization.create') } |
401 | 192 |
|
402 | 193 | let(:same_time_event_json) do |
403 | 194 | { |
|
429 | 220 | end |
430 | 221 |
|
431 | 222 | it 'returns events at the given timestamp' do |
432 | | - get "/v3/audit_events?created_ats=#{timestamp}", nil, admin_header |
| 223 | + get "/v3/audit_events?updated_ats=#{timestamp}", nil, admin_header |
433 | 224 |
|
434 | 225 | expect(last_response).to have_status_code(200) |
435 | 226 | expect( |
|
0 commit comments