-
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.
feat: implement login by phone (#63)
- Loading branch information
Showing
19 changed files
with
379 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,31 @@ | ||
package exceptions | ||
|
||
import "github.com/savannahghi/errorcodeutil" | ||
|
||
// NormalizeMSISDNError returns an error when normalizing the msisdn fails | ||
func NormalizeMSISDNError(err error) error { | ||
return &errorcodeutil.CustomError{ | ||
Err: err, | ||
Message: NormalizeMSISDNErrMsg, | ||
Code: int(errorcodeutil.Internal), | ||
} | ||
} | ||
|
||
// PinMismatchError displays an error when the supplied PIN | ||
// does not match the PIN stored | ||
func PinMismatchError(err error) error { | ||
return &errorcodeutil.CustomError{ | ||
Err: err, | ||
Message: PINMismatchErrMsg, | ||
Code: int(errorcodeutil.PINMismatch), | ||
} | ||
} | ||
|
||
// ExpiredPinError displays an error when the pin | ||
// is expired | ||
func ExpiredPinError() error { | ||
return &errorcodeutil.CustomError{ | ||
Message: ExpiredPinErrMsg, | ||
Code: 10, | ||
} | ||
} |
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,16 @@ | ||
package exceptions | ||
|
||
const ( | ||
// NormalizeMSISDNErrMsg is the error message displayed when | ||
// normalize the msisdn(phone number) fails | ||
NormalizeMSISDNErrMsg = "unable to normalize the phonenumber" | ||
|
||
// PINMismatchErrMsg is the error message displayed when | ||
// the user supplied PIN number does not match the PIN | ||
// record we have stored | ||
PINMismatchErrMsg = "wrong PIN credentials supplied" | ||
|
||
// ExpiredPinErrMsg is the error message displayed when the user supplied pin | ||
// has expired | ||
ExpiredPinErrMsg = "the user pin has expired" | ||
) |
23 changes: 23 additions & 0 deletions
23
pkg/mycarehub/infrastructure/database/postgres/gorm/config_test.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,23 @@ | ||
package gorm_test | ||
|
||
import ( | ||
"log" | ||
"os" | ||
"testing" | ||
|
||
"github.com/savannahghi/mycarehub/pkg/mycarehub/infrastructure/database/postgres/gorm" | ||
) | ||
|
||
var testingDB *gorm.PGInstance | ||
|
||
func TestMain(m *testing.M) { | ||
log.Println("setting up test database") | ||
var err error | ||
testingDB, err = gorm.NewPGInstance() | ||
if err != nil { | ||
os.Exit(1) | ||
} | ||
|
||
log.Printf("Running tests ...") | ||
os.Exit(m.Run()) | ||
} |
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
69 changes: 69 additions & 0 deletions
69
pkg/mycarehub/infrastructure/database/postgres/gorm/create_test.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,69 @@ | ||
package gorm_test | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
"time" | ||
|
||
"github.com/google/uuid" | ||
"github.com/savannahghi/feedlib" | ||
"github.com/savannahghi/mycarehub/pkg/mycarehub/infrastructure/database/postgres/gorm" | ||
) | ||
|
||
func TestPGInstance_SavePin(t *testing.T) { | ||
ctx := context.Background() | ||
|
||
type args struct { | ||
ctx context.Context | ||
pinData *gorm.PINData | ||
} | ||
|
||
id := uuid.New().String() | ||
pinPayload := &gorm.PINData{ | ||
PINDataID: &id, | ||
UserID: id, | ||
HashedPIN: "1234", | ||
ValidFrom: time.Now(), | ||
ValidTo: time.Now(), | ||
IsValid: true, | ||
Flavour: feedlib.FlavourConsumer, | ||
Salt: "1234", | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
want bool | ||
wantErr bool | ||
}{ | ||
{ | ||
name: "Happy Case - Successfully save pin", | ||
args: args{ | ||
ctx: ctx, | ||
pinData: pinPayload, | ||
}, | ||
want: true, | ||
wantErr: false, | ||
}, | ||
{ | ||
name: "Sad Case - Fail to save pin", | ||
args: args{ | ||
ctx: ctx, | ||
pinData: nil, | ||
}, | ||
want: false, | ||
wantErr: true, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
got, err := testingDB.SavePin(tt.args.ctx, tt.args.pinData) | ||
if (err != nil) != tt.wantErr { | ||
t.Errorf("PGInstance.SavePin() error = %v, wantErr %v", err, tt.wantErr) | ||
return | ||
} | ||
if got != tt.want { | ||
t.Errorf("PGInstance.SavePin() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} |
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
Oops, something went wrong.