diff --git a/client/organization.go b/client/organization.go index 628f7c9b..a714d747 100644 --- a/client/organization.go +++ b/client/organization.go @@ -72,6 +72,14 @@ func (client *ApiClient) OrganizationPolicyUpdate(payload OrganizationPolicyUpda return nil, err } + if payload.DefaultTtl != nil && *payload.DefaultTtl == "" { + payload.DefaultTtl = nil + } + + if payload.MaxTtl != nil && *payload.MaxTtl == "" { + payload.MaxTtl = nil + } + var result Organization if err := client.http.Post("/organizations/"+id+"/policies", payload, &result); err != nil { return nil, err diff --git a/client/organization_test.go b/client/organization_test.go index 8affa26e..7e14abe2 100644 --- a/client/organization_test.go +++ b/client/organization_test.go @@ -139,6 +139,46 @@ var _ = Describe("Organization", func() { }) }) + Describe("Emtpy string is passed as null", func() { + updatedMockOrganization := mockOrganization + updatedMockOrganization.DefaultTtl = nil + updatedMockOrganization.MaxTtl = nil + + var updatedOrganization *Organization + var err error + + emptyString := "" + + BeforeEach(func() { + mockOrganizationIdCall(organizationId) + originalUpdatePayload := OrganizationPolicyUpdatePayload{ + DefaultTtl: &emptyString, + MaxTtl: &emptyString, + } + + sentUpdatePayload := OrganizationPolicyUpdatePayload{ + DefaultTtl: nil, + MaxTtl: nil, + } + + httpCall = mockHttpClient.EXPECT(). + Post("/organizations/"+organizationId+"/policies", sentUpdatePayload, gomock.Any()). + Do(func(path string, request interface{}, response *Organization) { + *response = updatedMockOrganization + }).Times(1) + + updatedOrganization, err = apiClient.OrganizationPolicyUpdate(originalUpdatePayload) + }) + + It("Should not return an error", func() { + Expect(err).To(BeNil()) + }) + + It("Should return organization received from API", func() { + Expect(*updatedOrganization).To(Equal(updatedMockOrganization)) + }) + }) + Describe("OrganizationUserUpdateRole", func() { userId := "userId" roleId := "roleId"