Skip to content

Commit

Permalink
Fix remaining tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jayjay-w committed Feb 19, 2025
1 parent c265675 commit b592f0e
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 69 deletions.
14 changes: 7 additions & 7 deletions test/models/ability_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,12 @@ def teardown
create_team_user user: u, team: t, role: 'admin'
pm1 = create_project_media team: t
pm2 = create_project_media team: t2
a1 = create_annotation annotated: pm1
a2 = create_annotation annotated: pm2
tag1 = create_tag annotated: pm1
tag2 = create_tag annotated: pm2
with_current_user_and_team(u, t) do
a = Ability.new
assert a.can?(:destroy, a1)
assert a.cannot?(:destroy, a2)
assert a.can?(:destroy, tag1)
assert a.cannot?(:destroy, tag2)
end
end
end
Expand Down Expand Up @@ -940,7 +940,7 @@ def teardown
assert ability.can?(:destroy, task1)
assert ability.can?(:update, task2)
assert ability.can?(:destroy, task2)
c.destroy!
task1.destroy!
v = PaperTrail::Version.last
assert ability.cannot?(:destroy, v)
end
Expand Down Expand Up @@ -1135,8 +1135,8 @@ def teardown
create_team_user team: t, user: u
pm = create_project_media project: p
task1 = create_task annotated: pm
task.assign_user(u.id)
a = c.assignments.last
task1.assign_user(u.id)
a = task1.assignments.last

t2 = create_team
p2 = create_project team: t2
Expand Down
2 changes: 1 addition & 1 deletion test/models/annotation_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ class AnnotationTest < ActiveSupport::TestCase
create_team_user user: u, team: t
p = create_project team: t
pm = create_project_media project: p
a = create_annotation annotated: pm
a = create_tag annotated: pm
assert_difference 'Assignment.count', 1 do
a.assign_user(u.id)
end
Expand Down
2 changes: 1 addition & 1 deletion test/models/dynamic_annotation/annotation_type_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class DynamicAnnotation::AnnotationTypeTest < ActiveSupport::TestCase
test "should not create annotation type with reserved name" do
assert_no_difference 'DynamicAnnotation::AnnotationType.count' do
assert_raises ActiveRecord::RecordInvalid do
create_annotation_type annotation_type: 'comment'
create_annotation_type annotation_type: 'tag'
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion test/models/media_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ def setup
create_team_user user: u, team: t, role: 'admin'
p = create_project team: t
m = create_valid_media project_id: p.id
perm_keys = ["read Link", "update Link", "create Task", "destroy Link", "create ProjectMedia", "create Comment", "create Tag", "create Dynamic"].sort
perm_keys = ["read Link", "update Link", "create Task", "destroy Link", "create ProjectMedia", "create Tag", "create Dynamic"].sort

# load permissions as owner
with_current_user_and_team(u, t) { assert_equal perm_keys, JSON.parse(m.permissions).keys.sort }
Expand Down
2 changes: 1 addition & 1 deletion test/models/project_media_5_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ def setup
p = create_project team: t
pm = create_project_media project: p, current_user: u
perm_keys = [
"read ProjectMedia", "update ProjectMedia", "destroy ProjectMedia", "create Comment",
"read ProjectMedia", "update ProjectMedia", "destroy ProjectMedia",
"create Tag", "create Task", "create Dynamic", "not_spam ProjectMedia", "restore ProjectMedia", "confirm ProjectMedia",
"embed ProjectMedia", "lock Annotation","update Status", "administer Content", "create Relationship",
"create Source", "update Source", "create ClaimDescription"
Expand Down
63 changes: 5 additions & 58 deletions test/models/team_bot_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -209,72 +209,19 @@ def setup
#assert_not_nil tb2bt
end

test "should notify team bots in background when annotation is created or updated" do
t1 = create_team
p1 = create_project team: t1
pm1 = create_project_media project: p1
tb1a = create_team_bot team_author_id: t1.id, set_events: [{ event: 'create_annotation_comment', graphql: nil }]
tb1b = create_team_bot team_author_id: t1.id, set_events: [{ event: 'update_annotation_comment', graphql: nil }]

t2 = create_team
p2 = create_project team: t2
pm2 = create_project_media project: p2
tb2a = create_team_bot team_author_id: t2.id, set_events: [{ event: 'create_annotation_comment', graphql: nil }]
tb2b = create_team_bot team_author_id: t2.id, set_events: [{ event: 'update_annotation_comment', graphql: nil }]

#assert_nil tb1a.reload.last_called_at
#assert_nil tb1b.reload.last_called_at
#assert_nil tb2a.reload.last_called_at
#assert_nil tb2b.reload.last_called_at

tg1 = create_tag annotated: pm1

#tb1at = tb1a.reload.last_called_at
#assert_not_nil tb1at
#assert_nil tb1b.reload.last_called_at
#assert_nil tb2a.reload.last_called_at
#assert_nil tb2b.reload.last_called_at

tg2 = create_tag annotated: pm2

#tb2at = tb2a.reload.last_called_at
#assert_equal tb1at, tb1a.reload.last_called_at
#assert_nil tb1b.reload.last_called_at
#assert_not_nil tb2at
#assert_nil tb2b.reload.last_called_at

tg1.updated_at = Time.now
tg1.save!

#tb1bt = tb1b.reload.last_called_at
#assert_equal tb1at, tb1a.reload.last_called_at
#assert_not_nil tb1bt
#assert_equal tb2at, tb2a.reload.last_called_at
#assert_nil tb2b.reload.last_called_at

tg2.updated_at = Time.now
tg2.save!

#tb2bt = tb2b.reload.last_called_at
#assert_equal tb1at, tb1a.reload.last_called_at
#assert_equal tb1bt, tb1b.reload.last_called_at
#assert_equal tb2at, tb2a.reload.last_called_at
#assert_not_nil tb2bt
end

test "should get GraphQL result" do
t = create_team private: true
p = create_project team: t
tb = create_team_bot team_author_id: t.id
pm = create_project_media project: p
tg = create_tag text: 'Test tag'
task = create_task label: 'Test task'
s = create_source name: 'Test Source'
assert_equal pm.id, tb.graphql_result('id, dbid', pm, t)['dbid']
assert_equal 'Test Source', tb.graphql_result('id, dbid, name', s, t)['name']
require 'byebug'
byebug
assert_equal({ tag: 'Test tag' }.to_json, tb.graphql_result('id, dbid, content', tg, t)['content'])
assert tb.graphql_result('invalid fragment', tg, t).has_key?('error')
result = tb.graphql_result('id, dbid, content', task, t)
json_content = JSON.parse(result['content'])
assert_equal 'Test task', json_content['label']
assert tb.graphql_result('invalid fragment', task, t).has_key?('error')
end

test "should call bot over event subscription" do
Expand Down

0 comments on commit b592f0e

Please sign in to comment.