diff --git a/CHANGELOG.md b/CHANGELOG.md index a0758ad1f6..a8f1047a01 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,9 @@ and this project adheres to ### Added +- Introduces collections, a programatic workflow data sharing resource. + [#2551](https://github.com/OpenFn/lightning/issues/2551) + ### Changed ### Fixed diff --git a/lib/lightning/collections.ex b/lib/lightning/collections.ex index 819ce13298..dc821203a9 100644 --- a/lib/lightning/collections.ex +++ b/lib/lightning/collections.ex @@ -31,7 +31,8 @@ defmodule Lightning.Collections do end end - @spec put(String.t(), String.t(), String.t()) :: {:ok, Item.t()} | {:error, Ecto.Changeset.t()} + @spec put(String.t(), String.t(), String.t()) :: + {:ok, Item.t()} | {:error, Ecto.Changeset.t()} def put(col_name, key, value) do with nil <- Repo.get_by(Item, collection_name: col_name, key: key) do %Item{} diff --git a/test/lightning/collections_test.exs b/test/lightning/collections_test.exs index 28b5a9c14a..9527a7213a 100644 --- a/test/lightning/collections_test.exs +++ b/test/lightning/collections_test.exs @@ -61,7 +61,8 @@ defmodule Lightning.CollectionsTest do test "returns an :error if the collection does not exist" do insert(:collection_item, key: "existing_key") - assert {:error, :not_found} = Collections.get("nonexistent", "existing_key") + assert {:error, :not_found} = + Collections.get("nonexistent", "existing_key") end test "returns nil if the item key does not exist" do @@ -97,7 +98,17 @@ defmodule Lightning.CollectionsTest do end test "returns an :error if the collection does not exist" do - assert {:error, %{errors: [collection_name: {"does not exist", [constraint: :foreign, constraint_name: "collections_items_collection_name_fkey"]}]}} = Collections.put("nonexistent", "key", "value") + assert {:error, + %{ + errors: [ + collection_name: + {"does not exist", + [ + constraint: :foreign, + constraint_name: "collections_items_collection_name_fkey" + ]} + ] + }} = Collections.put("nonexistent", "key", "value") end end