summaryrefslogtreecommitdiff
path: root/test/support/fixtures
diff options
context:
space:
mode:
authorDawid Rycerz <dawid@rycerz.xyz>2025-03-23 17:11:39 +0100
committerDawid Rycerz <dawid@rycerz.xyz>2025-04-05 21:16:51 +0200
commit0ab2e5ba2b0631b28b5b1405559237b3913c878f (patch)
tree791cea788b0a62bc483d0041fbd0c655d2ad49e8 /test/support/fixtures
feat: initialize Phoenix application for weather alerts
This commit sets up the initial Silmataivas project structure, including: Phoenix web framework configuration, database models for users and locations, weather polling service, notification system, Docker and deployment configurations, CI/CD pipeline setup
Diffstat (limited to 'test/support/fixtures')
-rw-r--r--test/support/fixtures/locations_fixtures.ex69
-rw-r--r--test/support/fixtures/users_fixtures.ex41
2 files changed, 110 insertions, 0 deletions
diff --git a/test/support/fixtures/locations_fixtures.ex b/test/support/fixtures/locations_fixtures.ex
new file mode 100644
index 0000000..3b73074
--- /dev/null
+++ b/test/support/fixtures/locations_fixtures.ex
@@ -0,0 +1,69 @@
+defmodule Silmataivas.LocationsFixtures do
+ @moduledoc """
+ This module defines test helpers for creating
+ entities via the `Silmataivas.Locations` context.
+ """
+
+ import Silmataivas.UsersFixtures
+
+ @doc """
+ Generate a location.
+ """
+ def location_fixture(attrs \\ %{}) do
+ # Create a user first if user_id is not provided
+ user =
+ if Map.has_key?(attrs, :user_id) or Map.has_key?(attrs, "user_id"),
+ do: nil,
+ else: user_fixture()
+
+ {:ok, location} =
+ attrs
+ |> Enum.into(%{
+ latitude: 120.5,
+ longitude: 120.5,
+ user_id: (user && user.id) || attrs[:user_id] || attrs["user_id"]
+ })
+ |> Silmataivas.Locations.create_location()
+
+ location
+ end
+
+ @doc """
+ Generate a location with a specific user.
+ """
+ def location_fixture_with_user(user, attrs \\ %{}) do
+ {:ok, location} =
+ attrs
+ |> Enum.into(%{
+ latitude: 120.5,
+ longitude: 120.5,
+ user_id: user.id
+ })
+ |> Silmataivas.Locations.create_location()
+
+ location
+ end
+
+ @doc """
+ Generate location attributes with invalid values.
+ """
+ def invalid_location_attrs do
+ %{
+ latitude: nil,
+ longitude: nil,
+ user_id: nil
+ }
+ end
+
+ @doc """
+ Generate location attributes with extreme values.
+ """
+ def extreme_location_attrs do
+ %{
+ # Extreme value outside normal range
+ latitude: 1000.0,
+ # Extreme value outside normal range
+ longitude: 1000.0
+ }
+ end
+end
diff --git a/test/support/fixtures/users_fixtures.ex b/test/support/fixtures/users_fixtures.ex
new file mode 100644
index 0000000..8c26ab5
--- /dev/null
+++ b/test/support/fixtures/users_fixtures.ex
@@ -0,0 +1,41 @@
+defmodule Silmataivas.UsersFixtures do
+ @moduledoc """
+ This module defines test helpers for creating
+ entities via the `Silmataivas.Users` context.
+ """
+
+ @doc """
+ Generate a unique user user_id.
+ """
+ def unique_user_user_id, do: "some user_id#{System.unique_integer([:positive])}"
+
+ @doc """
+ Generate a user.
+ """
+ def user_fixture(attrs \\ %{}) do
+ {:ok, user} =
+ attrs
+ |> Enum.into(%{
+ role: "user",
+ user_id: unique_user_user_id()
+ })
+ |> Silmataivas.Users.create_user()
+
+ user
+ end
+
+ @doc """
+ Generate an admin user.
+ """
+ def admin_fixture(attrs \\ %{}) do
+ {:ok, user} =
+ attrs
+ |> Enum.into(%{
+ role: "admin",
+ user_id: unique_user_user_id()
+ })
+ |> Silmataivas.Users.create_user()
+
+ user
+ end
+end