github.com/cozy/cozy-stack@v0.0.0-20240327093429-939e4a21320e/worker/push/push_test.go (about)

     1  package push
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/cozy/cozy-stack/model/account"
     7  	"github.com/cozy/cozy-stack/pkg/config/config"
     8  	"github.com/cozy/cozy-stack/pkg/couchdb"
     9  	"github.com/cozy/cozy-stack/pkg/prefixer"
    10  	"github.com/cozy/cozy-stack/tests/testutils"
    11  	"github.com/stretchr/testify/assert"
    12  	"github.com/stretchr/testify/require"
    13  )
    14  
    15  func TestPush(t *testing.T) {
    16  	if testing.Short() {
    17  		t.Skip("a couchdb is required for this test: test skipped due to the use of --short flag")
    18  	}
    19  
    20  	config.UseTestFile(t)
    21  	testutils.NeedCouchdb(t)
    22  
    23  	t.Run("get firebase client", func(t *testing.T) {
    24  		contextName := "foo"
    25  		slug := "bar"
    26  
    27  		// Ensure that the global fcmClient is nil for this test, and restore its
    28  		// old value after the test
    29  		oldFcmClient := fcmClient
    30  		fcmClient = nil
    31  		defer func() {
    32  			fcmClient = oldFcmClient
    33  		}()
    34  
    35  		// Create an account type for the test
    36  		typ := account.AccountType{
    37  			DocID:         contextName + "/" + slug,
    38  			Slug:          slug,
    39  			AndroidAPIKey: "th3_f1r3b4s3_k3y",
    40  		}
    41  		err := couchdb.CreateNamedDoc(prefixer.SecretsPrefixer, &typ)
    42  		require.NoError(t, err)
    43  
    44  		defer func() {
    45  			_ = couchdb.DeleteDoc(prefixer.SecretsPrefixer, &typ)
    46  		}()
    47  
    48  		client := getFirebaseClient(slug, contextName)
    49  		assert.NotNil(t, client)
    50  	})
    51  }