-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve usecase implementation and add acceptance tests Signed-off-by: Otieno Calvine <nyarangaotieno@gmail.com>
- Loading branch information
Showing
10 changed files
with
364 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package mock | ||
|
||
import ( | ||
"context" | ||
"io" | ||
"net/http" | ||
"net/url" | ||
) | ||
|
||
// OCLMock instantiates all the mock functions | ||
type OCLMock struct { | ||
MakeRequestFn func(method string, path string, params url.Values, body io.Reader) (*http.Response, error) | ||
ListConceptsFn func( | ||
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) ([]map[string]interface{}, error) | ||
GetConceptFn func( | ||
ctx context.Context, org string, source string, concept string, | ||
includeMappings bool, includeInverseMappings bool) (map[string]interface{}, error) | ||
} | ||
|
||
// NewOCLMock is a new instance of OCLMock | ||
func NewOCLMock() *OCLMock { | ||
return &OCLMock{ | ||
MakeRequestFn: func(method string, path string, params url.Values, body io.Reader) (*http.Response, error) { | ||
return &http.Response{}, nil | ||
}, | ||
ListConceptsFn: func( | ||
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) ([]map[string]interface{}, error) { | ||
return nil, nil | ||
}, | ||
GetConceptFn: func( | ||
ctx context.Context, org string, source string, concept string, | ||
includeMappings bool, includeInverseMappings bool) (map[string]interface{}, error) { | ||
return nil, nil | ||
}, | ||
} | ||
} | ||
|
||
//MakeRequest is the MakeRequest mock | ||
func (ocl *OCLMock) MakeRequest(method string, path string, params url.Values, body io.Reader) (*http.Response, error) { | ||
return ocl.MakeRequestFn(method, path, params, body) | ||
} | ||
|
||
//ListConcepts is the ListConcepts mock | ||
func (ocl *OCLMock) ListConcepts( | ||
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) ([]map[string]interface{}, error) { | ||
return ocl.ListConceptsFn( | ||
ctx, | ||
org, | ||
source, | ||
verbose, | ||
q, | ||
sortAsc, | ||
sortDesc, | ||
conceptClass, | ||
dataType, | ||
locale, | ||
includeRetired, | ||
includeMappings, | ||
includeInverseMappings, | ||
) | ||
} | ||
|
||
// GetConcept is the GetConcept mock | ||
func (ocl *OCLMock) GetConcept( | ||
ctx context.Context, org string, source string, concept string, | ||
includeMappings bool, includeInverseMappings bool) (map[string]interface{}, error) { | ||
return ocl.GetConceptFn( | ||
ctx, | ||
org, | ||
source, | ||
concept, | ||
includeMappings, | ||
includeInverseMappings, | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,75 @@ | ||
package usecases | ||
package ocl | ||
|
||
import ( | ||
"context" | ||
"io" | ||
"net/http" | ||
"net/url" | ||
|
||
"github.com/savannahghi/clinical/pkg/clinical/infrastructure" | ||
) | ||
|
||
// UseCases represents all the Open Concept Lab business logic | ||
type UseCases interface { | ||
MakeRequest(method string, path string, params url.Values, body io.Reader) (*http.Response, error) | ||
ListConcepts( | ||
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) ([]map[string]interface{}, error) | ||
GetConcept( | ||
ctx context.Context, org string, source string, concept string, | ||
includeMappings bool, includeInverseMappings bool) (map[string]interface{}, error) | ||
} | ||
|
||
// UseCasesImpl represents the OCL usecase implementation | ||
type UseCasesImpl struct { | ||
infrastructure infrastructure.Infrastructure | ||
} | ||
|
||
// NewUseCasesImpl initializes Open Concept Lab implementation | ||
func NewUseCasesImpl(infrastructure infrastructure.Infrastructure) *UseCasesImpl { | ||
return &UseCasesImpl{infrastructure: infrastructure} | ||
} | ||
|
||
// MakeRequest composes an authenticated OCL request that has the correct content type | ||
func (ocl *UseCasesImpl) MakeRequest(method string, path string, params url.Values, body io.Reader) (*http.Response, error) { | ||
return ocl.infrastructure.OpenConceptLab.MakeRequest(method, path, params, body) | ||
} | ||
|
||
// ListConcepts retrieves a single concept from OpenConceptLab. | ||
func (ocl *UseCasesImpl) ListConcepts( | ||
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) ([]map[string]interface{}, error) { | ||
return ocl.infrastructure.OpenConceptLab.ListConcepts( | ||
ctx, | ||
org, | ||
source, | ||
verbose, | ||
q, | ||
sortAsc, | ||
sortDesc, | ||
conceptClass, | ||
dataType, | ||
locale, | ||
includeRetired, | ||
includeMappings, | ||
includeInverseMappings, | ||
) | ||
} | ||
|
||
// GetConcept searches for matching concepts on OpenConceptLab | ||
func (ocl *UseCasesImpl) GetConcept( | ||
ctx context.Context, org string, source string, concept string, | ||
includeMappings bool, includeInverseMappings bool) (map[string]interface{}, error) { | ||
return ocl.infrastructure.OpenConceptLab.GetConcept( | ||
ctx, | ||
org, | ||
source, | ||
concept, | ||
includeMappings, | ||
includeInverseMappings, | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.