Skip to content

Commit

Permalink
fix(CPL-312): fixt profile syncing input and output
Browse files Browse the repository at this point in the history
  • Loading branch information
BiKodes committed Apr 18, 2024
1 parent e46c655 commit 6b761ce
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 54 deletions.
5 changes: 3 additions & 2 deletions healthcrm.go
Original file line number Diff line number Diff line change
Expand Up @@ -397,8 +397,9 @@ func (h *HealthCRMLib) CreateProfile(ctx context.Context, profile *ProfileInput)
return nil, fmt.Errorf("could not read response: %w", err)
}

if response.StatusCode != http.StatusCreated {
return nil, errors.New(string(respBytes))
if response.StatusCode != http.StatusAccepted {
err := fmt.Errorf("unexpected status %v returned", response.StatusCode)
return nil, err
}

var profileResponse *ProfileOutput
Expand Down
28 changes: 7 additions & 21 deletions healthcrm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1215,6 +1215,7 @@ func TestHealthCRMLib_CreateProfile(t *testing.T) {
args: args{
ctx: context.Background(),
profile: &ProfileInput{
ProfileID: gofakeit.UUID(),
FirstName: "TestProfile",
LastName: "BikoTest",
OtherName: "SteveTest",
Expand Down Expand Up @@ -1268,34 +1269,19 @@ func TestHealthCRMLib_CreateProfile(t *testing.T) {
path := fmt.Sprintf("%s/v1/identities/profiles/", BaseURL)
httpmock.RegisterResponder(http.MethodPost, path, func(r *http.Request) (*http.Response, error) {
resp := &ProfileOutput{
FirstName: gofakeit.FirstName(),
LastName: gofakeit.LastName(),
OtherName: gofakeit.BeerName(),
DateOfBirth: gofakeit.Date().String(),
Gender: gofakeit.Gender(),
EnrolmentDate: gofakeit.Date().String(),
SladeCode: "50202",
ServiceCode: "50",
Contacts: []*ProfileContactOutput{
{
ContactType: "PHONE_NUMBER",
ContactValue: "+254788223223",
},
},
Identifiers: []*ProfileIdentifierOutput{
{
IdentifierType: "SLADE_CODE",
IdentifierValue: "3243",
},
},
ID: gofakeit.UUID(),
ProfileID: gofakeit.UUID(),
HealthID: "50932",
SladeCode: "50202",
}
return httpmock.NewJsonResponse(http.StatusCreated, resp)
return httpmock.NewJsonResponse(http.StatusAccepted, resp)
})
}
if tt.name == "Sad Case: Unable To Create Profile" {
path := fmt.Sprintf("%s/v1/identities/profiles/", BaseURL)
httpmock.RegisterResponder(http.MethodPost, path, func(r *http.Request) (*http.Response, error) {
resp := &ProfileInput{
ProfileID: gofakeit.UUID(),
FirstName: gofakeit.FirstName(),
LastName: gofakeit.LastName(),
OtherName: gofakeit.BeerName(),
Expand Down
1 change: 1 addition & 0 deletions input.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ type ServiceIdentifierInput struct {

// ProfileInput is the host of users data or a brief description of a person
type ProfileInput struct {
ProfileID string `json:"profile_id"`
FirstName string `json:"first_name"`
LastName string `json:"last_name"`
OtherName string `json:"other_name"`
Expand Down
35 changes: 4 additions & 31 deletions output.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,35 +100,8 @@ type ServiceIdentifier struct {

// ProfileOutput is used to display profile(s)
type ProfileOutput struct {
ID string `json:"id,omitempty"`
Created string `json:"created,omitempty"`
Active bool `json:"active"`
FirstName string `json:"first_name"`
LastName string `json:"last_name"`
OtherName string `json:"other_name"`
DateOfBirth string `json:"date_of_birth"`
Gender string `json:"gender"`
EnrolmentDate string `json:"enrolment_date"`
SladeCode string `json:"slade_code"`
ServiceCode string `json:"service_code"`
Contacts []*ProfileContactOutput `json:"contacts,omitempty"`
Identifiers []*ProfileIdentifierOutput `json:"identifiers,omitempty"`
}

// ProfileContactOutput is used to show profile contacts
type ProfileContactOutput struct {
ID string `json:"id"`
ContactType string `json:"contact_type"`
ContactValue string `json:"contact_value"`
DateVerified string `json:"date_verified"`
Verified bool `json:"verifed,omitempty"`
}

// ProfileIndentifierOutput is used to display profile identifiers
type ProfileIdentifierOutput struct {
ID string `json:"id"`
IdentifierType string `json:"identifier_type"`
IdentifierValue string `json:"identifier_value"`
ValidFrom string `json:"valid_from"`
ValidTo string `json:"valid_to"`
ID string `json:"id"`
ProfileID string `json:"profile_id"`
HealthID string `json:"health_id,omitempty"`
SladeCode string `json:"slade_code"`
}

0 comments on commit 6b761ce

Please sign in to comment.