diff options
| author | Dawid Rycerz <dawid@rycerz.xyz> | 2025-03-23 17:11:39 +0100 |
|---|---|---|
| committer | Dawid Rycerz <dawid@rycerz.xyz> | 2025-04-05 21:16:51 +0200 |
| commit | 0ab2e5ba2b0631b28b5b1405559237b3913c878f (patch) | |
| tree | 791cea788b0a62bc483d0041fbd0c655d2ad49e8 /test/support/fixtures/locations_fixtures.ex | |
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/locations_fixtures.ex')
| -rw-r--r-- | test/support/fixtures/locations_fixtures.ex | 69 |
1 files changed, 69 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 |
