Skip to content

Commit

Permalink
fix: create program
Browse files Browse the repository at this point in the history
- return organisation object after creating a program

Signed-off-by: Kathurima Kimathi <kathurimakimathi415@gmail.com>
  • Loading branch information
KathurimaKimathi committed Oct 25, 2023
1 parent e22e55b commit bd5eb53
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 8 deletions.
1 change: 0 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ jobs:
- name: Run lint and tests
run: |
gosec -exclude=G601,G304,G101 ./...
go-acc -o coverage.txt --ignore generated,cmd,graph,tests ./... -- -timeout 60m
grep -v "generated.go" coverage.txt | grep -v "_gen.go" | grep -v "mocks.go" | grep -v "*mocks.go" | grep -v "mock.go" | grep -v "*mock.go" | grep -v "*resolvers*go" | grep -v "*.resolvers.go" | grep -v "server.go" > coverage.out
go tool cover -html=coverage.out -o coverage.html
Expand Down
28 changes: 22 additions & 6 deletions pkg/mycarehub/infrastructure/database/postgres/pg_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -1014,13 +1014,29 @@ func (d *MyCareHubDb) CreateProgram(ctx context.Context, input *dto.ProgramInput
return nil, err
}

organisation, err := d.query.GetOrganisation(ctx, program.OrganisationID)
if err != nil {
return nil, err
}

return &domain.Program{
ID: program.ID,
Active: program.Active,
Name: program.Name,
Description: program.Description,
Organisation: domain.Organisation{ID: program.OrganisationID},
Facilities: facilities,
ID: program.ID,
Active: program.Active,
Name: program.Name,
Description: program.Description,
Organisation: domain.Organisation{
ID: *organisation.ID,
Active: organisation.Active,
Code: organisation.Code,
Name: organisation.Name,
Description: organisation.Description,
EmailAddress: organisation.EmailAddress,
PhoneNumber: organisation.PhoneNumber,
PostalAddress: organisation.PostalAddress,
PhysicalAddress: organisation.PhysicalAddress,
DefaultCountry: organisation.DefaultCountry,
},
Facilities: facilities,
}, nil
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1965,6 +1965,19 @@ func TestMyCareHubDb_CreateProgram(t *testing.T) {
},
wantErr: true,
},
{
name: "Sad case: failed to get organisation",
args: args{
ctx: context.Background(),
input: &dto.ProgramInput{
Name: gofakeit.BeerBlg(),
Description: gofakeit.BS(),
OrganisationID: uuid.NewString(),
Facilities: []string{gofakeit.UUID()},
},
},
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand All @@ -1987,6 +2000,12 @@ func TestMyCareHubDb_CreateProgram(t *testing.T) {
return nil, fmt.Errorf("fan error occurred")
}
}
if tt.name == "Sad case: failed to get organisation" {
fakeGorm.MockGetOrganisationFn = func(ctx context.Context, id string) (*gorm.Organisation, error) {
return nil, fmt.Errorf("error")
}
}

d := NewMyCareHubDb(fakeGorm, fakeGorm, fakeGorm, fakeGorm)
_, err := d.CreateProgram(tt.args.ctx, tt.args.input)
if (err != nil) != tt.wantErr {
Expand Down
2 changes: 1 addition & 1 deletion pkg/mycarehub/usecases/user/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -1408,7 +1408,7 @@ func (us *UseCasesUserImpl) RegisterStaffProfile(ctx context.Context, input dto.
}, nil
}

// RegisterStaff is used to register a staff user on our in mycarehub
// RegisterStaff is used to register a staff user in mycarehub
func (us *UseCasesUserImpl) RegisterStaff(ctx context.Context, input dto.StaffRegistrationInput) (*dto.StaffRegistrationOutput, error) {
loggedInUserID, err := us.ExternalExt.GetLoggedInUserUID(ctx)
if err != nil {
Expand Down

0 comments on commit bd5eb53

Please sign in to comment.