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,64 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"testing"
|
||||
|
||||
"git.sendico.io/tech/sxchnge/bff/pkg/db/storable"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
)
|
||||
|
||||
// The frontend parses owner as {"ref": ..., "kind": ...}; a regression to the
|
||||
// nested {"Ref": {"ref": ...}} shape breaks every recipients screen.
|
||||
func TestOwnerJSONIsFlat(t *testing.T) {
|
||||
ref, err := bson.ObjectIDFromHex("69834f22fff13a7457793b6c")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
out, err := json.Marshal(Owner{
|
||||
Ref: storable.Ref{Ref: ref},
|
||||
Kind: "account",
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
want := `{"ref":"69834f22fff13a7457793b6c","kind":"account"}`
|
||||
if string(out) != want {
|
||||
t.Fatalf("owner JSON = %s, want %s", out, want)
|
||||
}
|
||||
|
||||
var back Owner
|
||||
if err := json.Unmarshal(out, &back); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if back.Ref.Ref != ref || back.Kind != "account" {
|
||||
t.Fatalf("round-trip lost data: %+v", back)
|
||||
}
|
||||
}
|
||||
|
||||
// Mongo queries filter on owner.ref / owner.kind (see auth.ScopedDBImp), so
|
||||
// the BSON document must keep those exact paths.
|
||||
func TestOwnerBSONPathsUnchanged(t *testing.T) {
|
||||
ref, err := bson.ObjectIDFromHex("69834f22fff13a7457793b6c")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
out, err := bson.Marshal(Owner{
|
||||
Ref: storable.Ref{Ref: ref},
|
||||
Kind: "account",
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
var doc bson.M
|
||||
if err := bson.Unmarshal(out, &doc); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if doc["ref"] != ref || doc["kind"] != "account" {
|
||||
t.Fatalf("bson doc = %v, want flat ref/kind", doc)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user