Delete test/plausible/stats/goal_suggestions_test.exs with huggingface_hub
Browse files
test/plausible/stats/goal_suggestions_test.exs
DELETED
|
@@ -1,508 +0,0 @@
|
|
| 1 |
-
defmodule Plausible.Stats.GoalSuggestionsTest do
|
| 2 |
-
use Plausible.DataCase, async: true
|
| 3 |
-
alias Plausible.Stats.GoalSuggestions
|
| 4 |
-
|
| 5 |
-
describe "suggest_event_names/3" do
|
| 6 |
-
setup [:create_user, :create_site]
|
| 7 |
-
|
| 8 |
-
test "returns custom event goal suggestions including imported data, ordered by visitor count",
|
| 9 |
-
%{site: site} do
|
| 10 |
-
site_import = insert(:site_import, site: site)
|
| 11 |
-
|
| 12 |
-
populate_stats(
|
| 13 |
-
site,
|
| 14 |
-
site_import.id,
|
| 15 |
-
[
|
| 16 |
-
build(:event, name: "Signup"),
|
| 17 |
-
build(:event, name: "Signup"),
|
| 18 |
-
build(:event, name: "Signup"),
|
| 19 |
-
build(:event, name: "Signup"),
|
| 20 |
-
build(:event, name: "Signup Newsletter"),
|
| 21 |
-
build(:event, name: "Signup Newsletter"),
|
| 22 |
-
build(:imported_custom_events, name: "Signup Newsletter", visitors: 3),
|
| 23 |
-
build(:imported_custom_events, name: "Outbound Link: Click", visitors: 50)
|
| 24 |
-
] ++ build_list(10, :event, name: "Purchase", user_id: 123)
|
| 25 |
-
)
|
| 26 |
-
|
| 27 |
-
assert GoalSuggestions.suggest_event_names(site, "") == [
|
| 28 |
-
"Outbound Link: Click",
|
| 29 |
-
"Signup Newsletter",
|
| 30 |
-
"Signup",
|
| 31 |
-
"Purchase"
|
| 32 |
-
]
|
| 33 |
-
end
|
| 34 |
-
|
| 35 |
-
test "returns custom event goal suggestions with search input, including imported data",
|
| 36 |
-
%{site: site} do
|
| 37 |
-
site_import = insert(:site_import, site: site)
|
| 38 |
-
|
| 39 |
-
populate_stats(site, site_import.id, [
|
| 40 |
-
build(:event, name: "Some Signup"),
|
| 41 |
-
build(:event, name: "Some Signup"),
|
| 42 |
-
build(:event, name: "Some Signup"),
|
| 43 |
-
build(:event, name: "sign"),
|
| 44 |
-
build(:event, name: "A Sign"),
|
| 45 |
-
build(:event, name: "A Sign"),
|
| 46 |
-
build(:event, name: "Not Matching"),
|
| 47 |
-
build(:imported_custom_events, name: "GA Signup", visitors: 4),
|
| 48 |
-
build(:imported_custom_events, name: "Not Matching", visitors: 3)
|
| 49 |
-
])
|
| 50 |
-
|
| 51 |
-
assert GoalSuggestions.suggest_event_names(site, "Sign") == [
|
| 52 |
-
"GA Signup",
|
| 53 |
-
"Some Signup",
|
| 54 |
-
"A Sign",
|
| 55 |
-
"sign"
|
| 56 |
-
]
|
| 57 |
-
end
|
| 58 |
-
|
| 59 |
-
test "ignores 'pageview' and 'engagement' event names", %{site: site} do
|
| 60 |
-
populate_stats(site, [
|
| 61 |
-
build(:event, name: "Signup"),
|
| 62 |
-
build(:pageview,
|
| 63 |
-
user_id: 1,
|
| 64 |
-
timestamp: NaiveDateTime.utc_now() |> NaiveDateTime.add(-1, :minute)
|
| 65 |
-
),
|
| 66 |
-
build(:engagement, user_id: 1, timestamp: NaiveDateTime.utc_now())
|
| 67 |
-
])
|
| 68 |
-
|
| 69 |
-
assert GoalSuggestions.suggest_event_names(site, "") == ["Signup"]
|
| 70 |
-
end
|
| 71 |
-
|
| 72 |
-
test "ignores event names with either white space on either end or consisting only of whitespace",
|
| 73 |
-
%{site: site} do
|
| 74 |
-
site_import = insert(:site_import, site: site)
|
| 75 |
-
|
| 76 |
-
populate_stats(site, site_import.id, [
|
| 77 |
-
build(:event, name: "Signup"),
|
| 78 |
-
build(:event, name: " Signup2"),
|
| 79 |
-
build(:event, name: " Signup2 "),
|
| 80 |
-
build(:event, name: "Signup2 "),
|
| 81 |
-
build(:event, name: " "),
|
| 82 |
-
build(:imported_custom_events, name: "Auth", visitors: 3),
|
| 83 |
-
build(:imported_custom_events, name: " Auth2", visitors: 3),
|
| 84 |
-
build(:imported_custom_events, name: " Auth2 ", visitors: 3),
|
| 85 |
-
build(:imported_custom_events, name: "Auth2 ", visitors: 3),
|
| 86 |
-
build(:imported_custom_events, name: " ", visitors: 3),
|
| 87 |
-
build(:pageview)
|
| 88 |
-
])
|
| 89 |
-
|
| 90 |
-
assert GoalSuggestions.suggest_event_names(site, "") == ["Auth", "Signup"]
|
| 91 |
-
end
|
| 92 |
-
|
| 93 |
-
test "can exclude goals from being suggested", %{site: site} do
|
| 94 |
-
populate_stats(site, [build(:event, name: "Signup")])
|
| 95 |
-
|
| 96 |
-
assert GoalSuggestions.suggest_event_names(site, "", exclude: ["Signup"]) == []
|
| 97 |
-
end
|
| 98 |
-
|
| 99 |
-
test "does not suggest event names longer than schema allows", %{site: site} do
|
| 100 |
-
populate_stats(site, [build(:event, name: String.duplicate("A", 121))])
|
| 101 |
-
|
| 102 |
-
assert GoalSuggestions.suggest_event_names(site, "") == []
|
| 103 |
-
end
|
| 104 |
-
end
|
| 105 |
-
|
| 106 |
-
describe "suggest_custom_property_names/3" do
|
| 107 |
-
setup [:create_user, :create_site]
|
| 108 |
-
|
| 109 |
-
test "returns custom property names from the last 30 days, ordered by usage count", %{
|
| 110 |
-
site: site
|
| 111 |
-
} do
|
| 112 |
-
populate_stats(site, [
|
| 113 |
-
build(:event,
|
| 114 |
-
name: "Purchase",
|
| 115 |
-
"meta.key": ["amount", "plan"],
|
| 116 |
-
"meta.value": ["100", "business"],
|
| 117 |
-
timestamp: NaiveDateTime.utc_now() |> NaiveDateTime.shift(day: -1)
|
| 118 |
-
),
|
| 119 |
-
build(:event,
|
| 120 |
-
name: "Purchase",
|
| 121 |
-
"meta.key": ["plan"],
|
| 122 |
-
"meta.value": ["enterprise"],
|
| 123 |
-
timestamp: NaiveDateTime.utc_now() |> NaiveDateTime.shift(day: -5)
|
| 124 |
-
),
|
| 125 |
-
build(:event,
|
| 126 |
-
name: "Signup",
|
| 127 |
-
"meta.key": ["plan", "referrer"],
|
| 128 |
-
"meta.value": ["starter", "friend"],
|
| 129 |
-
timestamp: NaiveDateTime.utc_now() |> NaiveDateTime.shift(day: -10)
|
| 130 |
-
),
|
| 131 |
-
build(:event,
|
| 132 |
-
name: "Click",
|
| 133 |
-
"meta.key": ["button_id"],
|
| 134 |
-
"meta.value": ["submit-btn"],
|
| 135 |
-
timestamp: NaiveDateTime.utc_now() |> NaiveDateTime.shift(day: -20)
|
| 136 |
-
)
|
| 137 |
-
])
|
| 138 |
-
|
| 139 |
-
# "plan" appears 3 times, "amount" 1 time, "referrer" 1 time, "button_id" 1 time
|
| 140 |
-
assert GoalSuggestions.suggest_custom_property_names(site, "") == [
|
| 141 |
-
"plan",
|
| 142 |
-
"referrer",
|
| 143 |
-
"amount",
|
| 144 |
-
"button_id"
|
| 145 |
-
]
|
| 146 |
-
end
|
| 147 |
-
|
| 148 |
-
test "filters property names by search input", %{site: site} do
|
| 149 |
-
populate_stats(site, [
|
| 150 |
-
build(:event,
|
| 151 |
-
name: "Purchase",
|
| 152 |
-
"meta.key": ["plan_type", "payment_method", "amount"],
|
| 153 |
-
"meta.value": ["business", "credit_card", "100"],
|
| 154 |
-
timestamp: NaiveDateTime.utc_now() |> NaiveDateTime.shift(day: -1)
|
| 155 |
-
),
|
| 156 |
-
build(:event,
|
| 157 |
-
name: "Signup",
|
| 158 |
-
"meta.key": ["referrer", "plan_name"],
|
| 159 |
-
"meta.value": ["google", "starter"],
|
| 160 |
-
timestamp: NaiveDateTime.utc_now() |> NaiveDateTime.shift(day: -2)
|
| 161 |
-
)
|
| 162 |
-
])
|
| 163 |
-
|
| 164 |
-
assert GoalSuggestions.suggest_custom_property_names(site, "plan") == [
|
| 165 |
-
"plan_name",
|
| 166 |
-
"plan_type"
|
| 167 |
-
]
|
| 168 |
-
end
|
| 169 |
-
|
| 170 |
-
test "excludes events older than 30 days", %{site: site} do
|
| 171 |
-
populate_stats(site, [
|
| 172 |
-
build(:event,
|
| 173 |
-
name: "Purchase",
|
| 174 |
-
"meta.key": ["recent_prop"],
|
| 175 |
-
"meta.value": ["value1"],
|
| 176 |
-
timestamp: NaiveDateTime.utc_now() |> NaiveDateTime.shift(day: -29)
|
| 177 |
-
),
|
| 178 |
-
build(:event,
|
| 179 |
-
name: "Purchase",
|
| 180 |
-
"meta.key": ["old_prop"],
|
| 181 |
-
"meta.value": ["value2"],
|
| 182 |
-
timestamp: NaiveDateTime.utc_now() |> NaiveDateTime.shift(day: -31)
|
| 183 |
-
)
|
| 184 |
-
])
|
| 185 |
-
|
| 186 |
-
assert GoalSuggestions.suggest_custom_property_names(site, "") == ["recent_prop"]
|
| 187 |
-
assert GoalSuggestions.suggest_custom_property_names(site, "prop") == ["recent_prop"]
|
| 188 |
-
end
|
| 189 |
-
|
| 190 |
-
test "returns empty list when no custom properties exist", %{site: site} do
|
| 191 |
-
populate_stats(site, [
|
| 192 |
-
build(:event, name: "Purchase", timestamp: NaiveDateTime.utc_now())
|
| 193 |
-
])
|
| 194 |
-
|
| 195 |
-
assert GoalSuggestions.suggest_custom_property_names(site, "") == []
|
| 196 |
-
end
|
| 197 |
-
|
| 198 |
-
test "handles nil search input", %{site: site} do
|
| 199 |
-
populate_stats(site, [
|
| 200 |
-
build(:event,
|
| 201 |
-
name: "Purchase",
|
| 202 |
-
"meta.key": ["plan"],
|
| 203 |
-
"meta.value": ["business"],
|
| 204 |
-
timestamp: NaiveDateTime.utc_now()
|
| 205 |
-
)
|
| 206 |
-
])
|
| 207 |
-
|
| 208 |
-
assert GoalSuggestions.suggest_custom_property_names(site, nil) == ["plan"]
|
| 209 |
-
end
|
| 210 |
-
|
| 211 |
-
test "includes allowed_prop_names from site configuration when no event data exists", %{
|
| 212 |
-
site: site
|
| 213 |
-
} do
|
| 214 |
-
site =
|
| 215 |
-
site
|
| 216 |
-
|> Ecto.Changeset.change(allowed_event_props: ["prop_a", "prop_b", "prop_c"])
|
| 217 |
-
|> Repo.update!()
|
| 218 |
-
|
| 219 |
-
suggestions = GoalSuggestions.suggest_custom_property_names(site, "")
|
| 220 |
-
|
| 221 |
-
assert suggestions == ["prop_a", "prop_b", "prop_c"]
|
| 222 |
-
end
|
| 223 |
-
|
| 224 |
-
test "combines event_prop_names and allowed_prop_names, prioritizing event usage", %{
|
| 225 |
-
site: site
|
| 226 |
-
} do
|
| 227 |
-
site =
|
| 228 |
-
site
|
| 229 |
-
|> Ecto.Changeset.change(
|
| 230 |
-
allowed_event_props: ["allowed_prop", "shared_prop", "another_allowed"]
|
| 231 |
-
)
|
| 232 |
-
|> Repo.update!()
|
| 233 |
-
|
| 234 |
-
populate_stats(site, [
|
| 235 |
-
build(:event,
|
| 236 |
-
name: "Purchase",
|
| 237 |
-
"meta.key": ["event_prop"],
|
| 238 |
-
"meta.value": ["value1"],
|
| 239 |
-
timestamp: NaiveDateTime.utc_now() |> NaiveDateTime.shift(day: -1)
|
| 240 |
-
),
|
| 241 |
-
build(:event,
|
| 242 |
-
name: "Purchase",
|
| 243 |
-
"meta.key": ["event_prop"],
|
| 244 |
-
"meta.value": ["value2"],
|
| 245 |
-
timestamp: NaiveDateTime.utc_now() |> NaiveDateTime.shift(day: -2)
|
| 246 |
-
),
|
| 247 |
-
build(:event,
|
| 248 |
-
name: "Signup",
|
| 249 |
-
"meta.key": ["shared_prop"],
|
| 250 |
-
"meta.value": ["value3"],
|
| 251 |
-
timestamp: NaiveDateTime.utc_now() |> NaiveDateTime.shift(day: -3)
|
| 252 |
-
)
|
| 253 |
-
])
|
| 254 |
-
|
| 255 |
-
suggestions = GoalSuggestions.suggest_custom_property_names(site, "")
|
| 256 |
-
|
| 257 |
-
assert suggestions == ["event_prop", "shared_prop", "allowed_prop", "another_allowed"]
|
| 258 |
-
end
|
| 259 |
-
|
| 260 |
-
test "filters allowed_prop_names by search input (case-insensitive)", %{
|
| 261 |
-
site: site
|
| 262 |
-
} do
|
| 263 |
-
site =
|
| 264 |
-
site
|
| 265 |
-
|> Ecto.Changeset.change(
|
| 266 |
-
allowed_event_props: ["plan_type", "user_plan", "payment_method", "amount"]
|
| 267 |
-
)
|
| 268 |
-
|> Repo.update!()
|
| 269 |
-
|
| 270 |
-
suggestions = GoalSuggestions.suggest_custom_property_names(site, "plan")
|
| 271 |
-
|
| 272 |
-
assert suggestions == ["plan_type", "user_plan"]
|
| 273 |
-
end
|
| 274 |
-
|
| 275 |
-
test "filters both event_prop_names and allowed_prop_names by search input", %{site: site} do
|
| 276 |
-
site =
|
| 277 |
-
site
|
| 278 |
-
|> Ecto.Changeset.change(allowed_event_props: ["plan_type", "user_plan", "amount"])
|
| 279 |
-
|> Repo.update!()
|
| 280 |
-
|
| 281 |
-
populate_stats(site, [
|
| 282 |
-
build(:event,
|
| 283 |
-
name: "Purchase",
|
| 284 |
-
"meta.key": ["plan_name", "payment_method"],
|
| 285 |
-
"meta.value": ["business", "credit_card"],
|
| 286 |
-
timestamp: NaiveDateTime.utc_now() |> NaiveDateTime.shift(day: -1)
|
| 287 |
-
)
|
| 288 |
-
])
|
| 289 |
-
|
| 290 |
-
suggestions = GoalSuggestions.suggest_custom_property_names(site, "plan")
|
| 291 |
-
|
| 292 |
-
assert suggestions == ["plan_name", "plan_type", "user_plan"]
|
| 293 |
-
end
|
| 294 |
-
|
| 295 |
-
test "handles case-insensitive search matching for allowed_prop_names", %{site: site} do
|
| 296 |
-
site =
|
| 297 |
-
site
|
| 298 |
-
|> Ecto.Changeset.change(allowed_event_props: ["UserPlan", "PLAN_TYPE", "Payment_Method"])
|
| 299 |
-
|> Repo.update!()
|
| 300 |
-
|
| 301 |
-
suggestions = GoalSuggestions.suggest_custom_property_names(site, "plan")
|
| 302 |
-
|
| 303 |
-
assert suggestions == ["PLAN_TYPE", "UserPlan"]
|
| 304 |
-
end
|
| 305 |
-
|
| 306 |
-
test "deduplicates when property exists in both event_prop_names and allowed_prop_names", %{
|
| 307 |
-
site: site
|
| 308 |
-
} do
|
| 309 |
-
site =
|
| 310 |
-
site
|
| 311 |
-
|> Ecto.Changeset.change(allowed_event_props: ["plan", "amount", "referrer"])
|
| 312 |
-
|> Repo.update!()
|
| 313 |
-
|
| 314 |
-
populate_stats(site, [
|
| 315 |
-
build(:event,
|
| 316 |
-
name: "Purchase",
|
| 317 |
-
"meta.key": ["plan", "category"],
|
| 318 |
-
"meta.value": ["business", "software"],
|
| 319 |
-
timestamp: NaiveDateTime.utc_now() |> NaiveDateTime.shift(day: -1)
|
| 320 |
-
),
|
| 321 |
-
build(:event,
|
| 322 |
-
name: "Purchase",
|
| 323 |
-
"meta.key": ["plan"],
|
| 324 |
-
"meta.value": ["enterprise"],
|
| 325 |
-
timestamp: NaiveDateTime.utc_now() |> NaiveDateTime.shift(day: -2)
|
| 326 |
-
)
|
| 327 |
-
])
|
| 328 |
-
|
| 329 |
-
suggestions = GoalSuggestions.suggest_custom_property_names(site, "")
|
| 330 |
-
|
| 331 |
-
# plan appears only once
|
| 332 |
-
assert suggestions == ["plan", "category", "amount", "referrer"]
|
| 333 |
-
end
|
| 334 |
-
|
| 335 |
-
test "handles empty allowed_event_props gracefully", %{site: site} do
|
| 336 |
-
site =
|
| 337 |
-
site
|
| 338 |
-
|> Ecto.Changeset.change(allowed_event_props: [])
|
| 339 |
-
|> Repo.update!()
|
| 340 |
-
|
| 341 |
-
populate_stats(site, [
|
| 342 |
-
build(:event,
|
| 343 |
-
name: "Purchase",
|
| 344 |
-
"meta.key": ["plan"],
|
| 345 |
-
"meta.value": ["business"],
|
| 346 |
-
timestamp: NaiveDateTime.utc_now()
|
| 347 |
-
)
|
| 348 |
-
])
|
| 349 |
-
|
| 350 |
-
suggestions = GoalSuggestions.suggest_custom_property_names(site, "")
|
| 351 |
-
assert suggestions == ["plan"]
|
| 352 |
-
end
|
| 353 |
-
|
| 354 |
-
test "handles nil allowed_event_props gracefully", %{site: site} do
|
| 355 |
-
site =
|
| 356 |
-
site
|
| 357 |
-
|> Ecto.Changeset.change(allowed_event_props: nil)
|
| 358 |
-
|> Repo.update!()
|
| 359 |
-
|
| 360 |
-
populate_stats(site, [
|
| 361 |
-
build(:event,
|
| 362 |
-
name: "Purchase",
|
| 363 |
-
"meta.key": ["plan"],
|
| 364 |
-
"meta.value": ["business"],
|
| 365 |
-
timestamp: NaiveDateTime.utc_now()
|
| 366 |
-
)
|
| 367 |
-
])
|
| 368 |
-
|
| 369 |
-
suggestions = GoalSuggestions.suggest_custom_property_names(site, "")
|
| 370 |
-
assert suggestions == ["plan"]
|
| 371 |
-
end
|
| 372 |
-
end
|
| 373 |
-
|
| 374 |
-
describe "suggest_custom_property_values/3" do
|
| 375 |
-
setup [:create_user, :create_site]
|
| 376 |
-
|
| 377 |
-
test "returns custom property values for a given key from the last 30 days", %{site: site} do
|
| 378 |
-
populate_stats(site, [
|
| 379 |
-
build(:event,
|
| 380 |
-
name: "Purchase",
|
| 381 |
-
"meta.key": ["plan"],
|
| 382 |
-
"meta.value": ["business"],
|
| 383 |
-
timestamp: NaiveDateTime.utc_now() |> NaiveDateTime.shift(day: -1)
|
| 384 |
-
),
|
| 385 |
-
build(:event,
|
| 386 |
-
name: "Purchase",
|
| 387 |
-
"meta.key": ["plan"],
|
| 388 |
-
"meta.value": ["business"],
|
| 389 |
-
timestamp: NaiveDateTime.utc_now() |> NaiveDateTime.shift(day: -2)
|
| 390 |
-
),
|
| 391 |
-
build(:event,
|
| 392 |
-
name: "Purchase",
|
| 393 |
-
"meta.key": ["plan"],
|
| 394 |
-
"meta.value": ["enterprise"],
|
| 395 |
-
timestamp: NaiveDateTime.utc_now() |> NaiveDateTime.shift(day: -3)
|
| 396 |
-
),
|
| 397 |
-
build(:event,
|
| 398 |
-
name: "Signup",
|
| 399 |
-
"meta.key": ["plan"],
|
| 400 |
-
"meta.value": ["starter"],
|
| 401 |
-
timestamp: NaiveDateTime.utc_now() |> NaiveDateTime.shift(day: -5)
|
| 402 |
-
)
|
| 403 |
-
])
|
| 404 |
-
|
| 405 |
-
assert GoalSuggestions.suggest_custom_property_values(site, "plan", "") == [
|
| 406 |
-
"business",
|
| 407 |
-
"starter",
|
| 408 |
-
"enterprise"
|
| 409 |
-
]
|
| 410 |
-
end
|
| 411 |
-
|
| 412 |
-
test "filters property values by search input", %{site: site} do
|
| 413 |
-
populate_stats(site, [
|
| 414 |
-
build(:event,
|
| 415 |
-
name: "Purchase",
|
| 416 |
-
"meta.key": ["plan"],
|
| 417 |
-
"meta.value": ["business_monthly"],
|
| 418 |
-
timestamp: NaiveDateTime.utc_now() |> NaiveDateTime.shift(day: -1)
|
| 419 |
-
),
|
| 420 |
-
build(:event,
|
| 421 |
-
name: "Purchase",
|
| 422 |
-
"meta.key": ["plan"],
|
| 423 |
-
"meta.value": ["business_yearly"],
|
| 424 |
-
timestamp: NaiveDateTime.utc_now() |> NaiveDateTime.shift(day: -2)
|
| 425 |
-
),
|
| 426 |
-
build(:event,
|
| 427 |
-
name: "Purchase",
|
| 428 |
-
"meta.key": ["plan"],
|
| 429 |
-
"meta.value": ["starter"],
|
| 430 |
-
timestamp: NaiveDateTime.utc_now() |> NaiveDateTime.shift(day: -3)
|
| 431 |
-
)
|
| 432 |
-
])
|
| 433 |
-
|
| 434 |
-
assert GoalSuggestions.suggest_custom_property_values(site, "plan", "business") == [
|
| 435 |
-
"business_yearly",
|
| 436 |
-
"business_monthly"
|
| 437 |
-
]
|
| 438 |
-
end
|
| 439 |
-
|
| 440 |
-
test "excludes events older than 30 days", %{site: site} do
|
| 441 |
-
populate_stats(site, [
|
| 442 |
-
build(:event,
|
| 443 |
-
name: "Purchase",
|
| 444 |
-
"meta.key": ["plan"],
|
| 445 |
-
"meta.value": ["recent_plan"],
|
| 446 |
-
timestamp: NaiveDateTime.utc_now() |> NaiveDateTime.shift(day: -29)
|
| 447 |
-
),
|
| 448 |
-
build(:event,
|
| 449 |
-
name: "Purchase",
|
| 450 |
-
"meta.key": ["plan"],
|
| 451 |
-
"meta.value": ["old_plan"],
|
| 452 |
-
timestamp: NaiveDateTime.utc_now() |> NaiveDateTime.shift(day: -31)
|
| 453 |
-
)
|
| 454 |
-
])
|
| 455 |
-
|
| 456 |
-
assert GoalSuggestions.suggest_custom_property_values(site, "plan", "") == [
|
| 457 |
-
"recent_plan"
|
| 458 |
-
]
|
| 459 |
-
end
|
| 460 |
-
|
| 461 |
-
test "handles nil search input", %{site: site} do
|
| 462 |
-
populate_stats(site, [
|
| 463 |
-
build(:event,
|
| 464 |
-
name: "Purchase",
|
| 465 |
-
"meta.key": ["plan"],
|
| 466 |
-
"meta.value": ["business"],
|
| 467 |
-
timestamp: NaiveDateTime.utc_now()
|
| 468 |
-
)
|
| 469 |
-
])
|
| 470 |
-
|
| 471 |
-
assert GoalSuggestions.suggest_custom_property_values(site, "plan", nil) == ["business"]
|
| 472 |
-
end
|
| 473 |
-
|
| 474 |
-
test "orders values by count", %{site: site} do
|
| 475 |
-
populate_stats(site, [
|
| 476 |
-
build(:event,
|
| 477 |
-
name: "Purchase",
|
| 478 |
-
"meta.key": ["plan"],
|
| 479 |
-
"meta.value": ["starter"],
|
| 480 |
-
timestamp: NaiveDateTime.utc_now()
|
| 481 |
-
),
|
| 482 |
-
build(:event,
|
| 483 |
-
name: "Purchase",
|
| 484 |
-
"meta.key": ["plan"],
|
| 485 |
-
"meta.value": ["business"],
|
| 486 |
-
timestamp: NaiveDateTime.utc_now()
|
| 487 |
-
),
|
| 488 |
-
build(:event,
|
| 489 |
-
name: "Purchase",
|
| 490 |
-
"meta.key": ["plan"],
|
| 491 |
-
"meta.value": ["business"],
|
| 492 |
-
timestamp: NaiveDateTime.utc_now()
|
| 493 |
-
),
|
| 494 |
-
build(:event,
|
| 495 |
-
name: "Purchase",
|
| 496 |
-
"meta.key": ["plan"],
|
| 497 |
-
"meta.value": ["business"],
|
| 498 |
-
timestamp: NaiveDateTime.utc_now()
|
| 499 |
-
)
|
| 500 |
-
])
|
| 501 |
-
|
| 502 |
-
assert GoalSuggestions.suggest_custom_property_values(site, "plan", "") == [
|
| 503 |
-
"business",
|
| 504 |
-
"starter"
|
| 505 |
-
]
|
| 506 |
-
end
|
| 507 |
-
end
|
| 508 |
-
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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