From 6b5d1182f1ac2c9898613f8fcd41222641177cde Mon Sep 17 00:00:00 2001
From: jbhusson <jonah@elixxir.io>
Date: Thu, 6 Feb 2020 16:19:32 -0800
Subject: [PATCH] move notifications functions to separate file

---
 api/client.go             | 46 ----------------------------------
 api/client_test.go        | 46 ----------------------------------
 api/notifications.go      | 52 +++++++++++++++++++++++++++++++++++++++
 api/notifications_test.go | 50 +++++++++++++++++++++++++++++++++++++
 4 files changed, 102 insertions(+), 92 deletions(-)
 create mode 100644 api/notifications.go
 create mode 100644 api/notifications_test.go

diff --git a/api/client.go b/api/client.go
index d7832a00e..36cf6203e 100644
--- a/api/client.go
+++ b/api/client.go
@@ -25,7 +25,6 @@ import (
 	"gitlab.com/elixxir/client/rekey"
 	"gitlab.com/elixxir/client/user"
 	"gitlab.com/elixxir/comms/connect"
-	"gitlab.com/elixxir/comms/mixmessages"
 	"gitlab.com/elixxir/crypto/cyclic"
 	"gitlab.com/elixxir/crypto/large"
 	"gitlab.com/elixxir/crypto/signature/rsa"
@@ -596,48 +595,3 @@ func (cl *Client) WriteToSessionFile(replacement string, store globals.Storage)
 
 	return nil
 }
-
-// RegisterForNotifications sends a message to notification bot indicating it
-// is registering for notifications
-func (cl *Client) RegisterForNotifications(notificationToken []byte) error {
-	// Pull the host from the manage
-	notificationBotHost, ok := cl.receptionManager.Comms.GetHost(id.NOTIFICATION_BOT)
-	if !ok {
-		return errors.New("Failed to retrieve host for notification bot")
-	}
-
-	// Send the register message
-	_, err := cl.receptionManager.Comms.RegisterForNotifications(notificationBotHost,
-		&mixmessages.NotificationToken{
-			Token: notificationToken,
-		})
-	if err != nil {
-		err := errors.Errorf(
-			"RegisterForNotifications: Unable to register for notifications! %s", err)
-		return err
-	}
-
-	return nil
-
-}
-
-// UnregisterForNotifications sends a message to notification bot indicating it
-// no longer wants to be registered for notifications
-func (cl *Client) UnregisterForNotifications() error {
-	// Pull the host from the manage
-	notificationBotHost, ok := cl.receptionManager.Comms.GetHost(id.NOTIFICATION_BOT)
-	if !ok {
-		return errors.New("Failed to retrieve host for notification bot")
-	}
-
-	// Send the unregister message
-	_, err := cl.receptionManager.Comms.UnregisterForNotifications(notificationBotHost)
-	if err != nil {
-		err := errors.Errorf(
-			"RegisterForNotifications: Unable to register for notifications! %s", err)
-		return err
-	}
-
-	return nil
-
-}
diff --git a/api/client_test.go b/api/client_test.go
index 3260a0f70..a1d46003f 100644
--- a/api/client_test.go
+++ b/api/client_test.go
@@ -560,49 +560,3 @@ func TestClient_GetCommManager(t *testing.T) {
 		t.Error("Received session not the same as the real session")
 	}
 }
