From 0ab2e5ba2b0631b28b5b1405559237b3913c878f Mon Sep 17 00:00:00 2001 From: Dawid Rycerz Date: Sun, 23 Mar 2025 17:11:39 +0100 Subject: 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 --- test/support/fixtures/locations_fixtures.ex | 69 +++++++++++++++++++++++++++++ test/support/fixtures/users_fixtures.ex | 41 +++++++++++++++++ 2 files changed, 110 insertions(+) create mode 100644 test/support/fixtures/locations_fixtures.ex create mode 100644 test/support/fixtures/users_fixtures.ex (limited to 'test/support/fixtures') 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 -- cgit v1.2.3