mirror of
https://github.com/andwati/zitadel.git
synced 2026-11-09 15:45:12 +00:00
feat(relational): implement session repository (#11109)
# Which Problems Are Solved As part of going to a relation storage model, we need to implement the repository for handling sessions and their events. # How the Problems Are Solved - Adds a migration step to create the necessary tables and types in the database. - Adds the repository implementation for sessions. - Implements a projection handler for session events to handle the events written by the old command handlers. - Updates the `Session` type and `SessionRepository` interface: - added `CreatorID` - Adjusted `Delete` method to return amount of affected columns - Removed sub-repository clumns from the main interface - Added `CreatorIDCondition`, `ExpirationCondition`, `ExistsFactor` and `ExistsMetadata` - Removed `SetUserAgent` - Methods of `SessionFactor` and `SessionChallenge` have been made public - fixed enumer on `SessionFactorType` - Adds a `JSON` type to the repository package to easy can JSON columns, resp. jsonb object inside a property of a `JSONArray` object. - Adds a `NoChange` interface, which can be implemented to signal that a `Change` interface implementation is not writing any changes to the statement builder, e.g. `CTEChange` # Additional Changes - Fixes the operators enums. `TextOperations` had wrong comments and `NumberOperations` additionally also had from comparisons. - Fixes downgrade of migration step 008. # Additional Context - closes https://github.com/zitadel/zitadel/issues/10212
This commit is contained in:
@@ -0,0 +1,102 @@
|
||||
package repository_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/zitadel/zitadel/backend/v3/storage/database"
|
||||
"github.com/zitadel/zitadel/backend/v3/storage/database/repository"
|
||||
)
|
||||
|
||||
func TestJSON_Scan(t *testing.T) {
|
||||
type want struct {
|
||||
err error
|
||||
res *testObject
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
src any
|
||||
want want
|
||||
}{
|
||||
{
|
||||
name: "nil",
|
||||
src: nil,
|
||||
want: want{
|
||||
err: nil,
|
||||
res: nil,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "[]byte with data",
|
||||
src: []byte(`{"id":"1","number":1,"active":true}`),
|
||||
want: want{
|
||||
err: nil,
|
||||
res: &testObject{ID: "1", Number: 1, Active: true},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "[]byte without data",
|
||||
src: []byte(`{}`),
|
||||
want: want{
|
||||
err: nil,
|
||||
res: &testObject{},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "nil []byte",
|
||||
src: []byte(nil),
|
||||
want: want{
|
||||
err: nil,
|
||||
res: nil,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "string with data",
|
||||
src: `{"id":"2","number":2,"active":false}`,
|
||||
want: want{
|
||||
err: nil,
|
||||
res: &testObject{ID: "2", Number: 2, Active: false},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "string without data",
|
||||
src: `{}`,
|
||||
want: want{
|
||||
err: nil,
|
||||
res: &testObject{},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "empty string",
|
||||
src: ``,
|
||||
want: want{
|
||||
err: nil,
|
||||
res: nil,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "unsupported type",
|
||||
src: 12345,
|
||||
want: want{
|
||||
err: repository.ErrScanSource,
|
||||
res: nil,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "invalid json",
|
||||
src: []byte(`this is not json`),
|
||||
want: want{
|
||||
err: new(database.ScanError),
|
||||
res: nil,
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
var a repository.JSON[testObject]
|
||||
gotErr := a.Scan(tt.src)
|
||||
require.ErrorIs(t, gotErr, tt.want.err)
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user