Skip to content

Commit

Permalink
chore: add ocl integration tests
Browse files Browse the repository at this point in the history
Signed-off-by: Otieno Calvine <nyarangaotieno@gmail.com>
  • Loading branch information
NYARAS committed Oct 4, 2021
1 parent c35c3a1 commit 475072b
Show file tree
Hide file tree
Showing 4 changed files with 176 additions and 75 deletions.
1 change: 0 additions & 1 deletion pkg/clinical/infrastructure/datastore/services/firebase.go

This file was deleted.

74 changes: 0 additions & 74 deletions pkg/clinical/infrastructure/datastore/services/ocl.go

This file was deleted.

5 changes: 5 additions & 0 deletions pkg/clinical/presentation/interactor/interactor.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,21 @@ package interactor
import (
"github.com/savannahghi/clinical/pkg/clinical/infrastructure"
"github.com/savannahghi/clinical/pkg/clinical/usecases"
"github.com/savannahghi/clinical/pkg/clinical/usecases/ocl"
)

// Usecases is an interface that combines of all usescases
type Usecases interface {
usecases.ClinicalUseCase
usecases.FHIRUseCase
ocl.UseCases
}

// Interactor is an implementation of the usecases interface
type Interactor struct {
usecases.ClinicalUseCase
usecases.FHIRUseCase
ocl.UseCases
}

// NewUsecasesInteractor initializes a new usecases interactor
Expand All @@ -23,10 +26,12 @@ func NewUsecasesInteractor(
) Usecases {
fhir := usecases.NewFHIRUseCaseImpl(infrastructure)
clinical := usecases.NewClinicalUseCaseImpl(infrastructure, fhir)
ocl := ocl.NewUseCasesImpl(infrastructure)

impl := &Interactor{
clinical,
fhir,
ocl,
}

return impl
Expand Down
171 changes: 171 additions & 0 deletions pkg/clinical/usecases/ocl/ocl_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
package ocl_test

import (
"context"
"log"
"os"
"testing"

"github.com/savannahghi/clinical/pkg/clinical/infrastructure"
"github.com/savannahghi/clinical/pkg/clinical/presentation/interactor"
"github.com/stretchr/testify/assert"
)

var (
testUsecaseInteractor interactor.Usecases
testInfrastructure infrastructure.Infrastructure
)

func TestMain(m *testing.M) {
ctx := context.Background()
os.Setenv("ENVIRONMENT", "staging")
os.Setenv("ROOT_COLLECTION_SUFFIX", "staging")

log.Printf("Running tests ...")

infra, err := InitializeTestInfrastructure(ctx)
if err != nil {
log.Printf("failed to initialize infrastructure: %v", err)
}

testInfrastructure = infra

svc, err := InitializeTestService(ctx)
if err != nil {
log.Printf("failed to initialize test service: %v", err)
}
testUsecaseInteractor = svc

code := m.Run()

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

os.Exit(code)
}

func InitializeTestService(ctx context.Context) (interactor.Usecases, error) {

infrastructure := infrastructure.NewInfrastructureInteractor()

usecases := interactor.NewUsecasesInteractor(
infrastructure,
)
return usecases, nil
}

func InitializeTestInfrastructure(ctx context.Context) (infrastructure.Infrastructure, error) {
return infrastructure.NewInfrastructureInteractor(), nil
}

func TestUseCasesImpl_ListConcepts(t *testing.T) {
svc := testUsecaseInteractor
type args struct {
ctx context.Context
org string
source string
verbose bool
q *string
sortAsc *string
sortDesc *string
conceptClass *string
dataType *string
locale *string
includeRetired *bool
includeMappings *bool
includeInverseMappings *bool
}
tests := []struct {
name string
args args
wantErr bool
}{
{
name: "good case",
args: args{
ctx: context.Background(),
org: "CIEL",
source: "CIEL",
verbose: true,
},
wantErr: false,
},
{
name: "sad case",
args: args{
ctx: context.Background(),
org: "this is unknown org",
source: "CIEL",
verbose: true,
},
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
ocl := svc
got, err := ocl.ListConcepts(tt.args.ctx, tt.args.org, tt.args.source, tt.args.verbose, tt.args.q, tt.args.sortAsc, tt.args.sortDesc, tt.args.conceptClass, tt.args.dataType, tt.args.locale, tt.args.includeRetired, tt.args.includeMappings, tt.args.includeInverseMappings)
if (err != nil) != tt.wantErr {
t.Errorf("Service.ListConcepts() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !tt.wantErr {
assert.NotNil(t, got)
}
})
}
}

func TestUseCasesImpl_GetConcept(t *testing.T) {
svc := testUsecaseInteractor
type args struct {
ctx context.Context
org string
source string
concept string
includeMappings bool
includeInverseMappings bool
}
tests := []struct {
name string
args args
wantErr bool
}{
{
name: "valid_who_icd_concept",
args: args{
ctx: context.Background(),
org: "CIEL",
source: "CIEL",
concept: "106",
includeMappings: true,
includeInverseMappings: false,
},
wantErr: false,
},
{
name: "sad case -- nil concept in the payload",
args: args{
ctx: context.Background(),
org: "CIEL",
source: "CIEL",
includeMappings: true,
includeInverseMappings: false,
},
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
ocl := svc
got, err := ocl.GetConcept(tt.args.ctx, tt.args.org, tt.args.source, tt.args.concept, tt.args.includeMappings, tt.args.includeInverseMappings)
if (err != nil) != tt.wantErr {
t.Errorf("UseCasesImpl.GetConcept() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !tt.wantErr {
assert.NotNil(t, got)
assert.Contains(t, got, "display_name")
}
})
}
}

0 comments on commit 475072b

Please sign in to comment.