Compare commits

..

No commits in common. "4fa936d774bc773d12e8cb36e4216cf6d1194517" and "f66fc6b6d7a19cd0fd152734d85093b25288d211" have entirely different histories.

9 changed files with 95 additions and 1307 deletions

View File

@ -3,7 +3,6 @@ package postgres
import ( import (
"context" "context"
"errors" "errors"
errors2 "git.dragse.it/anthrove/otter-space-sdk/pkg/errors" errors2 "git.dragse.it/anthrove/otter-space-sdk/pkg/errors"
"git.dragse.it/anthrove/otter-space-sdk/pkg/models" "git.dragse.it/anthrove/otter-space-sdk/pkg/models"
@ -43,9 +42,7 @@ func GetPostByAnthroveID(ctx context.Context, db *gorm.DB, anthrovePostID models
return nil, &errors2.EntityValidationFailed{Reason: "anthrovePostID is not set"} return nil, &errors2.EntityValidationFailed{Reason: "anthrovePostID is not set"}
} }
if len(anthrovePostID) != 25 { //TODO maybe check ofor id length too...?
return nil, &errors2.EntityValidationFailed{Reason: "anthrovePostID needs to be 25 characters long"}
}
var post models.Post var post models.Post
result := db.WithContext(ctx).First(&post, "id = ?", anthrovePostID) result := db.WithContext(ctx).First(&post, "id = ?", anthrovePostID)

View File

@ -3,12 +3,11 @@ package postgres
import ( import (
"context" "context"
"fmt" "fmt"
"testing"
"git.dragse.it/anthrove/otter-space-sdk/pkg/models" "git.dragse.it/anthrove/otter-space-sdk/pkg/models"
"git.dragse.it/anthrove/otter-space-sdk/test" "git.dragse.it/anthrove/otter-space-sdk/test"
_ "github.com/lib/pq" _ "github.com/lib/pq"
"gorm.io/gorm" "gorm.io/gorm"
"testing"
) )
func TestCreateAnthrovePostNode(t *testing.T) { func TestCreateAnthrovePostNode(t *testing.T) {
@ -189,7 +188,7 @@ func TestGetPostBySourceURL(t *testing.T) {
t.Fatal("Could not create source", err) t.Fatal("Could not create source", err)
} }
err = CreateReferenceBetweenPostAndSource(ctx, gormDB, post.ID, models.AnthroveSourceDomain(source.Domain)) err = CreateReferenceBetweenPostAndSource(ctx, gormDB, models.AnthrovePostID(post.ID), models.AnthroveSourceDomain(source.Domain))
if err != nil { if err != nil {
t.Fatal("Could not create source reference", err) t.Fatal("Could not create source reference", err)
} }

View File

@ -3,7 +3,6 @@ package postgres
import ( import (
"context" "context"
"errors" "errors"
errors2 "git.dragse.it/anthrove/otter-space-sdk/pkg/errors" errors2 "git.dragse.it/anthrove/otter-space-sdk/pkg/errors"
"git.dragse.it/anthrove/otter-space-sdk/pkg/models" "git.dragse.it/anthrove/otter-space-sdk/pkg/models"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
@ -14,11 +13,11 @@ func CreateReferenceBetweenPostAndSource(ctx context.Context, db *gorm.DB, anthr
var source models.Source var source models.Source
if anthrovePostID == "" { if anthrovePostID == "" {
return &errors2.EntityValidationFailed{Reason: errors2.AnthroveUserIDIsEmpty} return &errors2.EntityValidationFailed{Reason: "anthrovePostID cannot be empty"}
} }
if len(anthrovePostID) != 25 { if len(anthrovePostID) != 25 {
return &errors2.EntityValidationFailed{Reason: errors2.AnthroveUserIDToShort} return &errors2.EntityValidationFailed{Reason: "anthrovePostID needs to be 25 characters long"}
} }
if sourceDomain == "" { if sourceDomain == "" {
@ -63,11 +62,11 @@ func CreateReferenceBetweenPostAndSource(ctx context.Context, db *gorm.DB, anthr
func CreateReferenceBetweenUserAndPost(ctx context.Context, db *gorm.DB, anthroveUserID models.AnthroveUserID, anthrovePostID models.AnthrovePostID) error { func CreateReferenceBetweenUserAndPost(ctx context.Context, db *gorm.DB, anthroveUserID models.AnthroveUserID, anthrovePostID models.AnthrovePostID) error {
if anthrovePostID == "" { if anthrovePostID == "" {
return &errors2.EntityValidationFailed{Reason: errors2.AnthroveUserIDIsEmpty} return &errors2.EntityValidationFailed{Reason: "anthrovePostID cannot be empty"}
} }
if len(anthrovePostID) != 25 { if len(anthrovePostID) != 25 {
return &errors2.EntityValidationFailed{Reason: errors2.AnthroveUserIDToShort} return &errors2.EntityValidationFailed{Reason: "anthrovePostID needs to be 25 characters long"}
} }
if anthroveUserID == "" { if anthroveUserID == "" {
@ -103,11 +102,11 @@ func CheckReferenceBetweenUserAndPost(ctx context.Context, db *gorm.DB, anthrove
var count int64 var count int64
if anthrovePostID == "" { if anthrovePostID == "" {
return false, &errors2.EntityValidationFailed{Reason: errors2.AnthroveUserIDIsEmpty} return false, &errors2.EntityValidationFailed{Reason: "anthrovePostID cannot be empty"}
} }
if len(anthrovePostID) != 25 { if len(anthrovePostID) != 25 {
return false, &errors2.EntityValidationFailed{Reason: errors2.AnthroveUserIDToShort} return false, &errors2.EntityValidationFailed{Reason: "anthrovePostID needs to be 25 characters long"}
} }
if anthroveUserID == "" { if anthroveUserID == "" {

View File

@ -3,7 +3,6 @@ package postgres
import ( import (
"context" "context"
"errors" "errors"
errors2 "git.dragse.it/anthrove/otter-space-sdk/pkg/errors" errors2 "git.dragse.it/anthrove/otter-space-sdk/pkg/errors"
"git.dragse.it/anthrove/otter-space-sdk/pkg/models" "git.dragse.it/anthrove/otter-space-sdk/pkg/models"
@ -49,7 +48,7 @@ func GetAllSource(ctx context.Context, db *gorm.DB) ([]models.Source, error) {
if result.Error != nil { if result.Error != nil {
if errors.Is(result.Error, gorm.ErrRecordNotFound) { if errors.Is(result.Error, gorm.ErrRecordNotFound) {
return nil, &errors2.NoDataFound{} return nil, &errors2.NoDataFound{}
} } // TODO really...? i don't think this error handling should be here..? / not possible
return nil, result.Error return nil, result.Error
} }

View File

@ -3,7 +3,6 @@ package postgres
import ( import (
"context" "context"
"errors" "errors"
errors2 "git.dragse.it/anthrove/otter-space-sdk/pkg/errors" errors2 "git.dragse.it/anthrove/otter-space-sdk/pkg/errors"
"git.dragse.it/anthrove/otter-space-sdk/pkg/models" "git.dragse.it/anthrove/otter-space-sdk/pkg/models"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
@ -79,7 +78,7 @@ func GetTags(ctx context.Context, db *gorm.DB) ([]models.Tag, error) {
result := db.WithContext(ctx).Find(&tags) result := db.WithContext(ctx).Find(&tags)
if result.Error != nil { if result.Error != nil {
if errors.Is(result.Error, gorm.ErrRecordNotFound) { if errors.Is(result.Error, gorm.ErrRecordNotFound) { // TODO really...? i don't think this error handling should be here..? / not possible
return nil, &errors2.NoDataFound{} return nil, &errors2.NoDataFound{}
} }
return nil, result.Error return nil, result.Error

View File

@ -3,7 +3,6 @@ package postgres
import ( import (
"context" "context"
"errors" "errors"
errors2 "git.dragse.it/anthrove/otter-space-sdk/pkg/errors" errors2 "git.dragse.it/anthrove/otter-space-sdk/pkg/errors"
"git.dragse.it/anthrove/otter-space-sdk/pkg/models" "git.dragse.it/anthrove/otter-space-sdk/pkg/models"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
@ -13,11 +12,11 @@ import (
func CreateUser(ctx context.Context, db *gorm.DB, anthroveUserID models.AnthroveUserID) error { func CreateUser(ctx context.Context, db *gorm.DB, anthroveUserID models.AnthroveUserID) error {
if anthroveUserID == "" { if anthroveUserID == "" {
return &errors2.EntityValidationFailed{Reason: errors2.AnthroveUserIDIsEmpty} return &errors2.EntityValidationFailed{Reason: "anthroveUserID cannot be empty"}
} }
if len(anthroveUserID) != 25 { if len(anthroveUserID) != 25 {
return &errors2.EntityValidationFailed{Reason: errors2.AnthroveUserIDToShort} return &errors2.EntityValidationFailed{Reason: "anthroveUserID needs to be 25 characters long"}
} }
user := models.User{ user := models.User{
@ -34,17 +33,21 @@ func CreateUser(ctx context.Context, db *gorm.DB, anthroveUserID models.Anthrove
return result.Error return result.Error
} }
if result.RowsAffected == 0 {
return &errors2.NoDataWritten{}
}
return nil return nil
} }
func CreateUserWithRelationToSource(ctx context.Context, db *gorm.DB, anthroveUserID models.AnthroveUserID, sourceID models.AnthroveSourceID, accountId string, accountUsername string) error { func CreateUserWithRelationToSource(ctx context.Context, db *gorm.DB, anthroveUserID models.AnthroveUserID, sourceID models.AnthroveSourceID, accountId string, accountUsername string) error {
if anthroveUserID == "" { if anthroveUserID == "" {
return &errors2.EntityValidationFailed{Reason: errors2.AnthroveUserIDIsEmpty} return &errors2.EntityValidationFailed{Reason: "anthroveUserID cannot be empty"}
} }
if len(anthroveUserID) != 25 { if len(anthroveUserID) != 25 {
return &errors2.EntityValidationFailed{Reason: errors2.AnthroveUserIDToShort} return &errors2.EntityValidationFailed{Reason: "anthroveUserID needs to be 25 characters long"}
} }
if accountId == "" { if accountId == "" {
@ -103,11 +106,11 @@ func GetUserFavoritesCount(ctx context.Context, db *gorm.DB, anthroveUserID mode
var count int64 var count int64
if anthroveUserID == "" { if anthroveUserID == "" {
return 0, &errors2.EntityValidationFailed{Reason: errors2.AnthroveUserIDIsEmpty} return 0, &errors2.EntityValidationFailed{Reason: "anthroveUserID cannot be empty"}
} }
if len(anthroveUserID) != 25 { if len(anthroveUserID) != 25 {
return 0, &errors2.EntityValidationFailed{Reason: errors2.AnthroveUserIDToShort} return 0, &errors2.EntityValidationFailed{Reason: "anthroveUserID needs to be 25 characters long"}
} }
result := db.WithContext(ctx).Model(&models.UserFavorites{}).Where("user_id = ?", string(anthroveUserID)).Count(&count) result := db.WithContext(ctx).Model(&models.UserFavorites{}).Where("user_id = ?", string(anthroveUserID)).Count(&count)
@ -131,11 +134,11 @@ func GetUserSourceLinks(ctx context.Context, db *gorm.DB, anthroveUserID models.
userSourceMap := make(map[string]models.UserSource) userSourceMap := make(map[string]models.UserSource)
if anthroveUserID == "" { if anthroveUserID == "" {
return nil, &errors2.EntityValidationFailed{Reason: errors2.AnthroveUserIDIsEmpty} return nil, &errors2.EntityValidationFailed{Reason: "anthroveUserID cannot be empty"}
} }
if len(anthroveUserID) != 25 { if len(anthroveUserID) != 25 {
return nil, &errors2.EntityValidationFailed{Reason: errors2.AnthroveUserIDToShort} return nil, &errors2.EntityValidationFailed{Reason: "anthroveUserID needs to be 25 characters long"}
} }
result := db.WithContext(ctx).Model(&models.UserSource{}).Where("user_id = ?", string(anthroveUserID)).Find(&userSources) result := db.WithContext(ctx).Model(&models.UserSource{}).Where("user_id = ?", string(anthroveUserID)).Find(&userSources)
@ -179,11 +182,11 @@ func GetUserSourceBySourceID(ctx context.Context, db *gorm.DB, anthroveUserID mo
userSourceMap := make(map[string]models.UserSource) userSourceMap := make(map[string]models.UserSource)
if anthroveUserID == "" { if anthroveUserID == "" {
return nil, &errors2.EntityValidationFailed{Reason: errors2.AnthroveUserIDIsEmpty} return nil, &errors2.EntityValidationFailed{Reason: "anthroveUserID cannot be empty"}
} }
if len(anthroveUserID) != 25 { if len(anthroveUserID) != 25 {
return nil, &errors2.EntityValidationFailed{Reason: errors2.AnthroveUserIDToShort} return nil, &errors2.EntityValidationFailed{Reason: "anthroveUserID needs to be 25 characters long"}
} }
if sourceID == "" { if sourceID == "" {
@ -259,11 +262,11 @@ func GetUserFavoriteWithPagination(ctx context.Context, db *gorm.DB, anthroveUse
var favoritePosts []models.Post var favoritePosts []models.Post
if anthroveUserID == "" { if anthroveUserID == "" {
return nil, &errors2.EntityValidationFailed{Reason: errors2.AnthroveUserIDIsEmpty} return nil, &errors2.EntityValidationFailed{Reason: "anthroveUserID cannot be empty"}
} }
if len(anthroveUserID) != 25 { if len(anthroveUserID) != 25 {
return nil, &errors2.EntityValidationFailed{Reason: errors2.AnthroveUserIDToShort} return nil, &errors2.EntityValidationFailed{Reason: "anthroveUserID needs to be 25 characters long"}
} }
err := db.WithContext(ctx).Model(&models.UserFavorites{}).Where("user_id = ?", string(anthroveUserID)).Offset(skip).Limit(limit).Find(&userFavorites).Error err := db.WithContext(ctx).Model(&models.UserFavorites{}).Where("user_id = ?", string(anthroveUserID)).Offset(skip).Limit(limit).Find(&userFavorites).Error
@ -303,11 +306,11 @@ func GetUserTagWitRelationToFavedPosts(ctx context.Context, db *gorm.DB, anthrov
var userFavorites []models.UserFavorites var userFavorites []models.UserFavorites
if anthroveUserID == "" { if anthroveUserID == "" {
return nil, &errors2.EntityValidationFailed{Reason: errors2.AnthroveUserIDIsEmpty} return nil, &errors2.EntityValidationFailed{Reason: "anthroveUserID cannot be empty"}
} }
if len(anthroveUserID) != 25 { if len(anthroveUserID) != 25 {
return nil, &errors2.EntityValidationFailed{Reason: errors2.AnthroveUserIDToShort} return nil, &errors2.EntityValidationFailed{Reason: "anthroveUserID needs to be 25 characters long"}
} }
result := db.WithContext(ctx).Where("user_id = ?", string(anthroveUserID)).Find(&userFavorites) result := db.WithContext(ctx).Where("user_id = ?", string(anthroveUserID)).Find(&userFavorites)

View File

@ -3,12 +3,11 @@ package postgres
import ( import (
"context" "context"
"fmt" "fmt"
"reflect"
"testing"
"git.dragse.it/anthrove/otter-space-sdk/pkg/models" "git.dragse.it/anthrove/otter-space-sdk/pkg/models"
"git.dragse.it/anthrove/otter-space-sdk/test" "git.dragse.it/anthrove/otter-space-sdk/test"
"gorm.io/gorm" "gorm.io/gorm"
"reflect"
"testing"
) )
func TestCreateUser(t *testing.T) { func TestCreateUser(t *testing.T) {
@ -383,6 +382,8 @@ func TestGetUserSourceBySourceID(t *testing.T) {
} }
} }
// TODO: FIX THE FOUR REMAINING TESTS
func TestGetUserFavoriteNodeWithPagination(t *testing.T) { func TestGetUserFavoriteNodeWithPagination(t *testing.T) {
// Setup trow away containert // Setup trow away containert
ctx := context.Background() ctx := context.Background()
@ -393,39 +394,31 @@ func TestGetUserFavoriteNodeWithPagination(t *testing.T) {
defer container.Terminate(ctx) defer container.Terminate(ctx)
// Setup Test // Setup Test
validAnthroveUserID := models.AnthroveUserID(fmt.Sprintf("%025s", "User1"))
validPostID1 := models.AnthrovePostID(fmt.Sprintf("%025s", "Post1"))
validPostID2 := models.AnthrovePostID(fmt.Sprintf("%025s", "Post2"))
validPostID3 := models.AnthrovePostID(fmt.Sprintf("%025s", "Post3"))
validPostID4 := models.AnthrovePostID(fmt.Sprintf("%025s", "Post4"))
validPostID5 := models.AnthrovePostID(fmt.Sprintf("%025s", "Post5"))
validPostID6 := models.AnthrovePostID(fmt.Sprintf("%025s", "Post6"))
expectedResultPosts := []models.Post{ expectedResultPosts := []models.Post{
{ {
BaseModel: models.BaseModel[models.AnthrovePostID]{ID: validPostID1}, BaseModel: models.BaseModel[models.AnthrovePostID]{ID: models.AnthrovePostID(fmt.Sprintf("%-25s", "Post1"))},
Rating: "safe", Rating: "safe",
}, },
{ {
BaseModel: models.BaseModel[models.AnthrovePostID]{ID: validPostID2}, BaseModel: models.BaseModel[models.AnthrovePostID]{ID: models.AnthrovePostID(fmt.Sprintf("%-25s", "Post2"))},
Rating: "safe", Rating: "safe",
}, },
{ {
BaseModel: models.BaseModel[models.AnthrovePostID]{ID: validPostID3}, BaseModel: models.BaseModel[models.AnthrovePostID]{ID: models.AnthrovePostID(fmt.Sprintf("%-25s", "Post3"))},
Rating: "explicit", Rating: "explicit",
}, },
{ {
BaseModel: models.BaseModel[models.AnthrovePostID]{ID: validPostID4}, BaseModel: models.BaseModel[models.AnthrovePostID]{ID: models.AnthrovePostID(fmt.Sprintf("%-25s", "Post4"))},
Rating: "explicit", Rating: "explicit",
}, },
{ {
BaseModel: models.BaseModel[models.AnthrovePostID]{ID: validPostID5}, BaseModel: models.BaseModel[models.AnthrovePostID]{ID: models.AnthrovePostID(fmt.Sprintf("%-25s", "Post5"))},
Rating: "questionable", Rating: "questionable",
}, },
{ {
BaseModel: models.BaseModel[models.AnthrovePostID]{ID: validPostID6}, BaseModel: models.BaseModel[models.AnthrovePostID]{ID: models.AnthrovePostID(fmt.Sprintf("%-25s", "Post6"))},
Rating: "safe", Rating: "safe",
}, },
} }
@ -439,7 +432,7 @@ func TestGetUserFavoriteNodeWithPagination(t *testing.T) {
Posts: expectedResultPosts[:3], Posts: expectedResultPosts[:3],
} }
err = CreateUser(ctx, gormDB, validAnthroveUserID) err = CreateUser(ctx, gormDB, "1")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -449,7 +442,7 @@ func TestGetUserFavoriteNodeWithPagination(t *testing.T) {
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
err = CreateReferenceBetweenUserAndPost(ctx, gormDB, validAnthroveUserID, expectedResultPost.ID) err = CreateReferenceBetweenUserAndPost(ctx, gormDB, "1", models.AnthrovePostID(expectedResultPost.ID))
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -474,7 +467,7 @@ func TestGetUserFavoriteNodeWithPagination(t *testing.T) {
args: args{ args: args{
ctx: ctx, ctx: ctx,
db: gormDB, db: gormDB,
anthroveUserID: validAnthroveUserID, anthroveUserID: "1",
skip: 0, skip: 0,
limit: 2000, limit: 2000,
}, },
@ -486,7 +479,7 @@ func TestGetUserFavoriteNodeWithPagination(t *testing.T) {
args: args{ args: args{
ctx: ctx, ctx: ctx,
db: gormDB, db: gormDB,
anthroveUserID: validAnthroveUserID, anthroveUserID: "1",
skip: 2, skip: 2,
limit: 2000, limit: 2000,
}, },
@ -498,7 +491,7 @@ func TestGetUserFavoriteNodeWithPagination(t *testing.T) {
args: args{ args: args{
ctx: ctx, ctx: ctx,
db: gormDB, db: gormDB,
anthroveUserID: validAnthroveUserID, anthroveUserID: "1",
skip: 0, skip: 0,
limit: 3, limit: 3,
}, },
@ -531,54 +524,44 @@ func TestGetUserFavoritesCount(t *testing.T) {
// Setup Test // Setup Test
validAnthroveUserID := models.AnthroveUserID(fmt.Sprintf("%025s", "User1")) err = CreateUser(ctx, gormDB, "1")
if err != nil {
validPostID1 := models.AnthrovePostID(fmt.Sprintf("%025s", "Post1")) t.Fatal(err)
validPostID2 := models.AnthrovePostID(fmt.Sprintf("%025s", "Post2")) }
validPostID3 := models.AnthrovePostID(fmt.Sprintf("%025s", "Post3"))
validPostID4 := models.AnthrovePostID(fmt.Sprintf("%025s", "Post4"))
validPostID5 := models.AnthrovePostID(fmt.Sprintf("%025s", "Post5"))
validPostID6 := models.AnthrovePostID(fmt.Sprintf("%025s", "Post6"))
expectedResultPosts := []models.Post{ expectedResultPosts := []models.Post{
{ {
BaseModel: models.BaseModel[models.AnthrovePostID]{ID: validPostID1}, BaseModel: models.BaseModel[models.AnthrovePostID]{ID: "Post1"},
Rating: "safe", Rating: "safe",
}, },
{ {
BaseModel: models.BaseModel[models.AnthrovePostID]{ID: "Post2"},
BaseModel: models.BaseModel[models.AnthrovePostID]{ID: validPostID2},
Rating: "safe", Rating: "safe",
}, },
{ {
BaseModel: models.BaseModel[models.AnthrovePostID]{ID: validPostID3}, BaseModel: models.BaseModel[models.AnthrovePostID]{ID: "Post3"},
Rating: "explicit", Rating: "explicit",
}, },
{ {
BaseModel: models.BaseModel[models.AnthrovePostID]{ID: validPostID4}, BaseModel: models.BaseModel[models.AnthrovePostID]{ID: "Post4"},
Rating: "explicit", Rating: "explicit",
}, },
{ {
BaseModel: models.BaseModel[models.AnthrovePostID]{ID: validPostID5}, BaseModel: models.BaseModel[models.AnthrovePostID]{ID: "Post5"},
Rating: "questionable", Rating: "questionable",
}, },
{ {
BaseModel: models.BaseModel[models.AnthrovePostID]{ID: validPostID6}, BaseModel: models.BaseModel[models.AnthrovePostID]{ID: "Post6"},
Rating: "safe", Rating: "safe",
}, },
} }
err = CreateUser(ctx, gormDB, validAnthroveUserID)
if err != nil {
t.Fatal(err)
}
for _, post := range expectedResultPosts { for _, post := range expectedResultPosts {
err = CreatePost(ctx, gormDB, &post) err = CreatePost(ctx, gormDB, &post)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
err = CreateReferenceBetweenUserAndPost(ctx, gormDB, validAnthroveUserID, post.ID) err = CreateReferenceBetweenUserAndPost(ctx, gormDB, "1", models.AnthrovePostID(post.ID))
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -601,7 +584,7 @@ func TestGetUserFavoritesCount(t *testing.T) {
args: args{ args: args{
ctx: ctx, ctx: ctx,
db: gormDB, db: gormDB,
anthroveUserID: validAnthroveUserID, anthroveUserID: "1",
}, },
want: 6, want: 6,
wantErr: false, wantErr: false,
@ -614,7 +597,7 @@ func TestGetUserFavoritesCount(t *testing.T) {
anthroveUserID: "2", anthroveUserID: "2",
}, },
want: 0, want: 0,
wantErr: true, wantErr: false,
}, },
{ {
name: "Test 3: no anthroveUserID and 6 favorite posts", name: "Test 3: no anthroveUserID and 6 favorite posts",
@ -651,13 +634,8 @@ func TestGetUserSourceLinks(t *testing.T) {
defer container.Terminate(ctx) defer container.Terminate(ctx)
// Setup Test // Setup Test
validAnthroveUserID := models.AnthroveUserID(fmt.Sprintf("%025s", "User1"))
validSourceID1 := models.AnthroveSourceID(fmt.Sprintf("%025s", "Source1"))
validSourceID2 := models.AnthroveSourceID(fmt.Sprintf("%025s", "Source2"))
eSource := &models.Source{ eSource := &models.Source{
BaseModel: models.BaseModel[models.AnthroveSourceID]{ID: validSourceID1}, BaseModel: models.BaseModel[models.AnthroveSourceID]{ID: models.AnthroveSourceID(fmt.Sprintf("%025s", "1"))},
DisplayName: "e621", DisplayName: "e621",
Domain: "e621.net", Domain: "e621.net",
} }
@ -667,7 +645,7 @@ func TestGetUserSourceLinks(t *testing.T) {
} }
faSource := &models.Source{ faSource := &models.Source{
BaseModel: models.BaseModel[models.AnthroveSourceID]{ID: validSourceID2}, BaseModel: models.BaseModel[models.AnthroveSourceID]{ID: models.AnthroveSourceID(fmt.Sprintf("%025s", "2"))},
DisplayName: "fa", DisplayName: "fa",
Domain: "fa.net", Domain: "fa.net",
} }
@ -694,11 +672,11 @@ func TestGetUserSourceLinks(t *testing.T) {
}, },
} }
err = CreateUserWithRelationToSource(ctx, gormDB, validAnthroveUserID, eSource.ID, expectedResult["e621"].UserID, expectedResult["e621"].AccountUsername) err = CreateUserWithRelationToSource(ctx, gormDB, "1", eSource.ID, expectedResult["e621"].UserID, expectedResult["e621"].AccountUsername)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
err = CreateUserWithRelationToSource(ctx, gormDB, validAnthroveUserID, faSource.ID, expectedResult["fa"].UserID, expectedResult["fa"].AccountUsername) err = CreateUserWithRelationToSource(ctx, gormDB, "1", faSource.ID, expectedResult["fa"].UserID, expectedResult["fa"].AccountUsername)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -720,7 +698,7 @@ func TestGetUserSourceLinks(t *testing.T) {
args: args{ args: args{
ctx: ctx, ctx: ctx,
db: gormDB, db: gormDB,
anthroveUserID: validAnthroveUserID, anthroveUserID: "1",
}, },
want: expectedResult, want: expectedResult,
wantErr: false, wantErr: false,
@ -750,21 +728,15 @@ func TestGetUserTagNodeWitRelationToFavedPosts(t *testing.T) {
defer container.Terminate(ctx) defer container.Terminate(ctx)
// Setup Test // Setup Test
validAnthroveUserID := models.AnthroveUserID(fmt.Sprintf("%025s", "User1")) err = CreateUser(ctx, gormDB, "1")
validPostID1 := models.AnthrovePostID(fmt.Sprintf("%025s", "Post1"))
validPostID2 := models.AnthrovePostID(fmt.Sprintf("%025s", "Post2"))
validPostID3 := models.AnthrovePostID(fmt.Sprintf("%025s", "Post3"))
err = CreateUser(ctx, gormDB, validAnthroveUserID)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
posts := []models.Post{ posts := []models.Post{
{BaseModel: models.BaseModel[models.AnthrovePostID]{ID: validPostID1}, Rating: "safe"}, {BaseModel: models.BaseModel[models.AnthrovePostID]{ID: models.AnthrovePostID(fmt.Sprintf("%-25s", "Post1"))}, Rating: "safe"},
{BaseModel: models.BaseModel[models.AnthrovePostID]{ID: validPostID2}, Rating: "safe"}, {BaseModel: models.BaseModel[models.AnthrovePostID]{ID: models.AnthrovePostID(fmt.Sprintf("%-25s", "Post2"))}, Rating: "safe"},
{BaseModel: models.BaseModel[models.AnthrovePostID]{ID: validPostID3}, Rating: "explicit"}, {BaseModel: models.BaseModel[models.AnthrovePostID]{ID: models.AnthrovePostID(fmt.Sprintf("%-25s", "Post3"))}, Rating: "explicit"},
} }
for _, post := range posts { for _, post := range posts {
@ -772,7 +744,7 @@ func TestGetUserTagNodeWitRelationToFavedPosts(t *testing.T) {
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
err = CreateReferenceBetweenUserAndPost(ctx, gormDB, validAnthroveUserID, models.AnthrovePostID(post.ID)) err = CreateReferenceBetweenUserAndPost(ctx, gormDB, "1", models.AnthrovePostID(post.ID))
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -832,7 +804,7 @@ func TestGetUserTagNodeWitRelationToFavedPosts(t *testing.T) {
args: args{ args: args{
ctx: ctx, ctx: ctx,
db: gormDB, db: gormDB,
anthroveUserID: validAnthroveUserID, anthroveUserID: "1",
}, },
want: expectedResult, want: expectedResult,
wantErr: false, wantErr: false,

File diff suppressed because it is too large Load Diff

View File

@ -2,11 +2,6 @@ package errors
import "fmt" import "fmt"
const (
AnthroveUserIDIsEmpty = "anthrovePostID cannot be empty"
AnthroveUserIDToShort = "anthrovePostID needs to be 25 characters long"
)
type EntityValidationFailed struct { type EntityValidationFailed struct {
Reason string Reason string
} }