Skip to content

Commit

Permalink
Changelog and formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
jyeshe committed Oct 9, 2024
1 parent eea968f commit 77c5728
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion lib/lightning/collections.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down
15 changes: 13 additions & 2 deletions test/lightning/collections_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 77c5728

Please sign in to comment.