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