From 34081054bae90843ee0b22874e1e177f66e89f16 Mon Sep 17 00:00:00 2001 From: Devin Gaffney Date: Wed, 8 May 2024 23:33:41 -0700 Subject: [PATCH] fix test fixtures --- test/controllers/reports_controller_test.rb | 52 ++++++++++++++++++++- test/models/bot/alegre_v2_test.rb | 51 +++++++++++++++++++- 2 files changed, 100 insertions(+), 3 deletions(-) diff --git a/test/controllers/reports_controller_test.rb b/test/controllers/reports_controller_test.rb index 32e197a704..0af43ffdd5 100644 --- a/test/controllers/reports_controller_test.rb +++ b/test/controllers/reports_controller_test.rb @@ -40,8 +40,56 @@ def from_alegre(pm) pm5 = create_project_media team: @t, media: create_uploaded_video create_project_media team: @t - Bot::Alegre.stubs(:request).returns({ 'result' => [from_alegre(@pm), from_alegre(pm), from_alegre(pm2), from_alegre(pm3), from_alegre(pm4), from_alegre(pm5)] }) - + Bot::Alegre.stubs(:get_items_with_similar_media_v2).returns({ + @pm.id => { + score: 1.0, + context: {"team_id" => @pm.team_id, "project_media_id" => @pm.id, "temporary_media" => false}, + model: Bot::Alegre.get_type(@pm), + source_field: Bot::Alegre.get_type(@pm), + target_field: Bot::Alegre.get_type(@pm), + relationship_type: {:source=>"confirmed_sibling", :target=>"confirmed_sibling"} + }, + pm.id => { + score: 1.0, + context: {"team_id" => pm.team_id, "project_media_id" => pm.id, "temporary_media" => false}, + model: Bot::Alegre.get_type(pm), + source_field: Bot::Alegre.get_type(pm), + target_field: Bot::Alegre.get_type(pm), + relationship_type: {:source=>"confirmed_sibling", :target=>"confirmed_sibling"} + }, + pm2.id => { + score: 1.0, + context: {"team_id" => pm2.team_id, "project_media_id" => pm2.id, "temporary_media" => false}, + model: Bot::Alegre.get_type(pm2), + source_field: Bot::Alegre.get_type(pm2), + target_field: Bot::Alegre.get_type(pm2), + relationship_type: {:source=>"confirmed_sibling", :target=>"confirmed_sibling"} + }, + pm3.id => { + score: 1.0, + context: {"team_id" => pm3.team_id, "project_media_id" => pm3.id, "temporary_media" => false}, + model: Bot::Alegre.get_type(pm3), + source_field: Bot::Alegre.get_type(pm3), + target_field: Bot::Alegre.get_type(pm3), + relationship_type: {:source=>"confirmed_sibling", :target=>"confirmed_sibling"} + }, + pm4.id => { + score: 1.0, + context: {"team_id" => pm4.team_id, "project_media_id" => pm4.id, "temporary_media" => false}, + model: Bot::Alegre.get_type(pm4), + source_field: Bot::Alegre.get_type(pm4), + target_field: Bot::Alegre.get_type(pm4), + relationship_type: {:source=>"confirmed_sibling", :target=>"confirmed_sibling"} + }, + pm5.id => { + score: 1.0, + context: {"team_id" => pm5.team_id, "project_media_id" => pm5.id, "temporary_media" => false}, + model: Bot::Alegre.get_type(pm5), + source_field: Bot::Alegre.get_type(pm5), + target_field: Bot::Alegre.get_type(pm5), + relationship_type: {:source=>"confirmed_sibling", :target=>"confirmed_sibling"} + }, + }) post :index, params: {} assert_response :success assert_equal 7, json_response['data'].size diff --git a/test/models/bot/alegre_v2_test.rb b/test/models/bot/alegre_v2_test.rb index 12197f74d9..1a713d10b5 100644 --- a/test/models/bot/alegre_v2_test.rb +++ b/test/models/bot/alegre_v2_test.rb @@ -816,8 +816,57 @@ def teardown } } } + unconfirmed_params = { + "model_type": "image", + "data": { + "item": { + "id": "Y2hlY2stcHJvamVjdF9tZWRpYS0yMTQt", + "callback_url": "http://alegre:3100/presto/receive/add_item/image", + "url": "http://minio:9000/check-api-dev/uploads/uploaded_image/55/09572dedf610aad68090214303c14829.png", + "text": nil, + "raw": { + "doc_id": "Y2hlY2stcHJvamVjdF9tZWRpYS0yMTQt", + "context": { + "team_id": pm1.team_id, + "project_media_id": pm1.id, + "has_custom_id": true, + "temporary_media": false, + }, + "url": "http://minio:9000/check-api-dev/uploads/uploaded_image/55/09572dedf610aad68090214303c14829.png", + "threshold": 0.63, + "confirmed": false, + "created_at": "2024-03-14T22:05:47.588975", + "limit": 200, + "requires_callback": true, + "final_task": "search" + }, + "hash_value": "1110101010001011110100000011110010101000000010110101101010100101101111110101101001011010100001011111110101011010010000101010010110101101010110100000001010100101101010111110101000010101011100001110101010101111100001010101001011101010101011010001010101010010" + }, + "results": { + "result": [ + { + "id": "Y2hlY2stcHJvamVjdF9tZWRpYS0yMTQt", + "doc_id": "Y2hlY2stcHJvamVjdF9tZWRpYS0yMTQt", + "pdq": "1110101010001011110100000011110010101000000010110101101010100101101111110101101001011010100001011111110101011010010000101010010110101101010110100000001010100101101010111110101000010101011100001110101010101111100001010101001011101010101011010001010101010010", + "url": "http://minio:9000/check-api-dev/uploads/uploaded_image/55/09572dedf610aad68090214303c14829.png", + "context": [ + { + "team_id": pm2.team_id, + "has_custom_id": true, + "project_media_id": pm2.id, + "temporary_media": false, + } + ], + "score": 1.0, + "model": "image/pdq" + } + ] + } + } + } assert_difference 'Relationship.count' do # Simulate the webhook hitting the server and being executed.... + Bot::Alegre.process_alegre_callback(JSON.parse(unconfirmed_params.to_json)) relationship = Bot::Alegre.process_alegre_callback(JSON.parse(params.to_json)) #hack to force into stringed keys end assert_equal relationship.source, pm2 @@ -997,7 +1046,7 @@ def teardown test "should get_cached_data with right fallbacks" do pm1 = create_project_media team: @team, media: create_uploaded_audio - assert_equal Bot::Alegre.get_cached_data(Bot::Alegre.get_required_keys(pm1, nil)), {confirmed_results: [], suggested_or_confirmed_results: []} + assert_equal Bot::Alegre.get_cached_data(Bot::Alegre.get_required_keys(pm1, nil)), {confirmed_results: nil, suggested_or_confirmed_results: nil} end test "should relate project media for audio" do