BREAKING CHANGE: V2 of thr SDK #12

Merged
fenpaws merged 124 commits from develop/postgresql into main 2024-07-01 20:46:28 +00:00
Showing only changes of commit c0cae140f1 - Show all commits

View File

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