BREAKING CHANGE: V2 of thr SDK #12
@ -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,
|
||||||
|
Reference in New Issue
Block a user