Skip to content

Commit

Permalink
fix: tests
Browse files Browse the repository at this point in the history
  • Loading branch information
zoedsoupe committed Apr 21, 2024
1 parent 91dbcb3 commit fa6ab1c
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 44 deletions.
67 changes: 61 additions & 6 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

70 changes: 39 additions & 31 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -1,35 +1,43 @@
{
description = "A complete Supabase SDK for Elixir alchemists";
description = "Supabase SDK for Elixir";

outputs = {nixpkgs, ...}: let
for-all-systems = function:
nixpkgs.lib.genAttrs [
"x86_64-linux"
"aarch64-darwin"
] (system:
function rec {
pkgs = nixpkgs.legacyPackages.${system};
inherit (pkgs.beam.interpreters) erlang_26;
inherit (pkgs.beam) packagesWith;
beam-pkgs = packagesWith erlang_26;
});
in {
devShells = for-all-systems ({
pkgs,
beam-pkgs,
...
}: rec {
default = supabase-potion;
supabase-potion = pkgs.mkShell {
name = "supabase-potion";
shellHook = "mkdir -p $PWD/.nix-mix";
packages = with pkgs;
[beam-pkgs.elixir_1_15 mix2nix earthly]
++ lib.optional stdenv.isDarwin [
darwin.apple_sdk.frameworks.CoreServices
darwin.apple_sdk.frameworks.CoreFoundation
];
};
});
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.11";
flake-parts.url = "github:hercules-ci/flake-parts";
systems.url = "github:nix-systems/default";
};

outputs = {
flake-parts,
systems,
...
} @ inputs:
flake-parts.lib.mkFlake {inherit inputs;} {
systems = import systems;
perSystem = {
pkgs,
system,
...
}: let
inherit (pkgs.beam.interpreters) erlangR26;
inherit (pkgs.beam) packagesWith;
beam = packagesWith erlangR26;
in {
_module.args.pkgs = import inputs.nixpkgs {
inherit system;
config.allowUnfree = true;
};
devShells.default = with pkgs;
mkShell {
name = "supabase-ex";
packages = with pkgs;
[beam.elixir_1_16]
++ lib.optional stdenv.isLinux [inotify-tools]
++ lib.optional stdenv.isDarwin [
darwin.apple_sdk.frameworks.CoreServices
darwin.apple_sdk.frameworks.CoreFoundation
];
};
};
};
}
6 changes: 6 additions & 0 deletions lib/supabase/supervisor.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
defmodule Supabase.Supervisor do
@moduledoc """
This module is reponsable to start the `Supabase.ClientRegistry`
and `Supabase.ClientSupervisor` processes to manage clients
automatically,
"""

use Supervisor

def start_link(opts \\ []) do
Expand Down
12 changes: 5 additions & 7 deletions test/supabase_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ defmodule SupabaseTest do
describe "init_client/1" do
test "should return a valid PID on valid attrs" do
{:ok, pid} =
Supabase.init_client(%{
name: :test,
Supabase.init_client(:test, %{
conn: %{
base_url: "https://test.supabase.co",
api_key: "test"
Expand All @@ -31,7 +30,7 @@ defmodule SupabaseTest do
conn: {"can't be blank", [validation: :required]}
]

{:error, changeset} = Supabase.init_client(%{name: :test, conn: %{}})
{:error, changeset} = Supabase.init_client(:test, %{conn: %{}})
assert conn = changeset.changes.conn

assert conn.errors == [
Expand All @@ -44,8 +43,7 @@ defmodule SupabaseTest do
describe "init_client!/1" do
test "should return a valid PID on valid attrs" do
pid =
Supabase.init_client!(%{
name: :test2,
Supabase.init_client!(:test2, %{
conn: %{
base_url: "https://test.supabase.co",
api_key: "test"
Expand All @@ -61,13 +59,13 @@ defmodule SupabaseTest do

test "should raise MissingSupabaseConfig on missing base_url" do
assert_raise MissingSupabaseConfig, fn ->
Supabase.init_client!(%{name: :test, conn: %{api_key: "test"}})
Supabase.init_client!(:test, %{conn: %{api_key: "test"}})
end
end

test "should raise MissingSupabaseConfig on missing api_key" do
assert_raise MissingSupabaseConfig, fn ->
Supabase.init_client!(%{name: :test, conn: %{base_url: "https://test.supabase.co"}})
Supabase.init_client!(:test, %{conn: %{base_url: "https://test.supabase.co"}})
end
end
end
Expand Down

0 comments on commit fa6ab1c

Please sign in to comment.