-
-// Happy path
-func TestClient_RegisterForNotifications(t *testing.T) {
-	// Initialize client with dummy storage
-	storage := DummyStorage{LocationA: "Blah", StoreA: []byte{'a', 'b', 'c'}}
-	client, err := NewClient(&storage, "hello", "", def)
-	if err != nil {
-		t.Errorf("Failed to initialize dummy client: %s", err.Error())
-	}
-
-	// InitNetwork to gateways and reg server
-	err = client.InitNetwork()
-
-	if err != nil {
-		t.Errorf("Client failed of connect: %+v", err)
-	}
-
-	token := make([]byte, 32)
-
-	err = client.RegisterForNotifications(token)
-	if err != nil {
-		t.Errorf("Expected happy path, received error: %+v", err)
-	}
-}
-
-// Happy path
-func TestClient_UnregisterForNotifications(t *testing.T) {
-	// Initialize client with dummy storage
-	storage := DummyStorage{LocationA: "Blah", StoreA: []byte{'a', 'b', 'c'}}
-	client, err := NewClient(&storage, "hello", "", def)
-	if err != nil {
-		t.Errorf("Failed to initialize dummy client: %s", err.Error())
-	}
-
-	// InitNetwork to gateways and reg server
-	err = client.InitNetwork()
-
-	if err != nil {
-		t.Errorf("Client failed of connect: %+v", err)
-	}
-
-	err = client.UnregisterForNotifications()
-	if err != nil {
-		t.Errorf("Expected happy path, received error: %+v", err)
-	}
-}
diff --git a/api/notifications.go b/api/notifications.go
new file mode 100644
index 000000000..663daa315
--- /dev/null
+++ b/api/notifications.go
@@ -0,0 +1,52 @@
+package api
+
+import (
+	"github.com/pkg/errors"
+	"gitlab.com/elixxir/comms/mixmessages"
+	"gitlab.com/elixxir/primitives/id"
+)
+
+// RegisterForNotifications sends a message to notification bot indicating it
+// is registering for notifications
+func (cl *Client) RegisterForNotifications(notificationToken []byte) error {
+	// Pull the host from the manage
+	notificationBotHost, ok := cl.receptionManager.Comms.GetHost(id.NOTIFICATION_BOT)
+	if !ok {
+		return errors.New("Failed to retrieve host for notification bot")
+	}
+
+	// Send the register message
+	_, err := cl.receptionManager.Comms.RegisterForNotifications(notificationBotHost,
+		&mixmessages.NotificationToken{
+			Token: notificationToken,
+		})
+	if err != nil {
+		err := errors.Errorf(
+			"RegisterForNotifications: Unable to register for notifications! %s", err)
+		return err
+	}
+
+	return nil
+
+}
+
+// UnregisterForNotifications sends a message to notification bot indicating it
+// no longer wants to be registered for notifications
+func (cl *Client) UnregisterForNotifications() error {
+	// Pull the host from the manage
+	notificationBotHost, ok := cl.receptionManager.Comms.GetHost(id.NOTIFICATION_BOT)
+	if !ok {
+		return errors.New("Failed to retrieve host for notification bot")
+	}
+
+	// Send the unregister message
+	_, err := cl.receptionManager.Comms.UnregisterForNotifications(notificationBotHost)
+	if err != nil {
+		err := errors.Errorf(
+			"RegisterForNotifications: Unable to register for notifications! %s", err)
+		return err
+	}
+
+	return nil
+
+}
diff --git a/api/notifications_test.go b/api/notifications_test.go
new file mode 100644
index 000000000..b83345d4b
--- /dev/null
+++ b/api/notifications_test.go
@@ -0,0 +1,50 @@
+package api
+
+import "testing"
+
+// Happy path
+func TestClient_RegisterForNotifications(t *testing.T) {
+	// Initialize client with dummy storage
+	storage := DummyStorage{LocationA: "Blah", StoreA: []byte{'a', 'b', 'c'}}
+	client, err := NewClient(&storage, "hello", "", def)
+	if err != nil {
+		t.Errorf("Failed to initialize dummy client: %s", err.Error())
+		return
+	}
+
+	// InitNetwork to gateways and reg server
+	err = client.InitNetwork()
+
+	if err != nil {
+		t.Errorf("Client failed of connect: %+v", err)
+	}
+
+	token := make([]byte, 32)
+
+	err = client.RegisterForNotifications(token)
+	if err != nil {
+		t.Errorf("Expected happy path, received error: %+v", err)
+	}
+}
+
+// Happy path
+func TestClient_UnregisterForNotifications(t *testing.T) {
+	// Initialize client with dummy storage
+	storage := DummyStorage{LocationA: "Blah", StoreA: []byte{'a', 'b', 'c'}}
+	client, err := NewClient(&storage, "hello", "", def)
+	if err != nil {
+		t.Errorf("Failed to initialize dummy client: %s", err.Error())
+	}
+
+	// InitNetwork to gateways and reg server
+	err = client.InitNetwork()
+
+	if err != nil {
+		t.Errorf("Client failed of connect: %+v", err)
+	}
+
+	err = client.UnregisterForNotifications()
+	if err != nil {
+		t.Errorf("Expected happy path, received error: %+v", err)
+	}
+}
-- 
GitLab