initial commit

This commit is contained in:
dhax 2017-09-25 18:23:11 +02:00
commit 93d8310491
46 changed files with 3379 additions and 0 deletions

61
testing/mock/authStore.go Normal file
View file

@ -0,0 +1,61 @@
package mock
import "github.com/dhax/go-base/models"
type AuthStore struct {
GetByIDFn func(id int) (*models.Account, error)
GetByIDInvoked bool
GetByEmailFn func(email string) (*models.Account, error)
GetByEmailInvoked bool
GetByRefreshTokenFn func(token string) (*models.Account, *models.Token, error)
GetByRefreshTokenInvoked bool
UpdateAccountFn func(a *models.Account) error
UpdateAccountInvoked bool
SaveRefreshTokenFn func(u *models.Token) error
SaveRefreshTokenInvoked bool
DeleteRefreshTokenFn func(t *models.Token) error
DeleteRefreshTokenInvoked bool
PurgeExpiredTokenFn func() error
PurgeExpiredTokenInvoked bool
}
func (s *AuthStore) GetByID(id int) (*models.Account, error) {
s.GetByIDInvoked = true
return s.GetByIDFn(id)
}
func (s *AuthStore) GetByEmail(email string) (*models.Account, error) {
s.GetByEmailInvoked = true
return s.GetByEmailFn(email)
}
func (s *AuthStore) GetByRefreshToken(token string) (*models.Account, *models.Token, error) {
s.GetByRefreshTokenInvoked = true
return s.GetByRefreshTokenFn(token)
}
func (s *AuthStore) UpdateAccount(a *models.Account) error {
s.UpdateAccountInvoked = true
return s.UpdateAccountFn(a)
}
func (s *AuthStore) SaveRefreshToken(u *models.Token) error {
s.SaveRefreshTokenInvoked = true
return s.SaveRefreshTokenFn(u)
}
func (s *AuthStore) DeleteRefreshToken(t *models.Token) error {
s.DeleteRefreshTokenInvoked = true
return s.DeleteRefreshTokenFn(t)
}
func (s *AuthStore) PurgeExpiredToken() error {
s.PurgeExpiredTokenInvoked = true
return s.PurgeExpiredTokenFn()
}

View file

@ -0,0 +1,13 @@
package mock
import "github.com/dhax/go-base/email"
type EmailService struct {
LoginTokenFn func(name, email string, c email.LoginTokenContent) error
LoginTokenInvoked bool
}
func (s *EmailService) LoginToken(n, e string, c email.LoginTokenContent) error {
s.LoginTokenInvoked = true
return s.LoginTokenFn(n, e, c)
}

View file

@ -0,0 +1,44 @@
GET {{host}}/admin
Authorization: {{jwtAdmin}}
###
POST {{host}}/admin/accounts
Authorization: {{jwtAdmin}}
{
"email": "user@boot.io",
"name": "duplicate user",
"active": true,
"roles": ["user"]
}
###
GET {{host}}/admin/accounts/2
Authorization: {{jwtAdmin}}
###
PUT {{host}}/admin/accounts/2
Authorization: {{jwtAdmin}}
{
"email": "user@boot.io",
"name": "TEST USER",
"roles": ["user"]
}
###
DELETE {{host}}/admin/accounts/2
Authorization: {{jwtAdmin}}
###
POST {{host}}/admin/accounts
Authorization: {{jwtAdmin}}
{
"email": "{{$timestamp}}@mail.io",
"name": "test user",
"active": true,
"roles": ["admin","user"]
}
###
GET {{host}}/admin/accounts?limit=3&page=1&order=id desc
Authorization: {{jwtAdmin}}
###
GET {{host}}/admin/accounts?email__match=%@boot.io
Authorization: {{jwtAdmin}}
###

View file

@ -0,0 +1,33 @@
GET {{host}}/api/account
Authorization: {{jwtUser}}
###
PUT {{host}}/api/account
Authorization: {{jwtUser}}
{
"email": "user@boot.io",
"name": "User Boot",
"active": false,
"roles": ["user", "admin"]
}
###
DELETE {{host}}/api/account
Authorization: {{jwtUser}}
###
PUT {{host}}/api/account/token/3
Authorization: {{jwtUser}}
{
"identifier": "my token identifier"
}
###
DELETE {{host}}/api/account/token/1
Authorization: {{jwtUser}}
###
PUT {{host}}/api/account/profile
Authorization: {{jwtUser}}
{
"id": 3,
"theme": "dark"
}

View file

@ -0,0 +1,15 @@
GET {{host}}/api/profile
Authorization: {{jwtUser}}
###
PUT {{host}}/api/profile
Authorization: {{jwtUser}}
{
"email": "invalid",
"name": "test"
}
###
DELETE {{host}}/api/profile
Authorization: {{jwtUser}}
###