Skip to content
Snippets Groups Projects
Select Git revision
  • 4838dfdd91f142f06aa5d2d2402505fd61df672d
  • main default protected
  • development
  • integration
  • v1.1.5
  • v1.1.4
  • v1.1.3
  • v1.1.2
  • v1.1.1
  • v1.1.0
  • v1.0.0
11 results

ClientProcessStatusProvider.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)
    	}
    }
    */