Commit 1ec6425c0ccc04ffceec448288111d07684617f2
1 parent
648ba45f
Exists in
theme-brasil-digital-from-staging
and in
9 other branches
Tests for articles with category at the API
Showing
1 changed file
with
71 additions
and
0 deletions
Show diff stats
test/unit/api/articles_test.rb
| ... | ... | @@ -348,4 +348,75 @@ class ArticlesTest < ActiveSupport::TestCase |
| 348 | 348 | assert_equal [0, 1, 1], [a1.reload.hits, a2.reload.hits, a3.reload.hits] |
| 349 | 349 | end |
| 350 | 350 | |
| 351 | + | |
| 352 | + should 'list all events of a community in a given category' do | |
| 353 | + co = Community.create(identifier: 'my-community', name: 'name-my-community') | |
| 354 | + c1 = Category.create(environment: Environment.default, name: 'my-category') | |
| 355 | + c2 = Category.create(environment: Environment.default, name: 'dont-show-me-this-category') | |
| 356 | + e1 = fast_create(Event, :profile_id => co.id) | |
| 357 | + e2 = fast_create(Event, :profile_id => co.id) | |
| 358 | + e1.categories << c1 | |
| 359 | + e2.categories << c2 | |
| 360 | + e1.save! | |
| 361 | + e2.save! | |
| 362 | + params['content_type']='Event' | |
| 363 | + get "api/v1/communities/#{co.id}/articles?#{params.to_query}" | |
| 364 | + json = JSON.parse(last_response.body) | |
| 365 | + assert_equal json['articles'].count, 2 | |
| 366 | + end | |
| 367 | + | |
| 368 | + should 'list a event of a community in a given category' do | |
| 369 | + co = Community.create(identifier: 'my-community', name: 'name-my-community') | |
| 370 | + c1 = Category.create(environment: Environment.default, name: 'my-category') | |
| 371 | + c2 = Category.create(environment: Environment.default, name: 'dont-show-me-this-category') | |
| 372 | + e1 = fast_create(Event, :profile_id => co.id) | |
| 373 | + e2 = fast_create(Event, :profile_id => co.id) | |
| 374 | + e1.categories << c1 | |
| 375 | + e2.categories << c2 | |
| 376 | + e1.save! | |
| 377 | + e2.save! | |
| 378 | + params['categories_ids[]']=c1.id | |
| 379 | + params['content_type']='Event' | |
| 380 | + get "api/v1/communities/#{co.id}/articles?#{params.to_query}" | |
| 381 | + json = JSON.parse(last_response.body) | |
| 382 | + #should show only one article, since the other not in the same category | |
| 383 | + assert_equal 1, json['articles'].count | |
| 384 | + assert_equal e1.id, json['articles'][0]['id'] | |
| 385 | + end | |
| 386 | + | |
| 387 | + should 'list events of a community in a given 2 categories' do | |
| 388 | + co = Community.create(identifier: 'my-community', name: 'name-my-community') | |
| 389 | + c1 = Category.create(environment: Environment.default, name: 'my-category') | |
| 390 | + c2 = Category.create(environment: Environment.default, name: 'dont-show-me-this-category') | |
| 391 | + e1 = fast_create(Event, :profile_id => co.id) | |
| 392 | + e2 = fast_create(Event, :profile_id => co.id) | |
| 393 | + e1.categories << c1 | |
| 394 | + e2.categories << c2 | |
| 395 | + e1.save! | |
| 396 | + e2.save! | |
| 397 | + params['content_type']='Event' | |
| 398 | + params['categories_ids'] = [c1.id, c2.id] | |
| 399 | + get "api/v1/communities/#{co.id}/articles?#{params.to_query}" | |
| 400 | + json = JSON.parse(last_response.body) | |
| 401 | + assert_equal json['articles'].count, 2 | |
| 402 | + end | |
| 403 | + | |
| 404 | + should 'Show 2 events since it uses an IN operator for category instead of an OR' do | |
| 405 | + co = Community.create(identifier: 'my-community', name: 'name-my-community') | |
| 406 | + c1 = Category.create(environment: Environment.default, name: 'my-category') | |
| 407 | + c2 = Category.create(environment: Environment.default, name: 'dont-show-me-this-category') | |
| 408 | + c3 = Category.create(environment: Environment.default, name: 'extra-category') | |
| 409 | + e1 = fast_create(Event, :profile_id => co.id) | |
| 410 | + e2 = fast_create(Event, :profile_id => co.id) | |
| 411 | + e1.categories << c1 | |
| 412 | + e2.categories << c2 | |
| 413 | + e1.save! | |
| 414 | + e2.save! | |
| 415 | + params['content_type']='Event' | |
| 416 | + params['categories_ids'] = [c1.id, c2.id, c3.id] | |
| 417 | + get "api/v1/communities/#{co.id}/articles?#{params.to_query}" | |
| 418 | + json = JSON.parse(last_response.body) | |
| 419 | + assert_equal json['articles'].count, 2 | |
| 420 | + end | |
| 421 | + | |
| 351 | 422 | end | ... | ... |