Skip to content

Commit

Permalink
chore: purge firebase implementation (#131)
Browse files Browse the repository at this point in the history
  • Loading branch information
Salaton committed Jan 25, 2023
1 parent 9d757ed commit 3b8ab47
Show file tree
Hide file tree
Showing 18 changed files with 39 additions and 982 deletions.
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ go 1.16
require (
cloud.google.com/go/firestore v1.6.1
cloud.google.com/go/pubsub v1.21.0
firebase.google.com/go v3.13.0+incompatible
github.com/99designs/gqlgen v0.14.0
github.com/ahmetb/go-linq/v3 v3.2.0
github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d
Expand Down
14 changes: 0 additions & 14 deletions pkg/clinical/application/common/helpers/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@ import (
"github.com/savannahghi/clinical/pkg/clinical/application/common"
"github.com/savannahghi/clinical/pkg/clinical/domain"

fb "github.com/savannahghi/clinical/pkg/clinical/infrastructure/datastore/firebase"
"github.com/savannahghi/converterandformatter"
"github.com/savannahghi/enumutils"
"github.com/savannahghi/firebasetools"
"github.com/savannahghi/scalarutils"
log "github.com/sirupsen/logrus"
)
Expand Down Expand Up @@ -410,18 +408,6 @@ func ValidateEmail(
if !govalidator.IsEmail(email) {
return fmt.Errorf("invalid email format")
}

if optIn {
data := domain.EmailOptIn{
Email: email,
OptedIn: optIn,
}
_, err := firebasetools.SaveDataToFirestore(
firestoreClient, fb.EmailOptInCollectionName, data)
if err != nil {
return fmt.Errorf("unable to save email opt in: %v", err)
}
}
return nil
}

Expand Down
7 changes: 1 addition & 6 deletions pkg/clinical/application/common/testutils/testhelpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@ package testutils
import (
"context"

"cloud.google.com/go/firestore"
"github.com/savannahghi/clinical/pkg/clinical/application/extensions"
"github.com/savannahghi/clinical/pkg/clinical/infrastructure"
"github.com/savannahghi/clinical/pkg/clinical/infrastructure/datastore/fhir"
dataset "github.com/savannahghi/clinical/pkg/clinical/infrastructure/datastore/fhirdataset"
fb "github.com/savannahghi/clinical/pkg/clinical/infrastructure/datastore/firebase"
"github.com/savannahghi/clinical/pkg/clinical/infrastructure/services/openconceptlab"
"github.com/savannahghi/clinical/pkg/clinical/usecases"
"github.com/savannahghi/firebasetools"
Expand All @@ -21,12 +19,9 @@ func InitializeTestService(ctx context.Context) (usecases.Interactor, error) {
baseExtension := extensions.NewBaseExtensionImpl(fc)
repo := dataset.NewFHIRRepository()
fhir := fhir.NewFHIRStoreImpl(repo)
firestoreExt := fb.NewFirestoreClientExtension(&firestore.Client{})
fbExt := fb.NewFBClientExtensionImpl()
f := fb.NewFirebaseRepository(firestoreExt, fbExt)
ocl := openconceptlab.NewServiceOCL()

infrastructure := infrastructure.NewInfrastructureInteractor(baseExtension, repo, fhir, f, ocl)
infrastructure := infrastructure.NewInfrastructureInteractor(baseExtension, repo, fhir, ocl)

usecases := usecases.NewUsecasesInteractor(infrastructure)

Expand Down
68 changes: 6 additions & 62 deletions pkg/clinical/infrastructure/datastore/fhir/config_test.go

Large diffs are not rendered by default.

56 changes: 0 additions & 56 deletions pkg/clinical/infrastructure/datastore/fhirdataset/dataset_test.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
package fhirdataset_test

import (
"context"
"fmt"
"log"
"os"
"strings"
"testing"
"time"

"cloud.google.com/go/firestore"
"firebase.google.com/go/auth"
dataset "github.com/savannahghi/clinical/pkg/clinical/infrastructure/datastore/fhirdataset"
fb "github.com/savannahghi/clinical/pkg/clinical/infrastructure/datastore/firebase"
"github.com/savannahghi/firebasetools"
"github.com/tj/assert"
)

Expand All @@ -29,41 +22,11 @@ func TestMain(m *testing.M) {
os.Setenv("CLOUD_HEALTH_DATASET_ID", "datasetid")
os.Setenv("CLOUD_HEALTH_FHIRSTORE_ID", "fhirid")

// !NOTE!
// Under no circumstances should you remove this env var when testing
// You risk purging important collections, like our prod collections
os.Setenv("ROOT_COLLECTION_SUFFIX", fmt.Sprintf("clinical_ci_%v", time.Now().Unix()))
ctx := context.Background()
r := fb.Repository{} // They are nil
fsc, fbc := InitializeTestFirebaseClient(ctx)
if fsc == nil {
log.Printf("failed to initialize test FireStore client")
return
}
if fbc == nil {
log.Printf("failed to initialize test FireBase client")
return
}

purgeRecords := func() {
collections := []string{
r.GetEmailOptInCollectionName(),
}
for _, collection := range collections {
ref := fsc.Collection(collection)
_ = firebasetools.DeleteCollection(ctx, fsc, ref, 10)
}
}

// try clean up first
purgeRecords()

// do clean up
log.Printf("Running tests ...")
code := m.Run()

log.Printf("Tearing tests down ...")
purgeRecords()

// restore environment varibles to original values
os.Setenv(envOriginalValue, "ENVIRONMENT")
Expand All @@ -73,25 +36,6 @@ func TestMain(m *testing.M) {
os.Exit(code)
}

func InitializeTestFirebaseClient(ctx context.Context) (*firestore.Client, *auth.Client) {
fc := firebasetools.FirebaseClient{}
fa, err := fc.InitFirebase()
if err != nil {
log.Panicf("unable to initialize Firebase: %s", err)
}

fsc, err := fa.Firestore(ctx)
if err != nil {
log.Panicf("unable to initialize Firestore: %s", err)
}

fbc, err := fa.Auth(ctx)
if err != nil {
log.Panicf("can't initialize Firebase auth when setting up tests: %s", err)
}
return fsc, fbc
}

func TestRepository_CreateDataset(t *testing.T) {
fhirRepo := dataset.NewFHIRRepository()
tests := []struct {
Expand Down
89 changes: 0 additions & 89 deletions pkg/clinical/infrastructure/datastore/firebase/firebase.go

This file was deleted.

Loading

0 comments on commit 3b8ab47

Please sign in to comment.