Skip to content

Commit

Permalink
feat: Add Missing Methods for Blueprints
Browse files Browse the repository at this point in the history
  • Loading branch information
sccalabr committed Oct 25, 2023
1 parent aa28c83 commit 45d4aea
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 0 deletions.
27 changes: 27 additions & 0 deletions lib/novu/blueprints.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
defmodule Novu.Blueprints do
@moduledoc """
Provide access to the Novu Blueprints API
"""

alias Novu.Http

@doc """
Retrieve the current environment
[API Documentation](https://docs.novu.co/api-reference/get-v1blueprints)
"""
@spec get_blueprints(transaction_id :: String.t()) :: Http.response()
def get_blueprints(transaction_id) do
Http.get("/v1/blueprints/#{URI.encode(transaction_id)}")
end

@doc """
Returns a list of API keys
[API Documentation](https://docs.novu.co/api-reference/get-v1blueprintsgroup-by-category)
"""
@spec get_group_by_category :: Http.response()
def get_group_by_category do
Http.get("/v1/blueprints/group-by-category")
end
end
46 changes: 46 additions & 0 deletions test/novu/blueprints_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
defmodule Novu.BlueprintsTest do
use ExUnit.Case

import Novu.ApiTestHelpers

alias Novu.Blueprints

@test_api_key "test-api-key"

setup do
bypass = Bypass.open()

current_domain = Application.get_env(:novu, :domain)

Application.put_env(:novu, :domain, "http://localhost:#{bypass.port}")
Application.put_env(:novu, :api_key, @test_api_key)

on_exit(fn ->
Application.put_env(:novu, :domain, current_domain)
end)

{:ok, bypass: bypass}
end

describe "get_subscribers/1" do
test "creates a GET to /v1/blueprints", %{bypass: bypass} do
template_id = "template_id"

Bypass.expect(bypass, "GET", "/v1/blueprints//#{URI.encode(subscriber_id)}", fn conn ->

Check warning on line 29 in test/novu/blueprints_test.exs

View workflow job for this annotation

GitHub Actions / Test (Elixir 1.12 OTP 24)

variable "subscriber_id" does not exist and is being expanded to "subscriber_id()", please use parentheses to remove the ambiguity or change the variable name

Check failure on line 29 in test/novu/blueprints_test.exs

View workflow job for this annotation

GitHub Actions / Test (Elixir 1.12 OTP 24)

** (CompileError) test/novu/blueprints_test.exs:29: undefined function subscriber_id/0

Check warning on line 29 in test/novu/blueprints_test.exs

View workflow job for this annotation

GitHub Actions / Test (Elixir 1.13 OTP 25)

variable "subscriber_id" does not exist and is being expanded to "subscriber_id()", please use parentheses to remove the ambiguity or change the variable name

Check failure on line 29 in test/novu/blueprints_test.exs

View workflow job for this annotation

GitHub Actions / Test (Elixir 1.13 OTP 25)

** (CompileError) test/novu/blueprints_test.exs:29: undefined function subscriber_id/0 (expected Novu.BlueprintsTest to define such a function or for it to be imported, but none are available)

Check warning on line 29 in test/novu/blueprints_test.exs

View workflow job for this annotation

GitHub Actions / Test (Elixir 1.14 OTP 25)

variable "subscriber_id" does not exist and is being expanded to "subscriber_id()", please use parentheses to remove the ambiguity or change the variable name

Check failure on line 29 in test/novu/blueprints_test.exs

View workflow job for this annotation

GitHub Actions / Test (Elixir 1.14 OTP 25)

** (CompileError) test/novu/blueprints_test.exs:29: undefined function subscriber_id/0 (expected Novu.BlueprintsTest to define such a function or for it to be imported, but none are available)
novu_response(conn, 200, %{data: %{templateId: template_id}})
end)

assert {:ok, _body} = Blueprints.get_blueprints(template_id)
end
end

describe "get_group_by_category" do
test "creates a GET to /v1/blueprints/group-by-category", %{bypass: bypass} do
Bypass.expect(bypass, "GET", "/v1/blueprints/group-by-category", fn conn ->
novu_response(conn, 201, %{data: []})
end)

assert {:ok, _body} = Blueprints.get_group_by_category()
end
end
end

0 comments on commit 45d4aea

Please sign in to comment.