@@ -2,6 +2,8 @@ defmodule Keila.FilesTest do
2
2
use Keila.DataCase , async: false
3
3
use Keila.FileCase
4
4
5
+ alias Keila.Mailings
6
+
5
7
@ test_file "test/keila/files/keila.png"
6
8
@ test_file_jpg "test/keila/files/keila.jpg"
7
9
@@ -31,6 +33,41 @@ defmodule Keila.FilesTest do
31
33
assert nil == Files . get_file ( file . uuid )
32
34
end
33
35
36
+ @ tag :files
37
+ test "detect file usage in campaigns" do
38
+ project = insert! ( :project )
39
+
40
+ # Store a file
41
+ { :ok , file } =
42
+ Files . store_file ( project . id , @ test_file , filename: "keila.png" , type: "image/png" )
43
+
44
+ file_url = Files . get_file_url ( file . uuid )
45
+
46
+ campaign_with_uuid =
47
+ insert! ( :mailings_campaign ,
48
+ project_id: project . id ,
49
+ json_body: % { "blocks" => [ % { "type" => "image" , "data" => % { "src" => file . uuid } } ] }
50
+ )
51
+
52
+ campaign_with_url =
53
+ insert! ( :mailings_campaign ,
54
+ project_id: project . id ,
55
+ html_body: "<img src=\" #{ file_url } \" >"
56
+ )
57
+
58
+ uuid_results = Mailings . search_in_project_campaigns ( project . id , file . uuid )
59
+ assert length ( uuid_results ) == 2
60
+ assert campaign_with_uuid . id in Enum . map ( uuid_results , & & 1 . id )
61
+
62
+ url_results = Mailings . search_in_project_campaigns ( project . id , file_url )
63
+ assert length ( url_results ) == 1
64
+ assert campaign_with_url . id in Enum . map ( url_results , & & 1 . id )
65
+
66
+ other_project = insert! ( :project )
67
+ other_results = Mailings . search_in_project_campaigns ( other_project . id , file . uuid )
68
+ assert Enum . empty? ( other_results )
69
+ end
70
+
34
71
@ tag :files
35
72
test "Get project files" do
36
73
project = insert! ( :project )
@@ -47,6 +84,14 @@ defmodule Keila.FilesTest do
47
84
assert [ ] == Files . get_project_files ( project2 . id , paginate: false )
48
85
end
49
86
87
+ @ tag :files
88
+ test "Get project file" do
89
+ project = insert! ( :project )
90
+ file = insert! ( :file , project: project )
91
+
92
+ assert Files . get_project_file ( project . id , file . uuid ) == file
93
+ end
94
+
50
95
@ tag :files
51
96
test "Media type and extension match check" do
52
97
project = insert! ( :project )
0 commit comments