Skip to content

Commit

Permalink
test: handlers unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Muchogoc committed Mar 14, 2023
1 parent 69a3631 commit 645acfe
Show file tree
Hide file tree
Showing 12 changed files with 646 additions and 139 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ generate.sh
coverage.txt
.idea/
.gitmessage.txt
.vscode/
.vscode/

.DS_Store
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ require (
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/shopspring/decimal v1.3.1 // indirect
github.com/stretchr/objx v0.5.0 // indirect
github.com/ttacon/builder v0.0.0-20170518171403-c099f663e1c2 // indirect
github.com/ttacon/libphonenumber v1.2.1 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
Expand Down
26 changes: 23 additions & 3 deletions pkg/clinical/infrastructure/infrastructure.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"net/url"

"github.com/savannahghi/clinical/pkg/clinical/application/dto"
"github.com/savannahghi/clinical/pkg/clinical/infrastructure/services/mycarehub"
"github.com/savannahghi/clinical/pkg/clinical/domain"
"github.com/savannahghi/clinical/pkg/clinical/repository"
"github.com/savannahghi/interserviceclient"
"github.com/savannahghi/profileutils"
Expand Down Expand Up @@ -49,20 +49,40 @@ type BaseExtension interface {
GetPubSubTopic(m *pubsubtools.PubSubPayload) (string, error)
}

// IServiceMyCareHub represents mycarehub usecases
type IServiceMyCareHub interface {
UserProfile(
ctx context.Context,
userID string,
) (*domain.User, error)

AddFHIRIDToPatientProfile(
ctx context.Context,
fhirID string,
clientID string,
) error

AddFHIRIDToFacility(
ctx context.Context,
fhirID string,
facilityID string,
) error
}

// Infrastructure ...
type Infrastructure struct {
FHIR repository.FHIR
OpenConceptLab ServiceOCL
BaseExtension BaseExtension
MyCareHub mycarehub.IServiceMyCareHub
MyCareHub IServiceMyCareHub
}

// NewInfrastructureInteractor initializes a new Infrastructure
func NewInfrastructureInteractor(
ext BaseExtension,
fhir repository.FHIR,
openconceptlab ServiceOCL,
mycarehub mycarehub.IServiceMyCareHub,
mycarehub IServiceMyCareHub,
) Infrastructure {
return Infrastructure{
fhir,
Expand Down
19 changes: 0 additions & 19 deletions pkg/clinical/infrastructure/services/mycarehub/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,6 @@ const (
addFHIRIDToFacility = "internal/facilities"
)

// IServiceMyCareHub represents mycarehub usecases
type IServiceMyCareHub interface {
UserProfile(
ctx context.Context,
userID string,
) (*domain.User, error)

AddFHIRIDToPatientProfile(
ctx context.Context,
fhirID string,
clientID string,
) error
AddFHIRIDToFacility(
ctx context.Context,
fhirID string,
facilityID string,
) error
}

// ServiceMyCareHubImpl represents mycarehub usecases
type ServiceMyCareHubImpl struct {
MyCareHubClient extensions.ISCClientExtension
Expand Down
2 changes: 1 addition & 1 deletion pkg/clinical/presentation/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ func SetupRoutes(r *gin.Engine, authclient *authutils.Client, usecases usecases.

graphQL := r.Group("/graphql")
graphQL.Use(authutils.SladeAuthenticationGinMiddleware(*authclient))
graphQL.Use(rest.TenantIdentifierExtractionMiddleware(usecases))
graphQL.Use(rest.TenantIdentifierExtractionMiddleware(infra.FHIR))
graphQL.Any("", GQLHandler(usecases))

// Unauthenticated routes
Expand Down
1 change: 0 additions & 1 deletion pkg/clinical/presentation/graph/generated/generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions pkg/clinical/presentation/interactor/interactor.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import (

// UseCasesClinical represents all the patient business logic
type Clinical interface {
FindOrganizationByID(ctx context.Context, organizationID string) (*domain.FHIROrganizationRelayPayload, error)

CreateFHIROrganization(ctx context.Context, input domain.FHIROrganizationInput) (*domain.FHIROrganizationRelayPayload, error)
PatientHealthTimeline(ctx context.Context, input domain.HealthTimelineInput) (*domain.HealthTimeline, error)
GetMedicalData(ctx context.Context, patientID string) (*domain.MedicalData, error)
Expand All @@ -25,7 +23,6 @@ type Usecases interface {
// Interactor is an implementation of the usecases interface
type Interactor struct {
Clinical
infrastructure.Infrastructure
}

// NewUsecasesInteractor initializes a new usecases interactor
Expand All @@ -36,7 +33,6 @@ func NewUsecasesInteractor(

impl := &Interactor{
clinical,
infrastructure,
}

return impl
Expand Down
12 changes: 6 additions & 6 deletions pkg/clinical/presentation/rest/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package rest

import (
"encoding/json"
"fmt"
"net/http"

"github.com/gin-gonic/gin"
Expand All @@ -28,7 +29,7 @@ type PresentationHandlersImpl struct {

// NewPresentationHandlers initializes a new rest handlers usecase
func NewPresentationHandlers(usecases usecases.Interactor, extension BaseExtension) *PresentationHandlersImpl {
return &PresentationHandlersImpl{usecases: usecases}
return &PresentationHandlersImpl{usecases: usecases, baseExt: extension}
}

// ReceivePubSubPushMessage receives and processes a pubsub message
Expand Down Expand Up @@ -193,12 +194,10 @@ func (p PresentationHandlersImpl) ReceivePubSubPushMessage(c *gin.Context) {

return
}
}

resp := map[string]string{"Status": "Success"}
default:
err := fmt.Errorf("unknown topic ID: %v", topicID)

returnedResponse, err := json.Marshal(resp)
if err != nil {
serverutils.WriteJSONResponse(c.Writer, errorcodeutil.CustomError{
Err: err,
Message: err.Error(),
Expand All @@ -207,5 +206,6 @@ func (p PresentationHandlersImpl) ReceivePubSubPushMessage(c *gin.Context) {
return
}

_, _ = c.Writer.Write(returnedResponse)
resp := map[string]string{"Status": "Success"}
c.JSON(http.StatusOK, resp)
}
Loading

0 comments on commit 645acfe

Please sign in to comment.