test(postgres): finished test migrations to generic orm base
Some checks failed
Gitea Build Check / Build (push) Has been cancelled

Signed-off-by: SoXX <soxx@fenpa.ws>
This commit is contained in:
SoXX 2024-06-25 14:50:56 +02:00
parent 5aac1f2916
commit c0cae140f1

View File

@ -3,10 +3,11 @@ package database
import ( import (
"context" "context"
"fmt" "fmt"
"testing"
"git.dragse.it/anthrove/otter-space-sdk/internal/postgres" "git.dragse.it/anthrove/otter-space-sdk/internal/postgres"
"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"
"testing"
) )
func TestNewPostgresqlConnection(t *testing.T) { func TestNewPostgresqlConnection(t *testing.T) {
@ -96,7 +97,7 @@ func Test_postgresqlConnection_CreateUserWithRelationToSource(t *testing.T) {
// Setup Test // Setup Test
source := &models.Source{ source := &models.Source{
BaseModel: models.BaseModel{ID: fmt.Sprintf("%025s", "1")}, BaseModel: models.BaseModel[models.AnthroveSourceID]{ID: models.AnthroveSourceID(fmt.Sprintf("%025s", "1"))},
DisplayName: "e621", DisplayName: "e621",
Domain: "e621.net", Domain: "e621.net",
Icon: "icon.e621.net", Icon: "icon.e621.net",
@ -124,7 +125,7 @@ func Test_postgresqlConnection_CreateUserWithRelationToSource(t *testing.T) {
args: args{ args: args{
ctx: ctx, ctx: ctx,
anthroveUserID: "1", anthroveUserID: "1",
sourceID: models.AnthroveSourceID(source.ID), sourceID: source.ID,
accountId: "e1", accountId: "e1",
accountUsername: "marius", accountUsername: "marius",
}, },
@ -135,7 +136,7 @@ func Test_postgresqlConnection_CreateUserWithRelationToSource(t *testing.T) {
args: args{ args: args{
ctx: ctx, ctx: ctx,
anthroveUserID: "2", anthroveUserID: "2",
sourceID: models.AnthroveSourceID(source.ID), sourceID: source.ID,
accountId: "e1", accountId: "e1",
accountUsername: "marius", accountUsername: "marius",
}, },
@ -146,7 +147,7 @@ func Test_postgresqlConnection_CreateUserWithRelationToSource(t *testing.T) {
args: args{ args: args{
ctx: ctx, ctx: ctx,
anthroveUserID: "", anthroveUserID: "",
sourceID: models.AnthroveSourceID(source.ID), sourceID: source.ID,
accountId: "e1", accountId: "e1",
accountUsername: "marius", accountUsername: "marius",
}, },
@ -168,7 +169,7 @@ func Test_postgresqlConnection_CreateUserWithRelationToSource(t *testing.T) {
args: args{ args: args{
ctx: ctx, ctx: ctx,
anthroveUserID: "1", anthroveUserID: "1",
sourceID: models.AnthroveSourceID(source.ID), sourceID: source.ID,
accountId: "", accountId: "",
accountUsername: "marius", accountUsername: "marius",
}, },
@ -179,7 +180,7 @@ func Test_postgresqlConnection_CreateUserWithRelationToSource(t *testing.T) {
args: args{ args: args{
ctx: ctx, ctx: ctx,
anthroveUserID: "1", anthroveUserID: "1",
sourceID: models.AnthroveSourceID(source.ID), sourceID: source.ID,
accountId: "aa", accountId: "aa",
accountUsername: "", accountUsername: "",
}, },
@ -280,8 +281,8 @@ func Test_postgresqlConnection_CreatePost(t *testing.T) {
// Setup Tests // Setup Tests
validPost := &models.Post{ validPost := &models.Post{
BaseModel: models.BaseModel{ BaseModel: models.BaseModel[models.AnthrovePostID]{
ID: fmt.Sprintf("%025s", "1"), ID: models.AnthrovePostID(fmt.Sprintf("%025s", "1")),
}, },
Rating: "safe", Rating: "safe",
} }
@ -342,8 +343,8 @@ func Test_postgresqlConnection_CreateTagAndReferenceToPost(t *testing.T) {
// Setup Test // Setup Test
post := &models.Post{ post := &models.Post{
BaseModel: models.BaseModel{ BaseModel: models.BaseModel[models.AnthrovePostID]{
ID: fmt.Sprintf("%025s", "1"), ID: models.AnthrovePostID(fmt.Sprintf("%025s", "1")),
}, },
Rating: "safe", Rating: "safe",
} }
@ -373,7 +374,7 @@ func Test_postgresqlConnection_CreateTagAndReferenceToPost(t *testing.T) {
name: "Test 1: Valid PostID and Tag", name: "Test 1: Valid PostID and Tag",
args: args{ args: args{
ctx: ctx, ctx: ctx,
anthrovePostID: models.AnthrovePostID(post.ID), anthrovePostID: post.ID,
anthroveTag: tag, anthroveTag: tag,
}, },
wantErr: false, wantErr: false,
@ -382,7 +383,7 @@ func Test_postgresqlConnection_CreateTagAndReferenceToPost(t *testing.T) {
name: "Test 2: Valid PostID and no Tag", name: "Test 2: Valid PostID and no Tag",
args: args{ args: args{
ctx: ctx, ctx: ctx,
anthrovePostID: models.AnthrovePostID(post.ID), anthrovePostID: post.ID,
anthroveTag: nil, anthroveTag: nil,
}, },
wantErr: true, wantErr: true,
@ -430,8 +431,8 @@ func Test_postgresqlConnection_CreateReferenceBetweenPostAndSource(t *testing.T)
// Setup Test // Setup Test
post := &models.Post{ post := &models.Post{
BaseModel: models.BaseModel{ BaseModel: models.BaseModel[models.AnthrovePostID]{
ID: fmt.Sprintf("%025s", "1"), ID: models.AnthrovePostID(fmt.Sprintf("%025s", "1")),
}, },
Rating: "safe", Rating: "safe",
} }
@ -466,7 +467,7 @@ func Test_postgresqlConnection_CreateReferenceBetweenPostAndSource(t *testing.T)
name: "Test 1: Valid AnthrovePostID and anthroveSourceDomain", name: "Test 1: Valid AnthrovePostID and anthroveSourceDomain",
args: args{ args: args{
ctx: ctx, ctx: ctx,
anthrovePostID: models.AnthrovePostID(post.ID), anthrovePostID: post.ID,
sourceDomain: "e621.net", sourceDomain: "e621.net",
}, },
wantErr: false, wantErr: false,
@ -527,8 +528,8 @@ func Test_postgresqlConnection_CreateReferenceBetweenUserAndPost(t *testing.T) {
} }
post := &models.Post{ post := &models.Post{
BaseModel: models.BaseModel{ BaseModel: models.BaseModel[models.AnthrovePostID]{
ID: fmt.Sprintf("%025s", "1"), ID: models.AnthrovePostID(fmt.Sprintf("%025s", "1")),
}, },
Rating: "safe", Rating: "safe",
} }
@ -554,7 +555,7 @@ func Test_postgresqlConnection_CreateReferenceBetweenUserAndPost(t *testing.T) {
args: args{ args: args{
ctx: ctx, ctx: ctx,
anthroveUserID: "1", anthroveUserID: "1",
anthrovePostID: models.AnthrovePostID(post.ID), anthrovePostID: post.ID,
}, },
wantErr: false, wantErr: false,
}, },
@ -615,8 +616,8 @@ func Test_postgresqlConnection_CheckReferenceBetweenUserAndPost(t *testing.T) {
} }
post := &models.Post{ post := &models.Post{
BaseModel: models.BaseModel{ BaseModel: models.BaseModel[models.AnthrovePostID]{
ID: fmt.Sprintf("%025s", "1"), ID: models.AnthrovePostID(fmt.Sprintf("%025s", "1")),
}, },
Rating: "safe", Rating: "safe",
} }
@ -626,7 +627,7 @@ func Test_postgresqlConnection_CheckReferenceBetweenUserAndPost(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
err = postgres.CreateReferenceBetweenUserAndPost(ctx, gormDB, "1", models.AnthrovePostID(post.ID)) err = postgres.CreateReferenceBetweenUserAndPost(ctx, gormDB, "1", post.ID)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -648,7 +649,7 @@ func Test_postgresqlConnection_CheckReferenceBetweenUserAndPost(t *testing.T) {
args: args{ args: args{
ctx: ctx, ctx: ctx,
anthroveUserID: "1", anthroveUserID: "1",
anthrovePostID: models.AnthrovePostID(post.ID), anthrovePostID: post.ID,
}, },
want: true, want: true,
wantErr: false, wantErr: false,
@ -668,7 +669,7 @@ func Test_postgresqlConnection_CheckReferenceBetweenUserAndPost(t *testing.T) {
args: args{ args: args{
ctx: ctx, ctx: ctx,
anthroveUserID: "123", anthroveUserID: "123",
anthrovePostID: models.AnthrovePostID(post.ID), anthrovePostID: post.ID,
}, },
want: false, want: false,
wantErr: false, wantErr: false,
@ -714,8 +715,8 @@ func Test_postgresqlConnection_GetPostByAnthroveID(t *testing.T) {
// Setup Tests // Setup Tests
post := &models.Post{ post := &models.Post{
BaseModel: models.BaseModel{ BaseModel: models.BaseModel[models.AnthrovePostID]{
ID: fmt.Sprintf("%025s", "1"), ID: models.AnthrovePostID(fmt.Sprintf("%025s", "1")),
}, },
Rating: "safe", Rating: "safe",
} }
@ -740,7 +741,7 @@ func Test_postgresqlConnection_GetPostByAnthroveID(t *testing.T) {
name: "Test 1: Valid anthrovePostID", name: "Test 1: Valid anthrovePostID",
args: args{ args: args{
ctx: ctx, ctx: ctx,
anthrovePost: models.AnthrovePostID(post.ID), anthrovePost: post.ID,
}, },
want: post, want: post,
wantErr: false, wantErr: false,