From 123ac3188b69b7369bd7d3e101943fc052b8422b Mon Sep 17 00:00:00 2001 From: Muchogo Date: Mon, 13 Mar 2023 12:09:16 +0300 Subject: [PATCH] test: usecase unit tests --- .../presentation/interactor/interactor.go | 1 - pkg/clinical/usecases/clinical/config_test.go | 44 -- pkg/clinical/usecases/clinical/patient.go | 24 +- .../usecases/clinical/patient_unit_test.go | 400 +++++++++++++++--- pkg/clinical/usecases/clinical/utils_test.go | 355 ++++++++++++++++ 5 files changed, 702 insertions(+), 122 deletions(-) delete mode 100644 pkg/clinical/usecases/clinical/config_test.go create mode 100644 pkg/clinical/usecases/clinical/utils_test.go diff --git a/pkg/clinical/presentation/interactor/interactor.go b/pkg/clinical/presentation/interactor/interactor.go index 63a60069..ec75d66b 100644 --- a/pkg/clinical/presentation/interactor/interactor.go +++ b/pkg/clinical/presentation/interactor/interactor.go @@ -13,7 +13,6 @@ type Clinical interface { FindOrganizationByID(ctx context.Context, organizationID string) (*domain.FHIROrganizationRelayPayload, error) CreateFHIROrganization(ctx context.Context, input domain.FHIROrganizationInput) (*domain.FHIROrganizationRelayPayload, error) - PatientTimeline(ctx context.Context, patientID string, count int) ([]map[string]interface{}, error) PatientHealthTimeline(ctx context.Context, input domain.HealthTimelineInput) (*domain.HealthTimeline, error) GetMedicalData(ctx context.Context, patientID string) (*domain.MedicalData, error) } diff --git a/pkg/clinical/usecases/clinical/config_test.go b/pkg/clinical/usecases/clinical/config_test.go deleted file mode 100644 index 3ecf1930..00000000 --- a/pkg/clinical/usecases/clinical/config_test.go +++ /dev/null @@ -1,44 +0,0 @@ -package clinical_test - -import ( - "context" - "os" - "testing" - - "github.com/brianvoe/gofakeit" - "github.com/savannahghi/clinical/pkg/clinical/application/utils" - log "github.com/sirupsen/logrus" -) - -const ( // Repo the env to identify which repo to use - Repo = "REPOSITORY" - //FirebaseRepository is the value of the env when using firebase - FirebaseRepository = "firebase" - testPhotoBase64 = "/9j/4AAQSkZJRgABAQAAAQABAAD/2wCEAAkGBxMt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q1fCLqWCDtg9UzbXXl5EEMcCFF7PFeXlFD0qsu0ptRtGEb5XV5WAevSgxMhUPaOU+q8vIO06Y5rrqTeq8vKimtbjkhX0V5eUFOjKmGLy8gsbQxKpJXl5B/9k=" - instantFormat = "2006-01-02T15:04:05.999-07:00" - testProviderCode = "1234" -) - -func TestMain(m *testing.M) { - os.Setenv("ENVIRONMENT", "staging") - os.Setenv("ROOT_COLLECTION_SUFFIX", "staging") - os.Setenv("CLOUD_HEALTH_PUBSUB_TOPIC", "healthcloud-bewell-staging") - os.Setenv("CLOUD_HEALTH_DATASET_ID", "sghi-healthcare-staging") - os.Setenv("CLOUD_HEALTH_FHIRSTORE_ID", "sghi-healthcare-fhir-staging") - os.Setenv("REPOSITORY", "firebase") - - // run the tests - log.Printf("about to run tests\n") - code := m.Run() - log.Printf("finished running tests\n") - - // cleanup here - os.Exit(code) -} - -func addOrganisationContext(ctx context.Context, providerCode string) (context.Context, error) { - - value := gofakeit.UUID() - - return context.WithValue(ctx, utils.OrganizationIDContextKey, value), nil -} diff --git a/pkg/clinical/usecases/clinical/patient.go b/pkg/clinical/usecases/clinical/patient.go index 6873adb2..8d69f7e4 100644 --- a/pkg/clinical/usecases/clinical/patient.go +++ b/pkg/clinical/usecases/clinical/patient.go @@ -6,6 +6,7 @@ import ( "sync" linq "github.com/ahmetb/go-linq/v3" + "github.com/google/uuid" "github.com/savannahghi/clinical/pkg/clinical/application/common" "github.com/savannahghi/clinical/pkg/clinical/application/common/helpers" "github.com/savannahghi/clinical/pkg/clinical/application/utils" @@ -15,20 +16,6 @@ import ( log "github.com/sirupsen/logrus" ) -// constants and defaults -const ( - // LimitedProfileEncounterCount is the number of encounters to show when a - // patient has approved limited access to their health record - LimitedProfileEncounterCount = 5 - - RelationshipSystem = "http://terminology.hl7.org/CodeSystem/v2-0131" - RelationshipVersion = "2.9" - StringTimeParseMonthNameLayout = "2006-Jan-02" - StringTimeParseMonthNumberLayout = "2006-01-02" - SavannahAdminEmail = "SAVANNAH_ADMIN_EMAIL" - TwilioSMSNumberEnvVarName = "TWILIO_SMS_NUMBER" -) - // UseCasesClinicalImpl represents the patient usecase implementation type UseCasesClinicalImpl struct { infrastructure infrastructure.Infrastructure @@ -43,7 +30,12 @@ func NewUseCasesClinicalImpl(infra infrastructure.Infrastructure) *UseCasesClini // PatientTimeline return's the patient's historical timeline sorted in descending order i.e when it was first recorded // The timeline consists of Allergies, Observations, Medication statement and Test results -func (c *UseCasesClinicalImpl) PatientTimeline(ctx context.Context, patientID string, count int) ([]map[string]interface{}, error) { +func (c *UseCasesClinicalImpl) PatientTimeline(ctx context.Context, patientID string) ([]map[string]interface{}, error) { + _, err := uuid.Parse(patientID) + if err != nil { + return nil, fmt.Errorf("invalid patient id: %s", patientID) + } + timeline := []map[string]interface{}{} wg := &sync.WaitGroup{} mut := &sync.Mutex{} @@ -312,7 +304,7 @@ func (c *UseCasesClinicalImpl) GetMedicalData(ctx context.Context, patientID str // PatientHealthTimeline return's the patient's historical timeline sorted in descending order i.e when it was first recorded // The timeline consists of Allergies, Observations, Medication statement and Test results func (c *UseCasesClinicalImpl) PatientHealthTimeline(ctx context.Context, input domain.HealthTimelineInput) (*domain.HealthTimeline, error) { - records, err := c.PatientTimeline(ctx, input.PatientID, 0) + records, err := c.PatientTimeline(ctx, input.PatientID) if err != nil { utils.ReportErrorToSentry(err) return nil, fmt.Errorf("cannot retrieve patient timeline error: %w", err) diff --git a/pkg/clinical/usecases/clinical/patient_unit_test.go b/pkg/clinical/usecases/clinical/patient_unit_test.go index caf47c06..d72a2f05 100644 --- a/pkg/clinical/usecases/clinical/patient_unit_test.go +++ b/pkg/clinical/usecases/clinical/patient_unit_test.go @@ -4,8 +4,10 @@ import ( "context" "fmt" "testing" + "time" "github.com/brianvoe/gofakeit" + "github.com/savannahghi/clinical/pkg/clinical/application/common" fakeExtMock "github.com/savannahghi/clinical/pkg/clinical/application/extensions/mock" "github.com/savannahghi/clinical/pkg/clinical/domain" "github.com/savannahghi/clinical/pkg/clinical/infrastructure" @@ -14,6 +16,7 @@ import ( fakeOCLMock "github.com/savannahghi/clinical/pkg/clinical/infrastructure/services/openconceptlab/mock" clinicalUsecase "github.com/savannahghi/clinical/pkg/clinical/usecases/clinical" "github.com/savannahghi/firebasetools" + "github.com/savannahghi/scalarutils" "github.com/segmentio/ksuid" ) @@ -87,27 +90,29 @@ func TestUsecaseImpl_CreateFHIROrganization_Unittest(t *testing.T) { return nil, fmt.Errorf("Error creating fhir organization") } } - _, err := u.CreateFHIROrganization(tt.args.ctx, tt.args.input) + got, err := u.CreateFHIROrganization(tt.args.ctx, tt.args.input) if (err != nil) != tt.wantErr { t.Errorf("FHIRUseCaseImpl.CreateFHIROrganization() error = %v, wantErr %v", err, tt.wantErr) return } + + if tt.wantErr && got != nil { + t.Errorf("expected organisation to be nil for %v", tt.name) + return + } + + if !tt.wantErr && got == nil { + t.Errorf("expected organisation not to be nil for %v", tt.name) + return + } }) } } func TestClinicalUseCaseImpl_PatientTimeline(t *testing.T) { - ctx := context.Background() - ctx, err := addOrganisationContext(ctx, testProviderCode) - if err != nil { - t.Errorf("cant add test organisation context: %v\n", err) - return - } - type args struct { ctx context.Context patientID string - count int } tests := []struct { name string @@ -118,90 +123,80 @@ func TestClinicalUseCaseImpl_PatientTimeline(t *testing.T) { { name: "Happy case: patient timeline", args: args{ - ctx: ctx, + ctx: context.Background(), patientID: gofakeit.UUID(), - count: 4, }, wantErr: false, }, { name: "Sad Case - Fail to search allergy intolerance", args: args{ - ctx: ctx, + ctx: context.Background(), patientID: gofakeit.UUID(), - count: 4, }, wantErr: false, }, { name: "Sad Case - Fail to get allergy intolerance - nil node", args: args{ - ctx: ctx, + ctx: context.Background(), patientID: gofakeit.UUID(), - count: 4, }, wantErr: false, }, { name: "Happy Case - Successfully get allergy intolerance", args: args{ - ctx: ctx, + ctx: context.Background(), patientID: gofakeit.UUID(), - count: 4, }, wantErr: false, }, { name: "Sad Case - Fail to search observation", args: args{ - ctx: ctx, + ctx: context.Background(), patientID: gofakeit.UUID(), - count: 4, }, wantErr: false, }, { name: "Happy Case - Successfully get observation", args: args{ - ctx: ctx, + ctx: context.Background(), patientID: gofakeit.UUID(), - count: 4, }, wantErr: false, }, { name: "Sad Case - Fail to get observation - nil node", args: args{ - ctx: ctx, + ctx: context.Background(), patientID: gofakeit.UUID(), - count: 4, }, wantErr: false, }, { name: "Sad Case - Fail to search medication statement", args: args{ - ctx: ctx, + ctx: context.Background(), patientID: gofakeit.UUID(), - count: 4, }, wantErr: false, }, { name: "Happy Case - Successfully get medication statement", args: args{ - ctx: ctx, + ctx: context.Background(), patientID: gofakeit.UUID(), - count: 4, }, wantErr: false, }, { name: "Sad Case - Fail to search medication statement - nil node", args: args{ - ctx: ctx, + ctx: context.Background(), patientID: gofakeit.UUID(), - count: 4, }, wantErr: false, }, @@ -315,7 +310,7 @@ func TestClinicalUseCaseImpl_PatientTimeline(t *testing.T) { } } - got, err := u.PatientTimeline(tt.args.ctx, tt.args.patientID, tt.args.count) + got, err := u.PatientTimeline(tt.args.ctx, tt.args.patientID) if (err != nil) != tt.wantErr { t.Errorf("ClinicalUseCaseImpl.PatientTimeline() error = %v, wantErr %v", err, tt.wantErr) return @@ -336,13 +331,6 @@ func TestClinicalUseCaseImpl_PatientTimeline(t *testing.T) { } func TestClinicalUseCaseImpl_PatientHealthTimeline(t *testing.T) { - ctx := context.Background() - ctx, err := addOrganisationContext(ctx, testProviderCode) - if err != nil { - t.Errorf("cant add test organisation context: %v\n", err) - return - } - type args struct { ctx context.Context input domain.HealthTimelineInput @@ -356,7 +344,19 @@ func TestClinicalUseCaseImpl_PatientHealthTimeline(t *testing.T) { { name: "Happy case: patient timeline", args: args{ - ctx: ctx, + ctx: context.Background(), + input: domain.HealthTimelineInput{ + PatientID: gofakeit.UUID(), + Offset: 0, + Limit: 20, + }, + }, + wantErr: false, + }, + { + name: "Sad case: patient timeline invalid date", + args: args{ + ctx: context.Background(), input: domain.HealthTimelineInput{ PatientID: gofakeit.UUID(), Offset: 0, @@ -365,6 +365,18 @@ func TestClinicalUseCaseImpl_PatientHealthTimeline(t *testing.T) { }, wantErr: false, }, + { + name: "Sad case: invalid patient id", + args: args{ + ctx: context.Background(), + input: domain.HealthTimelineInput{ + PatientID: "invalid", + Offset: 0, + Limit: 20, + }, + }, + wantErr: true, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { @@ -376,6 +388,188 @@ func TestClinicalUseCaseImpl_PatientHealthTimeline(t *testing.T) { infra := infrastructure.NewInfrastructureInteractor(FakeExt, Fakefhir, FakeOCL, fakeMCH) u := clinicalUsecase.NewUseCasesClinicalImpl(infra) + if tt.name == "Happy case: patient timeline" { + Fakefhir.MockSearchFHIRAllergyIntoleranceFn = func(ctx context.Context, params map[string]interface{}) (*domain.FHIRAllergyIntoleranceRelayConnection, error) { + return &domain.FHIRAllergyIntoleranceRelayConnection{ + Edges: []*domain.FHIRAllergyIntoleranceRelayEdge{ + { + Cursor: new(string), + Node: &domain.FHIRAllergyIntolerance{ + RecordedDate: &scalarutils.Date{ + Year: 2019, + Month: 11, + Day: 10, + }, + }, + }, + { + Cursor: new(string), + Node: &domain.FHIRAllergyIntolerance{ + RecordedDate: &scalarutils.Date{ + Year: 2020, + Month: 11, + Day: 10, + }, + }, + }, + { + Cursor: new(string), + Node: &domain.FHIRAllergyIntolerance{ + RecordedDate: &scalarutils.Date{ + Year: 2021, + Month: 11, + Day: 10, + }, + }, + }, + { + Cursor: new(string), + Node: &domain.FHIRAllergyIntolerance{ + RecordedDate: &scalarutils.Date{ + Year: 2022, + Month: 11, + Day: 10, + }, + }, + }, + { + Cursor: new(string), + Node: &domain.FHIRAllergyIntolerance{ + RecordedDate: &scalarutils.Date{ + Year: 2023, + Month: 11, + Day: 10, + }, + }, + }, + { + Cursor: new(string), + Node: &domain.FHIRAllergyIntolerance{ + RecordedDate: &scalarutils.Date{ + Year: 2018, + Month: 11, + Day: 10, + }, + }, + }, + }, + PageInfo: &firebasetools.PageInfo{}, + }, nil + } + + Fakefhir.MockSearchFHIRMedicationStatementFn = func(ctx context.Context, params map[string]interface{}) (*domain.FHIRMedicationStatementRelayConnection, error) { + return &domain.FHIRMedicationStatementRelayConnection{ + Edges: []*domain.FHIRMedicationStatementRelayEdge{ + { + Cursor: new(string), + Node: &domain.FHIRMedicationStatement{ + EffectiveDateTime: &scalarutils.Date{ + Year: 2019, + Month: 11, + Day: 10, + }, + }, + }, + { + Cursor: new(string), + Node: &domain.FHIRMedicationStatement{ + EffectiveDateTime: &scalarutils.Date{ + Year: 2020, + Month: 12, + Day: 10, + }, + }, + }, + { + Cursor: new(string), + Node: &domain.FHIRMedicationStatement{ + EffectiveDateTime: &scalarutils.Date{ + Year: 2021, + Month: 10, + Day: 10, + }, + }, + }, + { + Cursor: new(string), + Node: &domain.FHIRMedicationStatement{ + EffectiveDateTime: &scalarutils.Date{ + Year: 2022, + Month: 11, + Day: 13, + }, + }, + }, + { + Cursor: new(string), + Node: &domain.FHIRMedicationStatement{ + EffectiveDateTime: &scalarutils.Date{ + Year: 2023, + Month: 11, + Day: 14, + }, + }, + }, + }, + PageInfo: &firebasetools.PageInfo{}, + }, nil + } + + Fakefhir.MockSearchFHIRObservationFn = func(ctx context.Context, params map[string]interface{}) (*domain.FHIRObservationRelayConnection, error) { + instant := scalarutils.Instant(time.Now().Format(time.RFC3339)) + + return &domain.FHIRObservationRelayConnection{ + Edges: []*domain.FHIRObservationRelayEdge{ + { + Cursor: new(string), + Node: &domain.FHIRObservation{ + EffectiveInstant: &instant, + }, + }, + { + Cursor: new(string), + Node: &domain.FHIRObservation{ + EffectiveInstant: &instant, + }, + }, + }, + PageInfo: &firebasetools.PageInfo{}, + }, nil + } + } + + if tt.name == "Sad case: patient timeline invalid date" { + Fakefhir.MockSearchFHIRObservationFn = func(ctx context.Context, params map[string]interface{}) (*domain.FHIRObservationRelayConnection, error) { + instant := scalarutils.Instant("") + + return &domain.FHIRObservationRelayConnection{ + Edges: []*domain.FHIRObservationRelayEdge{ + { + Cursor: new(string), + Node: &domain.FHIRObservation{ + EffectiveInstant: &instant, + }, + }, + { + Cursor: new(string), + Node: &domain.FHIRObservation{}, + }, + { + Cursor: new(string), + Node: &domain.FHIRObservation{ + EffectiveInstant: &instant, + }, + }, + { + Cursor: new(string), + Node: &domain.FHIRObservation{}, + }, + }, + PageInfo: &firebasetools.PageInfo{}, + }, nil + } + } + got, err := u.PatientHealthTimeline(tt.args.ctx, tt.args.input) if (err != nil) != tt.wantErr { t.Errorf("ClinicalUseCaseImpl.PatientHealthTimeline() error = %v, wantErr %v", err, tt.wantErr) @@ -397,12 +591,6 @@ func TestClinicalUseCaseImpl_PatientHealthTimeline(t *testing.T) { } func TestClinicalUseCaseImpl_GetMedicalData(t *testing.T) { - ctx := context.Background() - ctx, err := addOrganisationContext(ctx, testProviderCode) - if err != nil { - t.Errorf("cant add test organisation context: %v\n", err) - return - } type args struct { ctx context.Context @@ -417,7 +605,7 @@ func TestClinicalUseCaseImpl_GetMedicalData(t *testing.T) { { name: "Happy case: patient timeline", args: args{ - ctx: ctx, + ctx: context.Background(), patientID: gofakeit.UUID(), }, wantErr: false, @@ -425,7 +613,7 @@ func TestClinicalUseCaseImpl_GetMedicalData(t *testing.T) { { name: "Sad Case - Fail to search medication statement", args: args{ - ctx: ctx, + ctx: context.Background(), patientID: gofakeit.UUID(), }, wantErr: true, @@ -433,7 +621,7 @@ func TestClinicalUseCaseImpl_GetMedicalData(t *testing.T) { { name: "Sad Case - Fail to search medication statement - nil node", args: args{ - ctx: ctx, + ctx: context.Background(), patientID: gofakeit.UUID(), }, wantErr: false, @@ -441,7 +629,7 @@ func TestClinicalUseCaseImpl_GetMedicalData(t *testing.T) { { name: "Happy Case - Successfully search medication statement", args: args{ - ctx: ctx, + ctx: context.Background(), patientID: gofakeit.UUID(), }, wantErr: false, @@ -449,7 +637,7 @@ func TestClinicalUseCaseImpl_GetMedicalData(t *testing.T) { { name: "Sad Case - Fail to search allergy intolerance", args: args{ - ctx: ctx, + ctx: context.Background(), patientID: gofakeit.UUID(), }, wantErr: true, @@ -457,7 +645,7 @@ func TestClinicalUseCaseImpl_GetMedicalData(t *testing.T) { { name: "Sad Case - Fail to search allergy intolerance - nil node", args: args{ - ctx: ctx, + ctx: context.Background(), patientID: gofakeit.UUID(), }, wantErr: false, @@ -465,34 +653,58 @@ func TestClinicalUseCaseImpl_GetMedicalData(t *testing.T) { { name: "Happy Case - Successfully search allergy intolerance", args: args{ - ctx: ctx, + ctx: context.Background(), patientID: gofakeit.UUID(), }, wantErr: false, }, { - name: "Sad Case - Fail to search observation", + name: "Sad Case - Fail to search observation - nil node", args: args{ - ctx: ctx, + ctx: context.Background(), patientID: gofakeit.UUID(), }, - wantErr: true, + wantErr: false, }, { - name: "Sad Case - Fail to search observation - nil node", + name: "Happy Case - Successfully search observation", args: args{ - ctx: ctx, + ctx: context.Background(), patientID: gofakeit.UUID(), }, wantErr: false, }, { - name: "Happy Case - Successfully search observation", + name: "Sad Case - Fail to search weight", args: args{ - ctx: ctx, + ctx: context.Background(), patientID: gofakeit.UUID(), }, - wantErr: false, + wantErr: true, + }, + { + name: "Sad Case - Fail to search BMI", + args: args{ + ctx: context.Background(), + patientID: gofakeit.UUID(), + }, + wantErr: true, + }, + { + name: "Sad Case - Fail to search viralLoad", + args: args{ + ctx: context.Background(), + patientID: gofakeit.UUID(), + }, + wantErr: true, + }, + { + name: "Sad Case - Fail to search cd4Count", + args: args{ + ctx: context.Background(), + patientID: gofakeit.UUID(), + }, + wantErr: true, }, } for _, tt := range tests { @@ -571,9 +783,75 @@ func TestClinicalUseCaseImpl_GetMedicalData(t *testing.T) { } } - if tt.name == "Sad Case - Fail to search observation" { + if tt.name == "Sad Case - Fail to search weight" { + fakeFHIR.MockSearchFHIRObservationFn = func(ctx context.Context, params map[string]interface{}) (*domain.FHIRObservationRelayConnection, error) { + if params["code"] == common.WeightCIELTerminologyCode { + return nil, fmt.Errorf("failed to search observation") + } + + return &domain.FHIRObservationRelayConnection{ + Edges: []*domain.FHIRObservationRelayEdge{ + { + Cursor: new(string), + Node: &domain.FHIRObservation{}, + }, + }, + PageInfo: &firebasetools.PageInfo{}, + }, nil + } + } + + if tt.name == "Sad Case - Fail to search BMI" { + fakeFHIR.MockSearchFHIRObservationFn = func(ctx context.Context, params map[string]interface{}) (*domain.FHIRObservationRelayConnection, error) { + if params["code"] == common.BMICIELTerminologyCode { + return nil, fmt.Errorf("failed to search observation") + } + + return &domain.FHIRObservationRelayConnection{ + Edges: []*domain.FHIRObservationRelayEdge{ + { + Cursor: new(string), + Node: &domain.FHIRObservation{}, + }, + }, + PageInfo: &firebasetools.PageInfo{}, + }, nil + } + } + + if tt.name == "Sad Case - Fail to search viralLoad" { fakeFHIR.MockSearchFHIRObservationFn = func(ctx context.Context, params map[string]interface{}) (*domain.FHIRObservationRelayConnection, error) { - return nil, fmt.Errorf("failed to search observation") + if params["code"] == common.ViralLoadCIELTerminologyCode { + return nil, fmt.Errorf("failed to search observation") + } + + return &domain.FHIRObservationRelayConnection{ + Edges: []*domain.FHIRObservationRelayEdge{ + { + Cursor: new(string), + Node: &domain.FHIRObservation{}, + }, + }, + PageInfo: &firebasetools.PageInfo{}, + }, nil + } + } + + if tt.name == "Sad Case - Fail to search cd4Count" { + fakeFHIR.MockSearchFHIRObservationFn = func(ctx context.Context, params map[string]interface{}) (*domain.FHIRObservationRelayConnection, error) { + if params["code"] == common.CD4CountCIELTerminologyCode { + return nil, fmt.Errorf("failed to search observation") + } + + return &domain.FHIRObservationRelayConnection{ + Edges: []*domain.FHIRObservationRelayEdge{ + { + Cursor: new(string), + Node: &domain.FHIRObservation{}, + }, + }, + PageInfo: &firebasetools.PageInfo{}, + }, nil } } diff --git a/pkg/clinical/usecases/clinical/utils_test.go b/pkg/clinical/usecases/clinical/utils_test.go new file mode 100644 index 00000000..50e2a223 --- /dev/null +++ b/pkg/clinical/usecases/clinical/utils_test.go @@ -0,0 +1,355 @@ +package clinical_test + +import ( + "context" + "fmt" + "testing" + + "github.com/brianvoe/gofakeit" + "github.com/savannahghi/clinical/pkg/clinical/application/dto" + fakeExtMock "github.com/savannahghi/clinical/pkg/clinical/application/extensions/mock" + "github.com/savannahghi/clinical/pkg/clinical/domain" + "github.com/savannahghi/clinical/pkg/clinical/infrastructure" + fakeFHIRMock "github.com/savannahghi/clinical/pkg/clinical/infrastructure/datastore/cloudhealthcare/mock" + fakeMyCarehubMock "github.com/savannahghi/clinical/pkg/clinical/infrastructure/services/mycarehub/mock" + fakeOCLMock "github.com/savannahghi/clinical/pkg/clinical/infrastructure/services/openconceptlab/mock" + clinicalUsecase "github.com/savannahghi/clinical/pkg/clinical/usecases/clinical" + "github.com/savannahghi/enumutils" + "github.com/savannahghi/scalarutils" +) + +func TestUseCasesClinicalImpl_GetTenantMetaTags(t *testing.T) { + type args struct { + ctx context.Context + } + tests := []struct { + name string + args args + wantErr bool + }{ + { + name: "happy case: get tenant org from context", + args: args{ + ctx: context.Background(), + }, + wantErr: false, + }, + { + name: "sad case: missing tenant org in context", + args: args{ + ctx: context.Background(), + }, + wantErr: true, + }, + { + name: "sad case: error retrieving organisation", + args: args{ + ctx: context.Background(), + }, + wantErr: true, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + FakeExt := fakeExtMock.NewFakeBaseExtensionMock() + Fakefhir := fakeFHIRMock.NewFHIRMock() + FakeOCL := fakeOCLMock.NewFakeOCLMock() + fakeMCH := fakeMyCarehubMock.NewFakeMyCareHubServiceMock() + + infra := infrastructure.NewInfrastructureInteractor(FakeExt, Fakefhir, FakeOCL, fakeMCH) + c := clinicalUsecase.NewUseCasesClinicalImpl(infra) + + if tt.name == "sad case: missing tenant org in context" { + FakeExt.MockGetTenantIdentifiersFn = func(ctx context.Context) (*dto.TenantIdentifiers, error) { + return nil, fmt.Errorf("failed to to get identifiers") + } + } + + if tt.name == "sad case: error retrieving organisation" { + Fakefhir.MockFindOrganizationByIDFn = func(ctx context.Context, organisationID string) (*domain.FHIROrganizationRelayPayload, error) { + return nil, fmt.Errorf("failed to find organization") + } + } + + got, err := c.GetTenantMetaTags(tt.args.ctx) + if (err != nil) != tt.wantErr { + t.Errorf("UseCasesClinicalImpl.GetTenantMetaTags() error = %v, wantErr %v", err, tt.wantErr) + return + } + + if tt.wantErr && got != nil { + t.Errorf("expected result to be nil for %v", tt.name) + return + } + + if !tt.wantErr && got == nil { + t.Errorf("expected result not to be nil for %v", tt.name) + return + } + }) + } +} + +func TestUseCasesClinicalImpl_ContactsToContactPointInput(t *testing.T) { + + type args struct { + ctx context.Context + phones []*domain.PhoneNumberInput + emails []*domain.EmailInput + } + tests := []struct { + name string + args args + wantErr bool + }{ + { + name: "happy case: nil inputs", + args: args{ + ctx: context.Background(), + phones: nil, + emails: nil, + }, + wantErr: false, + }, + { + name: "happy case: contacts to contact point", + args: args{ + ctx: context.Background(), + phones: []*domain.PhoneNumberInput{ + { + Msisdn: gofakeit.Phone(), + VerificationCode: "1234", + IsUssd: false, + CommunicationOptIn: false, + }, + }, + emails: []*domain.EmailInput{ + { + Email: gofakeit.Email(), + CommunicationOptIn: false, + }, + }, + }, + wantErr: false, + }, + { + name: "sad case: invalid phone", + args: args{ + ctx: context.Background(), + phones: []*domain.PhoneNumberInput{ + { + Msisdn: "0722", + VerificationCode: "1234", + IsUssd: false, + CommunicationOptIn: false, + }, + }, + emails: []*domain.EmailInput{ + { + Email: gofakeit.Email(), + CommunicationOptIn: false, + }, + }, + }, + wantErr: true, + }, + { + name: "sad case: invalid email", + args: args{ + ctx: context.Background(), + phones: []*domain.PhoneNumberInput{ + { + Msisdn: gofakeit.Phone(), + VerificationCode: "1234", + IsUssd: false, + CommunicationOptIn: false, + }, + }, + emails: []*domain.EmailInput{ + { + Email: "invalid", + CommunicationOptIn: false, + }, + }, + }, + wantErr: true, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + FakeExt := fakeExtMock.NewFakeBaseExtensionMock() + Fakefhir := fakeFHIRMock.NewFHIRMock() + FakeOCL := fakeOCLMock.NewFakeOCLMock() + fakeMCH := fakeMyCarehubMock.NewFakeMyCareHubServiceMock() + + infra := infrastructure.NewInfrastructureInteractor(FakeExt, Fakefhir, FakeOCL, fakeMCH) + c := clinicalUsecase.NewUseCasesClinicalImpl(infra) + + got, err := c.ContactsToContactPointInput(tt.args.ctx, tt.args.phones, tt.args.emails) + if (err != nil) != tt.wantErr { + t.Errorf("UseCasesClinicalImpl.ContactsToContactPointInput() error = %v, wantErr %v", err, tt.wantErr) + return + } + + if tt.wantErr && got != nil { + t.Errorf("expected result to be nil for %v", tt.name) + return + } + }) + } +} + +func TestUseCasesClinicalImpl_SimplePatientRegistrationInputToPatientInput(t *testing.T) { + + type args struct { + ctx context.Context + input domain.SimplePatientRegistrationInput + } + tests := []struct { + name string + args args + wantErr bool + }{ + { + name: "happy case: fhir patient input", + args: args{ + ctx: context.Background(), + input: domain.SimplePatientRegistrationInput{ + ID: gofakeit.UUID(), + Names: []*domain.NameInput{ + { + FirstName: gofakeit.Name(), + LastName: gofakeit.Name(), + }, + }, + IdentificationDocuments: []*domain.IdentificationDocument{ + { + DocumentType: domain.IDDocumentTypePassport, + DocumentNumber: gofakeit.SSN(), + }, + }, + BirthDate: scalarutils.Date{ + Year: 2000, + Month: 10, + Day: 10, + }, + PhoneNumbers: []*domain.PhoneNumberInput{}, + Photos: []*domain.PhotoInput{ + { + PhotoContentType: enumutils.ContentTypeJpg, + PhotoBase64data: "qweqwdwedwed", + PhotoFilename: "test", + }, + }, + Emails: []*domain.EmailInput{ + { + Email: gofakeit.Email(), + CommunicationOptIn: false, + }, + }, + PhysicalAddresses: []*domain.PhysicalAddress{ + { + MapsCode: "123", + PhysicalAddress: "1234", + }, + }, + PostalAddresses: []*domain.PostalAddress{ + { + PostalAddress: "1234", + PostalCode: "1234", + }, + }, + Gender: "", + Active: true, + MaritalStatus: "", + Languages: []enumutils.Language{"en"}, + ReplicateUSSD: false, + }, + }, + wantErr: false, + }, + { + name: "sad case: invalid email", + args: args{ + ctx: context.Background(), + input: domain.SimplePatientRegistrationInput{ + ID: gofakeit.UUID(), + Names: []*domain.NameInput{ + { + FirstName: gofakeit.Name(), + LastName: gofakeit.Name(), + }, + }, + IdentificationDocuments: []*domain.IdentificationDocument{ + { + DocumentType: domain.IDDocumentTypePassport, + DocumentNumber: gofakeit.SSN(), + }, + }, + BirthDate: scalarutils.Date{ + Year: 2000, + Month: 10, + Day: 10, + }, + PhoneNumbers: []*domain.PhoneNumberInput{}, + Photos: []*domain.PhotoInput{ + { + PhotoContentType: enumutils.ContentTypeJpg, + PhotoBase64data: "qweqwdwedwed", + PhotoFilename: "test", + }, + }, + Emails: []*domain.EmailInput{ + { + Email: "invalid", + CommunicationOptIn: false, + }, + }, + PhysicalAddresses: []*domain.PhysicalAddress{ + { + MapsCode: "123", + PhysicalAddress: "1234", + }, + }, + PostalAddresses: []*domain.PostalAddress{ + { + PostalAddress: "1234", + PostalCode: "1234", + }, + }, + Active: true, + Languages: []enumutils.Language{"en"}, + ReplicateUSSD: false, + }, + }, + wantErr: true, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + ext := fakeExtMock.NewFakeBaseExtensionMock() + fhir := fakeFHIRMock.NewFHIRMock() + ocl := fakeOCLMock.NewFakeOCLMock() + mch := fakeMyCarehubMock.NewFakeMyCareHubServiceMock() + + infra := infrastructure.NewInfrastructureInteractor(ext, fhir, ocl, mch) + c := clinicalUsecase.NewUseCasesClinicalImpl(infra) + + got, err := c.SimplePatientRegistrationInputToPatientInput(tt.args.ctx, tt.args.input) + if (err != nil) != tt.wantErr { + t.Errorf("UseCasesClinicalImpl.SimplePatientRegistrationInputToPatientInput() error = %v, wantErr %v", err, tt.wantErr) + return + } + + if tt.wantErr && got != nil { + t.Errorf("expected result to be nil for %v", tt.name) + return + } + + if !tt.wantErr && got == nil { + t.Errorf("expected result not to be nil for %v", tt.name) + return + } + }) + } +}