From e9bda893d6d7b98e07c6c60559647f950aefc3bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?CORNIERE=20R=C3=A9mi?= Date: Tue, 14 Jan 2020 23:47:18 +0100 Subject: [PATCH] Added tests for new Owner namespace function --- stanza/pubsub_owner_test.go | 52 +++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/stanza/pubsub_owner_test.go b/stanza/pubsub_owner_test.go index 665fba3..b7cf6db 100644 --- a/stanza/pubsub_owner_test.go +++ b/stanza/pubsub_owner_test.go @@ -816,6 +816,58 @@ func TestGetFormFieldsCmd(t *testing.T) { } +func TestNewFormSubmissionOwner(t *testing.T) { + expectedReq := "" + + " " + + " " + + "http://jabber.org/protocol/pubsub#node_config " + + "604800 roster " + + " friends servants " + + "courtiers " + + subR, err := stanza.NewFormSubmissionOwner("pubsub.shakespeare.lit", + "princely_musings", + []*stanza.Field{ + {Var: "FORM_TYPE", Type: stanza.FieldTypeHidden, ValuesList: []string{"http://jabber.org/protocol/pubsub#node_config"}}, + {Var: "pubsub#item_expire", ValuesList: []string{"604800"}}, + {Var: "pubsub#access_model", ValuesList: []string{"roster"}}, + {Var: "pubsub#roster_groups_allowed", ValuesList: []string{"friends", "servants", "courtiers"}}, + }) + subR.Id = "config2" + if err != nil { + t.Fatalf("Could not create request : %s", err) + } + + if _, e := checkMarshalling(t, subR); e != nil { + t.Fatalf("Failed to check marshalling for generated sub request : %s", e) + } + + pubsub, ok := subR.Payload.(*stanza.PubSubOwner) + if !ok { + t.Fatalf("payload is not a pubsub in namespace owner !") + } + + conf, ok := pubsub.OwnerUseCase.(*stanza.ConfigureOwner) + if !ok { + t.Fatalf("pubsub does not contain a configure node !") + } + + if conf.Form == nil { + t.Fatalf("the form is absent from the configuration submission !") + } + if len(conf.Form.Fields) != 4 { + t.Fatalf("expected 4 fields, found %d", len(conf.Form.Fields)) + } + if len(conf.Form.Fields[3].ValuesList) != 3 { + t.Fatalf("expected 3 values in fourth field, found %d", len(conf.Form.Fields[3].ValuesList)) + } + + data, err := xml.Marshal(subR) + if err := compareMarshal(expectedReq, string(data)); err != nil { + t.Fatalf(err.Error()) + } +} + func getPubSubOwnerPayload(response string) (*stanza.PubSubOwner, error) { var respIQ stanza.IQ err := xml.Unmarshal([]byte(response), &respIQ)