github.com/akamai/AkamaiOPEN-edgegrid-golang/v8@v8.1.0/pkg/botman/custom_defined_bot_test.go (about)

     1  package botman
     2  
     3  import (
     4  	"context"
     5  	"encoding/json"
     6  	"errors"
     7  	"net/http"
     8  	"net/http/httptest"
     9  	"testing"
    10  
    11  	"github.com/akamai/AkamaiOPEN-edgegrid-golang/v8/pkg/session"
    12  	"github.com/stretchr/testify/assert"
    13  	"github.com/stretchr/testify/require"
    14  )
    15  
    16  // Test Get CustomDefinedBot List
    17  func TestBotman_GetCustomDefinedBotList(t *testing.T) {
    18  
    19  	tests := map[string]struct {
    20  		params           GetCustomDefinedBotListRequest
    21  		responseStatus   int
    22  		responseBody     string
    23  		expectedPath     string
    24  		expectedResponse *GetCustomDefinedBotListResponse
    25  		withError        func(*testing.T, error)
    26  	}{
    27  		"200 OK": {
    28  			params: GetCustomDefinedBotListRequest{
    29  				ConfigID: 43253,
    30  				Version:  15,
    31  			},
    32  			responseStatus: http.StatusOK,
    33  			responseBody: `
    34  {
    35  	"bots": [
    36  		{"botId":"b85e3eaa-d334-466d-857e-33308ce416be", "testKey":"testValue1"},
    37  		{"botId":"69acad64-7459-4c1d-9bad-672600150127", "testKey":"testValue2"},
    38  		{"botId":"cc9c3f89-e179-4892-89cf-d5e623ba9dc7", "testKey":"testValue3"},
    39  		{"botId":"10c54ea3-e3cb-4fc0-b0e0-fa3658aebd7b", "testKey":"testValue4"},
    40  		{"botId":"4d64d85a-a07f-485a-bbac-24c60658a1b8", "testKey":"testValue5"}
    41  	]
    42  }`,
    43  			expectedPath: "/appsec/v1/configs/43253/versions/15/custom-defined-bots",
    44  			expectedResponse: &GetCustomDefinedBotListResponse{
    45  				Bots: []map[string]interface{}{
    46  					{"botId": "b85e3eaa-d334-466d-857e-33308ce416be", "testKey": "testValue1"},
    47  					{"botId": "69acad64-7459-4c1d-9bad-672600150127", "testKey": "testValue2"},
    48  					{"botId": "cc9c3f89-e179-4892-89cf-d5e623ba9dc7", "testKey": "testValue3"},
    49  					{"botId": "10c54ea3-e3cb-4fc0-b0e0-fa3658aebd7b", "testKey": "testValue4"},
    50  					{"botId": "4d64d85a-a07f-485a-bbac-24c60658a1b8", "testKey": "testValue5"},
    51  				},
    52  			},
    53  		},
    54  		"200 OK One Record": {
    55  			params: GetCustomDefinedBotListRequest{
    56  				ConfigID: 43253,
    57  				Version:  15,
    58  				BotID:    "cc9c3f89-e179-4892-89cf-d5e623ba9dc7",
    59  			},
    60  			responseStatus: http.StatusOK,
    61  			responseBody: `
    62  {
    63  	"bots":[
    64  		{"botId":"b85e3eaa-d334-466d-857e-33308ce416be", "testKey":"testValue1"},
    65  		{"botId":"69acad64-7459-4c1d-9bad-672600150127", "testKey":"testValue2"},
    66  		{"botId":"cc9c3f89-e179-4892-89cf-d5e623ba9dc7", "testKey":"testValue3"},
    67  		{"botId":"10c54ea3-e3cb-4fc0-b0e0-fa3658aebd7b", "testKey":"testValue4"},
    68  		{"botId":"4d64d85a-a07f-485a-bbac-24c60658a1b8", "testKey":"testValue5"}
    69  	]
    70  }`,
    71  			expectedPath: "/appsec/v1/configs/43253/versions/15/custom-defined-bots",
    72  			expectedResponse: &GetCustomDefinedBotListResponse{
    73  				Bots: []map[string]interface{}{
    74  					{"botId": "cc9c3f89-e179-4892-89cf-d5e623ba9dc7", "testKey": "testValue3"},
    75  				},
    76  			},
    77  		},
    78  		"500 internal server error": {
    79  			params: GetCustomDefinedBotListRequest{
    80  				ConfigID: 43253,
    81  				Version:  15,
    82  			},
    83  			responseStatus: http.StatusInternalServerError,
    84  			responseBody: `
    85  {
    86      "type": "internal_error",
    87      "title": "Internal Server Error",
    88      "detail": "Error fetching data",
    89      "status": 500
    90  }`,
    91  			expectedPath: "/appsec/v1/configs/43253/versions/15/custom-defined-bots",
    92  			withError: func(t *testing.T, err error) {
    93  				want := &Error{
    94  					Type:       "internal_error",
    95  					Title:      "Internal Server Error",
    96  					Detail:     "Error fetching data",
    97  					StatusCode: http.StatusInternalServerError,
    98  				}
    99  				assert.True(t, errors.Is(err, want), "want: %s; got: %s", want, err)
   100  			},
   101  		},
   102  		"Missing ConfigID": {
   103  			params: GetCustomDefinedBotListRequest{
   104  				Version: 15,
   105  			},
   106  			withError: func(t *testing.T, err error) {
   107  				want := ErrStructValidation
   108  				assert.True(t, errors.Is(err, want), "want: %s; got: %s", want, err)
   109  				assert.Contains(t, err.Error(), "ConfigID")
   110  			},
   111  		},
   112  		"Missing Version": {
   113  			params: GetCustomDefinedBotListRequest{
   114  				ConfigID: 43253,
   115  			},
   116  			withError: func(t *testing.T, err error) {
   117  				want := ErrStructValidation
   118  				assert.True(t, errors.Is(err, want), "want: %s; got: %s", want, err)
   119  				assert.Contains(t, err.Error(), "Version")
   120  			},
   121  		},
   122  	}
   123  
   124  	for name, test := range tests {
   125  		t.Run(name, func(t *testing.T) {
   126  			mockServer := httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
   127  				assert.Equal(t, test.expectedPath, r.URL.String())
   128  				assert.Equal(t, http.MethodGet, r.Method)
   129  				w.WriteHeader(test.responseStatus)
   130  				_, err := w.Write([]byte(test.responseBody))
   131  				assert.NoError(t, err)
   132  			}))
   133  			client := mockAPIClient(t, mockServer)
   134  			result, err := client.GetCustomDefinedBotList(
   135  				session.ContextWithOptions(
   136  					context.Background(),
   137  				),
   138  				test.params)
   139  			if test.withError != nil {
   140  				test.withError(t, err)
   141  				return
   142  			}
   143  			require.NoError(t, err)
   144  			assert.Equal(t, test.expectedResponse, result)
   145  		})
   146  	}
   147  }
   148  
   149  // Test Get CustomDefinedBot
   150  func TestBotman_GetCustomDefinedBot(t *testing.T) {
   151  	tests := map[string]struct {
   152  		params           GetCustomDefinedBotRequest
   153  		responseStatus   int
   154  		responseBody     string
   155  		expectedPath     string
   156  		expectedResponse map[string]interface{}
   157  		withError        func(*testing.T, error)
   158  	}{
   159  		"200 OK": {
   160  			params: GetCustomDefinedBotRequest{
   161  				ConfigID: 43253,
   162  				Version:  15,
   163  				BotID:    "cc9c3f89-e179-4892-89cf-d5e623ba9dc7",
   164  			},
   165  			responseStatus:   http.StatusOK,
   166  			responseBody:     `{"botId":"cc9c3f89-e179-4892-89cf-d5e623ba9dc7", "testKey":"testValue3"}`,
   167  			expectedPath:     "/appsec/v1/configs/43253/versions/15/custom-defined-bots/cc9c3f89-e179-4892-89cf-d5e623ba9dc7",
   168  			expectedResponse: map[string]interface{}{"botId": "cc9c3f89-e179-4892-89cf-d5e623ba9dc7", "testKey": "testValue3"},
   169  		},
   170  		"500 internal server error": {
   171  			params: GetCustomDefinedBotRequest{
   172  				ConfigID: 43253,
   173  				Version:  15,
   174  				BotID:    "cc9c3f89-e179-4892-89cf-d5e623ba9dc7",
   175  			},
   176  			responseStatus: http.StatusInternalServerError,
   177  			responseBody: `
   178  			{
   179  				"type": "internal_error",
   180  				"title": "Internal Server Error",
   181  				"detail": "Error fetching data"
   182  			}`,
   183  			expectedPath: "/appsec/v1/configs/43253/versions/15/custom-defined-bots/cc9c3f89-e179-4892-89cf-d5e623ba9dc7",
   184  			withError: func(t *testing.T, err error) {
   185  				want := &Error{
   186  					Type:       "internal_error",
   187  					Title:      "Internal Server Error",
   188  					Detail:     "Error fetching data",
   189  					StatusCode: http.StatusInternalServerError,
   190  				}
   191  				assert.True(t, errors.Is(err, want), "want: %s; got: %s", want, err)
   192  			},
   193  		},
   194  		"Missing ConfigID": {
   195  			params: GetCustomDefinedBotRequest{
   196  				Version: 15,
   197  				BotID:   "cc9c3f89-e179-4892-89cf-d5e623ba9dc7",
   198  			},
   199  			withError: func(t *testing.T, err error) {
   200  				want := ErrStructValidation
   201  				assert.True(t, errors.Is(err, want), "want: %s; got: %s", want, err)
   202  				assert.Contains(t, err.Error(), "ConfigID")
   203  			},
   204  		},
   205  		"Missing Version": {
   206  			params: GetCustomDefinedBotRequest{
   207  				ConfigID: 43253,
   208  				BotID:    "cc9c3f89-e179-4892-89cf-d5e623ba9dc7",
   209  			},
   210  			withError: func(t *testing.T, err error) {
   211  				want := ErrStructValidation
   212  				assert.True(t, errors.Is(err, want), "want: %s; got: %s", want, err)
   213  				assert.Contains(t, err.Error(), "Version")
   214  			},
   215  		},
   216  		"Missing BotID": {
   217  			params: GetCustomDefinedBotRequest{
   218  				ConfigID: 43253,
   219  				Version:  15,
   220  			},
   221  			withError: func(t *testing.T, err error) {
   222  				want := ErrStructValidation
   223  				assert.True(t, errors.Is(err, want), "want: %s; got: %s", want, err)
   224  				assert.Contains(t, err.Error(), "BotID")
   225  			},
   226  		},
   227  	}
   228  
   229  	for name, test := range tests {
   230  		t.Run(name, func(t *testing.T) {
   231  			mockServer := httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
   232  				assert.Equal(t, test.expectedPath, r.URL.String())
   233  				assert.Equal(t, http.MethodGet, r.Method)
   234  				w.WriteHeader(test.responseStatus)
   235  				_, err := w.Write([]byte(test.responseBody))
   236  				assert.NoError(t, err)
   237  			}))
   238  			client := mockAPIClient(t, mockServer)
   239  			result, err := client.GetCustomDefinedBot(context.Background(), test.params)
   240  			if test.withError != nil {
   241  				test.withError(t, err)
   242  				return
   243  			}
   244  			require.NoError(t, err)
   245  			assert.Equal(t, test.expectedResponse, result)
   246  		})
   247  	}
   248  }
   249  
   250  // Test Create CustomDefinedBot
   251  func TestBotman_CreateCustomDefinedBot(t *testing.T) {
   252  
   253  	tests := map[string]struct {
   254  		params           CreateCustomDefinedBotRequest
   255  		prop             *CreateCustomDefinedBotRequest
   256  		responseStatus   int
   257  		responseBody     string
   258  		expectedPath     string
   259  		expectedResponse map[string]interface{}
   260  		withError        func(*testing.T, error)
   261  	}{
   262  		"201 Created": {
   263  			params: CreateCustomDefinedBotRequest{
   264  				ConfigID:    43253,
   265  				Version:     15,
   266  				JsonPayload: json.RawMessage(`{"testKey":"testValue3"}`),
   267  			},
   268  			responseStatus:   http.StatusCreated,
   269  			responseBody:     `{"botId":"cc9c3f89-e179-4892-89cf-d5e623ba9dc7", "testKey":"testValue3"}`,
   270  			expectedResponse: map[string]interface{}{"botId": "cc9c3f89-e179-4892-89cf-d5e623ba9dc7", "testKey": "testValue3"},
   271  			expectedPath:     "/appsec/v1/configs/43253/versions/15/custom-defined-bots",
   272  		},
   273  		"500 internal server error": {
   274  			params: CreateCustomDefinedBotRequest{
   275  				ConfigID:    43253,
   276  				Version:     15,
   277  				JsonPayload: json.RawMessage(`{"testKey":"testValue3"}`),
   278  			},
   279  			responseStatus: http.StatusInternalServerError,
   280  			responseBody: `
   281  			{
   282  				"type": "internal_error",
   283  				"title": "Internal Server Error",
   284  				"detail": "Error creating data"
   285  			}`,
   286  			expectedPath: "/appsec/v1/configs/43253/versions/15/custom-defined-bots",
   287  			withError: func(t *testing.T, err error) {
   288  				want := &Error{
   289  					Type:       "internal_error",
   290  					Title:      "Internal Server Error",
   291  					Detail:     "Error creating data",
   292  					StatusCode: http.StatusInternalServerError,
   293  				}
   294  				assert.True(t, errors.Is(err, want), "want: %s; got: %s", want, err)
   295  			},
   296  		},
   297  		"Missing ConfigID": {
   298  			params: CreateCustomDefinedBotRequest{
   299  				Version:     15,
   300  				JsonPayload: json.RawMessage(`{"testKey":"testValue3"}`),
   301  			},
   302  			withError: func(t *testing.T, err error) {
   303  				want := ErrStructValidation
   304  				assert.True(t, errors.Is(err, want), "want: %s; got: %s", want, err)
   305  				assert.Contains(t, err.Error(), "ConfigID")
   306  			},
   307  		},
   308  		"Missing Version": {
   309  			params: CreateCustomDefinedBotRequest{
   310  				ConfigID:    43253,
   311  				JsonPayload: json.RawMessage(`{"testKey":"testValue3"}`),
   312  			},
   313  			withError: func(t *testing.T, err error) {
   314  				want := ErrStructValidation
   315  				assert.True(t, errors.Is(err, want), "want: %s; got: %s", want, err)
   316  				assert.Contains(t, err.Error(), "Version")
   317  			},
   318  		},
   319  		"Missing JsonPayload": {
   320  			params: CreateCustomDefinedBotRequest{
   321  				ConfigID: 43253,
   322  				Version:  15,
   323  			},
   324  			withError: func(t *testing.T, err error) {
   325  				want := ErrStructValidation
   326  				assert.True(t, errors.Is(err, want), "want: %s; got: %s", want, err)
   327  				assert.Contains(t, err.Error(), "JsonPayload")
   328  			},
   329  		},
   330  	}
   331  
   332  	for name, test := range tests {
   333  		t.Run(name, func(t *testing.T) {
   334  			mockServer := httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
   335  				assert.Equal(t, test.expectedPath, r.URL.String())
   336  				assert.Equal(t, http.MethodPost, r.Method)
   337  				w.WriteHeader(test.responseStatus)
   338  				if len(test.responseBody) > 0 {
   339  					_, err := w.Write([]byte(test.responseBody))
   340  					assert.NoError(t, err)
   341  				}
   342  			}))
   343  			client := mockAPIClient(t, mockServer)
   344  			result, err := client.CreateCustomDefinedBot(session.ContextWithOptions(context.Background()), test.params)
   345  			if test.withError != nil {
   346  				test.withError(t, err)
   347  				return
   348  			}
   349  			require.NoError(t, err)
   350  			assert.Equal(t, test.expectedResponse, result)
   351  		})
   352  	}
   353  }
   354  
   355  // Test Update CustomDefinedBot
   356  func TestBotman_UpdateCustomDefinedBot(t *testing.T) {
   357  	tests := map[string]struct {
   358  		params           UpdateCustomDefinedBotRequest
   359  		responseStatus   int
   360  		responseBody     string
   361  		expectedPath     string
   362  		expectedResponse map[string]interface{}
   363  		withError        func(*testing.T, error)
   364  	}{
   365  		"200 Success": {
   366  			params: UpdateCustomDefinedBotRequest{
   367  				ConfigID:    43253,
   368  				Version:     10,
   369  				BotID:       "cc9c3f89-e179-4892-89cf-d5e623ba9dc7",
   370  				JsonPayload: json.RawMessage(`{"botId":"cc9c3f89-e179-4892-89cf-d5e623ba9dc7", "testKey":"testValue3"}`),
   371  			},
   372  			responseStatus:   http.StatusOK,
   373  			responseBody:     `{"botId":"cc9c3f89-e179-4892-89cf-d5e623ba9dc7", "testKey":"testValue3"}`,
   374  			expectedResponse: map[string]interface{}{"botId": "cc9c3f89-e179-4892-89cf-d5e623ba9dc7", "testKey": "testValue3"},
   375  			expectedPath:     "/appsec/v1/configs/43253/versions/10/custom-defined-bots/cc9c3f89-e179-4892-89cf-d5e623ba9dc7",
   376  		},
   377  		"500 internal server error": {
   378  			params: UpdateCustomDefinedBotRequest{
   379  				ConfigID:    43253,
   380  				Version:     10,
   381  				BotID:       "cc9c3f89-e179-4892-89cf-d5e623ba9dc7",
   382  				JsonPayload: json.RawMessage(`{"botId":"cc9c3f89-e179-4892-89cf-d5e623ba9dc7", "testKey":"testValue3"}`),
   383  			},
   384  			responseStatus: http.StatusInternalServerError,
   385  			responseBody: `
   386  			{
   387  				"type": "internal_error",
   388  				"title": "Internal Server Error",
   389  				"detail": "Error creating zone"
   390  			}`,
   391  			expectedPath: "/appsec/v1/configs/43253/versions/10/custom-defined-bots/cc9c3f89-e179-4892-89cf-d5e623ba9dc7",
   392  			withError: func(t *testing.T, err error) {
   393  				want := &Error{
   394  					Type:       "internal_error",
   395  					Title:      "Internal Server Error",
   396  					Detail:     "Error creating zone",
   397  					StatusCode: http.StatusInternalServerError,
   398  				}
   399  				assert.True(t, errors.Is(err, want), "want: %s; got: %s", want, err)
   400  			},
   401  		},
   402  		"Missing ConfigID": {
   403  			params: UpdateCustomDefinedBotRequest{
   404  				Version:     15,
   405  				BotID:       "cc9c3f89-e179-4892-89cf-d5e623ba9dc7",
   406  				JsonPayload: json.RawMessage(`{"botId":"cc9c3f89-e179-4892-89cf-d5e623ba9dc7", "testKey":"testValue3"}`),
   407  			},
   408  			withError: func(t *testing.T, err error) {
   409  				want := ErrStructValidation
   410  				assert.True(t, errors.Is(err, want), "want: %s; got: %s", want, err)
   411  				assert.Contains(t, err.Error(), "ConfigID")
   412  			},
   413  		},
   414  		"Missing Version": {
   415  			params: UpdateCustomDefinedBotRequest{
   416  				ConfigID:    43253,
   417  				BotID:       "cc9c3f89-e179-4892-89cf-d5e623ba9dc7",
   418  				JsonPayload: json.RawMessage(`{"botId":"cc9c3f89-e179-4892-89cf-d5e623ba9dc7", "testKey":"testValue3"}`),
   419  			},
   420  			withError: func(t *testing.T, err error) {
   421  				want := ErrStructValidation
   422  				assert.True(t, errors.Is(err, want), "want: %s; got: %s", want, err)
   423  				assert.Contains(t, err.Error(), "Version")
   424  			},
   425  		},
   426  		"Missing JsonPayload": {
   427  			params: UpdateCustomDefinedBotRequest{
   428  				ConfigID: 43253,
   429  				Version:  15,
   430  				BotID:    "cc9c3f89-e179-4892-89cf-d5e623ba9dc7",
   431  			},
   432  			withError: func(t *testing.T, err error) {
   433  				want := ErrStructValidation
   434  				assert.True(t, errors.Is(err, want), "want: %s; got: %s", want, err)
   435  				assert.Contains(t, err.Error(), "JsonPayload")
   436  			},
   437  		},
   438  		"Missing BotID": {
   439  			params: UpdateCustomDefinedBotRequest{
   440  				ConfigID:    43253,
   441  				Version:     15,
   442  				JsonPayload: json.RawMessage(`{"botId":"cc9c3f89-e179-4892-89cf-d5e623ba9dc7", "testKey":"testValue3"}`),
   443  			},
   444  			withError: func(t *testing.T, err error) {
   445  				want := ErrStructValidation
   446  				assert.True(t, errors.Is(err, want), "want: %s; got: %s", want, err)
   447  				assert.Contains(t, err.Error(), "BotID")
   448  			},
   449  		},
   450  	}
   451  
   452  	for name, test := range tests {
   453  		t.Run(name, func(t *testing.T) {
   454  			mockServer := httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
   455  				assert.Equal(t, test.expectedPath, r.URL.Path)
   456  				assert.Equal(t, http.MethodPut, r.Method)
   457  				w.WriteHeader(test.responseStatus)
   458  				if len(test.responseBody) > 0 {
   459  					_, err := w.Write([]byte(test.responseBody))
   460  					assert.NoError(t, err)
   461  				}
   462  			}))
   463  			client := mockAPIClient(t, mockServer)
   464  			result, err := client.UpdateCustomDefinedBot(session.ContextWithOptions(context.Background()), test.params)
   465  			if test.withError != nil {
   466  				test.withError(t, err)
   467  				return
   468  			}
   469  			require.NoError(t, err)
   470  			assert.Equal(t, test.expectedResponse, result)
   471  		})
   472  	}
   473  }
   474  
   475  // Test Remove CustomDefinedBot
   476  func TestBotman_RemoveCustomDefinedBot(t *testing.T) {
   477  	tests := map[string]struct {
   478  		params           RemoveCustomDefinedBotRequest
   479  		responseStatus   int
   480  		responseBody     string
   481  		expectedPath     string
   482  		expectedResponse map[string]interface{}
   483  		withError        func(*testing.T, error)
   484  	}{
   485  		"200 Success": {
   486  			params: RemoveCustomDefinedBotRequest{
   487  				ConfigID: 43253,
   488  				Version:  10,
   489  				BotID:    "cc9c3f89-e179-4892-89cf-d5e623ba9dc7",
   490  			},
   491  			responseStatus: http.StatusNoContent,
   492  			expectedPath:   "/appsec/v1/configs/43253/versions/10/custom-defined-bots/cc9c3f89-e179-4892-89cf-d5e623ba9dc7",
   493  		},
   494  		"500 internal server error": {
   495  			params: RemoveCustomDefinedBotRequest{
   496  				ConfigID: 43253,
   497  				Version:  10,
   498  				BotID:    "cc9c3f89-e179-4892-89cf-d5e623ba9dc7",
   499  			},
   500  			responseStatus: http.StatusInternalServerError,
   501  			responseBody: `
   502  			{
   503  				"type": "internal_error",
   504  				"title": "Internal Server Error",
   505  				"detail": "Error deleting match target"
   506  			}`,
   507  			expectedPath: "/appsec/v1/configs/43253/versions/10/custom-defined-bots/cc9c3f89-e179-4892-89cf-d5e623ba9dc7",
   508  			withError: func(t *testing.T, err error) {
   509  				want := &Error{
   510  					Type:       "internal_error",
   511  					Title:      "Internal Server Error",
   512  					Detail:     "Error deleting match target",
   513  					StatusCode: http.StatusInternalServerError,
   514  				}
   515  				assert.True(t, errors.Is(err, want), "want: %s; got: %s", want, err)
   516  			},
   517  		},
   518  		"Missing ConfigID": {
   519  			params: RemoveCustomDefinedBotRequest{
   520  				Version: 15,
   521  				BotID:   "cc9c3f89-e179-4892-89cf-d5e623ba9dc7",
   522  			},
   523  			withError: func(t *testing.T, err error) {
   524  				want := ErrStructValidation
   525  				assert.True(t, errors.Is(err, want), "want: %s; got: %s", want, err)
   526  				assert.Contains(t, err.Error(), "ConfigID")
   527  			},
   528  		},
   529  		"Missing Version": {
   530  			params: RemoveCustomDefinedBotRequest{
   531  				ConfigID: 43253,
   532  				BotID:    "cc9c3f89-e179-4892-89cf-d5e623ba9dc7",
   533  			},
   534  			withError: func(t *testing.T, err error) {
   535  				want := ErrStructValidation
   536  				assert.True(t, errors.Is(err, want), "want: %s; got: %s", want, err)
   537  				assert.Contains(t, err.Error(), "Version")
   538  			},
   539  		},
   540  		"Missing BotID": {
   541  			params: RemoveCustomDefinedBotRequest{
   542  				ConfigID: 43253,
   543  				Version:  15,
   544  			},
   545  			withError: func(t *testing.T, err error) {
   546  				want := ErrStructValidation
   547  				assert.True(t, errors.Is(err, want), "want: %s; got: %s", want, err)
   548  				assert.Contains(t, err.Error(), "BotID")
   549  			},
   550  		},
   551  	}
   552  
   553  	for name, test := range tests {
   554  		t.Run(name, func(t *testing.T) {
   555  			mockServer := httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
   556  				assert.Equal(t, test.expectedPath, r.URL.Path)
   557  				assert.Equal(t, http.MethodDelete, r.Method)
   558  				w.WriteHeader(test.responseStatus)
   559  				if len(test.responseBody) > 0 {
   560  					_, err := w.Write([]byte(test.responseBody))
   561  					assert.NoError(t, err)
   562  				}
   563  			}))
   564  			client := mockAPIClient(t, mockServer)
   565  			err := client.RemoveCustomDefinedBot(session.ContextWithOptions(context.Background()), test.params)
   566  			if test.withError != nil {
   567  				test.withError(t, err)
   568  				return
   569  			}
   570  			require.NoError(t, err)
   571  		})
   572  	}
   573  }