auto style things

This commit is contained in:
Graham McIntire 2023-12-17 12:11:57 -06:00
parent e240954b25
commit da296d852d
47 changed files with 241 additions and 244 deletions

View file

@ -82,8 +82,7 @@
# You can customize the priority of any check
# Priority values are: `low, normal, high, higher`
#
{Credo.Check.Design.AliasUsage,
[priority: :low, if_nested_deeper_than: 2, if_called_more_often_than: 0]},
{Credo.Check.Design.AliasUsage, [priority: :low, if_nested_deeper_than: 2, if_called_more_often_than: 0]},
# You can also customize the exit_status of each check.
# If you don't want TODO comments to cause `mix credo` to fail, just
# set this value to 0 (zero).

View file

@ -1,6 +1,6 @@
[
import_deps: [:ecto, :ecto_sql, :phoenix, :stream_data],
subdirectories: ["priv/*/migrations"],
plugins: [Phoenix.LiveView.HTMLFormatter,Styler],
plugins: [Phoenix.LiveView.HTMLFormatter, Styler],
inputs: ["*.{heex,ex,exs}", "{config,lib,test}/**/*.{heex,ex,exs}", "priv/*/seeds.exs"]
]

View file

@ -33,8 +33,7 @@ config :aprs, Aprs.Mailer, adapter: Swoosh.Adapters.Local
config :esbuild,
version: "0.14.41",
default: [
args:
~w(js/app.js --bundle --target=es2017 --outdir=../priv/static/assets --external:/fonts/* --external:/images/*),
args: ~w(js/app.js --bundle --target=es2017 --outdir=../priv/static/assets --external:/fonts/* --external:/images/*),
cd: Path.expand("../assets", __DIR__),
env: %{"NODE_PATH" => Path.expand("../deps", __DIR__)}
]
@ -62,7 +61,7 @@ config :phoenix, :json_library, Jason
config :aprs,
ecto_repos: [Aprs.Repo],
aprs_is_server: System.get_env("APRS_SERVER", "dallas.aprs2.net"),
aprs_is_port: 14580,
aprs_is_port: 14_580,
aprs_is_default_filter: System.get_env("APRS_FILTER"),
aprs_is_login_id: System.get_env("APRS_CALLSIGN"),
aprs_is_password: System.get_env("APRS_PASSCODE"),

View file

@ -66,7 +66,7 @@ if config_env() == :prod do
config :aprs,
ecto_repos: [Aprs.Repo],
aprs_is_server: System.get_env("APRS_SERVER", "dallas.aprs2.net"),
aprs_is_port: 14580,
aprs_is_port: 14_580,
aprs_is_default_filter: System.get_env("APRS_FILTER"),
aprs_is_login_id: System.get_env("APRS_CALLSIGN"),
aprs_is_password: System.get_env("APRS_PASSCODE")

View file

@ -4,9 +4,11 @@ defmodule Aprs.Accounts do
"""
import Ecto.Query, warn: false
alias Aprs.Repo
alias Aprs.Accounts.{User, UserToken, UserNotifier}
alias Aprs.Accounts.User
alias Aprs.Accounts.UserNotifier
alias Aprs.Accounts.UserToken
alias Aprs.Repo
## Database getters
@ -38,8 +40,7 @@ defmodule Aprs.Accounts do
nil
"""
def get_user_by_email_and_password(email, password)
when is_binary(email) and is_binary(password) do
def get_user_by_email_and_password(email, password) when is_binary(email) and is_binary(password) do
user = Repo.get_by(User, email: email)
if User.valid_password?(user, password), do: user
end

View file

@ -1,5 +1,7 @@
defmodule Aprs.Accounts.User do
@moduledoc false
use Ecto.Schema
import Ecto.Changeset
schema "users" do
@ -122,7 +124,7 @@ defmodule Aprs.Accounts.User do
Confirms the account by setting `confirmed_at`.
"""
def confirm_changeset(user) do
now = NaiveDateTime.utc_now() |> NaiveDateTime.truncate(:second)
now = NaiveDateTime.truncate(NaiveDateTime.utc_now(), :second)
change(user, confirmed_at: now)
end

View file

@ -1,4 +1,5 @@
defmodule Aprs.Accounts.UserNotifier do
@moduledoc false
import Swoosh.Email
alias Aprs.Mailer

View file

@ -1,6 +1,9 @@
defmodule Aprs.Accounts.UserToken do
@moduledoc false
use Ecto.Schema
import Ecto.Query
alias Aprs.Accounts.UserToken
@hash_algorithm :sha256

View file

@ -1,11 +1,13 @@
defmodule Aprs.Archiver do
@moduledoc false
use GenServer
alias AprsWeb.Endpoint
require Jason
require Logger
# alias Aprs.{Packet, Repo}
alias AprsWeb.Endpoint
@topic "call"
# API

View file

@ -1,4 +1,5 @@
defmodule Aprs.Convert do
@moduledoc false
def wind(speed, :ultimeter, :mph), do: speed * 0.0621371192
def temp(value, :ultimeter, :f), do: value * 0.1

View file

@ -1,6 +1,9 @@
defmodule Aprs.DataExtended do
@moduledoc false
use Ecto.Schema
import Ecto.Changeset
alias Aprs.DataExtended
embedded_schema do

View file

@ -1,5 +1,7 @@
defmodule Aprs.Is do
@moduledoc false
use GenServer
require Logger
@aprs_timeout 30 * 1000
@ -14,7 +16,7 @@ defmodule Aprs.Is do
Process.flag(:trap_exit, true)
# Get startup parameters
server = Application.get_env(:aprs, :aprs_is_server, 'rotate.aprs2.net')
server = Application.get_env(:aprs, :aprs_is_server, ~c"rotate.aprs2.net")
port = Application.get_env(:aprs, :aprs_is_port, 14_580)
default_filter = Application.get_env(:aprs, :aprs_is_default_filter, "r/33/-96/100")
aprs_user_id = Application.get_env(:aprs, :aprs_is_login_id, "w5isp")
@ -40,8 +42,9 @@ defmodule Aprs.Is do
# end
with {:ok, socket} <- connect_to_aprs_is(server, port),
:ok <- send_login_string(socket, aprs_user_id, aprs_passcode, default_filter),
timer <- create_timer(@aprs_timeout) do
:ok <- send_login_string(socket, aprs_user_id, aprs_passcode, default_filter) do
timer = create_timer(@aprs_timeout)
{:ok,
%{
server: server,

View file

@ -1,4 +1,5 @@
defmodule Aprs.Is.IsSupervisor do
@moduledoc false
use Supervisor
def start_link(opts) do

View file

@ -1,3 +1,4 @@
defmodule Aprs.Mailer do
@moduledoc false
use Swoosh.Mailer, otp_app: :aprs
end

View file

@ -1,6 +1,9 @@
defmodule Aprs.Packet do
@moduledoc false
use Aprs.Schema
import Ecto.Changeset
alias Aprs.DataExtended
schema "packets" do

View file

@ -1,3 +1,4 @@
defmodule Aprs.Presence do
@moduledoc false
use Phoenix.Presence, otp_app: :aprs, pubsub_server: Aprs.PubSub
end

View file

@ -1,7 +1,9 @@
defmodule Aprs.Schema do
@moduledoc false
defmacro __using__(_) do
quote do
use Ecto.Schema
@primary_key {:id, :binary_id, autogenerate: true}
@foreign_key_type :binary_id
end

View file

@ -24,9 +24,9 @@ defmodule AprsWeb do
use Phoenix.Router, helpers: false
# Import common connection and controller functions to use in pipelines
import Plug.Conn
import Phoenix.Controller
import Phoenix.LiveView.Router
import Plug.Conn
end
end
@ -43,8 +43,8 @@ defmodule AprsWeb do
formats: [:html, :json],
layouts: [html: AprsWeb.Layouts]
import Plug.Conn
import AprsWeb.Gettext
import Plug.Conn
unquote(verified_routes())
end
@ -83,10 +83,10 @@ defmodule AprsWeb do
defp html_helpers do
quote do
# HTML escaping functionality
import Phoenix.HTML
# Core UI components and translation
import AprsWeb.CoreComponents
import AprsWeb.Gettext
import Phoenix.HTML
# Shortcut for generating JS commands
alias Phoenix.LiveView.JS

View file

@ -11,9 +11,10 @@ defmodule AprsWeb.CoreComponents do
"""
use Phoenix.Component
alias Phoenix.LiveView.JS
import AprsWeb.Gettext
alias Phoenix.LiveView.JS
@doc """
Renders a modal.
@ -359,11 +360,9 @@ defmodule AprsWeb.CoreComponents do
"""
end
defp input_border([] = _errors),
do: "border-zinc-300 focus:border-zinc-400 focus:ring-zinc-800/5"
defp input_border([] = _errors), do: "border-zinc-300 focus:border-zinc-400 focus:ring-zinc-800/5"
defp input_border([_ | _] = _errors),
do: "border-rose-400 focus:border-rose-400 focus:ring-rose-400/10"
defp input_border([_ | _] = _errors), do: "border-rose-400 focus:border-rose-400 focus:ring-rose-400/10"
@doc """
Renders a label.
@ -543,8 +542,7 @@ defmodule AprsWeb.CoreComponents do
JS.show(js,
to: selector,
transition:
{"transition-all transform ease-out duration-300",
"opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95",
{"transition-all transform ease-out duration-300", "opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95",
"opacity-100 translate-y-0 sm:scale-100"}
)
end
@ -554,8 +552,7 @@ defmodule AprsWeb.CoreComponents do
to: selector,
time: 200,
transition:
{"transition-all transform ease-in duration-200",
"opacity-100 translate-y-0 sm:scale-100",
{"transition-all transform ease-in duration-200", "opacity-100 translate-y-0 sm:scale-100",
"opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95"}
)
end

View file

@ -1,4 +1,5 @@
defmodule AprsWeb.Layouts do
@moduledoc false
use AprsWeb, :html
embed_templates "layouts/*"

View file

@ -1,5 +1,7 @@
defmodule AprsWeb.PacketsLive.Index do
@moduledoc false
use AprsWeb, :live_view
alias AprsWeb.Endpoint
@impl true

View file

@ -1,4 +1,5 @@
defmodule AprsWeb.UserConfirmationInstructionsLive do
@moduledoc false
use AprsWeb, :live_view
alias Aprs.Accounts
@ -16,8 +17,7 @@ defmodule AprsWeb.UserConfirmationInstructionsLive do
<p>
<.link href={~p"/users/register"}>Register</.link>
|
<.link href={~p"/users/log_in"}>Log in</.link>
| <.link href={~p"/users/log_in"}>Log in</.link>
</p>
"""
end

View file

@ -1,4 +1,5 @@
defmodule AprsWeb.UserConfirmationLive do
@moduledoc false
use AprsWeb, :live_view
alias Aprs.Accounts
@ -17,8 +18,7 @@ defmodule AprsWeb.UserConfirmationLive do
<p class="text-center mt-4">
<.link href={~p"/users/register"}>Register</.link>
|
<.link href={~p"/users/log_in"}>Log in</.link>
| <.link href={~p"/users/log_in"}>Log in</.link>
</p>
</div>
"""

View file

@ -1,4 +1,5 @@
defmodule AprsWeb.UserForgotPasswordLive do
@moduledoc false
use AprsWeb, :live_view
alias Aprs.Accounts
@ -21,8 +22,7 @@ defmodule AprsWeb.UserForgotPasswordLive do
</.simple_form>
<p class="text-center mt-4">
<.link href={~p"/users/register"}>Register</.link>
|
<.link href={~p"/users/log_in"}>Log in</.link>
| <.link href={~p"/users/log_in"}>Log in</.link>
</p>
</div>
"""

View file

@ -1,4 +1,5 @@
defmodule AprsWeb.UserLoginLive do
@moduledoc false
use AprsWeb, :live_view
def render(assigns) do

View file

@ -1,4 +1,5 @@
defmodule AprsWeb.UserRegistrationLive do
@moduledoc false
use AprsWeb, :live_view
alias Aprs.Accounts

View file

@ -1,4 +1,5 @@
defmodule AprsWeb.UserResetPasswordLive do
@moduledoc false
use AprsWeb, :live_view
alias Aprs.Accounts
@ -33,8 +34,7 @@ defmodule AprsWeb.UserResetPasswordLive do
<p class="text-center mt-4">
<.link href={~p"/users/register"}>Register</.link>
|
<.link href={~p"/users/log_in"}>Log in</.link>
| <.link href={~p"/users/log_in"}>Log in</.link>
</p>
</div>
"""

View file

@ -1,4 +1,5 @@
defmodule AprsWeb.UserSettingsLive do
@moduledoc false
use AprsWeb, :live_view
alias Aprs.Accounts

View file

@ -1,5 +1,7 @@
defmodule AprsWeb.Telemetry do
@moduledoc false
use Supervisor
import Telemetry.Metrics
def start_link(arg) do
@ -70,8 +72,7 @@ defmodule AprsWeb.Telemetry do
),
summary("aprs.repo.query.idle_time",
unit: {:native, :millisecond},
description:
"The time the connection spent waiting before being checked out for the query"
description: "The time the connection spent waiting before being checked out for the query"
),
# VM Metrics

View file

@ -1,8 +1,9 @@
defmodule AprsWeb.UserAuth do
@moduledoc false
use AprsWeb, :verified_routes
import Plug.Conn
import Phoenix.Controller
import Plug.Conn
alias Aprs.Accounts

View file

@ -3,44 +3,46 @@ defmodule Parser do
Main parsing library
"""
# import Bitwise
alias Aprs.{Convert, Packet}
alias Parser.Types.{MicE, Position}
alias Aprs.Convert
alias Aprs.Packet
alias Parser.Types.MicE
alias Parser.Types.Position
require Logger
def parse(message) do
try do
[sender, path, data] = String.split(message, [">", ":"], parts: 3)
[sender, path, data] = String.split(message, [">", ":"], parts: 3)
with [base_callsign, ssid] <- parse_callsign(sender),
data_type <- parse_datatype(String.first(data)),
data <- String.trim(data),
[destination, path] <- String.split(path, ",", parts: 2),
data_extended <- parse_data(data_type, destination, data) do
{:ok,
%Packet{
# TODO: temporary for liveview
id: Ecto.UUID.generate(),
sender: sender,
path: path,
destination: destination,
information_field: data,
data_type: data_type,
base_callsign: base_callsign,
ssid: ssid,
data_extended: data_extended
}}
else
true ->
{:error, "PARSE ERROR"}
end
rescue
_ ->
# Logger.debug("PARSE ERROR: " <> message)
{:ok, file} = File.open("./badpackets.txt", [:append])
IO.binwrite(file, message <> "\n\n")
File.close(file)
{:error, :invalid_packet}
with [base_callsign, ssid] <- parse_callsign(sender),
data_type = parse_datatype(String.first(data)),
data = String.trim(data),
[destination, path] <- String.split(path, ",", parts: 2) do
data_extended = parse_data(data_type, destination, data)
{:ok,
%Packet{
# TODO: temporary for liveview
id: Ecto.UUID.generate(),
sender: sender,
path: path,
destination: destination,
information_field: data,
data_type: data_type,
base_callsign: base_callsign,
ssid: ssid,
data_extended: data_extended
}}
else
true ->
{:error, "PARSE ERROR"}
end
rescue
_ ->
# Logger.debug("PARSE ERROR: " <> message)
{:ok, file} = File.open("./badpackets.txt", [:append])
IO.binwrite(file, message <> "\n\n")
File.close(file)
{:error, :invalid_packet}
end
def parse_callsign(callsign) do
@ -80,11 +82,9 @@ defmodule Parser do
def parse_data(:mic_e_old, destination, data), do: parse_mic_e(destination, data)
def parse_data(:position, _destination, data), do: parse_position_without_timestamp(false, data)
def parse_data(:position_with_message, _destination, data),
do: parse_position_without_timestamp(true, data)
def parse_data(:position_with_message, _destination, data), do: parse_position_without_timestamp(true, data)
def parse_data(:timestamped_position, _destination, data),
do: parse_position_with_timestamp(false, data)
def parse_data(:timestamped_position, _destination, data), do: parse_position_with_timestamp(false, data)
def parse_data(
:timestamped_position_with_message,
@ -94,14 +94,9 @@ defmodule Parser do
parse_position_with_datetime_and_weather(true, date_time_position, weather_report)
end
def parse_data(:timestamped_position_with_message, _destination, data),
do: parse_position_with_timestamp(true, data)
def parse_data(:timestamped_position_with_message, _destination, data), do: parse_position_with_timestamp(true, data)
def parse_data(
:message,
_destination,
<<":", addressee::binary-size(9), ":", message_text::binary>>
) do
def parse_data(:message, _destination, <<":", addressee::binary-size(9), ":", message_text::binary>>) do
# Aprs messages can have an optional message number tacked onto the end
# for the purposes of acknowledging message receipt.
# The sender tacks the message number onto the end of the message,
@ -129,13 +124,9 @@ defmodule Parser do
def parse_data(_type, _destination, _data), do: nil
def parse_position_with_datetime_and_weather(
aprs_messaging?,
date_time_position_data,
weather_report
) do
<<time::binary-size(7), latitude::binary-size(8), sym_table_id::binary-size(1),
longitude::binary-size(9)>> = date_time_position_data
def parse_position_with_datetime_and_weather(aprs_messaging?, date_time_position_data, weather_report) do
<<time::binary-size(7), latitude::binary-size(8), sym_table_id::binary-size(1), longitude::binary-size(9)>> =
date_time_position_data
# position = Parser.Types.Position.from_aprs(latitude, longitude)
%{latitude: lat, longitude: lon} = Parser.Types.Position.from_aprs(latitude, longitude)
@ -153,8 +144,8 @@ defmodule Parser do
end
def decode_compressed_position(
<<"/", latitude::binary-size(4), longitude::binary-size(4), _symbol::binary-size(1),
_cs::binary-size(2), _compression_type::binary-size(2), _rest::binary>>
<<"/", latitude::binary-size(4), longitude::binary-size(4), _symbol::binary-size(1), _cs::binary-size(2),
_compression_type::binary-size(2), _rest::binary>>
) do
lat = convert_to_base91(latitude)
lon = convert_to_base91(longitude)
@ -214,32 +205,29 @@ defmodule Parser do
def parse_position_without_timestamp(
aprs_messaging?,
<<_dti::binary-size(1), latitude::binary-size(8), sym_table_id::binary-size(1),
longitude::binary-size(9), symbol_code::binary-size(1), comment::binary>>
<<_dti::binary-size(1), latitude::binary-size(8), sym_table_id::binary-size(1), longitude::binary-size(9),
symbol_code::binary-size(1), comment::binary>>
) do
try do
# position = Position.from_aprs(latitude, longitude)
%{latitude: lat, longitude: lon} = Parser.Types.Position.from_aprs(latitude, longitude)
# position = Position.from_aprs(latitude, longitude)
%{latitude: lat, longitude: lon} = Parser.Types.Position.from_aprs(latitude, longitude)
%{
latitude: lat,
longitude: lon,
symbol_table_id: sym_table_id,
symbol_code: symbol_code,
comment: comment,
data_type: :position,
aprs_messaging?: aprs_messaging?
}
rescue
e -> Logger.error(Exception.format(:error, e, __STACKTRACE__))
end
%{
latitude: lat,
longitude: lon,
symbol_table_id: sym_table_id,
symbol_code: symbol_code,
comment: comment,
data_type: :position,
aprs_messaging?: aprs_messaging?
}
rescue
e -> Logger.error(Exception.format(:error, e, __STACKTRACE__))
end
def parse_position_without_timestamp(
aprs_messaging?,
<<_dti::binary-size(1), "/", latitude::binary-size(4), longitude::binary-size(4),
sym_table_id::binary-size(1), _cs::binary-size(2), _compression_type::binary-size(1),
comment::binary>> = message
<<_dti::binary-size(1), "/", latitude::binary-size(4), longitude::binary-size(4), sym_table_id::binary-size(1),
_cs::binary-size(2), _compression_type::binary-size(1), comment::binary>> = message
) do
# {:ok, file} = File.open("./compressed.txt", [:append])
# IO.binwrite(
@ -278,28 +266,25 @@ defmodule Parser do
def parse_position_with_timestamp(
aprs_messaging?,
<<_dti::binary-size(1), time::binary-size(7), latitude::binary-size(8),
sym_table_id::binary-size(1), longitude::binary-size(9), symbol_code::binary-size(1),
comment::binary>>
<<_dti::binary-size(1), time::binary-size(7), latitude::binary-size(8), sym_table_id::binary-size(1),
longitude::binary-size(9), symbol_code::binary-size(1), comment::binary>>
) do
try do
position = Position.from_aprs(latitude, longitude)
%{latitude: lat, longitude: lon} = Parser.Types.Position.from_aprs(latitude, longitude)
position = Position.from_aprs(latitude, longitude)
%{latitude: lat, longitude: lon} = Parser.Types.Position.from_aprs(latitude, longitude)
%{
latitude: lat,
longitude: lon,
position: position,
time: time,
symbol_table_id: sym_table_id,
symbol_code: symbol_code,
comment: comment,
data_type: :position,
aprs_messaging?: aprs_messaging?
}
rescue
e -> Logger.error(Exception.format(:error, e, __STACKTRACE__))
end
%{
latitude: lat,
longitude: lon,
position: position,
time: time,
symbol_table_id: sym_table_id,
symbol_code: symbol_code,
comment: comment,
data_type: :position,
aprs_messaging?: aprs_messaging?
}
rescue
e -> Logger.error(Exception.format(:error, e, __STACKTRACE__))
end
def parse_mic_e(destination_field, information_field) do
@ -356,7 +341,7 @@ defmodule Parser do
min = digits |> Enum.slice(2..3) |> Enum.join() |> String.to_integer()
fractional = digits |> Enum.slice(4..5) |> Enum.join() |> String.to_integer()
[ns, lo, ew] = destination_field |> to_charlist |> Enum.slice(3..5)
[ns, lo, ew] = destination_field |> to_charlist() |> Enum.slice(3..5)
north_south_indicator =
case ns do
@ -405,7 +390,7 @@ defmodule Parser do
# Convert the bits to binary to get the array index
index = message_bit_1 * 4 + message_bit_2 * 2 + message_bit_3
# need to invert this from the actual array index
display_index = to_string(7 - index) |> String.pad_leading(2, "0")
display_index = (7 - index) |> to_string() |> String.pad_leading(2, "0")
[message_code, message_description] =
case message_type do
@ -432,9 +417,8 @@ defmodule Parser do
end
def parse_mic_e_information(
<<dti::binary-size(1), d28::integer, m28::integer, f28::integer, sp28::integer,
dc28::integer, se28::integer, symbol::binary-size(1), table::binary-size(1),
message::binary>> = _information_field,
<<dti::binary-size(1), d28::integer, m28::integer, f28::integer, sp28::integer, dc28::integer, se28::integer,
symbol::binary-size(1), table::binary-size(1), message::binary>> = _information_field,
longitude_offset
) do
m =

View file

@ -54,12 +54,10 @@ defmodule Parser.Types.Position do
end
defp convert_garbage_to_zero(value) do
try do
_ = String.to_float(value)
value
rescue
ArgumentError -> "00000.00"
end
_ = String.to_float(value)
value
rescue
ArgumentError -> "00000.00"
end
# def to_string(%__MODULE__{} = position) do
@ -93,10 +91,5 @@ defmodule Parser.Types.Position do
# |> Float.round(2)
defp convert_fractional(fractional),
do:
fractional
|> String.trim()
|> String.pad_leading(4, "0")
|> String.to_float()
|> Kernel.*(60)
do: fractional |> String.trim() |> String.pad_leading(4, "0") |> String.to_float() |> Kernel.*(60)
end

View file

@ -1,10 +1,11 @@
defmodule Aprs.AccountsTest do
use Aprs.DataCase
alias Aprs.Accounts
import Aprs.AccountsFixtures
alias Aprs.Accounts.{User, UserToken}
alias Aprs.Accounts
alias Aprs.Accounts.User
alias Aprs.Accounts.UserToken
describe "get_user_by_email/1" do
test "does not return the user if the email does not exist" do

View file

@ -1,5 +1,6 @@
defmodule Aprs.ConvertTest do
use ExUnit.Case
alias Aprs.Convert
describe "wind/3" do

View file

@ -56,13 +56,9 @@ defmodule AprsWeb.UserSessionControllerTest do
test "login following registration", %{conn: conn, user: user} do
conn =
conn
|> post(~p"/users/log_in", %{
post(conn, ~p"/users/log_in", %{
"_action" => "registered",
"user" => %{
"email" => user.email,
"password" => valid_user_password()
}
"user" => %{"email" => user.email, "password" => valid_user_password()}
})
assert redirected_to(conn) == ~p"/"
@ -71,13 +67,9 @@ defmodule AprsWeb.UserSessionControllerTest do
test "login following password update", %{conn: conn, user: user} do
conn =
conn
|> post(~p"/users/log_in", %{
post(conn, ~p"/users/log_in", %{
"_action" => "password_updated",
"user" => %{
"email" => user.email,
"password" => valid_user_password()
}
"user" => %{"email" => user.email, "password" => valid_user_password()}
})
assert redirected_to(conn) == ~p"/users/settings"

View file

@ -1,8 +1,8 @@
defmodule AprsWeb.UserConfirmationInstructionsLiveTest do
use AprsWeb.ConnCase
import Phoenix.LiveViewTest
import Aprs.AccountsFixtures
import Phoenix.LiveViewTest
alias Aprs.Accounts
alias Aprs.Repo

View file

@ -1,8 +1,8 @@
defmodule AprsWeb.UserConfirmationLiveTest do
use AprsWeb.ConnCase
import Phoenix.LiveViewTest
import Aprs.AccountsFixtures
import Phoenix.LiveViewTest
alias Aprs.Accounts
alias Aprs.Repo

View file

@ -1,8 +1,8 @@
defmodule AprsWeb.UserForgotPasswordLiveTest do
use AprsWeb.ConnCase
import Phoenix.LiveViewTest
import Aprs.AccountsFixtures
import Phoenix.LiveViewTest
alias Aprs.Accounts
alias Aprs.Repo

View file

@ -1,8 +1,8 @@
defmodule AprsWeb.UserLoginLiveTest do
use AprsWeb.ConnCase
import Phoenix.LiveViewTest
import Aprs.AccountsFixtures
import Phoenix.LiveViewTest
describe "Log in page" do
test "renders log in page", %{conn: conn} do
@ -45,9 +45,7 @@ defmodule AprsWeb.UserLoginLiveTest do
{:ok, lv, _html} = live(conn, ~p"/users/log_in")
form =
form(lv, "#login_form",
user: %{email: "test@email.com", password: "123456", remember_me: true}
)
form(lv, "#login_form", user: %{email: "test@email.com", password: "123456", remember_me: true})
conn = submit_form(form, conn)

View file

@ -1,8 +1,8 @@
defmodule AprsWeb.UserRegistrationLiveTest do
use AprsWeb.ConnCase
import Phoenix.LiveViewTest
import Aprs.AccountsFixtures
import Phoenix.LiveViewTest
describe "Registration page" do
test "renders registration page", %{conn: conn} do

View file

@ -1,8 +1,8 @@
defmodule AprsWeb.UserResetPasswordLiveTest do
use AprsWeb.ConnCase
import Phoenix.LiveViewTest
import Aprs.AccountsFixtures
import Phoenix.LiveViewTest
alias Aprs.Accounts
@ -39,9 +39,7 @@ defmodule AprsWeb.UserResetPasswordLiveTest do
result =
lv
|> element("#reset_password_form")
|> render_change(
user: %{"password" => "secret12", "confirmation_password" => "secret123456"}
)
|> render_change(user: %{"password" => "secret12", "confirmation_password" => "secret123456"})
assert result =~ "should be at least 12 character"
assert result =~ "does not match password"

View file

@ -1,9 +1,10 @@
defmodule AprsWeb.UserSettingsLiveTest do
use AprsWeb.ConnCase
alias Aprs.Accounts
import Phoenix.LiveViewTest
import Aprs.AccountsFixtures
import Phoenix.LiveViewTest
alias Aprs.Accounts
describe "Settings page" do
test "renders settings page", %{conn: conn} do

View file

@ -1,10 +1,11 @@
defmodule AprsWeb.UserAuthTest do
use AprsWeb.ConnCase, async: true
alias Phoenix.LiveView
import Aprs.AccountsFixtures
alias Aprs.Accounts
alias AprsWeb.UserAuth
import Aprs.AccountsFixtures
alias Phoenix.LiveView
@remember_me_cookie "_aprs_web_user_remember_me"
@ -139,7 +140,7 @@ defmodule AprsWeb.UserAuthTest do
end
test "assigns nil to current_user assign if there isn't a user_token", %{conn: conn} do
session = conn |> get_session()
session = get_session(conn)
{:cont, updated_socket} =
UserAuth.on_mount(:mount_current_user, %{}, session, %LiveView.Socket{})
@ -173,7 +174,7 @@ defmodule AprsWeb.UserAuthTest do
end
test "redirects to login page if there isn't a user_token ", %{conn: conn} do
session = conn |> get_session()
session = get_session(conn)
socket = %LiveView.Socket{
endpoint: AprsWeb.Endpoint,
@ -200,7 +201,7 @@ defmodule AprsWeb.UserAuthTest do
end
test "Don't redirect is there is no authenticated user", %{conn: conn} do
session = conn |> get_session()
session = get_session(conn)
assert {:cont, _updated_socket} =
UserAuth.on_mount(

View file

@ -75,64 +75,64 @@ defmodule Parser.ParserTest do
describe "parse_datatype/1" do
test "position" do
%{
":" => :message,
">" => :status,
"!" => :position,
"/" => :timestamped_position,
"=" => :position_with_message,
"@" => :timestamped_position_with_message,
";" => :object,
"`" => :mic_e,
"'" => :mic_e_old,
"_" => :weather,
"T" => :telemetry,
"$" => :raw_gps_ultimeter,
"<" => :station_capabilities,
"?" => :query,
"{" => :user_defined,
"}" => :third_party_traffic,
"" => :unknown_datatype
}
|> Enum.each(fn {key, value} ->
assert Parser.parse_datatype(key) == value
end)
Enum.each(
%{
":" => :message,
">" => :status,
"!" => :position,
"/" => :timestamped_position,
"=" => :position_with_message,
"@" => :timestamped_position_with_message,
";" => :object,
"`" => :mic_e,
"'" => :mic_e_old,
"_" => :weather,
"T" => :telemetry,
"$" => :raw_gps_ultimeter,
"<" => :station_capabilities,
"?" => :query,
"{" => :user_defined,
"}" => :third_party_traffic,
"" => :unknown_datatype
},
fn {key, value} -> assert Parser.parse_datatype(key) == value end
)
end
end
describe "parse_manufacturer/3" do
test "with any manufacturer" do
[
%{matcher: [" ", nil, nil], result: "Original MIC-E"},
%{matcher: [">", nil, "="], result: "Kenwood TH-D72"},
%{matcher: [">", nil, "^"], result: "Kenwood TH-D74"},
%{matcher: [">", nil, nil], result: "Kenwood TH-D74A"},
%{matcher: ["]", nil, "="], result: "Kenwood DM-710"},
%{matcher: ["]", nil, nil], result: "Kenwood DM-700"},
%{matcher: ["`", "_", " "], result: "Yaesu VX-8"},
%{matcher: ["`", "_", "\""], result: "Yaesu FTM-350"},
%{matcher: ["`", "_", "#"], result: "Yaesu VX-8G"},
%{matcher: ["`", "_", "$"], result: "Yaesu FT1D"},
%{matcher: ["`", "_", "%"], result: "Yaesu FTM-400DR"},
%{matcher: ["`", "_", ")"], result: "Yaesu FTM-100D"},
%{matcher: ["`", "_", "("], result: "Yaesu FT2D"},
%{matcher: ["`", " ", "X"], result: "AP510"},
%{matcher: ["`", nil, nil], result: "Mic-Emsg"},
%{matcher: ["'", "|", "3"], result: "Byonics TinyTrack3"},
%{matcher: ["'", "|", "4"], result: "Byonics TinyTrack4"},
%{matcher: ["'", ":", "4"], result: "SCS GmbH & Co. P4dragon DR-7400 modems"},
%{matcher: ["'", ":", "8"], result: "SCS GmbH & Co. P4dragon DR-7800 modems"},
%{matcher: ["'", nil, nil], result: "McTrackr"},
%{matcher: [nil, "\"", nil], result: "Hamhud ?"},
%{matcher: [nil, "/", nil], result: "Argent ?"},
%{matcher: [nil, "^", nil], result: "HinzTec anyfrog"},
%{matcher: [nil, "*", nil], result: "APOZxx www.KissOZ.dk Tracker. OZ1EKD and OZ7HVO"},
%{matcher: [nil, "~", nil], result: "Other"},
%{matcher: [nil, nil, nil], result: :unknown_manufacturer}
]
|> Enum.each(fn %{matcher: [s1, s2, s3], result: result} ->
assert Parser.parse_manufacturer(s1, s2, s3) == result
end)
Enum.each(
[
%{matcher: [" ", nil, nil], result: "Original MIC-E"},
%{matcher: [">", nil, "="], result: "Kenwood TH-D72"},
%{matcher: [">", nil, "^"], result: "Kenwood TH-D74"},
%{matcher: [">", nil, nil], result: "Kenwood TH-D74A"},
%{matcher: ["]", nil, "="], result: "Kenwood DM-710"},
%{matcher: ["]", nil, nil], result: "Kenwood DM-700"},
%{matcher: ["`", "_", " "], result: "Yaesu VX-8"},
%{matcher: ["`", "_", "\""], result: "Yaesu FTM-350"},
%{matcher: ["`", "_", "#"], result: "Yaesu VX-8G"},
%{matcher: ["`", "_", "$"], result: "Yaesu FT1D"},
%{matcher: ["`", "_", "%"], result: "Yaesu FTM-400DR"},
%{matcher: ["`", "_", ")"], result: "Yaesu FTM-100D"},
%{matcher: ["`", "_", "("], result: "Yaesu FT2D"},
%{matcher: ["`", " ", "X"], result: "AP510"},
%{matcher: ["`", nil, nil], result: "Mic-Emsg"},
%{matcher: ["'", "|", "3"], result: "Byonics TinyTrack3"},
%{matcher: ["'", "|", "4"], result: "Byonics TinyTrack4"},
%{matcher: ["'", ":", "4"], result: "SCS GmbH & Co. P4dragon DR-7400 modems"},
%{matcher: ["'", ":", "8"], result: "SCS GmbH & Co. P4dragon DR-7800 modems"},
%{matcher: ["'", nil, nil], result: "McTrackr"},
%{matcher: [nil, "\"", nil], result: "Hamhud ?"},
%{matcher: [nil, "/", nil], result: "Argent ?"},
%{matcher: [nil, "^", nil], result: "HinzTec anyfrog"},
%{matcher: [nil, "*", nil], result: "APOZxx www.KissOZ.dk Tracker. OZ1EKD and OZ7HVO"},
%{matcher: [nil, "~", nil], result: "Other"},
%{matcher: [nil, nil, nil], result: :unknown_manufacturer}
],
fn %{matcher: [s1, s2, s3], result: result} -> assert Parser.parse_manufacturer(s1, s2, s3) == result end
)
end
end

View file

@ -20,14 +20,14 @@ defmodule AprsWeb.ConnCase do
using do
quote do
# The default endpoint for testing
@endpoint AprsWeb.Endpoint
use AprsWeb, :verified_routes
# Import conveniences for testing with connections
import Plug.Conn
import Phoenix.ConnTest
import AprsWeb.ConnCase
import Phoenix.ConnTest
import Plug.Conn
@endpoint AprsWeb.Endpoint
end
end

View file

@ -18,12 +18,12 @@ defmodule Aprs.DataCase do
using do
quote do
alias Aprs.Repo
import Aprs.DataCase
import Ecto
import Ecto.Changeset
import Ecto.Query
import Aprs.DataCase
alias Aprs.Repo
end
end

View file

@ -1,5 +1,6 @@
defmodule Parser.Types.PositionTest do
use ExUnit.Case
alias Parser.Types.Position
describe "from_aprs/2" do