Skip to content

Testing with auth #76

Answered by eandre
Minivera asked this question in Help
Aug 26, 2021 · 1 comments · 1 reply
Discussion options

You must be logged in to vote

I've thought about this as well and we should definitely do something to make this easier to test (probably add the ability to inject auth data into an API call by wrapping the context, or something like that).

Until then, I suggest taking the business logic part and extracting it as a separate function that takes the auth data as a parameter:

//encore:api auth
func ListCollections(ctx context.Context) (*ListCollectionsResponse, error) {
	userData := auth.Data().(*identity.UserData)
	return listCollections(ctx, userData)
}

func listCollections(ctx context.Context, userData *identity.UserData) (*ListCollectionsResponse, error) {
	collections, err := models.ListCollections(ctx, userData.ID)
	

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@Minivera
Comment options

Answer selected by Minivera
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
2 participants