github.com/google/go-github/v68@v68.0.0/github/reactions_test.go (about)

     1  // Copyright 2016 The go-github AUTHORS. All rights reserved.
     2  //
     3  // Use of this source code is governed by a BSD-style
     4  // license that can be found in the LICENSE file.
     5  
     6  package github
     7  
     8  import (
     9  	"context"
    10  	"fmt"
    11  	"net/http"
    12  	"testing"
    13  
    14  	"github.com/google/go-cmp/cmp"
    15  )
    16  
    17  func TestReaction_Marshal(t *testing.T) {
    18  	t.Parallel()
    19  	testJSONMarshal(t, &Reaction{}, "{}")
    20  
    21  	r := &Reaction{
    22  		ID:      Ptr(int64(1)),
    23  		User:    nil,
    24  		NodeID:  Ptr("n"),
    25  		Content: Ptr("+1"),
    26  	}
    27  
    28  	want := `{
    29  		"id": 1,
    30  		"node_id": "n",
    31  		"content": "+1"
    32  	}`
    33  
    34  	testJSONMarshal(t, r, want)
    35  }
    36  
    37  func TestReactions_Marshal(t *testing.T) {
    38  	t.Parallel()
    39  	testJSONMarshal(t, &Reactions{}, "{}")
    40  
    41  	r := &Reactions{
    42  		TotalCount: Ptr(1),
    43  		PlusOne:    Ptr(1),
    44  		MinusOne:   Ptr(1),
    45  		Laugh:      Ptr(1),
    46  		Confused:   Ptr(1),
    47  		Heart:      Ptr(1),
    48  		Hooray:     Ptr(1),
    49  		Rocket:     Ptr(1),
    50  		Eyes:       Ptr(1),
    51  		URL:        Ptr("u"),
    52  	}
    53  
    54  	want := `{
    55  		"total_count": 1,
    56  		"+1": 1,
    57  		"-1": 1,
    58  		"laugh": 1,
    59  		"confused": 1,
    60  		"heart": 1,
    61  		"hooray": 1,
    62  		"rocket": 1,
    63  		"eyes": 1,
    64  		"url": "u"
    65  	}`
    66  
    67  	testJSONMarshal(t, r, want)
    68  }
    69  
    70  func TestReactionsService_ListCommentReactions(t *testing.T) {
    71  	t.Parallel()
    72  	client, mux, _ := setup(t)
    73  
    74  	mux.HandleFunc("/repos/o/r/comments/1/reactions", func(w http.ResponseWriter, r *http.Request) {
    75  		testMethod(t, r, "GET")
    76  		testHeader(t, r, "Accept", mediaTypeReactionsPreview)
    77  
    78  		testFormValues(t, r, values{"content": "+1"})
    79  		fmt.Fprint(w, `[{"id":1,"user":{"login":"l","id":2},"content":"+1"}]`)
    80  	})
    81  
    82  	opt := &ListCommentReactionOptions{Content: "+1"}
    83  	ctx := context.Background()
    84  	reactions, _, err := client.Reactions.ListCommentReactions(ctx, "o", "r", 1, opt)
    85  	if err != nil {
    86  		t.Errorf("ListCommentReactions returned error: %v", err)
    87  	}
    88  	want := []*Reaction{{ID: Ptr(int64(1)), User: &User{Login: Ptr("l"), ID: Ptr(int64(2))}, Content: Ptr("+1")}}
    89  	if !cmp.Equal(reactions, want) {
    90  		t.Errorf("ListCommentReactions = %+v, want %+v", reactions, want)
    91  	}
    92  
    93  	const methodName = "ListCommentReactions"
    94  	testBadOptions(t, methodName, func() (err error) {
    95  		_, _, err = client.Reactions.ListCommentReactions(ctx, "\n", "\n", -1, opt)
    96  		return err
    97  	})
    98  
    99  	testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
   100  		got, resp, err := client.Reactions.ListCommentReactions(ctx, "o", "r", 1, opt)
   101  		if got != nil {
   102  			t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
   103  		}
   104  		return resp, err
   105  	})
   106  }
   107  
   108  func TestReactionsService_CreateCommentReaction(t *testing.T) {
   109  	t.Parallel()
   110  	client, mux, _ := setup(t)
   111  
   112  	mux.HandleFunc("/repos/o/r/comments/1/reactions", func(w http.ResponseWriter, r *http.Request) {
   113  		testMethod(t, r, "POST")
   114  		testHeader(t, r, "Accept", mediaTypeReactionsPreview)
   115  
   116  		w.WriteHeader(http.StatusCreated)
   117  		assertWrite(t, w, []byte(`{"id":1,"user":{"login":"l","id":2},"content":"+1"}`))
   118  	})
   119  
   120  	ctx := context.Background()
   121  	got, _, err := client.Reactions.CreateCommentReaction(ctx, "o", "r", 1, "+1")
   122  	if err != nil {
   123  		t.Errorf("CreateCommentReaction returned error: %v", err)
   124  	}
   125  	want := &Reaction{ID: Ptr(int64(1)), User: &User{Login: Ptr("l"), ID: Ptr(int64(2))}, Content: Ptr("+1")}
   126  	if !cmp.Equal(got, want) {
   127  		t.Errorf("CreateCommentReaction = %+v, want %+v", got, want)
   128  	}
   129  
   130  	const methodName = "CreateCommentReaction"
   131  	testBadOptions(t, methodName, func() (err error) {
   132  		_, _, err = client.Reactions.CreateCommentReaction(ctx, "\n", "\n", -1, "\n")
   133  		return err
   134  	})
   135  
   136  	testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
   137  		got, resp, err := client.Reactions.CreateCommentReaction(ctx, "o", "r", 1, "+1")
   138  		if got != nil {
   139  			t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
   140  		}
   141  		return resp, err
   142  	})
   143  }
   144  
   145  func TestReactionsService_ListIssueReactions(t *testing.T) {
   146  	t.Parallel()
   147  	client, mux, _ := setup(t)
   148  
   149  	mux.HandleFunc("/repos/o/r/issues/1/reactions", func(w http.ResponseWriter, r *http.Request) {
   150  		testMethod(t, r, "GET")
   151  		testHeader(t, r, "Accept", mediaTypeReactionsPreview)
   152  
   153  		w.WriteHeader(http.StatusOK)
   154  		assertWrite(t, w, []byte(`[{"id":1,"user":{"login":"l","id":2},"content":"+1"}]`))
   155  	})
   156  
   157  	ctx := context.Background()
   158  	got, _, err := client.Reactions.ListIssueReactions(ctx, "o", "r", 1, nil)
   159  	if err != nil {
   160  		t.Errorf("ListIssueReactions returned error: %v", err)
   161  	}
   162  	want := []*Reaction{{ID: Ptr(int64(1)), User: &User{Login: Ptr("l"), ID: Ptr(int64(2))}, Content: Ptr("+1")}}
   163  	if !cmp.Equal(got, want) {
   164  		t.Errorf("ListIssueReactions = %+v, want %+v", got, want)
   165  	}
   166  }
   167  
   168  func TestReactionsService_ListIssueReactions_coverage(t *testing.T) {
   169  	t.Parallel()
   170  	client, _, _ := setup(t)
   171  
   172  	ctx := context.Background()
   173  
   174  	const methodName = "ListIssueReactions"
   175  	testBadOptions(t, methodName, func() (err error) {
   176  		_, _, err = client.Reactions.ListIssueReactions(ctx, "\n", "\n", -1, &ListOptions{})
   177  		return err
   178  	})
   179  
   180  	testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
   181  		got, resp, err := client.Reactions.ListIssueReactions(ctx, "o", "r", 1, nil)
   182  		if got != nil {
   183  			t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
   184  		}
   185  		return resp, err
   186  	})
   187  }
   188  
   189  func TestReactionsService_CreateIssueReaction(t *testing.T) {
   190  	t.Parallel()
   191  	client, mux, _ := setup(t)
   192  
   193  	mux.HandleFunc("/repos/o/r/issues/1/reactions", func(w http.ResponseWriter, r *http.Request) {
   194  		testMethod(t, r, "POST")
   195  		testHeader(t, r, "Accept", mediaTypeReactionsPreview)
   196  
   197  		w.WriteHeader(http.StatusCreated)
   198  		assertWrite(t, w, []byte(`{"id":1,"user":{"login":"l","id":2},"content":"+1"}`))
   199  	})
   200  
   201  	ctx := context.Background()
   202  	got, _, err := client.Reactions.CreateIssueReaction(ctx, "o", "r", 1, "+1")
   203  	if err != nil {
   204  		t.Errorf("CreateIssueReaction returned error: %v", err)
   205  	}
   206  	want := &Reaction{ID: Ptr(int64(1)), User: &User{Login: Ptr("l"), ID: Ptr(int64(2))}, Content: Ptr("+1")}
   207  	if !cmp.Equal(got, want) {
   208  		t.Errorf("CreateIssueReaction = %+v, want %+v", got, want)
   209  	}
   210  
   211  	const methodName = "CreateIssueReaction"
   212  	testBadOptions(t, methodName, func() (err error) {
   213  		_, _, err = client.Reactions.CreateIssueReaction(ctx, "\n", "\n", -1, "\n")
   214  		return err
   215  	})
   216  
   217  	testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
   218  		got, resp, err := client.Reactions.CreateIssueReaction(ctx, "o", "r", 1, "+1")
   219  		if got != nil {
   220  			t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
   221  		}
   222  		return resp, err
   223  	})
   224  }
   225  
   226  func TestReactionsService_ListIssueCommentReactions(t *testing.T) {
   227  	t.Parallel()
   228  	client, mux, _ := setup(t)
   229  
   230  	mux.HandleFunc("/repos/o/r/issues/comments/1/reactions", func(w http.ResponseWriter, r *http.Request) {
   231  		testMethod(t, r, "GET")
   232  		testHeader(t, r, "Accept", mediaTypeReactionsPreview)
   233  
   234  		w.WriteHeader(http.StatusOK)
   235  		assertWrite(t, w, []byte(`[{"id":1,"user":{"login":"l","id":2},"content":"+1"}]`))
   236  	})
   237  
   238  	ctx := context.Background()
   239  	got, _, err := client.Reactions.ListIssueCommentReactions(ctx, "o", "r", 1, nil)
   240  	if err != nil {
   241  		t.Errorf("ListIssueCommentReactions returned error: %v", err)
   242  	}
   243  	want := []*Reaction{{ID: Ptr(int64(1)), User: &User{Login: Ptr("l"), ID: Ptr(int64(2))}, Content: Ptr("+1")}}
   244  	if !cmp.Equal(got, want) {
   245  		t.Errorf("ListIssueCommentReactions = %+v, want %+v", got, want)
   246  	}
   247  }
   248  
   249  func TestReactionsService_ListIssueCommentReactions_coverage(t *testing.T) {
   250  	t.Parallel()
   251  	client, _, _ := setup(t)
   252  
   253  	ctx := context.Background()
   254  
   255  	const methodName = "ListIssueCommentReactions"
   256  	testBadOptions(t, methodName, func() (err error) {
   257  		_, _, err = client.Reactions.ListIssueCommentReactions(ctx, "\n", "\n", -1, &ListOptions{})
   258  		return err
   259  	})
   260  
   261  	testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
   262  		got, resp, err := client.Reactions.ListIssueCommentReactions(ctx, "o", "r", 1, nil)
   263  		if got != nil {
   264  			t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
   265  		}
   266  		return resp, err
   267  	})
   268  }
   269  
   270  func TestReactionsService_CreateIssueCommentReaction(t *testing.T) {
   271  	t.Parallel()
   272  	client, mux, _ := setup(t)
   273  
   274  	mux.HandleFunc("/repos/o/r/issues/comments/1/reactions", func(w http.ResponseWriter, r *http.Request) {
   275  		testMethod(t, r, "POST")
   276  		testHeader(t, r, "Accept", mediaTypeReactionsPreview)
   277  
   278  		w.WriteHeader(http.StatusCreated)
   279  		assertWrite(t, w, []byte(`{"id":1,"user":{"login":"l","id":2},"content":"+1"}`))
   280  	})
   281  
   282  	ctx := context.Background()
   283  	got, _, err := client.Reactions.CreateIssueCommentReaction(ctx, "o", "r", 1, "+1")
   284  	if err != nil {
   285  		t.Errorf("CreateIssueCommentReaction returned error: %v", err)
   286  	}
   287  	want := &Reaction{ID: Ptr(int64(1)), User: &User{Login: Ptr("l"), ID: Ptr(int64(2))}, Content: Ptr("+1")}
   288  	if !cmp.Equal(got, want) {
   289  		t.Errorf("CreateIssueCommentReaction = %+v, want %+v", got, want)
   290  	}
   291  
   292  	const methodName = "CreateIssueCommentReaction"
   293  	testBadOptions(t, methodName, func() (err error) {
   294  		_, _, err = client.Reactions.CreateIssueCommentReaction(ctx, "\n", "\n", -1, "\n")
   295  		return err
   296  	})
   297  
   298  	testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
   299  		got, resp, err := client.Reactions.CreateIssueCommentReaction(ctx, "o", "r", 1, "+1")
   300  		if got != nil {
   301  			t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
   302  		}
   303  		return resp, err
   304  	})
   305  }
   306  
   307  func TestReactionsService_ListPullRequestCommentReactions(t *testing.T) {
   308  	t.Parallel()
   309  	client, mux, _ := setup(t)
   310  
   311  	mux.HandleFunc("/repos/o/r/pulls/comments/1/reactions", func(w http.ResponseWriter, r *http.Request) {
   312  		testMethod(t, r, "GET")
   313  		testHeader(t, r, "Accept", mediaTypeReactionsPreview)
   314  
   315  		w.WriteHeader(http.StatusOK)
   316  		assertWrite(t, w, []byte(`[{"id":1,"user":{"login":"l","id":2},"content":"+1"}]`))
   317  	})
   318  
   319  	ctx := context.Background()
   320  	got, _, err := client.Reactions.ListPullRequestCommentReactions(ctx, "o", "r", 1, nil)
   321  	if err != nil {
   322  		t.Errorf("ListPullRequestCommentReactions returned error: %v", err)
   323  	}
   324  	want := []*Reaction{{ID: Ptr(int64(1)), User: &User{Login: Ptr("l"), ID: Ptr(int64(2))}, Content: Ptr("+1")}}
   325  	if !cmp.Equal(got, want) {
   326  		t.Errorf("ListPullRequestCommentReactions = %+v, want %+v", got, want)
   327  	}
   328  }
   329  
   330  func TestReactionsService_ListPullRequestCommentReactions_coverage(t *testing.T) {
   331  	t.Parallel()
   332  	client, _, _ := setup(t)
   333  
   334  	ctx := context.Background()
   335  
   336  	const methodName = "ListPullRequestCommentReactions"
   337  	testBadOptions(t, methodName, func() (err error) {
   338  		_, _, err = client.Reactions.ListPullRequestCommentReactions(ctx, "\n", "\n", -1, &ListOptions{})
   339  		return err
   340  	})
   341  
   342  	testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
   343  		got, resp, err := client.Reactions.ListPullRequestCommentReactions(ctx, "o", "r", 1, nil)
   344  		if got != nil {
   345  			t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
   346  		}
   347  		return resp, err
   348  	})
   349  }
   350  
   351  func TestReactionsService_CreatePullRequestCommentReaction(t *testing.T) {
   352  	t.Parallel()
   353  	client, mux, _ := setup(t)
   354  
   355  	mux.HandleFunc("/repos/o/r/pulls/comments/1/reactions", func(w http.ResponseWriter, r *http.Request) {
   356  		testMethod(t, r, "POST")
   357  		testHeader(t, r, "Accept", mediaTypeReactionsPreview)
   358  
   359  		w.WriteHeader(http.StatusCreated)
   360  		assertWrite(t, w, []byte(`{"id":1,"user":{"login":"l","id":2},"content":"+1"}`))
   361  	})
   362  
   363  	ctx := context.Background()
   364  	got, _, err := client.Reactions.CreatePullRequestCommentReaction(ctx, "o", "r", 1, "+1")
   365  	if err != nil {
   366  		t.Errorf("CreatePullRequestCommentReaction returned error: %v", err)
   367  	}
   368  	want := &Reaction{ID: Ptr(int64(1)), User: &User{Login: Ptr("l"), ID: Ptr(int64(2))}, Content: Ptr("+1")}
   369  	if !cmp.Equal(got, want) {
   370  		t.Errorf("CreatePullRequestCommentReaction = %+v, want %+v", got, want)
   371  	}
   372  
   373  	const methodName = "CreatePullRequestCommentReaction"
   374  	testBadOptions(t, methodName, func() (err error) {
   375  		_, _, err = client.Reactions.CreatePullRequestCommentReaction(ctx, "\n", "\n", -1, "\n")
   376  		return err
   377  	})
   378  
   379  	testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
   380  		got, resp, err := client.Reactions.CreatePullRequestCommentReaction(ctx, "o", "r", 1, "+1")
   381  		if got != nil {
   382  			t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
   383  		}
   384  		return resp, err
   385  	})
   386  }
   387  
   388  func TestReactionsService_ListTeamDiscussionReactions(t *testing.T) {
   389  	t.Parallel()
   390  	client, mux, _ := setup(t)
   391  
   392  	mux.HandleFunc("/teams/1/discussions/2/reactions", func(w http.ResponseWriter, r *http.Request) {
   393  		testMethod(t, r, "GET")
   394  		testHeader(t, r, "Accept", mediaTypeReactionsPreview)
   395  
   396  		w.WriteHeader(http.StatusOK)
   397  		assertWrite(t, w, []byte(`[{"id":1,"user":{"login":"l","id":2},"content":"+1"}]`))
   398  	})
   399  
   400  	ctx := context.Background()
   401  	got, _, err := client.Reactions.ListTeamDiscussionReactions(ctx, 1, 2, nil)
   402  	if err != nil {
   403  		t.Errorf("ListTeamDiscussionReactions returned error: %v", err)
   404  	}
   405  	want := []*Reaction{{ID: Ptr(int64(1)), User: &User{Login: Ptr("l"), ID: Ptr(int64(2))}, Content: Ptr("+1")}}
   406  	if !cmp.Equal(got, want) {
   407  		t.Errorf("ListTeamDiscussionReactions = %+v, want %+v", got, want)
   408  	}
   409  }
   410  
   411  func TestReactionsService_ListTeamDiscussionReactions_coverage(t *testing.T) {
   412  	t.Parallel()
   413  	client, _, _ := setup(t)
   414  
   415  	ctx := context.Background()
   416  
   417  	const methodName = "ListTeamDiscussionReactions"
   418  	testBadOptions(t, methodName, func() (err error) {
   419  		_, _, err = client.Reactions.ListTeamDiscussionReactions(ctx, -1, -2, &ListOptions{})
   420  		return err
   421  	})
   422  
   423  	testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
   424  		got, resp, err := client.Reactions.ListTeamDiscussionReactions(ctx, 1, 2, nil)
   425  		if got != nil {
   426  			t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
   427  		}
   428  		return resp, err
   429  	})
   430  }
   431  
   432  func TestReactionsService_CreateTeamDiscussionReaction(t *testing.T) {
   433  	t.Parallel()
   434  	client, mux, _ := setup(t)
   435  
   436  	mux.HandleFunc("/teams/1/discussions/2/reactions", func(w http.ResponseWriter, r *http.Request) {
   437  		testMethod(t, r, "POST")
   438  		testHeader(t, r, "Accept", mediaTypeReactionsPreview)
   439  
   440  		w.WriteHeader(http.StatusCreated)
   441  		assertWrite(t, w, []byte(`{"id":1,"user":{"login":"l","id":2},"content":"+1"}`))
   442  	})
   443  
   444  	ctx := context.Background()
   445  	got, _, err := client.Reactions.CreateTeamDiscussionReaction(ctx, 1, 2, "+1")
   446  	if err != nil {
   447  		t.Errorf("CreateTeamDiscussionReaction returned error: %v", err)
   448  	}
   449  	want := &Reaction{ID: Ptr(int64(1)), User: &User{Login: Ptr("l"), ID: Ptr(int64(2))}, Content: Ptr("+1")}
   450  	if !cmp.Equal(got, want) {
   451  		t.Errorf("CreateTeamDiscussionReaction = %+v, want %+v", got, want)
   452  	}
   453  
   454  	const methodName = "CreateTeamDiscussionReaction"
   455  	testBadOptions(t, methodName, func() (err error) {
   456  		_, _, err = client.Reactions.CreateTeamDiscussionReaction(ctx, -1, -2, "\n")
   457  		return err
   458  	})
   459  
   460  	testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
   461  		got, resp, err := client.Reactions.CreateTeamDiscussionReaction(ctx, 1, 2, "+1")
   462  		if got != nil {
   463  			t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
   464  		}
   465  		return resp, err
   466  	})
   467  }
   468  
   469  func TestReactionService_ListTeamDiscussionCommentReactions(t *testing.T) {
   470  	t.Parallel()
   471  	client, mux, _ := setup(t)
   472  
   473  	mux.HandleFunc("/teams/1/discussions/2/comments/3/reactions", func(w http.ResponseWriter, r *http.Request) {
   474  		testMethod(t, r, "GET")
   475  		testHeader(t, r, "Accept", mediaTypeReactionsPreview)
   476  
   477  		w.WriteHeader(http.StatusOK)
   478  		assertWrite(t, w, []byte(`[{"id":1,"user":{"login":"l","id":2},"content":"+1"}]`))
   479  	})
   480  
   481  	ctx := context.Background()
   482  	got, _, err := client.Reactions.ListTeamDiscussionCommentReactions(ctx, 1, 2, 3, nil)
   483  	if err != nil {
   484  		t.Errorf("ListTeamDiscussionCommentReactions returned error: %v", err)
   485  	}
   486  	want := []*Reaction{{ID: Ptr(int64(1)), User: &User{Login: Ptr("l"), ID: Ptr(int64(2))}, Content: Ptr("+1")}}
   487  	if !cmp.Equal(got, want) {
   488  		t.Errorf("ListTeamDiscussionCommentReactions = %+v, want %+v", got, want)
   489  	}
   490  }
   491  
   492  func TestReactionService_ListTeamDiscussionCommentReactions_coverage(t *testing.T) {
   493  	t.Parallel()
   494  	client, _, _ := setup(t)
   495  
   496  	ctx := context.Background()
   497  
   498  	const methodName = "ListTeamDiscussionCommentReactions"
   499  	testBadOptions(t, methodName, func() (err error) {
   500  		_, _, err = client.Reactions.ListTeamDiscussionCommentReactions(ctx, -1, -2, -3, &ListOptions{})
   501  		return err
   502  	})
   503  
   504  	testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
   505  		got, resp, err := client.Reactions.ListTeamDiscussionCommentReactions(ctx, 1, 2, 3, nil)
   506  		if got != nil {
   507  			t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
   508  		}
   509  		return resp, err
   510  	})
   511  }
   512  
   513  func TestReactionService_CreateTeamDiscussionCommentReaction(t *testing.T) {
   514  	t.Parallel()
   515  	client, mux, _ := setup(t)
   516  
   517  	mux.HandleFunc("/teams/1/discussions/2/comments/3/reactions", func(w http.ResponseWriter, r *http.Request) {
   518  		testMethod(t, r, "POST")
   519  		testHeader(t, r, "Accept", mediaTypeReactionsPreview)
   520  
   521  		w.WriteHeader(http.StatusCreated)
   522  		assertWrite(t, w, []byte(`{"id":1,"user":{"login":"l","id":2},"content":"+1"}`))
   523  	})
   524  
   525  	ctx := context.Background()
   526  	got, _, err := client.Reactions.CreateTeamDiscussionCommentReaction(ctx, 1, 2, 3, "+1")
   527  	if err != nil {
   528  		t.Errorf("CreateTeamDiscussionCommentReaction returned error: %v", err)
   529  	}
   530  	want := &Reaction{ID: Ptr(int64(1)), User: &User{Login: Ptr("l"), ID: Ptr(int64(2))}, Content: Ptr("+1")}
   531  	if !cmp.Equal(got, want) {
   532  		t.Errorf("CreateTeamDiscussionCommentReaction = %+v, want %+v", got, want)
   533  	}
   534  
   535  	const methodName = "CreateTeamDiscussionCommentReaction"
   536  	testBadOptions(t, methodName, func() (err error) {
   537  		_, _, err = client.Reactions.CreateTeamDiscussionCommentReaction(ctx, -1, -2, -3, "\n")
   538  		return err
   539  	})
   540  
   541  	testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
   542  		got, resp, err := client.Reactions.CreateTeamDiscussionCommentReaction(ctx, 1, 2, 3, "+1")
   543  		if got != nil {
   544  			t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
   545  		}
   546  		return resp, err
   547  	})
   548  }
   549  
   550  func TestReactionsService_DeleteCommitCommentReaction(t *testing.T) {
   551  	t.Parallel()
   552  	client, mux, _ := setup(t)
   553  
   554  	mux.HandleFunc("/repos/o/r/comments/1/reactions/2", func(w http.ResponseWriter, r *http.Request) {
   555  		testMethod(t, r, "DELETE")
   556  		testHeader(t, r, "Accept", mediaTypeReactionsPreview)
   557  
   558  		w.WriteHeader(http.StatusNoContent)
   559  	})
   560  
   561  	ctx := context.Background()
   562  	if _, err := client.Reactions.DeleteCommentReaction(ctx, "o", "r", 1, 2); err != nil {
   563  		t.Errorf("DeleteCommentReaction returned error: %v", err)
   564  	}
   565  
   566  	const methodName = "DeleteCommentReaction"
   567  	testBadOptions(t, methodName, func() (err error) {
   568  		_, err = client.Reactions.DeleteCommentReaction(ctx, "\n", "\n", -1, -2)
   569  		return err
   570  	})
   571  
   572  	testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
   573  		return client.Reactions.DeleteCommentReaction(ctx, "o", "r", 1, 2)
   574  	})
   575  }
   576  
   577  func TestReactionsService_DeleteCommitCommentReactionByRepoID(t *testing.T) {
   578  	t.Parallel()
   579  	client, mux, _ := setup(t)
   580  
   581  	mux.HandleFunc("/repositories/1/comments/2/reactions/3", func(w http.ResponseWriter, r *http.Request) {
   582  		testMethod(t, r, "DELETE")
   583  		testHeader(t, r, "Accept", mediaTypeReactionsPreview)
   584  
   585  		w.WriteHeader(http.StatusNoContent)
   586  	})
   587  
   588  	ctx := context.Background()
   589  	if _, err := client.Reactions.DeleteCommentReactionByID(ctx, 1, 2, 3); err != nil {
   590  		t.Errorf("DeleteCommentReactionByRepoID returned error: %v", err)
   591  	}
   592  
   593  	const methodName = "DeleteCommentReactionByID"
   594  	testBadOptions(t, methodName, func() (err error) {
   595  		_, err = client.Reactions.DeleteCommentReactionByID(ctx, -1, -2, -3)
   596  		return err
   597  	})
   598  
   599  	testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
   600  		return client.Reactions.DeleteCommentReactionByID(ctx, 1, 2, 3)
   601  	})
   602  }
   603  
   604  func TestReactionsService_DeleteIssueReaction(t *testing.T) {
   605  	t.Parallel()
   606  	client, mux, _ := setup(t)
   607  
   608  	mux.HandleFunc("/repos/o/r/issues/1/reactions/2", func(w http.ResponseWriter, r *http.Request) {
   609  		testMethod(t, r, "DELETE")
   610  		testHeader(t, r, "Accept", mediaTypeReactionsPreview)
   611  
   612  		w.WriteHeader(http.StatusNoContent)
   613  	})
   614  
   615  	ctx := context.Background()
   616  	if _, err := client.Reactions.DeleteIssueReaction(ctx, "o", "r", 1, 2); err != nil {
   617  		t.Errorf("DeleteIssueReaction returned error: %v", err)
   618  	}
   619  
   620  	const methodName = "DeleteIssueReaction"
   621  	testBadOptions(t, methodName, func() (err error) {
   622  		_, err = client.Reactions.DeleteIssueReaction(ctx, "\n", "\n", -1, -2)
   623  		return err
   624  	})
   625  
   626  	testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
   627  		return client.Reactions.DeleteIssueReaction(ctx, "o", "r", 1, 2)
   628  	})
   629  }
   630  
   631  func TestReactionsService_DeleteIssueReactionByRepoID(t *testing.T) {
   632  	t.Parallel()
   633  	client, mux, _ := setup(t)
   634  
   635  	mux.HandleFunc("/repositories/1/issues/2/reactions/3", func(w http.ResponseWriter, r *http.Request) {
   636  		testMethod(t, r, "DELETE")
   637  		testHeader(t, r, "Accept", mediaTypeReactionsPreview)
   638  
   639  		w.WriteHeader(http.StatusNoContent)
   640  	})
   641  
   642  	ctx := context.Background()
   643  	if _, err := client.Reactions.DeleteIssueReactionByID(ctx, 1, 2, 3); err != nil {
   644  		t.Errorf("DeleteIssueReactionByRepoID returned error: %v", err)
   645  	}
   646  
   647  	const methodName = "DeleteIssueReactionByID"
   648  	testBadOptions(t, methodName, func() (err error) {
   649  		_, err = client.Reactions.DeleteIssueReactionByID(ctx, -1, -2, -3)
   650  		return err
   651  	})
   652  
   653  	testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
   654  		return client.Reactions.DeleteIssueReactionByID(ctx, 1, 2, 3)
   655  	})
   656  }
   657  
   658  func TestReactionsService_DeleteIssueCommentReaction(t *testing.T) {
   659  	t.Parallel()
   660  	client, mux, _ := setup(t)
   661  
   662  	mux.HandleFunc("/repos/o/r/issues/comments/1/reactions/2", func(w http.ResponseWriter, r *http.Request) {
   663  		testMethod(t, r, "DELETE")
   664  		testHeader(t, r, "Accept", mediaTypeReactionsPreview)
   665  
   666  		w.WriteHeader(http.StatusNoContent)
   667  	})
   668  
   669  	ctx := context.Background()
   670  	if _, err := client.Reactions.DeleteIssueCommentReaction(ctx, "o", "r", 1, 2); err != nil {
   671  		t.Errorf("DeleteIssueCommentReaction returned error: %v", err)
   672  	}
   673  
   674  	const methodName = "DeleteIssueCommentReaction"
   675  	testBadOptions(t, methodName, func() (err error) {
   676  		_, err = client.Reactions.DeleteIssueCommentReaction(ctx, "\n", "\n", -1, -2)
   677  		return err
   678  	})
   679  
   680  	testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
   681  		return client.Reactions.DeleteIssueCommentReaction(ctx, "o", "r", 1, 2)
   682  	})
   683  }
   684  
   685  func TestReactionsService_DeleteIssueCommentReactionByRepoID(t *testing.T) {
   686  	t.Parallel()
   687  	client, mux, _ := setup(t)
   688  
   689  	mux.HandleFunc("/repositories/1/issues/comments/2/reactions/3", func(w http.ResponseWriter, r *http.Request) {
   690  		testMethod(t, r, "DELETE")
   691  		testHeader(t, r, "Accept", mediaTypeReactionsPreview)
   692  
   693  		w.WriteHeader(http.StatusNoContent)
   694  	})
   695  
   696  	ctx := context.Background()
   697  	if _, err := client.Reactions.DeleteIssueCommentReactionByID(ctx, 1, 2, 3); err != nil {
   698  		t.Errorf("DeleteIssueCommentReactionByRepoID returned error: %v", err)
   699  	}
   700  
   701  	const methodName = "DeleteIssueCommentReactionByID"
   702  	testBadOptions(t, methodName, func() (err error) {
   703  		_, err = client.Reactions.DeleteIssueCommentReactionByID(ctx, -1, -2, -3)
   704  		return err
   705  	})
   706  
   707  	testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
   708  		return client.Reactions.DeleteIssueCommentReactionByID(ctx, 1, 2, 3)
   709  	})
   710  }
   711  
   712  func TestReactionsService_DeletePullRequestCommentReaction(t *testing.T) {
   713  	t.Parallel()
   714  	client, mux, _ := setup(t)
   715  
   716  	mux.HandleFunc("/repos/o/r/pulls/comments/1/reactions/2", func(w http.ResponseWriter, r *http.Request) {
   717  		testMethod(t, r, "DELETE")
   718  		testHeader(t, r, "Accept", mediaTypeReactionsPreview)
   719  
   720  		w.WriteHeader(http.StatusNoContent)
   721  	})
   722  
   723  	ctx := context.Background()
   724  	if _, err := client.Reactions.DeletePullRequestCommentReaction(ctx, "o", "r", 1, 2); err != nil {
   725  		t.Errorf("DeletePullRequestCommentReaction returned error: %v", err)
   726  	}
   727  
   728  	const methodName = "DeletePullRequestCommentReaction"
   729  	testBadOptions(t, methodName, func() (err error) {
   730  		_, err = client.Reactions.DeletePullRequestCommentReaction(ctx, "\n", "\n", -1, -2)
   731  		return err
   732  	})
   733  
   734  	testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
   735  		return client.Reactions.DeletePullRequestCommentReaction(ctx, "o", "r", 1, 2)
   736  	})
   737  }
   738  
   739  func TestReactionsService_DeletePullRequestCommentReactionByRepoID(t *testing.T) {
   740  	t.Parallel()
   741  	client, mux, _ := setup(t)
   742  
   743  	mux.HandleFunc("/repositories/1/pulls/comments/2/reactions/3", func(w http.ResponseWriter, r *http.Request) {
   744  		testMethod(t, r, "DELETE")
   745  		testHeader(t, r, "Accept", mediaTypeReactionsPreview)
   746  
   747  		w.WriteHeader(http.StatusNoContent)
   748  	})
   749  
   750  	ctx := context.Background()
   751  	if _, err := client.Reactions.DeletePullRequestCommentReactionByID(ctx, 1, 2, 3); err != nil {
   752  		t.Errorf("DeletePullRequestCommentReactionByRepoID returned error: %v", err)
   753  	}
   754  
   755  	const methodName = "DeletePullRequestCommentReactionByID"
   756  	testBadOptions(t, methodName, func() (err error) {
   757  		_, err = client.Reactions.DeletePullRequestCommentReactionByID(ctx, -1, -2, -3)
   758  		return err
   759  	})
   760  
   761  	testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
   762  		return client.Reactions.DeletePullRequestCommentReactionByID(ctx, 1, 2, 3)
   763  	})
   764  }
   765  
   766  func TestReactionsService_DeleteTeamDiscussionReaction(t *testing.T) {
   767  	t.Parallel()
   768  	client, mux, _ := setup(t)
   769  
   770  	mux.HandleFunc("/orgs/o/teams/s/discussions/1/reactions/2", func(w http.ResponseWriter, r *http.Request) {
   771  		testMethod(t, r, "DELETE")
   772  		testHeader(t, r, "Accept", mediaTypeReactionsPreview)
   773  
   774  		w.WriteHeader(http.StatusNoContent)
   775  	})
   776  
   777  	ctx := context.Background()
   778  	if _, err := client.Reactions.DeleteTeamDiscussionReaction(ctx, "o", "s", 1, 2); err != nil {
   779  		t.Errorf("DeleteTeamDiscussionReaction returned error: %v", err)
   780  	}
   781  
   782  	const methodName = "DeleteTeamDiscussionReaction"
   783  	testBadOptions(t, methodName, func() (err error) {
   784  		_, err = client.Reactions.DeleteTeamDiscussionReaction(ctx, "\n", "\n", -1, -2)
   785  		return err
   786  	})
   787  
   788  	testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
   789  		return client.Reactions.DeleteTeamDiscussionReaction(ctx, "o", "s", 1, 2)
   790  	})
   791  }
   792  
   793  func TestReactionsService_DeleteTeamDiscussionReactionByTeamIDAndOrgID(t *testing.T) {
   794  	t.Parallel()
   795  	client, mux, _ := setup(t)
   796  
   797  	mux.HandleFunc("/organizations/1/team/2/discussions/3/reactions/4", func(w http.ResponseWriter, r *http.Request) {
   798  		testMethod(t, r, "DELETE")
   799  		testHeader(t, r, "Accept", mediaTypeReactionsPreview)
   800  
   801  		w.WriteHeader(http.StatusNoContent)
   802  	})
   803  
   804  	ctx := context.Background()
   805  	if _, err := client.Reactions.DeleteTeamDiscussionReactionByOrgIDAndTeamID(ctx, 1, 2, 3, 4); err != nil {
   806  		t.Errorf("DeleteTeamDiscussionReactionByTeamIDAndOrgID returned error: %v", err)
   807  	}
   808  
   809  	const methodName = "DeleteTeamDiscussionReactionByOrgIDAndTeamID"
   810  	testBadOptions(t, methodName, func() (err error) {
   811  		_, err = client.Reactions.DeleteTeamDiscussionReactionByOrgIDAndTeamID(ctx, -1, -2, -3, -4)
   812  		return err
   813  	})
   814  
   815  	testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
   816  		return client.Reactions.DeleteTeamDiscussionReactionByOrgIDAndTeamID(ctx, 1, 2, 3, 4)
   817  	})
   818  }
   819  
   820  func TestReactionsService_DeleteTeamDiscussionCommentReaction(t *testing.T) {
   821  	t.Parallel()
   822  	client, mux, _ := setup(t)
   823  
   824  	mux.HandleFunc("/orgs/o/teams/s/discussions/1/comments/2/reactions/3", func(w http.ResponseWriter, r *http.Request) {
   825  		testMethod(t, r, "DELETE")
   826  		testHeader(t, r, "Accept", mediaTypeReactionsPreview)
   827  
   828  		w.WriteHeader(http.StatusNoContent)
   829  	})
   830  
   831  	ctx := context.Background()
   832  	if _, err := client.Reactions.DeleteTeamDiscussionCommentReaction(ctx, "o", "s", 1, 2, 3); err != nil {
   833  		t.Errorf("DeleteTeamDiscussionCommentReaction returned error: %v", err)
   834  	}
   835  
   836  	const methodName = "DeleteTeamDiscussionCommentReaction"
   837  	testBadOptions(t, methodName, func() (err error) {
   838  		_, err = client.Reactions.DeleteTeamDiscussionCommentReaction(ctx, "\n", "\n", -1, -2, -3)
   839  		return err
   840  	})
   841  
   842  	testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
   843  		return client.Reactions.DeleteTeamDiscussionCommentReaction(ctx, "o", "s", 1, 2, 3)
   844  	})
   845  }
   846  
   847  func TestReactionsService_DeleteTeamDiscussionCommentReactionByTeamIDAndOrgID(t *testing.T) {
   848  	t.Parallel()
   849  	client, mux, _ := setup(t)
   850  
   851  	mux.HandleFunc("/organizations/1/team/2/discussions/3/comments/4/reactions/5", func(w http.ResponseWriter, r *http.Request) {
   852  		testMethod(t, r, "DELETE")
   853  		testHeader(t, r, "Accept", mediaTypeReactionsPreview)
   854  
   855  		w.WriteHeader(http.StatusNoContent)
   856  	})
   857  
   858  	ctx := context.Background()
   859  	if _, err := client.Reactions.DeleteTeamDiscussionCommentReactionByOrgIDAndTeamID(ctx, 1, 2, 3, 4, 5); err != nil {
   860  		t.Errorf("DeleteTeamDiscussionCommentReactionByTeamIDAndOrgID returned error: %v", err)
   861  	}
   862  
   863  	const methodName = "DeleteTeamDiscussionCommentReactionByOrgIDAndTeamID"
   864  	testBadOptions(t, methodName, func() (err error) {
   865  		_, err = client.Reactions.DeleteTeamDiscussionCommentReactionByOrgIDAndTeamID(ctx, -1, -2, -3, -4, -5)
   866  		return err
   867  	})
   868  
   869  	testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
   870  		return client.Reactions.DeleteTeamDiscussionCommentReactionByOrgIDAndTeamID(ctx, 1, 2, 3, 4, 5)
   871  	})
   872  }
   873  
   874  func TestReactionService_CreateReleaseReaction(t *testing.T) {
   875  	t.Parallel()
   876  	client, mux, _ := setup(t)
   877  
   878  	mux.HandleFunc("/repos/o/r/releases/1/reactions", func(w http.ResponseWriter, r *http.Request) {
   879  		testMethod(t, r, "POST")
   880  		testHeader(t, r, "Accept", mediaTypeReactionsPreview)
   881  
   882  		w.WriteHeader(http.StatusCreated)
   883  		assertWrite(t, w, []byte(`{"id":1,"user":{"login":"l","id":2},"content":"rocket"}`))
   884  	})
   885  
   886  	const methodName = "CreateReleaseReaction"
   887  	ctx := context.Background()
   888  	got, _, err := client.Reactions.CreateReleaseReaction(ctx, "o", "r", 1, "rocket")
   889  	if err != nil {
   890  		t.Errorf("%v returned error: %v", methodName, err)
   891  	}
   892  
   893  	want := &Reaction{ID: Ptr(int64(1)), User: &User{Login: Ptr("l"), ID: Ptr(int64(2))}, Content: Ptr("rocket")}
   894  	if !cmp.Equal(got, want) {
   895  		t.Errorf("%v = %+v, want %+v", methodName, got, want)
   896  	}
   897  
   898  	testBadOptions(t, methodName, func() (err error) {
   899  		_, _, err = client.Reactions.CreateReleaseReaction(ctx, "\n", "\n", -1, "\n")
   900  		return err
   901  	})
   902  
   903  	testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
   904  		got, resp, err := client.Reactions.CreateReleaseReaction(ctx, "o", "r", 1, "rocket")
   905  		if got != nil {
   906  			t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
   907  		}
   908  		return resp, err
   909  	})
   910  }