analytics/test/plausible_web/plugs/tracker_test.exs
RobertJoonas 11654ddc07
Script extension additions (#1915)
* added data-include attribute to plausible.exclusions.js

* reorder extensions in filename when serving the plausible script

* fix formatting

* tweaks after review

* changelog update
2022-05-27 10:11:40 +03:00

39 lines
1.2 KiB
Elixir

defmodule PlausibleWeb.TrackerTest do
use PlausibleWeb.ConnCase
use Plug.Test
test "returns legacy script p.js" do
assert String.contains?(get_script("p.js"), "; samesite=strict; path=/")
end
test "returns plausible script with every alias" do
plausible_js_response = get_script("plausible.js")
assert plausible_js_response == get_script("script.js")
assert plausible_js_response == get_script("analytics.js")
end
test "returns the right script extensions no matter the order" do
response = get_script("plausible.compat.file-downloads.hash.outbound-links.js")
assert String.contains?(response, "getElementById(\"plausible\")")
assert String.contains?(response, "file-types")
assert String.contains?(response, "hashchange")
assert String.contains?(response, "Outbound Link: Click")
assert !String.contains?(response, "data-exclude")
# local extension disabled
assert String.contains?(response, "/^localhost$|^127(\\.[0-9]+)")
assert response == get_script("plausible.outbound-links.file-downloads.compat.hash.js")
end
def get_script(filename) do
opts = PlausibleWeb.Tracker.init([])
conn(:get, "/js/#{filename}")
|> PlausibleWeb.Tracker.call(opts)
|> response(200)
end
end