mirror of
https://github.com/get-drexa/drive.git
synced 2026-02-02 13:11:18 +00:00
test(backend): move tests to *_test pkg
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
.PHONY: build build-docs build-all run run-docs docs install-tools fmt clean
|
||||
.PHONY: build build-docs build-all run run-docs docs install-tools fmt test clean
|
||||
|
||||
ROOT_DIR := $(abspath $(CURDIR)/../..)
|
||||
|
||||
# Build the API server
|
||||
build:
|
||||
@@ -39,6 +41,10 @@ fmt:
|
||||
go fmt ./...
|
||||
swag fmt
|
||||
|
||||
test:
|
||||
@mkdir -p $(ROOT_DIR)/.gocache $(ROOT_DIR)/.gomodcache
|
||||
@GOCACHE=$(ROOT_DIR)/.gocache GOMODCACHE=$(ROOT_DIR)/.gomodcache go test ./...
|
||||
|
||||
# Clean build artifacts
|
||||
clean:
|
||||
rm -rf bin/
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
//go:build integration
|
||||
|
||||
package drexa
|
||||
package drexa_test
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
@@ -15,6 +15,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/get-drexa/drexa/internal/database"
|
||||
"github.com/get-drexa/drexa/internal/drexa"
|
||||
"github.com/get-drexa/drexa/internal/organization"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/google/uuid"
|
||||
@@ -42,19 +43,26 @@ func TestRegistrationFlow(t *testing.T) {
|
||||
}
|
||||
t.Cleanup(func() { _ = os.RemoveAll(blobRoot) })
|
||||
|
||||
s, err := NewServer(Config{
|
||||
Server: ServerConfig{Port: 8080},
|
||||
Database: DatabaseConfig{
|
||||
db := database.NewFromPostgres(postgresURL)
|
||||
t.Cleanup(func() { _ = db.Close() })
|
||||
|
||||
if err := database.RunMigrations(ctx, db); err != nil {
|
||||
t.Fatalf("RunMigrations: %v", err)
|
||||
}
|
||||
|
||||
s, err := drexa.NewServer(drexa.Config{
|
||||
Server: drexa.ServerConfig{Port: 8080},
|
||||
Database: drexa.DatabaseConfig{
|
||||
PostgresURL: postgresURL,
|
||||
},
|
||||
JWT: JWTConfig{
|
||||
JWT: drexa.JWTConfig{
|
||||
Issuer: "drexa-test",
|
||||
Audience: "drexa-test",
|
||||
SecretKey: []byte("drexa-test-secret"),
|
||||
},
|
||||
Storage: StorageConfig{
|
||||
Mode: StorageModeFlat,
|
||||
Backend: StorageBackendFS,
|
||||
Storage: drexa.StorageConfig{
|
||||
Mode: drexa.StorageModeFlat,
|
||||
Backend: drexa.StorageBackendFS,
|
||||
RootPath: blobRoot,
|
||||
},
|
||||
})
|
||||
@@ -62,10 +70,6 @@ func TestRegistrationFlow(t *testing.T) {
|
||||
t.Fatalf("NewServer: %v", err)
|
||||
}
|
||||
|
||||
if err := database.RunMigrations(ctx, s.db); err != nil {
|
||||
t.Fatalf("RunMigrations: %v", err)
|
||||
}
|
||||
|
||||
type registerResponse struct {
|
||||
Account struct {
|
||||
ID string `json:"id"`
|
||||
@@ -94,7 +98,7 @@ func TestRegistrationFlow(t *testing.T) {
|
||||
}
|
||||
|
||||
var reg registerResponse
|
||||
doJSON(t, s.app, http.MethodPost, "/api/accounts", "", registerBody, http.StatusOK, ®)
|
||||
doJSON(t, s.App(), http.MethodPost, "/api/accounts", "", registerBody, http.StatusOK, ®)
|
||||
if reg.AccessToken == "" {
|
||||
t.Fatalf("expected access token in registration response")
|
||||
}
|
||||
@@ -129,7 +133,7 @@ func TestRegistrationFlow(t *testing.T) {
|
||||
}
|
||||
|
||||
var login loginResponse
|
||||
doJSON(t, s.app, http.MethodPost, "/api/auth/login", "", loginBody, http.StatusOK, &login)
|
||||
doJSON(t, s.App(), http.MethodPost, "/api/auth/login", "", loginBody, http.StatusOK, &login)
|
||||
if login.AccessToken == "" {
|
||||
t.Fatalf("expected access token in login response")
|
||||
}
|
||||
@@ -151,7 +155,7 @@ func TestRegistrationFlow(t *testing.T) {
|
||||
var drives []struct {
|
||||
ID string `json:"id"`
|
||||
}
|
||||
doJSON(t, s.app, http.MethodGet, "/api/my/drives", reg.AccessToken, nil, http.StatusOK, &drives)
|
||||
doJSON(t, s.App(), http.MethodGet, "/api/my/drives", reg.AccessToken, nil, http.StatusOK, &drives)
|
||||
if len(drives) != 1 {
|
||||
t.Fatalf("expected 1 drive, got %d", len(drives))
|
||||
}
|
||||
@@ -166,7 +170,7 @@ func TestRegistrationFlow(t *testing.T) {
|
||||
DisplayName string `json:"displayName"`
|
||||
Email string `json:"email"`
|
||||
}
|
||||
doJSON(t, s.app, http.MethodGet, "/api/users/me", reg.AccessToken, nil, http.StatusOK, &me)
|
||||
doJSON(t, s.App(), http.MethodGet, "/api/users/me", reg.AccessToken, nil, http.StatusOK, &me)
|
||||
if me.ID != reg.User.ID {
|
||||
t.Fatalf("unexpected user id: got %q want %q", me.ID, reg.User.ID)
|
||||
}
|
||||
@@ -182,7 +186,7 @@ func TestRegistrationFlow(t *testing.T) {
|
||||
Name string `json:"name"`
|
||||
Slug string `json:"slug"`
|
||||
}
|
||||
doJSON(t, s.app, http.MethodGet, "/api/users/me/organizations", reg.AccessToken, nil, http.StatusOK, &orgs)
|
||||
doJSON(t, s.App(), http.MethodGet, "/api/users/me/organizations", reg.AccessToken, nil, http.StatusOK, &orgs)
|
||||
if len(orgs) != 1 {
|
||||
t.Fatalf("expected 1 organization, got %d", len(orgs))
|
||||
}
|
||||
@@ -201,7 +205,7 @@ func TestRegistrationFlow(t *testing.T) {
|
||||
Name string `json:"name"`
|
||||
Slug string `json:"slug"`
|
||||
}
|
||||
doJSON(t, s.app, http.MethodGet, "/api/organizations/my", reg.AccessToken, nil, http.StatusOK, &myOrg)
|
||||
doJSON(t, s.App(), http.MethodGet, "/api/organizations/my", reg.AccessToken, nil, http.StatusOK, &myOrg)
|
||||
if myOrg.Kind != string(organization.KindPersonal) {
|
||||
t.Fatalf("unexpected personal org kind: %q", myOrg.Kind)
|
||||
}
|
||||
@@ -218,7 +222,7 @@ func TestRegistrationFlow(t *testing.T) {
|
||||
t.Fatalf("uuid: %v", err)
|
||||
}
|
||||
|
||||
_, err = s.db.ExecContext(ctx,
|
||||
_, err = db.ExecContext(ctx,
|
||||
`INSERT INTO organizations (id, kind, name, slug) VALUES (?, ?, ?, ?)`,
|
||||
orgID, organization.KindTeam, "Acme", "acme",
|
||||
)
|
||||
@@ -226,7 +230,7 @@ func TestRegistrationFlow(t *testing.T) {
|
||||
t.Fatalf("insert org: %v", err)
|
||||
}
|
||||
|
||||
_, err = s.db.ExecContext(ctx,
|
||||
_, err = db.ExecContext(ctx,
|
||||
`INSERT INTO accounts (id, org_id, user_id, role, status) VALUES (?, ?, ?, ?, ?)`,
|
||||
accountID, orgID, reg.User.ID, "member", "active",
|
||||
)
|
||||
@@ -240,7 +244,7 @@ func TestRegistrationFlow(t *testing.T) {
|
||||
Name string `json:"name"`
|
||||
Slug string `json:"slug"`
|
||||
}
|
||||
doJSON(t, s.app, http.MethodGet, "/api/organizations/acme", reg.AccessToken, nil, http.StatusOK, &got)
|
||||
doJSON(t, s.App(), http.MethodGet, "/api/organizations/acme", reg.AccessToken, nil, http.StatusOK, &got)
|
||||
if got.Slug != "acme" {
|
||||
t.Fatalf("unexpected org slug: %q", got.Slug)
|
||||
}
|
||||
@@ -257,7 +261,7 @@ func TestRegistrationFlow(t *testing.T) {
|
||||
Role string `json:"role"`
|
||||
Status string `json:"status"`
|
||||
}
|
||||
doJSON(t, s.app, http.MethodGet, fmt.Sprintf("/api/accounts/%s", reg.Account.ID), reg.AccessToken, nil, http.StatusOK, &got)
|
||||
doJSON(t, s.App(), http.MethodGet, fmt.Sprintf("/api/accounts/%s", reg.Account.ID), reg.AccessToken, nil, http.StatusOK, &got)
|
||||
if got.ID != reg.Account.ID {
|
||||
t.Fatalf("unexpected account id: got %q want %q", got.ID, reg.Account.ID)
|
||||
}
|
||||
@@ -272,7 +276,7 @@ func TestRegistrationFlow(t *testing.T) {
|
||||
}
|
||||
doJSON(
|
||||
t,
|
||||
s.app,
|
||||
s.App(),
|
||||
http.MethodGet,
|
||||
fmt.Sprintf("/api/my/drives/%s/directories/root/content?limit=100", reg.Drive.ID),
|
||||
reg.AccessToken,
|
||||
|
||||
@@ -163,3 +163,7 @@ func NewServer(c Config) (*Server, error) {
|
||||
func (s *Server) Start() error {
|
||||
return s.app.Listen(fmt.Sprintf(":%d", s.config.Server.Port))
|
||||
}
|
||||
|
||||
func (s *Server) App() *fiber.App {
|
||||
return s.app
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
//go:build integration
|
||||
|
||||
package drive
|
||||
package drive_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
|
||||
"github.com/get-drexa/drexa/internal/account"
|
||||
"github.com/get-drexa/drexa/internal/database"
|
||||
"github.com/get-drexa/drexa/internal/drive"
|
||||
"github.com/get-drexa/drexa/internal/organization"
|
||||
"github.com/get-drexa/drexa/internal/password"
|
||||
"github.com/get-drexa/drexa/internal/user"
|
||||
@@ -46,7 +47,7 @@ func TestService_DriveAccess(t *testing.T) {
|
||||
userSvc := user.NewService()
|
||||
orgSvc := organization.NewService()
|
||||
accSvc := account.NewService()
|
||||
driveSvc := NewService()
|
||||
driveSvc := drive.NewService()
|
||||
|
||||
testUser, err := userSvc.RegisterUser(ctx, db, user.UserRegistrationOptions{
|
||||
Email: "drive@example.com",
|
||||
@@ -75,7 +76,7 @@ func TestService_DriveAccess(t *testing.T) {
|
||||
t.Fatalf("CreateAccount(org2): %v", err)
|
||||
}
|
||||
|
||||
drive1, err := driveSvc.CreateDrive(ctx, db, CreateDriveOptions{
|
||||
drive1, err := driveSvc.CreateDrive(ctx, db, drive.CreateDriveOptions{
|
||||
OrgID: org1.ID,
|
||||
OwnerAccountID: &acc1.ID,
|
||||
Name: "Drive One",
|
||||
@@ -84,7 +85,7 @@ func TestService_DriveAccess(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("CreateDrive(org1): %v", err)
|
||||
}
|
||||
drive2, err := driveSvc.CreateDrive(ctx, db, CreateDriveOptions{
|
||||
drive2, err := driveSvc.CreateDrive(ctx, db, drive.CreateDriveOptions{
|
||||
OrgID: org2.ID,
|
||||
OwnerAccountID: &acc2.ID,
|
||||
Name: "Drive Two",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
//go:build integration
|
||||
|
||||
package organization
|
||||
package organization_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
|
||||
"github.com/get-drexa/drexa/internal/account"
|
||||
"github.com/get-drexa/drexa/internal/database"
|
||||
"github.com/get-drexa/drexa/internal/organization"
|
||||
"github.com/get-drexa/drexa/internal/password"
|
||||
"github.com/get-drexa/drexa/internal/user"
|
||||
"github.com/google/uuid"
|
||||
@@ -38,14 +39,14 @@ func TestService_CreatePersonalOrganization(t *testing.T) {
|
||||
t.Fatalf("RunMigrations: %v", err)
|
||||
}
|
||||
|
||||
svc := NewService()
|
||||
svc := organization.NewService()
|
||||
|
||||
org, err := svc.CreatePersonalOrganization(ctx, db, "Personal Org")
|
||||
if err != nil {
|
||||
t.Fatalf("CreatePersonalOrganization: %v", err)
|
||||
}
|
||||
if org.Kind != KindPersonal {
|
||||
t.Fatalf("unexpected org kind: got %q want %q", org.Kind, KindPersonal)
|
||||
if org.Kind != organization.KindPersonal {
|
||||
t.Fatalf("unexpected org kind: got %q want %q", org.Kind, organization.KindPersonal)
|
||||
}
|
||||
if org.Name != "Personal Org" {
|
||||
t.Fatalf("unexpected org name: got %q want %q", org.Name, "Personal Org")
|
||||
@@ -59,8 +60,8 @@ func TestService_CreatePersonalOrganization(t *testing.T) {
|
||||
if got.ID != org.ID {
|
||||
t.Fatalf("unexpected org id: got %q want %q", got.ID, org.ID)
|
||||
}
|
||||
if got.Kind != KindPersonal {
|
||||
t.Fatalf("unexpected org kind: got %q want %q", got.Kind, KindPersonal)
|
||||
if got.Kind != organization.KindPersonal {
|
||||
t.Fatalf("unexpected org kind: got %q want %q", got.Kind, organization.KindPersonal)
|
||||
}
|
||||
if got.Name != "Personal Org" {
|
||||
t.Fatalf("unexpected org name: got %q want %q", got.Name, "Personal Org")
|
||||
@@ -69,9 +70,9 @@ func TestService_CreatePersonalOrganization(t *testing.T) {
|
||||
|
||||
t.Run("organization by slug", func(t *testing.T) {
|
||||
slug := "test-org"
|
||||
orgWithSlug := &Organization{
|
||||
orgWithSlug := &organization.Organization{
|
||||
ID: uuid.Must(uuid.NewV7()),
|
||||
Kind: KindTeam,
|
||||
Kind: organization.KindTeam,
|
||||
Name: "Team Org",
|
||||
Slug: &slug,
|
||||
}
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
package organization
|
||||
package organization_test
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/get-drexa/drexa/internal/organization"
|
||||
)
|
||||
|
||||
func TestNormalizeSlug(t *testing.T) {
|
||||
@@ -61,7 +63,7 @@ func TestNormalizeSlug(t *testing.T) {
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
got, err := NormalizeSlug(tt.input)
|
||||
got, err := organization.NormalizeSlug(tt.input)
|
||||
if tt.wantErr {
|
||||
if err == nil {
|
||||
t.Fatalf("expected error, got none (slug=%q)", got)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
//go:build integration
|
||||
|
||||
package registration
|
||||
package registration_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
@@ -14,6 +14,7 @@ import (
|
||||
"github.com/get-drexa/drexa/internal/database"
|
||||
"github.com/get-drexa/drexa/internal/drive"
|
||||
"github.com/get-drexa/drexa/internal/organization"
|
||||
"github.com/get-drexa/drexa/internal/registration"
|
||||
"github.com/get-drexa/drexa/internal/user"
|
||||
"github.com/get-drexa/drexa/internal/virtualfs"
|
||||
"github.com/testcontainers/testcontainers-go/modules/postgres"
|
||||
@@ -62,9 +63,9 @@ func TestService_Register(t *testing.T) {
|
||||
accSvc := account.NewService()
|
||||
driveSvc := drive.NewService()
|
||||
|
||||
regSvc := NewService(userSvc, orgSvc, accSvc, driveSvc, vfs)
|
||||
regSvc := registration.NewService(userSvc, orgSvc, accSvc, driveSvc, vfs)
|
||||
|
||||
result, err := regSvc.Register(ctx, db, RegisterOptions{
|
||||
result, err := regSvc.Register(ctx, db, registration.RegisterOptions{
|
||||
Email: "reg@example.com",
|
||||
Password: "password123",
|
||||
DisplayName: "Reg User",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
//go:build integration
|
||||
|
||||
package sharing
|
||||
package sharing_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
@@ -16,6 +16,7 @@ import (
|
||||
"github.com/get-drexa/drexa/internal/drive"
|
||||
"github.com/get-drexa/drexa/internal/organization"
|
||||
"github.com/get-drexa/drexa/internal/password"
|
||||
"github.com/get-drexa/drexa/internal/sharing"
|
||||
"github.com/get-drexa/drexa/internal/user"
|
||||
"github.com/get-drexa/drexa/internal/virtualfs"
|
||||
"github.com/testcontainers/testcontainers-go/modules/postgres"
|
||||
@@ -128,36 +129,36 @@ func TestService_SharingScopes(t *testing.T) {
|
||||
t.Fatalf("WriteFile: %v", err)
|
||||
}
|
||||
|
||||
shareSvc, err := NewService(vfs)
|
||||
shareSvc, err := sharing.NewService(vfs)
|
||||
if err != nil {
|
||||
t.Fatalf("NewService: %v", err)
|
||||
}
|
||||
|
||||
t.Run("create share validation", func(t *testing.T) {
|
||||
if _, err := shareSvc.CreateShare(ctx, db, drv.ID, acc.ID, CreateShareOptions{}); err != ErrShareNoItems {
|
||||
if _, err := shareSvc.CreateShare(ctx, db, drv.ID, acc.ID, sharing.CreateShareOptions{}); err != sharing.ErrShareNoItems {
|
||||
t.Fatalf("expected ErrShareNoItems, got %v", err)
|
||||
}
|
||||
|
||||
if _, err := shareSvc.CreateShare(ctx, db, drv.ID, acc.ID, CreateShareOptions{
|
||||
if _, err := shareSvc.CreateShare(ctx, db, drv.ID, acc.ID, sharing.CreateShareOptions{
|
||||
Items: []*virtualfs.Node{root},
|
||||
}); err != ErrCannotShareRoot {
|
||||
}); err != sharing.ErrCannotShareRoot {
|
||||
t.Fatalf("expected ErrCannotShareRoot, got %v", err)
|
||||
}
|
||||
|
||||
if _, err := shareSvc.CreateShare(ctx, db, drv.ID, acc.ID, CreateShareOptions{
|
||||
if _, err := shareSvc.CreateShare(ctx, db, drv.ID, acc.ID, sharing.CreateShareOptions{
|
||||
Items: []*virtualfs.Node{dirNode, fileNode},
|
||||
}); err != ErrNotSameParent {
|
||||
}); err != sharing.ErrNotSameParent {
|
||||
t.Fatalf("expected ErrNotSameParent, got %v", err)
|
||||
}
|
||||
})
|
||||
|
||||
dirShare, err := shareSvc.CreateShare(ctx, db, drv.ID, acc.ID, CreateShareOptions{
|
||||
dirShare, err := shareSvc.CreateShare(ctx, db, drv.ID, acc.ID, sharing.CreateShareOptions{
|
||||
Items: []*virtualfs.Node{dirNode},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("CreateShare(dir): %v", err)
|
||||
}
|
||||
fileShare, err := shareSvc.CreateShare(ctx, db, drv.ID, acc.ID, CreateShareOptions{
|
||||
fileShare, err := shareSvc.CreateShare(ctx, db, drv.ID, acc.ID, sharing.CreateShareOptions{
|
||||
Items: []*virtualfs.Node{fileNode},
|
||||
})
|
||||
if err != nil {
|
||||
@@ -212,7 +213,7 @@ func TestService_SharingScopes(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("list shares includes expired", func(t *testing.T) {
|
||||
expiredShare, err := shareSvc.CreateShare(ctx, db, drv.ID, acc.ID, CreateShareOptions{
|
||||
expiredShare, err := shareSvc.CreateShare(ctx, db, drv.ID, acc.ID, sharing.CreateShareOptions{
|
||||
Items: []*virtualfs.Node{fileNode},
|
||||
ExpiresAt: time.Now().Add(-1 * time.Hour),
|
||||
})
|
||||
@@ -220,7 +221,7 @@ func TestService_SharingScopes(t *testing.T) {
|
||||
t.Fatalf("CreateShare(expired list): %v", err)
|
||||
}
|
||||
|
||||
activeShares, err := shareSvc.ListShares(ctx, db, drv.ID, ListSharesOptions{IncludesExpired: false})
|
||||
activeShares, err := shareSvc.ListShares(ctx, db, drv.ID, sharing.ListSharesOptions{IncludesExpired: false})
|
||||
if err != nil {
|
||||
t.Fatalf("ListShares(active): %v", err)
|
||||
}
|
||||
@@ -235,7 +236,7 @@ func TestService_SharingScopes(t *testing.T) {
|
||||
t.Fatalf("expected active shares to be listed")
|
||||
}
|
||||
|
||||
allShares, err := shareSvc.ListShares(ctx, db, drv.ID, ListSharesOptions{IncludesExpired: true})
|
||||
allShares, err := shareSvc.ListShares(ctx, db, drv.ID, sharing.ListSharesOptions{IncludesExpired: true})
|
||||
if err != nil {
|
||||
t.Fatalf("ListShares(all): %v", err)
|
||||
}
|
||||
@@ -252,26 +253,26 @@ func TestService_SharingScopes(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("find share not found", func(t *testing.T) {
|
||||
if _, err := shareSvc.FindShareByPublicID(ctx, db, "missing-share"); err != ErrShareNotFound {
|
||||
if _, err := shareSvc.FindShareByPublicID(ctx, db, "missing-share"); err != sharing.ErrShareNotFound {
|
||||
t.Fatalf("expected ErrShareNotFound, got %v", err)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("expired share", func(t *testing.T) {
|
||||
expiredShare, err := shareSvc.CreateShare(ctx, db, drv.ID, acc.ID, CreateShareOptions{
|
||||
expiredShare, err := shareSvc.CreateShare(ctx, db, drv.ID, acc.ID, sharing.CreateShareOptions{
|
||||
Items: []*virtualfs.Node{fileNode},
|
||||
ExpiresAt: time.Now().Add(-1 * time.Hour),
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("CreateShare(expired): %v", err)
|
||||
}
|
||||
if _, err := shareSvc.ResolveScopeForShare(ctx, db, nil, expiredShare); err != ErrShareExpired {
|
||||
if _, err := shareSvc.ResolveScopeForShare(ctx, db, nil, expiredShare); err != sharing.ErrShareExpired {
|
||||
t.Fatalf("expected ErrShareExpired, got %v", err)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("revoked share", func(t *testing.T) {
|
||||
revokedShare, err := shareSvc.CreateShare(ctx, db, drv.ID, acc.ID, CreateShareOptions{
|
||||
revokedShare, err := shareSvc.CreateShare(ctx, db, drv.ID, acc.ID, sharing.CreateShareOptions{
|
||||
Items: []*virtualfs.Node{fileNode},
|
||||
})
|
||||
if err != nil {
|
||||
@@ -285,31 +286,31 @@ func TestService_SharingScopes(t *testing.T) {
|
||||
t.Fatalf("update revoked share: %v", err)
|
||||
}
|
||||
revokedShare.RevokedAt = &now
|
||||
if _, err := shareSvc.ResolveScopeForShare(ctx, db, nil, revokedShare); err != ErrShareRevoked {
|
||||
if _, err := shareSvc.ResolveScopeForShare(ctx, db, nil, revokedShare); err != sharing.ErrShareRevoked {
|
||||
t.Fatalf("expected ErrShareRevoked, got %v", err)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("no permissions", func(t *testing.T) {
|
||||
noPermShare, err := shareSvc.CreateShare(ctx, db, drv.ID, acc.ID, CreateShareOptions{
|
||||
noPermShare, err := shareSvc.CreateShare(ctx, db, drv.ID, acc.ID, sharing.CreateShareOptions{
|
||||
Items: []*virtualfs.Node{fileNode},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("CreateShare(no permissions): %v", err)
|
||||
}
|
||||
if _, err := db.NewDelete().
|
||||
Model(&SharePermission{}).
|
||||
Model(&sharing.SharePermission{}).
|
||||
Where("share_id = ?", noPermShare.ID).
|
||||
Exec(ctx); err != nil {
|
||||
t.Fatalf("delete permissions: %v", err)
|
||||
}
|
||||
if _, err := shareSvc.ResolveScopeForShare(ctx, db, nil, noPermShare); err != ErrNoPermissions {
|
||||
if _, err := shareSvc.ResolveScopeForShare(ctx, db, nil, noPermShare); err != sharing.ErrNoPermissions {
|
||||
t.Fatalf("expected ErrNoPermissions, got %v", err)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("permission expired", func(t *testing.T) {
|
||||
expiredPermShare, err := shareSvc.CreateShare(ctx, db, drv.ID, acc.ID, CreateShareOptions{
|
||||
expiredPermShare, err := shareSvc.CreateShare(ctx, db, drv.ID, acc.ID, sharing.CreateShareOptions{
|
||||
Items: []*virtualfs.Node{fileNode},
|
||||
})
|
||||
if err != nil {
|
||||
@@ -317,31 +318,31 @@ func TestService_SharingScopes(t *testing.T) {
|
||||
}
|
||||
expiredAt := time.Now().Add(-1 * time.Hour)
|
||||
if _, err := db.NewUpdate().
|
||||
Model(&SharePermission{}).
|
||||
Model(&sharing.SharePermission{}).
|
||||
Set("expires_at = ?", expiredAt).
|
||||
Where("share_id = ?", expiredPermShare.ID).
|
||||
Exec(ctx); err != nil {
|
||||
t.Fatalf("update permission expiry: %v", err)
|
||||
}
|
||||
if _, err := shareSvc.ResolveScopeForShare(ctx, db, nil, expiredPermShare); err != ErrShareExpired {
|
||||
if _, err := shareSvc.ResolveScopeForShare(ctx, db, nil, expiredPermShare); err != sharing.ErrShareExpired {
|
||||
t.Fatalf("expected ErrShareExpired, got %v", err)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("no items", func(t *testing.T) {
|
||||
noItemsShare, err := shareSvc.CreateShare(ctx, db, drv.ID, acc.ID, CreateShareOptions{
|
||||
noItemsShare, err := shareSvc.CreateShare(ctx, db, drv.ID, acc.ID, sharing.CreateShareOptions{
|
||||
Items: []*virtualfs.Node{fileNode},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("CreateShare(no items): %v", err)
|
||||
}
|
||||
if _, err := db.NewDelete().
|
||||
Model(&ShareItem{}).
|
||||
Model(&sharing.ShareItem{}).
|
||||
Where("share_id = ?", noItemsShare.ID).
|
||||
Exec(ctx); err != nil {
|
||||
t.Fatalf("delete share items: %v", err)
|
||||
}
|
||||
if _, err := shareSvc.ResolveScopeForShare(ctx, db, nil, noItemsShare); err != ErrShareNoItems {
|
||||
if _, err := shareSvc.ResolveScopeForShare(ctx, db, nil, noItemsShare); err != sharing.ErrShareNoItems {
|
||||
t.Fatalf("expected ErrShareNoItems, got %v", err)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
//go:build integration
|
||||
|
||||
package user
|
||||
package user_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
@@ -11,6 +11,7 @@ import (
|
||||
|
||||
"github.com/get-drexa/drexa/internal/database"
|
||||
"github.com/get-drexa/drexa/internal/password"
|
||||
"github.com/get-drexa/drexa/internal/user"
|
||||
"github.com/testcontainers/testcontainers-go/modules/postgres"
|
||||
)
|
||||
|
||||
@@ -45,9 +46,9 @@ func TestService_UserQueries(t *testing.T) {
|
||||
t.Fatalf("HashString: %v", err)
|
||||
}
|
||||
|
||||
svc := NewService()
|
||||
svc := user.NewService()
|
||||
|
||||
user1, err := svc.RegisterUser(ctx, db, UserRegistrationOptions{
|
||||
user1, err := svc.RegisterUser(ctx, db, user.UserRegistrationOptions{
|
||||
Email: "alice@example.com",
|
||||
DisplayName: "Alice",
|
||||
Password: pw1,
|
||||
@@ -55,7 +56,7 @@ func TestService_UserQueries(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("RegisterUser(user1): %v", err)
|
||||
}
|
||||
user2, err := svc.RegisterUser(ctx, db, UserRegistrationOptions{
|
||||
user2, err := svc.RegisterUser(ctx, db, user.UserRegistrationOptions{
|
||||
Email: "bob@example.com",
|
||||
DisplayName: "Bob",
|
||||
Password: pw2,
|
||||
@@ -134,9 +135,9 @@ func TestService_RegisterUserConflict(t *testing.T) {
|
||||
t.Fatalf("HashString: %v", err)
|
||||
}
|
||||
|
||||
svc := NewService()
|
||||
svc := user.NewService()
|
||||
|
||||
_, err = svc.RegisterUser(ctx, db, UserRegistrationOptions{
|
||||
_, err = svc.RegisterUser(ctx, db, user.UserRegistrationOptions{
|
||||
Email: "conflict@example.com",
|
||||
DisplayName: "Conflict",
|
||||
Password: pw,
|
||||
@@ -145,7 +146,7 @@ func TestService_RegisterUserConflict(t *testing.T) {
|
||||
t.Fatalf("RegisterUser(first): %v", err)
|
||||
}
|
||||
|
||||
_, err = svc.RegisterUser(ctx, db, UserRegistrationOptions{
|
||||
_, err = svc.RegisterUser(ctx, db, user.UserRegistrationOptions{
|
||||
Email: "conflict@example.com",
|
||||
DisplayName: "Conflict 2",
|
||||
Password: pw,
|
||||
@@ -153,7 +154,7 @@ func TestService_RegisterUserConflict(t *testing.T) {
|
||||
if err == nil {
|
||||
t.Fatalf("expected conflict error, got nil")
|
||||
}
|
||||
var existsErr *AlreadyExistsError
|
||||
var existsErr *user.AlreadyExistsError
|
||||
if !errors.As(err, &existsErr) {
|
||||
t.Fatalf("expected AlreadyExistsError, got %T: %v", err, err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user