|
1 | 1 | package gitlab
|
2 | 2 |
|
3 | 3 | import (
|
| 4 | + "encoding/json" |
4 | 5 | "fmt"
|
| 6 | + "io" |
5 | 7 | "net/http"
|
6 | 8 | "net/url"
|
7 | 9 | "reflect"
|
@@ -593,3 +595,115 @@ func TestUpdateGroupWithIPRestrictionRanges(t *testing.T) {
|
593 | 595 | t.Errorf("Groups.UpdatedGroup returned %+v, want %+v", group, want)
|
594 | 596 | }
|
595 | 597 | }
|
| 598 | + |
| 599 | +func TestGetGroupWithEmailsEnabled(t *testing.T) { |
| 600 | + mux, client := setup(t) |
| 601 | + |
| 602 | + mux.HandleFunc("/api/v4/groups/1", |
| 603 | + func(w http.ResponseWriter, r *http.Request) { |
| 604 | + testMethod(t, r, http.MethodGet) |
| 605 | + |
| 606 | + // Modified from https://docs.gitlab.com/ee/api/groups.html#details-of-a-group |
| 607 | + fmt.Fprint(w, ` |
| 608 | + { |
| 609 | + "id": 1, |
| 610 | + "name": "test", |
| 611 | + "path": "test", |
| 612 | + "emails_enabled": true, |
| 613 | + "description": "Aliquid qui quis dignissimos distinctio ut commodi voluptas est.", |
| 614 | + "visibility": "public", |
| 615 | + "avatar_url": null, |
| 616 | + "web_url": "https://gitlab.example.com/groups/test", |
| 617 | + "request_access_enabled": false, |
| 618 | + "repository_storage": "default", |
| 619 | + "full_name": "test", |
| 620 | + "full_path": "test", |
| 621 | + "runners_token": "ba324ca7b1c77fc20bb9", |
| 622 | + "file_template_project_id": 1, |
| 623 | + "parent_id": null, |
| 624 | + "enabled_git_access_protocol": "all", |
| 625 | + "created_at": "2020-01-15T12:36:29.590Z", |
| 626 | + "prevent_sharing_groups_outside_hierarchy": false, |
| 627 | + "ip_restriction_ranges": null, |
| 628 | + "math_rendering_limits_enabled": true, |
| 629 | + "lock_math_rendering_limits_enabled": false |
| 630 | + }`) |
| 631 | + }) |
| 632 | + |
| 633 | + group, _, err := client.Groups.GetGroup(1, &GetGroupOptions{}) |
| 634 | + if err != nil { |
| 635 | + t.Errorf("Groups.UpdateGroup returned error: %v", err) |
| 636 | + } |
| 637 | + |
| 638 | + if !group.EmailsEnabled { |
| 639 | + t.Fatalf("Failed to parse `emails_enabled`. Wanted true, got %v", group.EmailsEnabled) |
| 640 | + } |
| 641 | +} |
| 642 | + |
| 643 | +func TestCreateGroupWithEmailsEnabled(t *testing.T) { |
| 644 | + mux, client := setup(t) |
| 645 | + |
| 646 | + mux.HandleFunc("/api/v4/groups", |
| 647 | + func(w http.ResponseWriter, r *http.Request) { |
| 648 | + testMethod(t, r, http.MethodPost) |
| 649 | + |
| 650 | + body, err := io.ReadAll(r.Body) |
| 651 | + if err != nil { |
| 652 | + t.Fatalf("Failed to read the request body. Error: %v", err) |
| 653 | + } |
| 654 | + |
| 655 | + // unmarshal into generic JSON since we don't want to test CreateGroupOptions using itself to validate. |
| 656 | + var bodyJson map[string]interface{} |
| 657 | + err = json.Unmarshal(body, &bodyJson) |
| 658 | + if err != nil { |
| 659 | + t.Fatalf("Failed to parse the request body into JSON. Error: %v", err) |
| 660 | + } |
| 661 | + |
| 662 | + if bodyJson["emails_enabled"] != true { |
| 663 | + t.Fatalf("Test failed. `emails_enabled` expected to be true, got %v", bodyJson["emails_enabled"]) |
| 664 | + } |
| 665 | + |
| 666 | + // Response is tested via the "GET" test, only test the actual request here. |
| 667 | + fmt.Fprint(w, ` |
| 668 | + {}`) |
| 669 | + }) |
| 670 | + |
| 671 | + _, _, err := client.Groups.CreateGroup(&CreateGroupOptions{EmailsEnabled: Ptr(true)}) |
| 672 | + if err != nil { |
| 673 | + t.Errorf("Groups.CreateGroup returned error: %v", err) |
| 674 | + } |
| 675 | +} |
| 676 | + |
| 677 | +func TestUpdateGroupWithEmailsEnabled(t *testing.T) { |
| 678 | + mux, client := setup(t) |
| 679 | + |
| 680 | + mux.HandleFunc("/api/v4/groups/1", |
| 681 | + func(w http.ResponseWriter, r *http.Request) { |
| 682 | + testMethod(t, r, http.MethodPut) |
| 683 | + |
| 684 | + body, err := io.ReadAll(r.Body) |
| 685 | + if err != nil { |
| 686 | + t.Fatalf("Failed to read the request body. Error: %v", err) |
| 687 | + } |
| 688 | + |
| 689 | + // unmarshal into generic JSON since we don't want to test UpdateGroupOptions using itself to validate. |
| 690 | + var bodyJson map[string]interface{} |
| 691 | + err = json.Unmarshal(body, &bodyJson) |
| 692 | + if err != nil { |
| 693 | + t.Fatalf("Failed to parse the request body into JSON. Error: %v", err) |
| 694 | + } |
| 695 | + |
| 696 | + if bodyJson["emails_enabled"] != true { |
| 697 | + t.Fatalf("Test failed. `emails_enabled` expected to be true, got %v", bodyJson["emails_enabled"]) |
| 698 | + } |
| 699 | + |
| 700 | + // Response is tested via the "GET" test, only test the actual request here. |
| 701 | + fmt.Fprint(w, ` |
| 702 | + {}`) |
| 703 | + }) |
| 704 | + |
| 705 | + _, _, err := client.Groups.UpdateGroup(1, &UpdateGroupOptions{EmailsEnabled: Ptr(true)}) |
| 706 | + if err != nil { |
| 707 | + t.Errorf("Groups.UpdateGroup returned error: %v", err) |
| 708 | + } |
| 709 | +} |
0 commit comments