@@ -624,6 +624,87 @@ func TestUpdateOrganization(t *testing.T) {
624624 }
625625}
626626
627+ func TestUpdateOrganizationOptsMarshalJSON (t * testing.T ) {
628+ tests := []struct {
629+ scenario string
630+ opts UpdateOrganizationOpts
631+ shouldExist map [string ]bool
632+ wantValue map [string ]string
633+ }{
634+ {
635+ scenario : "nil Domains and DomainData are omitted" ,
636+ opts : UpdateOrganizationOpts {
637+ Name : "Foo Corp" ,
638+ },
639+ shouldExist : map [string ]bool {
640+ "domains" : false ,
641+ "domain_data" : false ,
642+ "name" : true ,
643+ },
644+ },
645+ {
646+ scenario : "empty Domains slice serializes as empty array" ,
647+ opts : UpdateOrganizationOpts {
648+ Name : "Foo Corp" ,
649+ Domains : []string {},
650+ },
651+ shouldExist : map [string ]bool {
652+ "domains" : true ,
653+ "name" : true ,
654+ },
655+ wantValue : map [string ]string {
656+ "domains" : "[]" ,
657+ },
658+ },
659+ {
660+ scenario : "empty DomainData slice serializes as empty array" ,
661+ opts : UpdateOrganizationOpts {
662+ Name : "Foo Corp" ,
663+ DomainData : []OrganizationDomainData {},
664+ },
665+ shouldExist : map [string ]bool {
666+ "domain_data" : true ,
667+ "name" : true ,
668+ },
669+ wantValue : map [string ]string {
670+ "domain_data" : "[]" ,
671+ },
672+ },
673+ {
674+ scenario : "populated Domains serializes normally" ,
675+ opts : UpdateOrganizationOpts {
676+ Name : "Foo Corp" ,
677+ Domains : []string {"foo.com" },
678+ },
679+ shouldExist : map [string ]bool {
680+ "domains" : true ,
681+ },
682+ wantValue : map [string ]string {
683+ "domains" : `["foo.com"]` ,
684+ },
685+ },
686+ }
687+
688+ for _ , test := range tests {
689+ t .Run (test .scenario , func (t * testing.T ) {
690+ data , err := json .Marshal (test .opts )
691+ require .NoError (t , err )
692+
693+ var raw map [string ]json.RawMessage
694+ require .NoError (t , json .Unmarshal (data , & raw ))
695+
696+ for key , shouldExist := range test .shouldExist {
697+ _ , exists := raw [key ]
698+ require .Equal (t , shouldExist , exists , "key %q existence mismatch" , key )
699+ }
700+
701+ for key , want := range test .wantValue {
702+ require .JSONEq (t , want , string (raw [key ]), "key %q value mismatch" , key )
703+ }
704+ })
705+ }
706+ }
707+
627708func updateOrganizationTestHandler (w http.ResponseWriter , r * http.Request ) {
628709 auth := r .Header .Get ("Authorization" )
629710 if auth != "Bearer test" {
0 commit comments