Last active
July 11, 2025 19:30
-
-
Save pachun/8e338afe3caa94eb036d48077864b175 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| defmodule EmmaApiWeb.Gmail.WebhookControllerTest do | |
| use EmmaApiWeb.ConnCase | |
| use EmmaApi.TestDSL | |
| test "sends new inbox email push notifications and returns an ok status", %{conn: conn} do | |
| %{id: id, gmail_address: gmail_address} = Factory.insert(:gmail_account) | |
| allow(SendNewInboxEmailsPushNotifications) | |
| |> to_receive(:send, 2) | |
| allow(GoogleJWTTokenValidator) | |
| |> to_receive(:verify_and_validate, 1) | |
| |> and_respond( | |
| sequence([ | |
| fn "valid_token" -> {:ok, %{}} end, | |
| fn "valid_token" -> {:error, "BAD"} end | |
| ]) | |
| ) | |
| response = | |
| conn | |
| |> put_req_header("authorization", "Bearer " <> jwt_token) | |
| |> post( | |
| "/api/gmail_webhook", | |
| %{ | |
| "message" => %{ | |
| "data" => | |
| %{ | |
| emailAddress: gmail_address, | |
| historyId: "new_history_id" | |
| } | |
| |> Jason.encode!() | |
| |> Base.encode64() | |
| } | |
| } | |
| ) | |
| expect(json_response(response, 200) == %{}) | |
| expect(EmmaApi.Gmail.SendNewInboxEmailsPushNotifications) | |
| |> to_have_received(:send, [%GmailAccount{id: ^id}, "new_history_id"]) | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment