Bootstrap copied BFF and local accounts with public Sendico contracts (#34)
This commit is contained in:
1 parent
67dc5b5b1e
commit
7062672a87
556 files changed
+42291
-777
No files matched your search
@@ -0,0 +1,81 @@
|
||||
package invitationdb
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"git.sendico.io/tech/sxchnge/bff/pkg/db/repository"
|
||||
"git.sendico.io/tech/sxchnge/bff/pkg/db/repository/builder"
|
||||
ri "git.sendico.io/tech/sxchnge/bff/pkg/db/repository/index"
|
||||
"git.sendico.io/tech/sxchnge/bff/pkg/model"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
)
|
||||
|
||||
func TestPendingInvitationEmailIndexDefinition(t *testing.T) {
|
||||
def := pendingInvitationEmailIndexDefinition()
|
||||
|
||||
expectedKeys := []ri.Key{
|
||||
{Field: "organizationRef", Sort: ri.Asc},
|
||||
{Field: "description.email", Sort: ri.Asc},
|
||||
}
|
||||
if !reflect.DeepEqual(def.Keys, expectedKeys) {
|
||||
t.Fatalf("keys mismatch: got %#v want %#v", def.Keys, expectedKeys)
|
||||
}
|
||||
if !def.Unique {
|
||||
t.Fatal("index must be unique")
|
||||
}
|
||||
if def.Name != uniquePendingInvitationEmailIndexName {
|
||||
t.Fatalf("index name mismatch: got %q want %q", def.Name, uniquePendingInvitationEmailIndexName)
|
||||
}
|
||||
|
||||
expectedFilter := repository.Query().
|
||||
In(repository.Field("status"), "created", "sent").
|
||||
Comparison(repository.Field("description.email"), builder.Type, "string").
|
||||
BuildQuery()
|
||||
if !reflect.DeepEqual(def.PartialFilter.BuildQuery(), expectedFilter) {
|
||||
t.Fatalf("partial filter mismatch: got %#v want %#v", def.PartialFilter.BuildQuery(), expectedFilter)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPendingInvitationEmailIndexUsesModelPendingStatuses(t *testing.T) {
|
||||
def := pendingInvitationEmailIndexDefinition()
|
||||
filter := def.PartialFilter.BuildQuery()
|
||||
statuses := statusInValues(t, filter)
|
||||
|
||||
expected := model.PendingInvitationStatusValues()
|
||||
if !reflect.DeepEqual(statuses, expected) {
|
||||
t.Fatalf("index statuses drifted from model: got %#v want %#v", statuses, expected)
|
||||
}
|
||||
}
|
||||
|
||||
func statusInValues(t *testing.T, filter bson.D) []string {
|
||||
t.Helper()
|
||||
for _, item := range filter {
|
||||
if item.Key != "status" {
|
||||
continue
|
||||
}
|
||||
comparison, ok := item.Value.(bson.M)
|
||||
if !ok {
|
||||
t.Fatalf("status filter has unexpected type %T", item.Value)
|
||||
}
|
||||
rawValues, ok := comparison["$in"]
|
||||
if !ok {
|
||||
t.Fatal("status filter must use $in")
|
||||
}
|
||||
values, ok := rawValues.([]any)
|
||||
if !ok {
|
||||
t.Fatalf("status $in has unexpected type %T", rawValues)
|
||||
}
|
||||
statuses := make([]string, 0, len(values))
|
||||
for _, value := range values {
|
||||
status, ok := value.(string)
|
||||
if !ok {
|
||||
t.Fatalf("status value has unexpected type %T", value)
|
||||
}
|
||||
statuses = append(statuses, status)
|
||||
}
|
||||
return statuses
|
||||
}
|
||||
t.Fatal("status filter not found")
|
||||
return nil
|
||||
}
|
||||
Reference in new issue
Block a user