Skip to content

Commit

Permalink
Add tests for channel filtering on the Team model
Browse files Browse the repository at this point in the history
Add tests for `channel` filtering on the Team model
  • Loading branch information
jayjay-w committed Feb 25, 2025
1 parent 6b9a2ec commit df8962f
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions test/models/team_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1336,4 +1336,51 @@ def setup
assert_not_nil data
assert_equal data[0].length, data[1].length
end

test "should filter explainers by channel" do
t = create_team
e1 = create_explainer team: t, channel: "manual", trashed: false
e2 = create_explainer team: t, channel: "api", trashed: false
e3 = create_explainer team: t, channel: "manual", trashed: false

assert_equal 3, t.filtered_explainers(trashed: false).count

assert_equal 2, t.filtered_explainers(trashed: false, channel: "manual").count

assert_equal 1, t.filtered_explainers(trashed: false, channel: "api").count
end

test "should filter fact_checks by channel" do
t = create_team
cd1 = create_claim_description(project_media: create_project_media(team: t))
fc1 = create_fact_check(claim_description: cd1, channel: "manual", trashed: false)
cd2 = create_claim_description(project_media: create_project_media(team: t))
fc2 = create_fact_check(claim_description: cd2, channel: "api", trashed: false)
cd3 = create_claim_description(project_media: create_project_media(team: t))
fc3 = create_fact_check(claim_description: cd3, channel: "manual", trashed: false)

assert_equal 3, t.filtered_fact_checks(trashed: false).count

assert_equal 2, t.filtered_fact_checks(trashed: false, channel: "manual").count

assert_equal 1, t.filtered_fact_checks(trashed: false, channel: "api").count
end

test "should count articles by channel" do
t = create_team
e1 = create_explainer team: t, channel: "manual", trashed: false
cd1 = create_claim_description(project_media: create_project_media(team: t))
fc1 = create_fact_check(claim_description: cd1, channel: "manual", trashed: false)

total = t.filtered_explainers(trashed: false).count + t.filtered_fact_checks(trashed: false).count
assert_equal 2, total

total_manual = t.filtered_explainers(trashed: false, channel: "manual").count +
t.filtered_fact_checks(trashed: false, channel: "manual").count
assert_equal 2, total_manual

total_api = t.filtered_explainers(trashed: false, channel: "api").count +
t.filtered_fact_checks(trashed: false, channel: "api").count
assert_equal 0, total_api
end
end

0 comments on commit df8962f

Please sign in to comment.