shiori/internal/testutil/accounts.go
Felipe Martin 876d27f337
refactor: remove gin and use stdlib http server (#1064)
* refactor: base http server stdlib

* refactor: swagger and frontend routes

* fix: use global middlewares

* refactor: removed gin from testutils

* fix: object references in legacy webserver

* refactor: legacy, swagger and system handlers

* fix: added verbs to handlers

* fix: server handlers ordering

* refactor: bookmarks handlers

* refactor: system api routes

* tests: bookmark handlers

* refactor: migrated api auth routes

* chore: remove unused middlewares

* docs: add swagger docs to refactored system api

* chore: remove old auth routes

* refactor: account apis

* chore: removed old handlers

* fix: api v1 handlers missing middlewares

* refactor: migrated tag list route

* refactor: bookmark routes

* refactor: remove gin

* chore: make styles

* test: fixed tests

* test: generate binary file without text

* fix: global middleware missing from system api handler

* fix: incorrect api handler

* chore: avoid logging screenshot contents

* tests: bookmarks domain

* tests: shortcuts

* test: missing tests

* tests: server tests

* test: remove test using syscall to avoid windows errors

* chore: added middlewares
2025-02-26 20:50:48 +01:00

30 lines
828 B
Go

package testutil
import (
"context"
"time"
"github.com/go-shiori/shiori/internal/model"
)
// NewAdminUser creates a new admin user and returns its account and token.
// Use this when testing the API endpoints that require admin authentication to
// generate the user and obtain a token that can be easily added as `WithAuthToken()`
// option in the request.
func NewAdminUser(deps model.Dependencies) (*model.AccountDTO, string, error) {
account, err := deps.Domains().Accounts().CreateAccount(context.TODO(), model.AccountDTO{
Username: "admin",
Password: "admin",
Owner: model.Ptr(true),
})
if err != nil {
return nil, "", err
}
token, err := deps.Domains().Auth().CreateTokenForAccount(account, time.Now().Add(time.Hour*24*365))
if err != nil {
return nil, "", err
}
return account, token, nil
}