Skip to content

Commit

Permalink
Fixing flaky test
Browse files Browse the repository at this point in the history
  • Loading branch information
caiosba committed Oct 31, 2023
1 parent 7f6a46f commit f5b898c
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 63 deletions.
4 changes: 1 addition & 3 deletions app/graph/mutations/smooch_bot_mutations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ def resolve(id:, set_fields:)
if annotation.nil?
raise ActiveRecord::RecordNotFound
else
unless annotation.ability.can?(:update, annotation)
raise "No permission to update #{annotation.class.name}"
end
raise "No permission to update #{annotation.class.name}" unless annotation.ability.can?(:update, annotation)
SmoochAddSlackChannelUrlWorker.perform_in(
1.second,
id,
Expand Down
60 changes: 0 additions & 60 deletions test/controllers/graphql_controller_11_test.rb

This file was deleted.

23 changes: 23 additions & 0 deletions test/controllers/graphql_controller_6_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -276,4 +276,27 @@ def teardown
assert_equal 1, response['item_navigation_offset']
end

test "should set Smooch user Slack channel URL" do
u = create_user
t = create_team
p = create_project team: t
create_team_user team: t, user: u, role: 'admin'
set_fields = { smooch_user_data: { id: random_string }.to_json, smooch_user_app_id: 'fake', smooch_user_id: 'fake' }.to_json
d = create_dynamic_annotation annotated: p, annotation_type: 'smooch_user', set_fields: set_fields
authenticate_with_token
query = 'mutation { smoochBotAddSlackChannelUrl(input: { id: "' + d.id.to_s + '", set_fields: "{\"smooch_user_slack_channel_url\":\"' + random_url + '\"}" }) { annotation { dbid } } }'
post :create, params: { query: query }
assert_response :success
end

test "should not set Smooch user Slack channel URL" do
u = create_user
t = create_team
p = create_project team: t
create_team_user team: t, user: u, role: 'admin'
authenticate_with_token
query = 'mutation { smoochBotAddSlackChannelUrl(input: { id: "0", set_fields: "{\"smooch_user_slack_channel_url\":\"' + random_url + '\"}" }) { annotation { dbid } } }'
post :create, params: { query: query }
assert_response :success
end
end
18 changes: 18 additions & 0 deletions test/workers/smooch_add_slack_channel_url_worker_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
require_relative '../test_helper'

class SmoochAddSlackChannelUrlWorkerTest < ActiveSupport::TestCase
def setup
end

def teardown
end

test 'should set fields for annotation if annotation exists' do
create_annotation_type_and_fields('Smooch User', { 'Slack Channel URL' => ['Text'] })
a = create_dynamic_annotation annotation_type: 'smooch_user'
assert_nil a.reload.get_field_value('smooch_user_slack_channel_url')
url = random_url
SmoochAddSlackChannelUrlWorker.new.perform(a.id, { smooch_user_slack_channel_url: url }.to_json)
assert_equal url, a.reload.get_field_value('smooch_user_slack_channel_url')
end
end

0 comments on commit f5b898c

Please sign in to comment.