Skip to content
Snippets Groups Projects
Select Git revision
  • bfca8d844e5c36fe09712b3bea609e2a12b13644
  • main default protected
  • dev protected
  • hotfixes-oct-2022
  • refactor/avatar-cell
  • 1.1.5
  • 1.1.4
  • 1.1.3
  • 1.1
  • 1.0.8
  • 1.0.7
  • 1.0.6
12 results

DB+Message.swift

Blame
  • fcm_test.go 1.59 KiB
    ////////////////////////////////////////////////////////////////////////////////
    // Copyright © 2020 Privategrity Corporation                                   /
    //                                                                             /
    // All rights reserved.                                                        /
    ////////////////////////////////////////////////////////////////////////////////
    package firebase
    
    import (
    	"context"
    	"firebase.google.com/go/messaging"
    	"testing"
    )
    
    type MockSender struct{}
    
    const token = "foIh7-NdlksspjDwT8O5kT:APA91bEQUCFeAadkIE-T3fHqAIIYwZm8lks0wQRIp5oh0qtMtjHcPjQhVZ3IDntZlv7PYAcHvDeu_7ncI8GcAlKama7YjzSLO9MgtAjxZMFivVfzQb-BD-6u0-MrJNR6XoOB9YX059ZB"
    
    func (MockSender) Send(ctx context.Context, app *messaging.Message) (string, error) {
    	return "test", nil
    }
    
    // This tests the function which sends a notification to firebase.
    // Note: this requires you to have a valid token & service credentials
    func TestSendNotification(t *testing.T) {
    	app := MockSender{}
    
    	_, err := sendNotification(app, token)
    	if err != nil {
    		t.Error(err.Error())
    	}
    }
    
    // Unit test the NewFirebaseComm method
    func TestNewFirebaseComm(t *testing.T) {
    	comm := NewFirebaseComm()
    	if comm.SendNotification == nil {
    		t.Error("Failed to set functions in comm")
    	}
    }
    
    /*
     * This function can't be unit tested without mocking firebase's infrastructure to a degree that is counterproductive
    func TestSetupMessagingApp(t *testing.T) {
    	dir, _ := os.Getwd()
    	_, _, err := setupMessagingApp(dir+"/../creds/serviceAccountKey.json")
    	if err != nil {
    		t.Errorf("Failed to setup messaging app: %+v", err)
    	}
    }
    */