From 0b8d26f4afd1fff2291beca78a875403a7d63616 Mon Sep 17 00:00:00 2001 From: jjponz Date: Mon, 3 Feb 2020 11:19:34 +0100 Subject: [PATCH] Fix pubsub adapter (#35) * Send attributes to pubsub * Set fixture with valid data --- lib/postoffice/adapters/pubsub.ex | 5 +++-- test/postoffice/handlers/pubsub_test.exs | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/postoffice/adapters/pubsub.ex b/lib/postoffice/adapters/pubsub.ex index 46ef2f7c..b9fe6e81 100644 --- a/lib/postoffice/adapters/pubsub.ex +++ b/lib/postoffice/adapters/pubsub.ex @@ -7,7 +7,7 @@ defmodule Postoffice.Adapters.Pubsub do @impl true def publish(endpoint, message) do Logger.info("Publishing PubSub message to #{endpoint}") - %{payload: payload, attributes: _attributes} = message + %{payload: payload, attributes: attributes} = message # Authenticate {:ok, token} = Goth.Token.for_scope("https://www.googleapis.com/auth/cloud-platform") Logger.info("successfully generated token for pubsub") @@ -16,7 +16,8 @@ defmodule Postoffice.Adapters.Pubsub do request = %GoogleApi.PubSub.V1.Model.PublishRequest{ messages: [ %GoogleApi.PubSub.V1.Model.PubsubMessage{ - data: Base.encode64(Poison.encode!(payload)) + data: Base.encode64(Poison.encode!(payload)), + attributes: attributes } ] } diff --git a/test/postoffice/handlers/pubsub_test.exs b/test/postoffice/handlers/pubsub_test.exs index 88e585ab..40472967 100644 --- a/test/postoffice/handlers/pubsub_test.exs +++ b/test/postoffice/handlers/pubsub_test.exs @@ -10,8 +10,8 @@ defmodule Postoffice.Handlers.PubsubTest do alias Postoffice.Messaging.Message @valid_message_attrs %{ - attributes: %{}, - payload: %{}, + attributes: %{"attr" => "some_value"}, + payload: %{"key" => "value"}, public_id: "7488a646-e31f-11e4-aace-600308960662" } @valid_publisher_attrs %{