-
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.
Signed-off-by: Kathurima Kimathi <kathurimakimathi415@gmail.com>
- Loading branch information
1 parent
bdd5444
commit 48d7cbf
Showing
37 changed files
with
823 additions
and
132 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,8 @@ | ||
package dto | ||
|
||
// SegmentationPayload is used to stratify clients in advantage EMR. | ||
type SegmentationPayload struct { | ||
// ClinicalID represents the patient's ID in this service | ||
ClinicalID string `json:"clinical_id,omitempty"` | ||
SegmentLabel SegmentationCategory `json:"segment_label,omitempty"` | ||
} |
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,149 @@ | ||
package dto | ||
|
||
import ( | ||
"bytes" | ||
"strconv" | ||
"testing" | ||
) | ||
|
||
func TestConsentState_MarshalGQL(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
c SegmentationCategory | ||
wantW string | ||
}{ | ||
{ | ||
name: "valid type s", | ||
c: SegmentationCategoryLowRisk, | ||
wantW: strconv.Quote("CERVICAL_CANCER_LOW_RISK"), | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
w := &bytes.Buffer{} | ||
tt.c.MarshalGQL(w) | ||
if gotW := w.String(); gotW != tt.wantW { | ||
t.Errorf("SegmentationCategory.MarshalGQL() = %v, want %v", gotW, tt.wantW) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestSegmentationCategory_String(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
e SegmentationCategory | ||
want string | ||
}{ | ||
{ | ||
name: "CERVICAL_CANCER_TIPS", | ||
e: SegmentationCategoryNoRisk, | ||
want: "CERVICAL_CANCER_TIPS", | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if got := tt.e.String(); got != tt.want { | ||
t.Errorf("SegmentationCategory.String() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestSegmentationCategory_IsValid(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
e SegmentationCategory | ||
want bool | ||
}{ | ||
{ | ||
name: "valid type", | ||
e: SegmentationCategoryHighRiskNegative, | ||
want: true, | ||
}, | ||
{ | ||
name: "invalid type", | ||
e: SegmentationCategory("invalid"), | ||
want: false, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if got := tt.e.IsValid(); got != tt.want { | ||
t.Errorf("SegmentationCategory.IsValid() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestSegmentationCategory_UnmarshalGQL(t *testing.T) { | ||
value := SegmentationCategoryHighRiskNegative | ||
invalid := SegmentationCategory("invalid") | ||
type args struct { | ||
v interface{} | ||
} | ||
tests := []struct { | ||
name string | ||
e *SegmentationCategory | ||
args args | ||
wantErr bool | ||
}{ | ||
{ | ||
name: "valid type", | ||
e: &value, | ||
args: args{ | ||
v: "CERVICAL_CANCER_HIGH_RISK", | ||
}, | ||
wantErr: false, | ||
}, | ||
{ | ||
name: "invalid type", | ||
e: &invalid, | ||
args: args{ | ||
v: "this is not a valid type", | ||
}, | ||
wantErr: true, | ||
}, | ||
{ | ||
name: "non string type", | ||
e: &invalid, | ||
args: args{ | ||
v: 1, | ||
}, | ||
wantErr: true, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if err := tt.e.UnmarshalGQL(tt.args.v); (err != nil) != tt.wantErr { | ||
t.Errorf("SegmentationCategory.UnmarshalGQL() error = %v, wantErr %v", err, tt.wantErr) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestSegmentationCategory_MarshalGQL(t *testing.T) { | ||
w := &bytes.Buffer{} | ||
tests := []struct { | ||
name string | ||
e SegmentationCategory | ||
b *bytes.Buffer | ||
wantW string | ||
panic bool | ||
}{ | ||
{ | ||
name: "valid type enums", | ||
e: SegmentationCategoryHighRiskNegative, | ||
b: w, | ||
wantW: strconv.Quote("CERVICAL_CANCER_HIGH_RISK"), | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
tt.e.MarshalGQL(tt.b) | ||
if gotW := w.String(); gotW != tt.wantW { | ||
t.Errorf("SegmentationCategory.MarshalGQL() = %v, want %v", gotW, tt.wantW) | ||
} | ||
}) | ||
} | ||
} |
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
28 changes: 28 additions & 0 deletions
28
pkg/clinical/infrastructure/services/advantage/mock/auth_client_mock.go
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,28 @@ | ||
package mock | ||
|
||
import "github.com/savannahghi/authutils" | ||
|
||
// AuthClientMock mocks the authentication client methods | ||
type AuthClientMock struct { | ||
MockAuthenticateFn func() (*authutils.OAUTHResponse, error) | ||
} | ||
|
||
// NewAuthUtilsClientMock constructor initializes the auth utils client mock | ||
func NewAuthUtilsClientMock() *AuthClientMock { | ||
return &AuthClientMock{ | ||
MockAuthenticateFn: func() (*authutils.OAUTHResponse, error) { | ||
return &authutils.OAUTHResponse{ | ||
Scope: "", | ||
ExpiresIn: 0, | ||
AccessToken: "token", | ||
RefreshToken: "refresh_token", | ||
TokenType: "Bearer", | ||
}, nil | ||
}, | ||
} | ||
} | ||
|
||
// Authenticate mocks the implementation of the authentication mechanism provided by auth utils | ||
func (a *AuthClientMock) Authenticate() (*authutils.OAUTHResponse, error) { | ||
return a.MockAuthenticateFn() | ||
} |
26 changes: 26 additions & 0 deletions
26
pkg/clinical/infrastructure/services/advantage/mock/service_mock.go
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,26 @@ | ||
package mock | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/savannahghi/clinical/pkg/clinical/application/dto" | ||
) | ||
|
||
// FakeAdvantage mocks the implementation of advantage API methods | ||
type FakeAdvantage struct { | ||
MockSegmentPatient func(ctx context.Context, payload dto.SegmentationPayload) error | ||
} | ||
|
||
// NewFakeAdvantageMock is the advantage's mock methods constructor | ||
func NewFakeAdvantageMock() *FakeAdvantage { | ||
return &FakeAdvantage{ | ||
MockSegmentPatient: func(ctx context.Context, payload dto.SegmentationPayload) error { | ||
return nil | ||
}, | ||
} | ||
} | ||
|
||
// SegmentPatient mocks the implementation of patient segmentation usecase | ||
func (f *FakeAdvantage) SegmentPatient(ctx context.Context, payload dto.SegmentationPayload) error { | ||
return f.MockSegmentPatient(ctx, payload) | ||
} |
Oops, something went wrong.