diff --git a/go.mod b/go.mod index 7832ef42..1cebedc2 100644 --- a/go.mod +++ b/go.mod @@ -35,7 +35,7 @@ require ( github.com/vektah/gqlparser/v2 v2.1.0 gitlab.slade360emr.com/go/apiclient v0.0.14 gitlab.slade360emr.com/go/commontools/accounting v0.0.0-20210726041609-f5e1334c2640 - gitlab.slade360emr.com/go/commontools/crm v0.0.0-20210726041609-f5e1334c2640 + gitlab.slade360emr.com/go/commontools/crm v0.0.0-20210726041609-f5e1334c2640 // indirect go.opencensus.io v0.23.0 go.opentelemetry.io/contrib/instrumentation/github.com/gorilla/mux/otelmux v0.21.0 go.opentelemetry.io/otel v1.0.0-RC1 diff --git a/go.sum b/go.sum index 128553a4..a4a8a102 100644 --- a/go.sum +++ b/go.sum @@ -97,7 +97,6 @@ github.com/brianvoe/gofakeit v3.18.0+incompatible h1:wDOmHc9DLG4nRjUVVaxA+CEglKO github.com/brianvoe/gofakeit v3.18.0+incompatible/go.mod h1:kfwdRA90vvNhPutZWfH7WPaDzUjz+CZFqG+rPkOjGOc= github.com/brianvoe/gofakeit/v5 v5.11.2 h1:Ny5Nsf4z2023ZvYP8ujW8p5B1t5sxhdFaQ/0IYXbeSA= github.com/brianvoe/gofakeit/v5 v5.11.2/go.mod h1:/ZENnKqX+XrN8SORLe/fu5lZDIo1tuPncWuRD+eyhSI= -github.com/brianvoe/gofakeit/v6 v6.5.0 h1:zoWqGsuB8TB4MSwUZXtV3OwUSdzi8EHeXO8JfReRIHg= github.com/brianvoe/gofakeit/v6 v6.5.0/go.mod h1:palrJUk4Fyw38zIFB/uBZqsgzW5VsNllhHKKwAebzew= github.com/casbin/casbin/v2 v2.31.3 h1:NaPzGmLYWAtEgItUjqH8aGP6cvIYOY2X4HNMusCuuzY= github.com/casbin/casbin/v2 v2.31.3/go.mod h1:vByNa/Fchek0KZUgG5wEsl7iFsiviAYKRtgrQfcJqHg= diff --git a/pkg/onboarding/application/common/common.go b/pkg/onboarding/application/common/common.go index 8858efce..041bb496 100644 --- a/pkg/onboarding/application/common/common.go +++ b/pkg/onboarding/application/common/common.go @@ -79,12 +79,3 @@ const ( PartnerNavActionTitle = "Partners" PartnerNavActionDescription = "Partner Navigation action" ) - -// PubSub topic names -const ( - // CreateCRMContact is the TopicID for CRM contact creation - CreateCRMContact = "crm.contact.create" - - // UpdateCRMContact is the topicID for CRM contact updates - UpdateCRMContact = "crm.contact.update" -) diff --git a/pkg/onboarding/application/dto/input.go b/pkg/onboarding/application/dto/input.go index 58be0216..6e4f3f7b 100644 --- a/pkg/onboarding/application/dto/input.go +++ b/pkg/onboarding/application/dto/input.go @@ -11,7 +11,6 @@ import ( "github.com/savannahghi/profileutils" "github.com/savannahghi/scalarutils" dm "gitlab.slade360emr.com/go/commontools/accounting/pkg/domain" - CRMDomain "gitlab.slade360emr.com/go/commontools/crm/pkg/domain" ) // UserProfileInput is used to create or update a user's profile. @@ -303,21 +302,6 @@ type RegisterAdminInput struct { RoleIDs []string `json:"roleIDs"` } -// ContactLeadInput ... -type ContactLeadInput struct { - ContactType string `json:"contact_type,omitempty"` - ContactValue string `json:"contact_value,omitempty"` - FirstName string `json:"first_name,omitempty"` - LastName string `json:"last_name,omitempty"` - DateOfBirth scalarutils.Date `json:"date_of_birth,omitempty"` - IsSync bool `json:"isSync" firestore:"IsSync"` - TimeSync *time.Time `json:"timeSync" firestore:"TimeSync"` - OptOut CRMDomain.GeneralOptionType `json:"opt_out,omitempty"` - WantCover bool `json:"wantCover" firestore:"wantCover"` - ContactChannel string `json:"contact_channel,omitempty"` - IsRegistered bool `json:"is_registered,omitempty"` -} - // AgentFilterInput is used to supply filter parameters for agent filter inputs type AgentFilterInput struct { PhoneNumber string `json:"phoneNumber"` diff --git a/pkg/onboarding/application/dto/output.go b/pkg/onboarding/application/dto/output.go index cfe3e24c..2bc3f90a 100644 --- a/pkg/onboarding/application/dto/output.go +++ b/pkg/onboarding/application/dto/output.go @@ -4,7 +4,6 @@ import ( "github.com/savannahghi/firebasetools" "github.com/savannahghi/onboarding/pkg/onboarding/domain" "github.com/savannahghi/profileutils" - crmDomain "gitlab.slade360emr.com/go/commontools/crm/pkg/domain" ) // BusinessPartnerEdge is used to serialize GraphQL Relay edges for organization @@ -134,17 +133,6 @@ type UserInfo struct { UID string `json:"rawId,omitempty"` } -// Segment represents the Segments data -type Segment struct { - Properties crmDomain.ContactProperties `json:"properties" firestore:"properties"` - Wing string `json:"wing" firestore:"wing"` - MessageSent string `json:"message_sent" firestore:"message_sent"` - IsSynced string `json:"is_synced" firestore:"is_synced"` - TimeSynced string `json:"time_synced" firestore:"time_synced"` - PayerSladeCode string `json:"payer_slade_code" firestore:"payersladecode"` - MemberNumber string `json:"member_number" firestore:"membernumber"` -} - // RoleOutput is the formatted output with scopes and permissions type RoleOutput struct { ID string `json:"id"` diff --git a/pkg/onboarding/domain/models.go b/pkg/onboarding/domain/models.go index 61ec71be..fa77baeb 100644 --- a/pkg/onboarding/domain/models.go +++ b/pkg/onboarding/domain/models.go @@ -100,17 +100,6 @@ type NHIFDetails struct { NHIFCardPhotoID string `json:"nhifCardPhotoID" firestore:"nhifCardPhotoID"` } -// CRMContact represents a stored CRM contact -type CRMContact struct { - FirstName string `json:"first_name,omitempty"` - LastName string `json:"last_name,omitempty"` - DOB string `json:"dob,omitempty"` - PhoneNumber string `json:"phone_number,omitempty"` - OptOut string `json:"opt_out,omitempty"` - TimeStamp string `json:"time_stamp,omitempty"` - IsSynced string `json:"is_synced,omitempty"` -} - // Microservice identifies a micro-service that conforms to the Apollo Graphqql // federation specification. These microservices are composed by an Apollo // Gateway into a single data graph. diff --git a/pkg/onboarding/infrastructure/database/fb/firebase.go b/pkg/onboarding/infrastructure/database/fb/firebase.go index 6f8c8a15..a15a699a 100644 --- a/pkg/onboarding/infrastructure/database/fb/firebase.go +++ b/pkg/onboarding/infrastructure/database/fb/firebase.go @@ -47,7 +47,6 @@ const ( communicationsSettingsCollectionName = "communications_settings" smsCollectionName = "incoming_sms" firebaseExchangeRefreshTokenURL = "https://securetoken.googleapis.com/v1/token?key=" - marketingDataCollectionName = "marketing_data" rolesRevocationCollectionName = "role_revocations" rolesCollectionName = "user_roles" ) @@ -135,12 +134,6 @@ func (fr Repository) GetSMSCollectionName() string { return suffixed } -// GetMarketingDataCollectionName ... -func (fr Repository) GetMarketingDataCollectionName() string { - suffixed := firebasetools.SuffixCollection(marketingDataCollectionName) - return suffixed -} - // GetRolesCollectionName ... func (fr Repository) GetRolesCollectionName() string { suffixed := firebasetools.SuffixCollection(rolesCollectionName) diff --git a/pkg/onboarding/infrastructure/database/fb/firebase_integration_test.go b/pkg/onboarding/infrastructure/database/fb/firebase_integration_test.go index d1defa0e..f303c6dc 100644 --- a/pkg/onboarding/infrastructure/database/fb/firebase_integration_test.go +++ b/pkg/onboarding/infrastructure/database/fb/firebase_integration_test.go @@ -8,7 +8,6 @@ import ( "github.com/savannahghi/onboarding/pkg/onboarding/application/dto" "github.com/savannahghi/onboarding/pkg/onboarding/application/utils" - "gitlab.slade360emr.com/go/commontools/crm/pkg/infrastructure/services/hubspot" "fmt" @@ -36,13 +35,10 @@ import ( "github.com/savannahghi/onboarding/pkg/onboarding/infrastructure/services/engagement" - crmExt "github.com/savannahghi/onboarding/pkg/onboarding/infrastructure/services/crm" "github.com/savannahghi/onboarding/pkg/onboarding/infrastructure/services/messaging" pubsubmessaging "github.com/savannahghi/onboarding/pkg/onboarding/infrastructure/services/pubsub" "github.com/savannahghi/onboarding/pkg/onboarding/presentation/interactor" "github.com/savannahghi/onboarding/pkg/onboarding/usecases" - hubspotRepo "gitlab.slade360emr.com/go/commontools/crm/pkg/infrastructure/database/fs" - hubspotUsecases "gitlab.slade360emr.com/go/commontools/crm/pkg/usecases" ) const ( @@ -86,7 +82,6 @@ func TestMain(m *testing.M) { r.GetCustomerProfileCollectionName(), r.GetExperimentParticipantCollectionName(), r.GetKCYProcessCollectionName(), - r.GetMarketingDataCollectionName(), r.GetNHIFDetailsCollectionName(), r.GetProfileNudgesCollectionName(), r.GetSMSCollectionName(), @@ -148,18 +143,10 @@ func InitializeTestService(ctx context.Context) (*interactor.Interactor, error) firestoreExtension := fb.NewFirestoreClientExtension(fsc) fr := fb.NewFirebaseRepository(firestoreExtension, fbc) engage := engagement.NewServiceEngagementImpl(engagementClient, ext) - // hubspot usecases - hubspotService := hubspot.NewHubSpotService() - hubspotfr, err := hubspotRepo.NewHubSpotFirebaseRepository(ctx, hubspotService) - if err != nil { - return nil, fmt.Errorf("failed to initialize hubspot crm repository: %w", err) - } - hubspotUsecases := hubspotUsecases.NewHubSpotUsecases(hubspotfr) - crmExt := crmExt.NewCrmService(hubspotUsecases) + ps, err := pubsubmessaging.NewServicePubSubMessaging( pubSubClient, ext, - crmExt, fr, ) if err != nil { @@ -167,7 +154,7 @@ func InitializeTestService(ctx context.Context) (*interactor.Interactor, error) } mes := messaging.NewServiceMessagingImpl(ext) pinExt := extension.NewPINExtensionImpl() - profile := usecases.NewProfileUseCase(fr, ext, engage, ps, crmExt) + profile := usecases.NewProfileUseCase(fr, ext, engage, ps) supplier := usecases.NewSupplierUseCases(fr, profile, engage, mes, ext, ps) login := usecases.NewLoginUseCases(fr, profile, ext, pinExt) survey := usecases.NewSurveyUseCases(fr, ext) @@ -183,7 +170,6 @@ func InitializeTestService(ctx context.Context) (*interactor.Interactor, error) UserPIN: userpin, Engagement: engage, PubSub: ps, - CrmExt: crmExt, }, nil } diff --git a/pkg/onboarding/infrastructure/services/crm/mock/service_mock.go b/pkg/onboarding/infrastructure/services/crm/mock/service_mock.go deleted file mode 100644 index 217a1db6..00000000 --- a/pkg/onboarding/infrastructure/services/crm/mock/service_mock.go +++ /dev/null @@ -1,35 +0,0 @@ -package mock - -import ( - "context" - - hubspotDomain "gitlab.slade360emr.com/go/commontools/crm/pkg/domain" -) - -// FakeServiceCrm .. -type FakeServiceCrm struct { - OptOutFn func(ctx context.Context, phoneNumber string) (*hubspotDomain.CRMContact, error) - CreateHubSpotContactFn func(ctx context.Context, contact *hubspotDomain.CRMContact) (*hubspotDomain.CRMContact, error) - UpdateHubSpotContactFn func(ctx context.Context, contact *hubspotDomain.CRMContact) (*hubspotDomain.CRMContact, error) - GetContactByPhoneFn func(ctx context.Context, phone string) (*hubspotDomain.CRMContact, error) -} - -// OptOut .. -func (f *FakeServiceCrm) OptOut(ctx context.Context, phoneNumber string) (*hubspotDomain.CRMContact, error) { - return f.OptOutFn(ctx, phoneNumber) -} - -// CreateHubSpotContact .. -func (f *FakeServiceCrm) CreateHubSpotContact(ctx context.Context, contact *hubspotDomain.CRMContact) (*hubspotDomain.CRMContact, error) { - return f.CreateHubSpotContactFn(ctx, contact) -} - -// UpdateHubSpotContact .. -func (f *FakeServiceCrm) UpdateHubSpotContact(ctx context.Context, contact *hubspotDomain.CRMContact) (*hubspotDomain.CRMContact, error) { - return f.UpdateHubSpotContactFn(ctx, contact) -} - -// GetContactByPhone .. -func (f *FakeServiceCrm) GetContactByPhone(ctx context.Context, phone string) (*hubspotDomain.CRMContact, error) { - return f.GetContactByPhoneFn(ctx, phone) -} diff --git a/pkg/onboarding/infrastructure/services/crm/service.go b/pkg/onboarding/infrastructure/services/crm/service.go deleted file mode 100644 index 2019035c..00000000 --- a/pkg/onboarding/infrastructure/services/crm/service.go +++ /dev/null @@ -1,48 +0,0 @@ -package crm - -import ( - "context" - - hubspotDomain "gitlab.slade360emr.com/go/commontools/crm/pkg/domain" - hubspotUsecases "gitlab.slade360emr.com/go/commontools/crm/pkg/usecases" -) - -// ServiceCrm represents commontools crm lib usecases extension -type ServiceCrm interface { - OptOut(ctx context.Context, phoneNumber string) (*hubspotDomain.CRMContact, error) - CreateHubSpotContact(ctx context.Context, contact *hubspotDomain.CRMContact) (*hubspotDomain.CRMContact, error) - UpdateHubSpotContact(ctx context.Context, contact *hubspotDomain.CRMContact) (*hubspotDomain.CRMContact, error) - GetContactByPhone(ctx context.Context, phone string) (*hubspotDomain.CRMContact, error) -} - -// Hubspot interacts with `HubSpot` CRM usecases -type Hubspot struct { - hubSpotUsecases hubspotUsecases.HubSpotUsecases -} - -// NewCrmService inits a new crm instance -func NewCrmService(hubSpotUsecases hubspotUsecases.HubSpotUsecases) *Hubspot { - return &Hubspot{ - hubSpotUsecases: hubSpotUsecases, - } -} - -// OptOut marks a user as opted out of our marketing sms on both our firestore snd hubspot -func (h *Hubspot) OptOut(ctx context.Context, phoneNumber string) (*hubspotDomain.CRMContact, error) { - return h.hubSpotUsecases.OptOut(ctx, phoneNumber) -} - -// CreateHubSpotContact creates a hubspot contact on both our crm and firestore -func (h *Hubspot) CreateHubSpotContact(ctx context.Context, contact *hubspotDomain.CRMContact) (*hubspotDomain.CRMContact, error) { - return h.hubSpotUsecases.CreateHubSpotContact(ctx, contact) -} - -// UpdateHubSpotContact updates a hubspot contact on both our crm and firestore -func (h *Hubspot) UpdateHubSpotContact(ctx context.Context, contact *hubspotDomain.CRMContact) (*hubspotDomain.CRMContact, error) { - return h.hubSpotUsecases.UpdateHubSpotContact(ctx, contact) -} - -// GetContactByPhone gets a hubspot contact on both our crm and firestore -func (h *Hubspot) GetContactByPhone(ctx context.Context, phone string) (*hubspotDomain.CRMContact, error) { - return h.hubSpotUsecases.GetContactByPhone(ctx, phone) -} diff --git a/pkg/onboarding/infrastructure/services/pubsub/mock/service_mock.go b/pkg/onboarding/infrastructure/services/pubsub/mock/service_mock.go index 7e3d2eb5..e3b033b0 100644 --- a/pkg/onboarding/infrastructure/services/pubsub/mock/service_mock.go +++ b/pkg/onboarding/infrastructure/services/pubsub/mock/service_mock.go @@ -3,8 +3,6 @@ package mock import ( "context" "net/http" - - "gitlab.slade360emr.com/go/commontools/crm/pkg/domain" ) // FakeServicePubSub ... @@ -29,8 +27,6 @@ type FakeServicePubSub struct { r *http.Request, ) AddEngagementPubsubNameSpaceFn func(topic string) string - NotifyCreateContactFn func(ctx context.Context, contact domain.CRMContact) error - NotifyUpdateContactFn func(ctx context.Context, contact domain.CRMContact) error } // AddPubSubNamespace ... @@ -88,13 +84,3 @@ func (m *FakeServicePubSub) ReceivePubSubPushMessages( func (m *FakeServicePubSub) AddEngagementPubsubNameSpace(topic string) string { return m.AddEngagementPubsubNameSpaceFn(topic) } - -// NotifyCreateContact .. -func (m *FakeServicePubSub) NotifyCreateContact(ctx context.Context, contact domain.CRMContact) error { - return m.NotifyCreateContactFn(ctx, contact) -} - -// NotifyUpdateContact .. -func (m *FakeServicePubSub) NotifyUpdateContact(ctx context.Context, contact domain.CRMContact) error { - return m.NotifyUpdateContactFn(ctx, contact) -} diff --git a/pkg/onboarding/infrastructure/services/pubsub/publisher.go b/pkg/onboarding/infrastructure/services/pubsub/publisher.go deleted file mode 100644 index 4f0f87f2..00000000 --- a/pkg/onboarding/infrastructure/services/pubsub/publisher.go +++ /dev/null @@ -1,42 +0,0 @@ -package pubsubmessaging - -import ( - "context" - "encoding/json" - "fmt" - - "github.com/savannahghi/onboarding/pkg/onboarding/application/common" - "gitlab.slade360emr.com/go/commontools/crm/pkg/domain" -) - -func (ps *ServicePubSubMessaging) newPublish( - ctx context.Context, - data interface{}, - topic string, -) error { - payload, err := json.Marshal(data) - if err != nil { - return fmt.Errorf("unable to marshal data received: %v", err) - } - return ps.PublishToPubsub( - ctx, - ps.AddPubSubNamespace(topic), - payload, - ) -} - -// NotifyCreateContact publishes to crm.contact.create topic -func (ps *ServicePubSubMessaging) NotifyCreateContact( - ctx context.Context, - contact domain.CRMContact, -) error { - return ps.newPublish(ctx, contact, common.CreateCRMContact) -} - -// NotifyUpdateContact publishes to crm.contact.update topic -func (ps *ServicePubSubMessaging) NotifyUpdateContact( - ctx context.Context, - contact domain.CRMContact, -) error { - return ps.newPublish(ctx, contact, common.UpdateCRMContact) -} diff --git a/pkg/onboarding/infrastructure/services/pubsub/service.go b/pkg/onboarding/infrastructure/services/pubsub/service.go index dd994a1f..070973c0 100644 --- a/pkg/onboarding/infrastructure/services/pubsub/service.go +++ b/pkg/onboarding/infrastructure/services/pubsub/service.go @@ -6,11 +6,8 @@ import ( "net/http" "cloud.google.com/go/pubsub" - "github.com/savannahghi/onboarding/pkg/onboarding/application/common" "github.com/savannahghi/onboarding/pkg/onboarding/application/extension" - "github.com/savannahghi/onboarding/pkg/onboarding/infrastructure/services/crm" "github.com/savannahghi/onboarding/pkg/onboarding/repository" - "gitlab.slade360emr.com/go/commontools/crm/pkg/domain" ) const ( @@ -48,20 +45,12 @@ type ServicePubSub interface { r *http.Request, ) AddEngagementPubsubNameSpace(topic string) string - - // Publishers - NotifyCreateContact(ctx context.Context, contact domain.CRMContact) error - NotifyUpdateContact( - ctx context.Context, - contact domain.CRMContact, - ) error } // ServicePubSubMessaging sends "real" (production) notifications type ServicePubSubMessaging struct { client *pubsub.Client baseExt extension.BaseExtension - crm crm.ServiceCrm repo repository.OnboardingRepository } @@ -69,13 +58,11 @@ type ServicePubSubMessaging struct { func NewServicePubSubMessaging( client *pubsub.Client, ext extension.BaseExtension, - crm crm.ServiceCrm, repo repository.OnboardingRepository, ) (*ServicePubSubMessaging, error) { s := &ServicePubSubMessaging{ client: client, baseExt: ext, - crm: crm, repo: repo, } @@ -122,10 +109,7 @@ func (ps ServicePubSubMessaging) AddPubSubNamespace(topicName string) string { // TopicIDs returns the known (registered) topic IDs func (ps ServicePubSubMessaging) TopicIDs() []string { - return []string{ - ps.AddPubSubNamespace(common.CreateCRMContact), - ps.AddPubSubNamespace(common.UpdateCRMContact), - } + return []string{} } // PublishToPubsub sends a message to a specifeid Topic diff --git a/pkg/onboarding/infrastructure/services/pubsub/subscriber.go b/pkg/onboarding/infrastructure/services/pubsub/subscriber.go index e3bdfc04..732a6250 100644 --- a/pkg/onboarding/infrastructure/services/pubsub/subscriber.go +++ b/pkg/onboarding/infrastructure/services/pubsub/subscriber.go @@ -2,11 +2,8 @@ package pubsubmessaging import ( "encoding/json" - "fmt" "net/http" - "github.com/savannahghi/onboarding/pkg/onboarding/application/common" - "gitlab.slade360emr.com/go/commontools/crm/pkg/domain" "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/trace" ) @@ -48,53 +45,7 @@ func (ps ServicePubSubMessaging) ReceivePubSubPushMessages( )) switch topicID { - case ps.AddPubSubNamespace(common.CreateCRMContact): - var CRMContact domain.CRMContact - err := json.Unmarshal(message.Message.Data, &CRMContact) - if err != nil { - ps.baseExt.WriteJSONResponse( - w, - ps.baseExt.ErrorMap(err), - http.StatusBadRequest, - ) - return - } - if _, err = ps.crm.CreateHubSpotContact(ctx, &CRMContact); err != nil { - ps.baseExt.WriteJSONResponse( - w, - ps.baseExt.ErrorMap(err), - http.StatusBadRequest, - ) - return - } - case ps.AddPubSubNamespace(common.UpdateCRMContact): - var CRMContact domain.CRMContact - err := json.Unmarshal(message.Message.Data, &CRMContact) - if err != nil { - ps.baseExt.WriteJSONResponse( - w, - ps.baseExt.ErrorMap(err), - http.StatusBadRequest, - ) - return - } - if _, err = ps.crm.UpdateHubSpotContact(ctx, &CRMContact); err != nil { - ps.baseExt.WriteJSONResponse( - w, - ps.baseExt.ErrorMap(err), - http.StatusBadRequest, - ) - return - } - - default: - errMsg := fmt.Sprintf( - "pub sub handler error: unknown topic `%s`", - topicID, - ) - http.Error(w, errMsg, http.StatusBadRequest) - return } resp := map[string]string{"status": "success"} diff --git a/pkg/onboarding/presentation/config.go b/pkg/onboarding/presentation/config.go index 1ff8dbba..ad6174b3 100644 --- a/pkg/onboarding/presentation/config.go +++ b/pkg/onboarding/presentation/config.go @@ -18,7 +18,6 @@ import ( "github.com/savannahghi/onboarding/pkg/onboarding/domain" "github.com/savannahghi/onboarding/pkg/onboarding/infrastructure/database/fb" "github.com/savannahghi/onboarding/pkg/onboarding/infrastructure/services/engagement" - "gitlab.slade360emr.com/go/commontools/crm/pkg/infrastructure/services/hubspot" loginservice "github.com/savannahghi/onboarding/pkg/onboarding/infrastructure/services/login_service" "github.com/savannahghi/onboarding/pkg/onboarding/infrastructure/services/messaging" @@ -32,7 +31,6 @@ import ( "github.com/gorilla/mux" "github.com/savannahghi/firebasetools" "github.com/savannahghi/interserviceclient" - crmExt "github.com/savannahghi/onboarding/pkg/onboarding/infrastructure/services/crm" "github.com/savannahghi/onboarding/pkg/onboarding/presentation/graph" "github.com/savannahghi/onboarding/pkg/onboarding/presentation/graph/generated" "github.com/savannahghi/onboarding/pkg/onboarding/presentation/interactor" @@ -40,8 +38,6 @@ import ( adminSrv "github.com/savannahghi/onboarding/pkg/onboarding/usecases/admin" "github.com/savannahghi/serverutils" log "github.com/sirupsen/logrus" - hubspotRepo "gitlab.slade360emr.com/go/commontools/crm/pkg/infrastructure/database/fs" - hubspotUsecases "gitlab.slade360emr.com/go/commontools/crm/pkg/usecases" ) const ( @@ -112,18 +108,9 @@ func Router(ctx context.Context) (*mux.Router, error) { mes := messaging.NewServiceMessagingImpl(baseExt) pinExt := extension.NewPINExtensionImpl() - // hubspot usecases - hubspotService := hubspot.NewHubSpotService() - hubspotfr, err := hubspotRepo.NewHubSpotFirebaseRepository(ctx, hubspotService) - if err != nil { - return nil, fmt.Errorf("failed to initialize hubspot crm repository: %w", err) - } - hubspotUsecases := hubspotUsecases.NewHubSpotUsecases(hubspotfr) - crmExt := crmExt.NewCrmService(hubspotUsecases) pubSub, err := pubsubmessaging.NewServicePubSubMessaging( pubSubClient, baseExt, - crmExt, repo, ) if err != nil { @@ -131,7 +118,7 @@ func Router(ctx context.Context) (*mux.Router, error) { } // Initialize the usecases - profile := usecases.NewProfileUseCase(repo, baseExt, engage, pubSub, crmExt) + profile := usecases.NewProfileUseCase(repo, baseExt, engage, pubSub) supplier := usecases.NewSupplierUseCases(repo, profile, engage, mes, baseExt, pubSub) login := usecases.NewLoginUseCases(repo, profile, baseExt, pinExt) survey := usecases.NewSurveyUseCases(repo, baseExt) @@ -145,8 +132,7 @@ func Router(ctx context.Context) (*mux.Router, error) { i, err := interactor.NewOnboardingInteractor( profile, su, supplier, login, survey, userpin, engage, mes, nhif, pubSub, - sms, adminSrv, crmExt, - role, + sms, adminSrv, role, ) if err != nil { return nil, fmt.Errorf("can't instantiate service : %w", err) @@ -169,7 +155,6 @@ func Router(ctx context.Context) (*mux.Router, error) { r.Use(serverutils.CustomHTTPRequestMetricsMiddleware()) // Unauthenticated routes - r.Path("/optout").Methods(http.MethodPost, http.MethodOptions).HandlerFunc(h.OptOut()) r.Path("/switch_flagged_features").Methods( http.MethodPost, http.MethodOptions, diff --git a/pkg/onboarding/presentation/interactor/interactor.go b/pkg/onboarding/presentation/interactor/interactor.go index 8514859c..8592461b 100644 --- a/pkg/onboarding/presentation/interactor/interactor.go +++ b/pkg/onboarding/presentation/interactor/interactor.go @@ -5,7 +5,6 @@ package interactor import ( "github.com/savannahghi/onboarding/pkg/onboarding/infrastructure/services/engagement" - "github.com/savannahghi/onboarding/pkg/onboarding/infrastructure/services/crm" "github.com/savannahghi/onboarding/pkg/onboarding/infrastructure/services/messaging" pubsubmessaging "github.com/savannahghi/onboarding/pkg/onboarding/infrastructure/services/pubsub" "github.com/savannahghi/onboarding/pkg/onboarding/usecases" @@ -26,7 +25,6 @@ type Interactor struct { PubSub pubsubmessaging.ServicePubSub SMS usecases.SMSUsecase AdminSrv admin.Usecase - CrmExt crm.ServiceCrm Role usecases.RoleUseCase } @@ -44,7 +42,6 @@ func NewOnboardingInteractor( pubsub pubsubmessaging.ServicePubSub, sms usecases.SMSUsecase, admin admin.Usecase, - crmExt crm.ServiceCrm, role usecases.RoleUseCase, ) (*Interactor, error) { @@ -61,7 +58,6 @@ func NewOnboardingInteractor( PubSub: pubsub, SMS: sms, AdminSrv: admin, - CrmExt: crmExt, Role: role, }, nil } diff --git a/pkg/onboarding/presentation/rest/handlers.go b/pkg/onboarding/presentation/rest/handlers.go index ffcae965..262d738b 100644 --- a/pkg/onboarding/presentation/rest/handlers.go +++ b/pkg/onboarding/presentation/rest/handlers.go @@ -27,7 +27,6 @@ type HandlersInterfaces interface { CreateUserWithPhoneNumber() http.HandlerFunc UserRecoveryPhoneNumbers() http.HandlerFunc SetPrimaryPhoneNumber() http.HandlerFunc - OptOut() http.HandlerFunc LoginByPhone() http.HandlerFunc LoginAnonymous() http.HandlerFunc RequestPINReset() http.HandlerFunc @@ -170,35 +169,6 @@ func (h *HandlersInterfacesImpl) UserRecoveryPhoneNumbers() http.HandlerFunc { } } -//OptOut marks a person as opted out of our promotional/marketing messages -func (h *HandlersInterfacesImpl) OptOut() http.HandlerFunc { - return func(w http.ResponseWriter, r *http.Request) { - ctx := r.Context() - - p := &dto.PhoneNumberPayload{} - serverutils.DecodeJSONToTargetStruct(w, r, p) - if p.PhoneNumber == nil { - err := fmt.Errorf( - "expected a phone number to be provided", - ) - serverutils.WriteJSONResponse(w, err, http.StatusBadRequest) - return - } - - _, err := h.interactor.CrmExt.OptOut(ctx, *p.PhoneNumber) - if err != nil { - serverutils.WriteJSONResponse(w, err, http.StatusBadRequest) - return - } - - serverutils.WriteJSONResponse( - w, - dto.NewOKResp(fmt.Sprintf("%s has successfully been opted out", *p.PhoneNumber)), - http.StatusOK, - ) - } -} - // SetPrimaryPhoneNumber sets the provided phone number as the primary phone of the profile associated with it func (h *HandlersInterfacesImpl) SetPrimaryPhoneNumber() http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { diff --git a/pkg/onboarding/presentation/rest/handlers_test.go b/pkg/onboarding/presentation/rest/handlers_test.go index 16edc041..08f1d656 100644 --- a/pkg/onboarding/presentation/rest/handlers_test.go +++ b/pkg/onboarding/presentation/rest/handlers_test.go @@ -20,15 +20,12 @@ import ( "github.com/savannahghi/onboarding/pkg/onboarding/application/dto" "github.com/savannahghi/onboarding/pkg/onboarding/application/extension" "github.com/savannahghi/profileutils" - crmDomain "gitlab.slade360emr.com/go/commontools/crm/pkg/domain" - "gitlab.slade360emr.com/go/commontools/crm/pkg/infrastructure/services/hubspot" extMock "github.com/savannahghi/onboarding/pkg/onboarding/application/extension/mock" "github.com/savannahghi/onboarding/pkg/onboarding/domain" "github.com/savannahghi/onboarding/pkg/onboarding/infrastructure/services/engagement" engagementMock "github.com/savannahghi/onboarding/pkg/onboarding/infrastructure/services/engagement/mock" - crmExt "github.com/savannahghi/onboarding/pkg/onboarding/infrastructure/services/crm" "github.com/savannahghi/onboarding/pkg/onboarding/infrastructure/services/messaging" messagingMock "github.com/savannahghi/onboarding/pkg/onboarding/infrastructure/services/messaging/mock" pubsubmessaging "github.com/savannahghi/onboarding/pkg/onboarding/infrastructure/services/pubsub" @@ -39,8 +36,6 @@ import ( mockRepo "github.com/savannahghi/onboarding/pkg/onboarding/repository/mock" "github.com/savannahghi/onboarding/pkg/onboarding/usecases" adminSrv "github.com/savannahghi/onboarding/pkg/onboarding/usecases/admin" - hubspotRepo "gitlab.slade360emr.com/go/commontools/crm/pkg/infrastructure/database/fs" - hubspotUsecases "gitlab.slade360emr.com/go/commontools/crm/pkg/usecases" ) var fakeRepo mockRepo.FakeOnboardingRepository @@ -59,15 +54,7 @@ func InitializeFakeOnboardingInteractor() (*interactor.Interactor, error) { var pinExt extension.PINExtension = &fakePinExt var ps pubsubmessaging.ServicePubSub = &fakePubSub - // hubspot usecases - hubspotService := hubspot.NewHubSpotService() - hubspotfr, err := hubspotRepo.NewHubSpotFirebaseRepository(context.Background(), hubspotService) - if err != nil { - return nil, fmt.Errorf("failed to initialize hubspot crm repository: %w", err) - } - hubspotUsecases := hubspotUsecases.NewHubSpotUsecases(hubspotfr) - crmExt := crmExt.NewCrmService(hubspotUsecases) - profile := usecases.NewProfileUseCase(r, ext, engagementSvc, ps, crmExt) + profile := usecases.NewProfileUseCase(r, ext, engagementSvc, ps) login := usecases.NewLoginUseCases(r, profile, ext, pinExt) survey := usecases.NewSurveyUseCases(r, ext) supplier := usecases.NewSupplierUseCases( @@ -85,8 +72,7 @@ func InitializeFakeOnboardingInteractor() (*interactor.Interactor, error) { profile, su, supplier, login, survey, userpin, engagementSvc, messagingSvc, nhif, ps, sms, - adminSrv, crmExt, - role, + adminSrv, role, ) if err != nil { return nil, fmt.Errorf("can't instantiate service : %w", err) @@ -617,10 +603,6 @@ func TestHandlersInterfacesImpl_CreateUserWithPhoneNumber(t *testing.T) { }, nil } - fakePubSub.NotifyCreateContactFn = func(ctx context.Context, contact crmDomain.CRMContact) error { - return nil - } - fakeRepo.GetRolesByIDsFn = func(ctx context.Context, roleIDs []string) (*[]profileutils.Role, error) { roles := []profileutils.Role{ { diff --git a/pkg/onboarding/repository/mock/onboarding.go b/pkg/onboarding/repository/mock/onboarding.go index c995a90e..33d31a44 100644 --- a/pkg/onboarding/repository/mock/onboarding.go +++ b/pkg/onboarding/repository/mock/onboarding.go @@ -171,22 +171,19 @@ type FakeOnboardingRepository struct { UpdateAddressesFn func(ctx context.Context, id string, address profileutils.Address, addressType enumutils.AddressType) error ListUserProfilesFn func(ctx context.Context, role profileutils.RoleType) ([]*profileutils.UserProfile, error) UpdateOptOutFn func(ctx context.Context, option string, phoneNumber string) error - UpdateFavNavActionsFn func(ctx context.Context, id string, favActions []string) error - GetUserMarketingDataFn func(ctx context.Context, phoneNumber string) (*dto.Segment, error) - - //roles - CreateRoleFn func(ctx context.Context, profileID string, role dto.RoleInput) (*profileutils.Role, error) - GetAllRolesFn func(ctx context.Context) (*[]profileutils.Role, error) - UpdateRoleDetailsFn func(ctx context.Context, profileID string, role profileutils.Role) (*profileutils.Role, error) - GetRolesByIDsFn func(ctx context.Context, roleIDs []string) (*[]profileutils.Role, error) - GetRoleByIDFn func(ctx context.Context, roleID string) (*profileutils.Role, error) - GetRoleByNameFn func(ctx context.Context, roleName string) (*profileutils.Role, error) - CheckIfRoleNameExistsFn func(ctx context.Context, name string) (bool, error) - DeleteRoleFn func(ctx context.Context, roleID string) (bool, error) - CheckIfUserHasPermissionFn func(ctx context.Context, UID string, requiredPermission profileutils.Permission) (bool, error) - UpdateUserProfileEmailFn func(ctx context.Context, phone string, email string) error - GetUserProfilesByRoleIDFn func(ctx context.Context, role string) ([]*profileutils.UserProfile, error) - SaveRoleRevocationFn func(ctx context.Context, userID string, revocation dto.RoleRevocationInput) error + UpdateFavNavActionsFn func(ctx context.Context, id string, favActions []string) error //roles + CreateRoleFn func(ctx context.Context, profileID string, role dto.RoleInput) (*profileutils.Role, error) + GetAllRolesFn func(ctx context.Context) (*[]profileutils.Role, error) + UpdateRoleDetailsFn func(ctx context.Context, profileID string, role profileutils.Role) (*profileutils.Role, error) + GetRolesByIDsFn func(ctx context.Context, roleIDs []string) (*[]profileutils.Role, error) + GetRoleByIDFn func(ctx context.Context, roleID string) (*profileutils.Role, error) + GetRoleByNameFn func(ctx context.Context, roleName string) (*profileutils.Role, error) + CheckIfRoleNameExistsFn func(ctx context.Context, name string) (bool, error) + DeleteRoleFn func(ctx context.Context, roleID string) (bool, error) + CheckIfUserHasPermissionFn func(ctx context.Context, UID string, requiredPermission profileutils.Permission) (bool, error) + UpdateUserProfileEmailFn func(ctx context.Context, phone string, email string) error + GetUserProfilesByRoleIDFn func(ctx context.Context, role string) ([]*profileutils.UserProfile, error) + SaveRoleRevocationFn func(ctx context.Context, userID string, revocation dto.RoleRevocationInput) error //admins CreateAdminProfileFn func(ctx context.Context, adminProfile domain.AdminProfile) error @@ -803,14 +800,6 @@ func (f *FakeOnboardingRepository) UpdateFavNavActions( return f.UpdateFavNavActionsFn(ctx, id, favActions) } -// GetUserMarketingData ... -func (f *FakeOnboardingRepository) GetUserMarketingData( - ctx context.Context, - phoneNumber string, -) (*dto.Segment, error) { - return f.GetUserMarketingDataFn(ctx, phoneNumber) -} - //CreateRole ... func (f *FakeOnboardingRepository) CreateRole( ctx context.Context, diff --git a/pkg/onboarding/usecases/login_test.go b/pkg/onboarding/usecases/login_test.go index 59e25eee..0e4fea11 100644 --- a/pkg/onboarding/usecases/login_test.go +++ b/pkg/onboarding/usecases/login_test.go @@ -26,7 +26,6 @@ import ( "github.com/savannahghi/onboarding/pkg/onboarding/usecases" "github.com/savannahghi/profileutils" "github.com/savannahghi/serverutils" - "gitlab.slade360emr.com/go/commontools/crm/pkg/infrastructure/services/hubspot" "github.com/savannahghi/onboarding/pkg/onboarding/infrastructure/services/engagement" @@ -39,13 +38,10 @@ import ( extMock "github.com/savannahghi/onboarding/pkg/onboarding/application/extension/mock" engagementMock "github.com/savannahghi/onboarding/pkg/onboarding/infrastructure/services/engagement/mock" - crmExt "github.com/savannahghi/onboarding/pkg/onboarding/infrastructure/services/crm" messagingMock "github.com/savannahghi/onboarding/pkg/onboarding/infrastructure/services/messaging/mock" pubsubmessaging "github.com/savannahghi/onboarding/pkg/onboarding/infrastructure/services/pubsub" pubsubmessagingMock "github.com/savannahghi/onboarding/pkg/onboarding/infrastructure/services/pubsub/mock" adminSrv "github.com/savannahghi/onboarding/pkg/onboarding/usecases/admin" - hubspotRepo "gitlab.slade360emr.com/go/commontools/crm/pkg/infrastructure/database/fs" - hubspotUsecases "gitlab.slade360emr.com/go/commontools/crm/pkg/usecases" ) const ( @@ -91,7 +87,6 @@ func TestMain(m *testing.M) { r.GetCustomerProfileCollectionName(), r.GetExperimentParticipantCollectionName(), r.GetKCYProcessCollectionName(), - r.GetMarketingDataCollectionName(), r.GetNHIFDetailsCollectionName(), r.GetProfileNudgesCollectionName(), r.GetSMSCollectionName(), @@ -186,18 +181,9 @@ func InitializeTestService(ctx context.Context) (*interactor.Interactor, error) engagementClient := utils.NewInterServiceClient(engagementService, ext) engage := engagement.NewServiceEngagementImpl(engagementClient, ext) - // hubspot usecases - hubspotService := hubspot.NewHubSpotService() - hubspotfr, err := hubspotRepo.NewHubSpotFirebaseRepository(context.Background(), hubspotService) - if err != nil { - return nil, fmt.Errorf("failed to initialize hubspot crm repository: %w", err) - } - hubspotUsecases := hubspotUsecases.NewHubSpotUsecases(hubspotfr) - crmExt := crmExt.NewCrmService(hubspotUsecases) ps, err := pubsubmessaging.NewServicePubSubMessaging( pubSubClient, ext, - crmExt, repo, ) if err != nil { @@ -205,7 +191,7 @@ func InitializeTestService(ctx context.Context) (*interactor.Interactor, error) } mes := messaging.NewServiceMessagingImpl(ext) pinExt := extension.NewPINExtensionImpl() - profile := usecases.NewProfileUseCase(repo, ext, engage, ps, crmExt) + profile := usecases.NewProfileUseCase(repo, ext, engage, ps) supplier := usecases.NewSupplierUseCases(repo, profile, engage, mes, ext, ps) login := usecases.NewLoginUseCases(repo, profile, ext, pinExt) @@ -226,7 +212,6 @@ func InitializeTestService(ctx context.Context) (*interactor.Interactor, error) NHIF: nhif, PubSub: ps, SMS: sms, - CrmExt: crmExt, }, nil } @@ -442,15 +427,7 @@ func InitializeFakeOnboardingInteractor() (*interactor.Interactor, error) { var pinExt extension.PINExtension = &fakePinExt var ps pubsubmessaging.ServicePubSub = &fakePubSub - // hubspot usecases - hubspotService := hubspot.NewHubSpotService() - hubspotfr, err := hubspotRepo.NewHubSpotFirebaseRepository(context.Background(), hubspotService) - if err != nil { - return nil, fmt.Errorf("failed to initialize hubspot crm repository: %w", err) - } - hubspotUsecases := hubspotUsecases.NewHubSpotUsecases(hubspotfr) - crmExt := crmExt.NewCrmService(hubspotUsecases) - profile := usecases.NewProfileUseCase(r, ext, engagementSvc, ps, crmExt) + profile := usecases.NewProfileUseCase(r, ext, engagementSvc, ps) login := usecases.NewLoginUseCases(r, profile, ext, pinExt) survey := usecases.NewSurveyUseCases(r, ext) supplier := usecases.NewSupplierUseCases( @@ -467,8 +444,7 @@ func InitializeFakeOnboardingInteractor() (*interactor.Interactor, error) { profile, su, supplier, login, survey, userpin, engagementSvc, messagingSvc, nhif, ps, sms, - adminSrv, crmExt, - role, + adminSrv, role, ) if err != nil { return nil, fmt.Errorf("can't instantiate service : %w", err) diff --git a/pkg/onboarding/usecases/profile.go b/pkg/onboarding/usecases/profile.go index 48beb65b..af6776e1 100644 --- a/pkg/onboarding/usecases/profile.go +++ b/pkg/onboarding/usecases/profile.go @@ -3,7 +3,6 @@ package usecases import ( "context" "fmt" - "log" "strconv" "strings" "time" @@ -26,7 +25,6 @@ import ( "github.com/savannahghi/onboarding/pkg/onboarding/application/extension" "github.com/savannahghi/onboarding/pkg/onboarding/application/utils" "github.com/savannahghi/onboarding/pkg/onboarding/domain" - "github.com/savannahghi/onboarding/pkg/onboarding/infrastructure/services/crm" "github.com/savannahghi/onboarding/pkg/onboarding/infrastructure/services/engagement" pubsubmessaging "github.com/savannahghi/onboarding/pkg/onboarding/infrastructure/services/pubsub" "github.com/savannahghi/onboarding/pkg/onboarding/repository" @@ -184,7 +182,6 @@ type ProfileUseCaseImpl struct { baseExt extension.BaseExtension engagement engagement.ServiceEngagement pubsub pubsubmessaging.ServicePubSub - crm crm.ServiceCrm } // NewProfileUseCase returns a new a onboarding usecase @@ -193,14 +190,12 @@ func NewProfileUseCase( ext extension.BaseExtension, eng engagement.ServiceEngagement, pubsub pubsubmessaging.ServicePubSub, - crm crm.ServiceCrm, ) ProfileUseCase { return &ProfileUseCaseImpl{ onboardingRepository: r, baseExt: ext, engagement: eng, pubsub: pubsub, - crm: crm, } } @@ -320,21 +315,6 @@ func (p *ProfileUseCaseImpl) UpdatePrimaryPhoneNumber( return err } - contact, err := p.crm.GetContactByPhone(ctx, *profile.PrimaryPhone) - if err != nil { - return fmt.Errorf("failed to get contact %s: %w", *profile.PrimaryPhone, err) - } - if contact == nil { - return nil - } - - contact.Properties.Phone = phone - - if err = p.pubsub.NotifyUpdateContact(ctx, *contact); err != nil { - utils.RecordSpanError(span, err) - log.Printf("failed to publish to crm.contact.update topic: %v", err) - } - // check if number to be set as primary exists in the list of secondary phones index, exists := utils.FindItem(secondaryPhones, *phoneNumber) if exists { @@ -389,22 +369,6 @@ func (p *ProfileUseCaseImpl) UpdatePrimaryEmailAddress( return err } - // After updating the primary email, update it on the CRM too - contact, err := p.crm.GetContactByPhone(ctx, *profile.PrimaryPhone) - if err != nil { - return fmt.Errorf("failed to get contact %s: %w", *profile.PrimaryPhone, err) - } - if contact == nil { - return nil - } - - contact.Properties.Email = emailAddress - - if err = p.pubsub.NotifyUpdateContact(ctx, *contact); err != nil { - utils.RecordSpanError(span, err) - log.Printf("failed to publish to crm.contact.update topic: %v", err) - } - previousPrimaryEmail := profile.PrimaryEmailAddress secondaryEmails := profile.SecondaryEmailAddresses @@ -929,36 +893,6 @@ func (p *ProfileUseCaseImpl) UpdateBioData(ctx context.Context, data profileutil return err } - contact, err := p.crm.GetContactByPhone(ctx, *profile.PrimaryPhone) - if err != nil { - return fmt.Errorf("failed to get contact %s: %w", *profile.PrimaryPhone, err) - } - if contact == nil { - return nil - } - - if data.FirstName != nil { - contact.Properties.FirstName = *data.FirstName - } - - if data.LastName != nil { - contact.Properties.LastName = *data.LastName - } - - if data.DateOfBirth != nil { - dob := data.DateOfBirth.AsTime() - contact.Properties.DateOfBirth = dob - } - - if data.Gender != "" { - contact.Properties.Gender = data.Gender.String() - } - - if err = p.pubsub.NotifyUpdateContact(ctx, *contact); err != nil { - utils.RecordSpanError(span, err) - log.Printf("failed to publish to crm.contact.update topic: %v", err) - } - return nil } @@ -1067,26 +1001,6 @@ func (p *ProfileUseCaseImpl) SetPrimaryEmailAddress( return err } - profile, err := p.UserProfile(ctx) - if err != nil { - utils.RecordSpanError(span, err) - return err - } - - contact, err := p.crm.GetContactByPhone(ctx, *profile.PrimaryPhone) - if err != nil { - return fmt.Errorf("failed to get contact %s: %w", *profile.PrimaryPhone, err) - } - if contact == nil { - return nil - } - contact.Properties.Email = *profile.PrimaryPhone - - if err = p.pubsub.NotifyUpdateContact(ctx, *contact); err != nil { - utils.RecordSpanError(span, err) - log.Printf("failed to publish to crm.contact.update topic: %v", err) - } - // The `VerifyEmail` nudge is by default created for both flavours, `PRO` // and `CONSUMER`, thus if a user adds and verifies their `Primary Email` // we need to `Resolve` the nudge for this user in both flavours diff --git a/pkg/onboarding/usecases/profile_integration_test.go b/pkg/onboarding/usecases/profile_integration_test.go index 9f53370e..7b4d0066 100644 --- a/pkg/onboarding/usecases/profile_integration_test.go +++ b/pkg/onboarding/usecases/profile_integration_test.go @@ -20,51 +20,6 @@ import ( "github.com/stretchr/testify/assert" ) -func TestSetuserProfileOptOut(t *testing.T) { - s, err := InitializeTestService(context.Background()) - if err != nil { - t.Error("failed to setup signup usecase") - } - primaryPhone := interserviceclient.TestUserPhoneNumber - // clean up - _ = s.Signup.RemoveUserByPhoneNumber(context.Background(), primaryPhone) - otp, err := generateTestOTP(t, primaryPhone) - assert.Nil(t, err) - assert.NotNil(t, otp) - pin := "4567" - resp, err := s.Signup.CreateUserByPhone( - context.Background(), - &dto.SignUpInput{ - PhoneNumber: &primaryPhone, - PIN: &pin, - Flavour: feedlib.FlavourConsumer, - OTP: &otp.OTP, - }, - ) - assert.Nil(t, err) - assert.NotNil(t, resp) - assert.NotNil(t, resp.Profile) - assert.NotNil(t, resp.Profile.UserName) - - // login and assert whether the profile matches the one created earlier - login, err := s.Login.LoginByPhone(context.Background(), primaryPhone, pin, feedlib.FlavourConsumer) - assert.Nil(t, err) - assert.NotNil(t, login) - assert.NotNil(t, login.Profile.UserName) - assert.Equal(t, *login.Profile.UserName, *resp.Profile.UserName) - - // err = s.Onboarding.SetOptOut(context.Background(), "STOP", primaryPhone) - // assert.Nil(t, err) - - // //update the optout with START. It should still pass as it is a valid input for subscribing to crm - // err = s.Onboarding.SetOptOut(context.Background(), "START", primaryPhone) - // assert.Nil(t, err) - - // // update with an invalid option it should fail - // err = s.Onboarding.SetOptOut(context.Background(), "END", primaryPhone) - // assert.NotNil(t, err) -} - func TestSwitchUserFlaggedFeature(t *testing.T) { s, err := InitializeTestService(context.Background()) if err != nil { @@ -366,11 +321,11 @@ func TestSetPhoneAsPrimary(t *testing.T) { return } - _, exist := utils.FindItem(login5.Profile.SecondaryPhoneNumbers, secondaryPhone) + _, exist := utils.FindItem(login5.Profile.SecondaryPhoneNumbers, primaryPhone) if !exist { t.Errorf("the secondary phonenumber slice %v, does not contain %v", login5.Profile.SecondaryPhoneNumbers, - secondaryPhone, + primaryPhone, ) return } diff --git a/pkg/onboarding/usecases/profile_unit_test.go b/pkg/onboarding/usecases/profile_unit_test.go index 9449d752..72292a9e 100644 --- a/pkg/onboarding/usecases/profile_unit_test.go +++ b/pkg/onboarding/usecases/profile_unit_test.go @@ -19,7 +19,6 @@ import ( "github.com/savannahghi/onboarding/pkg/onboarding/usecases" "github.com/savannahghi/profileutils" "github.com/savannahghi/scalarutils" - CRMDomain "gitlab.slade360emr.com/go/commontools/crm/pkg/domain" ) func TestProfileUseCaseImpl_UpdateVerifiedUIDS(t *testing.T) { @@ -508,7 +507,7 @@ func TestProfileUseCaseImpl_UpdatePrimaryEmailAddress(t *testing.T) { ctx: ctx, emailAddress: "juha@gmail.com", }, - wantErr: false, // TODO: fix and make true + wantErr: true, }, } for _, tt := range tests { @@ -533,10 +532,6 @@ func TestProfileUseCaseImpl_UpdatePrimaryEmailAddress(t *testing.T) { return nil } - fakePubSub.NotifyUpdateContactFn = func(ctx context.Context, contact CRMDomain.CRMContact) error { - return nil - } - fakeRepo.UpdateSecondaryEmailAddressesFn = func(ctx context.Context, id string, emailAddresses []string) error { return nil } @@ -583,9 +578,7 @@ func TestProfileUseCaseImpl_UpdatePrimaryEmailAddress(t *testing.T) { fakeRepo.UpdatePrimaryEmailAddressFn = func(ctx context.Context, id string, emailAddress string) error { return nil } - fakePubSub.NotifyUpdateContactFn = func(ctx context.Context, contact CRMDomain.CRMContact) error { - return nil - } + fakeRepo.UpdateSecondaryEmailAddressesFn = func(ctx context.Context, id string, emailAddresses []string) error { return fmt.Errorf("unable to update secondary email") } @@ -758,10 +751,6 @@ func TestProfileUseCaseImpl_SetPrimaryEmailAddress(t *testing.T) { }, nil } - fakePubSub.NotifyUpdateContactFn = func(ctx context.Context, contact CRMDomain.CRMContact) error { - return nil - } - fakePubSub.TopicIDsFn = func() []string { return []string{uuid.New().String()} } @@ -2189,10 +2178,6 @@ func TestProfileUseCaseImpl_UpdatePrimaryPhoneNumber(t *testing.T) { return nil } - fakePubSub.NotifyUpdateContactFn = func(ctx context.Context, contact CRMDomain.CRMContact) error { - return nil - } - fakeRepo.UpdateSecondaryPhoneNumbersFn = func(ctx context.Context, id string, phoneNumbers []string) error { return nil } @@ -2226,10 +2211,6 @@ func TestProfileUseCaseImpl_UpdatePrimaryPhoneNumber(t *testing.T) { return nil } - fakePubSub.NotifyUpdateContactFn = func(ctx context.Context, contact CRMDomain.CRMContact) error { - return nil - } - fakeRepo.UpdateSecondaryPhoneNumbersFn = func(ctx context.Context, id string, phoneNumbers []string) error { return nil } @@ -2296,10 +2277,6 @@ func TestProfileUseCaseImpl_UpdatePrimaryPhoneNumber(t *testing.T) { return nil } - fakePubSub.NotifyUpdateContactFn = func(ctx context.Context, contact CRMDomain.CRMContact) error { - return nil - } - fakeRepo.UpdateSecondaryPhoneNumbersFn = func(ctx context.Context, id string, phoneNumbers []string) error { return fmt.Errorf("unable to update secondary phonenumber") } @@ -2480,10 +2457,6 @@ func TestProfileUseCase_UpdateBioData(t *testing.T) { }, nil } - fakePubSub.NotifyUpdateContactFn = func(ctx context.Context, contact CRMDomain.CRMContact) error { - return nil - } - fakeRepo.UpdateBioDataFn = func(ctx context.Context, id string, data profileutils.BioData) error { return nil } @@ -2517,10 +2490,6 @@ func TestProfileUseCase_UpdateBioData(t *testing.T) { }, nil } - fakePubSub.NotifyUpdateContactFn = func(ctx context.Context, contact CRMDomain.CRMContact) error { - return nil - } - fakeRepo.UpdateBioDataFn = func(ctx context.Context, id string, data profileutils.BioData) error { return nil } @@ -2553,9 +2522,6 @@ func TestProfileUseCase_UpdateBioData(t *testing.T) { PrimaryPhone: &phone, }, nil } - fakePubSub.NotifyUpdateContactFn = func(ctx context.Context, contact CRMDomain.CRMContact) error { - return nil - } fakeRepo.UpdateBioDataFn = func(ctx context.Context, id string, data profileutils.BioData) error { return nil @@ -2578,10 +2544,6 @@ func TestProfileUseCase_UpdateBioData(t *testing.T) { }, nil } - fakePubSub.NotifyUpdateContactFn = func(ctx context.Context, contact CRMDomain.CRMContact) error { - return nil - } - fakeRepo.UpdateBioDataFn = func(ctx context.Context, id string, data profileutils.BioData) error { return nil } @@ -2615,10 +2577,6 @@ func TestProfileUseCase_UpdateBioData(t *testing.T) { }, nil } - fakePubSub.NotifyUpdateContactFn = func(ctx context.Context, contact CRMDomain.CRMContact) error { - return nil - } - fakeRepo.UpdateBioDataFn = func(ctx context.Context, id string, data profileutils.BioData) error { return nil } diff --git a/pkg/onboarding/usecases/signup.go b/pkg/onboarding/usecases/signup.go index 3cbabd50..205a4ed9 100644 --- a/pkg/onboarding/usecases/signup.go +++ b/pkg/onboarding/usecases/signup.go @@ -2,7 +2,6 @@ package usecases import ( "context" - "log" "github.com/savannahghi/enumutils" "github.com/savannahghi/feedlib" @@ -15,7 +14,6 @@ import ( "github.com/savannahghi/onboarding/pkg/onboarding/repository" "github.com/savannahghi/profileutils" "github.com/savannahghi/scalarutils" - "gitlab.slade360emr.com/go/commontools/crm/pkg/domain" ) const ( @@ -222,20 +220,6 @@ func (s *SignUpUseCasesImpl) CreateUserByPhone( return nil, err } - contact := domain.CRMContact{ - Properties: domain.ContactProperties{ - Phone: *profile.PrimaryPhone, - FirstChannelOfContact: domain.ChannelOfContactApp, - BeWellEnrolled: domain.GeneralOptionTypeYes, - BeWellAware: domain.GeneralOptionTypeYes, - }, - } - - if err = s.pubsub.NotifyCreateContact(ctx, contact); err != nil { - utils.RecordSpanError(span, err) - log.Printf("failed to publish to crm.contact.create topic: %v", err) - } - // get navigation actions roles, err := s.onboardingRepository.GetRolesByIDs(ctx, profile.Roles) if err != nil { diff --git a/pkg/onboarding/usecases/signup_unit_test.go b/pkg/onboarding/usecases/signup_unit_test.go index b0477547..70c7a706 100644 --- a/pkg/onboarding/usecases/signup_unit_test.go +++ b/pkg/onboarding/usecases/signup_unit_test.go @@ -15,7 +15,6 @@ import ( "github.com/savannahghi/profileutils" "github.com/savannahghi/scalarutils" "gitlab.slade360emr.com/go/apiclient" - crmDomain "gitlab.slade360emr.com/go/commontools/crm/pkg/domain" ) func TestSignUpUseCasesImpl_RetirePushToken(t *testing.T) { @@ -344,14 +343,6 @@ func TestSignUpUseCasesImpl_CreateUserByPhone(t *testing.T) { }, nil } - fakePubSub.NotifyCreateContactFn = func(ctx context.Context, contact crmDomain.CRMContact) error { - return nil - } - - fakePubSub.NotifyCreateContactFn = func(ctx context.Context, contact crmDomain.CRMContact) error { - return nil - } - fakeRepo.GetRolesByIDsFn = func(ctx context.Context, roleIDs []string) (*[]profileutils.Role, error) { roles := []profileutils.Role{} return &roles, nil diff --git a/pkg/onboarding/usecases/supplier_internal_test.go b/pkg/onboarding/usecases/supplier_internal_test.go index 4ac752c2..90f681e6 100644 --- a/pkg/onboarding/usecases/supplier_internal_test.go +++ b/pkg/onboarding/usecases/supplier_internal_test.go @@ -12,17 +12,13 @@ import ( "github.com/savannahghi/onboarding/pkg/onboarding/application/utils" "github.com/savannahghi/onboarding/pkg/onboarding/repository" "github.com/savannahghi/serverutils" - "gitlab.slade360emr.com/go/commontools/crm/pkg/infrastructure/services/hubspot" "github.com/savannahghi/onboarding/pkg/onboarding/domain" "github.com/savannahghi/onboarding/pkg/onboarding/infrastructure/database/fb" "github.com/savannahghi/onboarding/pkg/onboarding/infrastructure/services/engagement" - crmExt "github.com/savannahghi/onboarding/pkg/onboarding/infrastructure/services/crm" "github.com/savannahghi/onboarding/pkg/onboarding/infrastructure/services/messaging" pubsubmessaging "github.com/savannahghi/onboarding/pkg/onboarding/infrastructure/services/pubsub" - hubspotRepo "gitlab.slade360emr.com/go/commontools/crm/pkg/infrastructure/database/fs" - hubspotUsecases "gitlab.slade360emr.com/go/commontools/crm/pkg/usecases" ) const ( @@ -73,19 +69,9 @@ func TestParseKYCAsMap(t *testing.T) { // Initialize ISC clients engagementClient := utils.NewInterServiceClient(engagementService, ext) engage := engagement.NewServiceEngagementImpl(engagementClient, ext) - // hubspot usecases - hubspotService := hubspot.NewHubSpotService() - hubspotfr, err := hubspotRepo.NewHubSpotFirebaseRepository(context.Background(), hubspotService) - if err != nil { - t.Errorf("failed to initialize hubspot crm repository: %w", err) - return - } - hubspotUsecases := hubspotUsecases.NewHubSpotUsecases(hubspotfr) - crmExt := crmExt.NewCrmService(hubspotUsecases) ps, err := pubsubmessaging.NewServicePubSubMessaging( pubSubClient, ext, - crmExt, repo, ) if err != nil { @@ -93,7 +79,7 @@ func TestParseKYCAsMap(t *testing.T) { return } mes := messaging.NewServiceMessagingImpl(ext) - profile := NewProfileUseCase(repo, ext, engage, ps, crmExt) + profile := NewProfileUseCase(repo, ext, engage, ps) supplier := SupplierUseCasesImpl{ repo: repo, diff --git a/tests/config_test.go b/tests/config_test.go index db5e09cc..25425f6d 100644 --- a/tests/config_test.go +++ b/tests/config_test.go @@ -32,16 +32,12 @@ import ( "github.com/savannahghi/profileutils" "github.com/savannahghi/serverutils" "github.com/sirupsen/logrus" - "gitlab.slade360emr.com/go/commontools/crm/pkg/infrastructure/services/hubspot" - crmExt "github.com/savannahghi/onboarding/pkg/onboarding/infrastructure/services/crm" "github.com/savannahghi/onboarding/pkg/onboarding/infrastructure/services/messaging" pubsubmessaging "github.com/savannahghi/onboarding/pkg/onboarding/infrastructure/services/pubsub" "github.com/savannahghi/onboarding/pkg/onboarding/presentation" "github.com/savannahghi/onboarding/pkg/onboarding/repository" "github.com/savannahghi/onboarding/pkg/onboarding/usecases" - hubspotRepo "gitlab.slade360emr.com/go/commontools/crm/pkg/infrastructure/database/fs" - hubspotUsecases "gitlab.slade360emr.com/go/commontools/crm/pkg/usecases" ) const ( @@ -120,18 +116,10 @@ func InitializeTestService(ctx context.Context) (*interactor.Interactor, error) // Initialize ISC clients engagementClient := utils.NewInterServiceClient(engagementService, ext) - hubspotService := hubspot.NewHubSpotService() - hubspotfr, err := hubspotRepo.NewHubSpotFirebaseRepository(context.Background(), hubspotService) - if err != nil { - return nil, fmt.Errorf("failed to initialize hubspot crm repository: %w", err) - } - hubspotUsecases := hubspotUsecases.NewHubSpotUsecases(hubspotfr) - crmExt := crmExt.NewCrmService(hubspotUsecases) engage := engagement.NewServiceEngagementImpl(engagementClient, ext) ps, err := pubsubmessaging.NewServicePubSubMessaging( pubSubClient, ext, - crmExt, repo, ) if err != nil { @@ -139,7 +127,7 @@ func InitializeTestService(ctx context.Context) (*interactor.Interactor, error) } mes := messaging.NewServiceMessagingImpl(ext) pinExt := extension.NewPINExtensionImpl() - profile := usecases.NewProfileUseCase(repo, ext, engage, ps, crmExt) + profile := usecases.NewProfileUseCase(repo, ext, engage, ps) supplier := usecases.NewSupplierUseCases(repo, profile, engage, mes, ext, ps) login := usecases.NewLoginUseCases(repo, profile, ext, pinExt) @@ -616,7 +604,6 @@ func TestMain(m *testing.M) { r.GetCustomerProfileCollectionName(), r.GetExperimentParticipantCollectionName(), r.GetKCYProcessCollectionName(), - r.GetMarketingDataCollectionName(), r.GetNHIFDetailsCollectionName(), r.GetProfileNudgesCollectionName(), r.GetSMSCollectionName(),