From fd1c54838eae7435fe44b9b4b988eae344ecc851 Mon Sep 17 00:00:00 2001 From: Jeremy Tellaa Date: Fri, 15 Nov 2024 10:05:20 +0100 Subject: [PATCH] chore: improve IPRestrictionRanges test --- groups_test.go | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/groups_test.go b/groups_test.go index 7138702d7..5124a537d 100644 --- a/groups_test.go +++ b/groups_test.go @@ -785,21 +785,38 @@ func TestUnshareGroupFromGroup(t *testing.T) { func TestUpdateGroupWithIPRestrictionRanges(t *testing.T) { mux, client := setup(t) + const ipRange = "192.168.0.0/24" mux.HandleFunc("/api/v4/groups/1", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, http.MethodPut) - fmt.Fprint(w, `{"id": 1, "ip_restriction_ranges" : "192.168.0.0/24"}`) + + body, err := io.ReadAll(r.Body) + if err != nil { + t.Fatalf("Failed to read the request body. Error: %v", err) + } + + var bodyJson map[string]interface{} + err = json.Unmarshal(body, &bodyJson) + if err != nil { + t.Fatalf("Failed to parse the request body into JSON. Error: %v", err) + } + + if bodyJson["ip_restriction_ranges"] != ipRange { + t.Fatalf("Test failed. `allowed_email_domains_list` expected to be '%v', got %v", ipRange, bodyJson["ip_restriction_ranges"]) + } + + fmt.Fprintf(w, `{"id": 1, "ip_restriction_ranges" : "%v"}`, ipRange) }) group, _, err := client.Groups.UpdateGroup(1, &UpdateGroupOptions{ - IPRestrictionRanges: Ptr("192.168.0.0/24"), + IPRestrictionRanges: Ptr(ipRange), }) if err != nil { t.Errorf("Groups.UpdateGroup returned error: %v", err) } - want := &Group{ID: 1, IPRestrictionRanges: "192.168.0.0/24"} + want := &Group{ID: 1, IPRestrictionRanges: ipRange} if !reflect.DeepEqual(want, group) { t.Errorf("Groups.UpdatedGroup returned %+v, want %+v", group, want) }