// Code generated by lark_sdk_gen. DO NOT EDIT.
/**
 * Copyright 2022 chyroc
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package test

import (
	"context"
	"fmt"
	"testing"

	"github.com/stretchr/testify/assert"

	"github.com/chyroc/lark"
)

func Test_Admin_Sample_Failed(t *testing.T) {
	as := assert.New(t)

	t.Run("request failed", func(t *testing.T) {
		cli := AppAllPermission.Ins()
		cli.Mock().MockGetTenantAccessToken(mockGetTenantAccessTokenFailed)
		cli.Mock().MockGetAppAccessToken(mockGetTenantAccessTokenFailed)
		moduleCli := cli.Admin

		t.Run("", func(t *testing.T) {

			_, _, err := moduleCli.AdminResetPassword(ctx, &lark.AdminResetPasswordReq{})
			as.NotNil(err)
			as.Equal(err.Error(), "failed")
		})

	})

	t.Run("request mock failed", func(t *testing.T) {
		cli := AppAllPermission.Ins()
		moduleCli := cli.Admin

		t.Run("", func(t *testing.T) {

			cli.Mock().MockAdminAdminResetPassword(func(ctx context.Context, request *lark.AdminResetPasswordReq, options ...lark.MethodOptionFunc) (*lark.AdminResetPasswordResp, *lark.Response, error) {
				return nil, nil, fmt.Errorf("mock-failed")
			})
			defer cli.Mock().UnMockAdminAdminResetPassword()

			_, _, err := moduleCli.AdminResetPassword(ctx, &lark.AdminResetPasswordReq{})
			as.NotNil(err)
			as.Equal(err.Error(), "mock-failed")
		})

		t.Run("", func(t *testing.T) {

			cli.Mock().MockAdminGetAdminDeptStats(func(ctx context.Context, request *lark.GetAdminDeptStatsReq, options ...lark.MethodOptionFunc) (*lark.GetAdminDeptStatsResp, *lark.Response, error) {
				return nil, nil, fmt.Errorf("mock-failed")
			})
			defer cli.Mock().UnMockAdminGetAdminDeptStats()

			_, _, err := moduleCli.GetAdminDeptStats(ctx, &lark.GetAdminDeptStatsReq{})
			as.NotNil(err)
			as.Equal(err.Error(), "mock-failed")
		})

		t.Run("", func(t *testing.T) {

			cli.Mock().MockAdminGetAdminUserStats(func(ctx context.Context, request *lark.GetAdminUserStatsReq, options ...lark.MethodOptionFunc) (*lark.GetAdminUserStatsResp, *lark.Response, error) {
				return nil, nil, fmt.Errorf("mock-failed")
			})
			defer cli.Mock().UnMockAdminGetAdminUserStats()

			_, _, err := moduleCli.GetAdminUserStats(ctx, &lark.GetAdminUserStatsReq{})
			as.NotNil(err)
			as.Equal(err.Error(), "mock-failed")
		})

		t.Run("", func(t *testing.T) {

			cli.Mock().MockAdminUploadAdminBadgeImage(func(ctx context.Context, request *lark.UploadAdminBadgeImageReq, options ...lark.MethodOptionFunc) (*lark.UploadAdminBadgeImageResp, *lark.Response, error) {
				return nil, nil, fmt.Errorf("mock-failed")
			})
			defer cli.Mock().UnMockAdminUploadAdminBadgeImage()

			_, _, err := moduleCli.UploadAdminBadgeImage(ctx, &lark.UploadAdminBadgeImageReq{})
			as.NotNil(err)
			as.Equal(err.Error(), "mock-failed")
		})

		t.Run("", func(t *testing.T) {

			cli.Mock().MockAdminCreateAdminBadge(func(ctx context.Context, request *lark.CreateAdminBadgeReq, options ...lark.MethodOptionFunc) (*lark.CreateAdminBadgeResp, *lark.Response, error) {
				return nil, nil, fmt.Errorf("mock-failed")
			})
			defer cli.Mock().UnMockAdminCreateAdminBadge()

			_, _, err := moduleCli.CreateAdminBadge(ctx, &lark.CreateAdminBadgeReq{})
			as.NotNil(err)
			as.Equal(err.Error(), "mock-failed")
		})

		t.Run("", func(t *testing.T) {

			cli.Mock().MockAdminUpdateAdminBadge(func(ctx context.Context, request *lark.UpdateAdminBadgeReq, options ...lark.MethodOptionFunc) (*lark.UpdateAdminBadgeResp, *lark.Response, error) {
				return nil, nil, fmt.Errorf("mock-failed")
			})
			defer cli.Mock().UnMockAdminUpdateAdminBadge()

			_, _, err := moduleCli.UpdateAdminBadge(ctx, &lark.UpdateAdminBadgeReq{})
			as.NotNil(err)
			as.Equal(err.Error(), "mock-failed")
		})

		t.Run("", func(t *testing.T) {

			cli.Mock().MockAdminGetAdminBadgeList(func(ctx context.Context, request *lark.GetAdminBadgeListReq, options ...lark.MethodOptionFunc) (*lark.GetAdminBadgeListResp, *lark.Response, error) {
				return nil, nil, fmt.Errorf("mock-failed")
			})
			defer cli.Mock().UnMockAdminGetAdminBadgeList()

			_, _, err := moduleCli.GetAdminBadgeList(ctx, &lark.GetAdminBadgeListReq{})
			as.NotNil(err)
			as.Equal(err.Error(), "mock-failed")
		})

		t.Run("", func(t *testing.T) {

			cli.Mock().MockAdminGetAdminBadge(func(ctx context.Context, request *lark.GetAdminBadgeReq, options ...lark.MethodOptionFunc) (*lark.GetAdminBadgeResp, *lark.Response, error) {
				return nil, nil, fmt.Errorf("mock-failed")
			})
			defer cli.Mock().UnMockAdminGetAdminBadge()

			_, _, err := moduleCli.GetAdminBadge(ctx, &lark.GetAdminBadgeReq{})
			as.NotNil(err)
			as.Equal(err.Error(), "mock-failed")
		})

		t.Run("", func(t *testing.T) {

			cli.Mock().MockAdminCreateAdminBadgeGrant(func(ctx context.Context, request *lark.CreateAdminBadgeGrantReq, options ...lark.MethodOptionFunc) (*lark.CreateAdminBadgeGrantResp, *lark.Response, error) {
				return nil, nil, fmt.Errorf("mock-failed")
			})
			defer cli.Mock().UnMockAdminCreateAdminBadgeGrant()

			_, _, err := moduleCli.CreateAdminBadgeGrant(ctx, &lark.CreateAdminBadgeGrantReq{})
			as.NotNil(err)
			as.Equal(err.Error(), "mock-failed")
		})

		t.Run("", func(t *testing.T) {

			cli.Mock().MockAdminUpdateAdminBadgeGrant(func(ctx context.Context, request *lark.UpdateAdminBadgeGrantReq, options ...lark.MethodOptionFunc) (*lark.UpdateAdminBadgeGrantResp, *lark.Response, error) {
				return nil, nil, fmt.Errorf("mock-failed")
			})
			defer cli.Mock().UnMockAdminUpdateAdminBadgeGrant()

			_, _, err := moduleCli.UpdateAdminBadgeGrant(ctx, &lark.UpdateAdminBadgeGrantReq{})
			as.NotNil(err)
			as.Equal(err.Error(), "mock-failed")
		})

		t.Run("", func(t *testing.T) {

			cli.Mock().MockAdminGetAdminBadgeGrantList(func(ctx context.Context, request *lark.GetAdminBadgeGrantListReq, options ...lark.MethodOptionFunc) (*lark.GetAdminBadgeGrantListResp, *lark.Response, error) {
				return nil, nil, fmt.Errorf("mock-failed")
			})
			defer cli.Mock().UnMockAdminGetAdminBadgeGrantList()

			_, _, err := moduleCli.GetAdminBadgeGrantList(ctx, &lark.GetAdminBadgeGrantListReq{})
			as.NotNil(err)
			as.Equal(err.Error(), "mock-failed")
		})

		t.Run("", func(t *testing.T) {

			cli.Mock().MockAdminGetAdminBadgeGrant(func(ctx context.Context, request *lark.GetAdminBadgeGrantReq, options ...lark.MethodOptionFunc) (*lark.GetAdminBadgeGrantResp, *lark.Response, error) {
				return nil, nil, fmt.Errorf("mock-failed")
			})
			defer cli.Mock().UnMockAdminGetAdminBadgeGrant()

			_, _, err := moduleCli.GetAdminBadgeGrant(ctx, &lark.GetAdminBadgeGrantReq{})
			as.NotNil(err)
			as.Equal(err.Error(), "mock-failed")
		})

		t.Run("", func(t *testing.T) {

			cli.Mock().MockAdminDeleteAdminBadgeGrant(func(ctx context.Context, request *lark.DeleteAdminBadgeGrantReq, options ...lark.MethodOptionFunc) (*lark.DeleteAdminBadgeGrantResp, *lark.Response, error) {
				return nil, nil, fmt.Errorf("mock-failed")
			})
			defer cli.Mock().UnMockAdminDeleteAdminBadgeGrant()

			_, _, err := moduleCli.DeleteAdminBadgeGrant(ctx, &lark.DeleteAdminBadgeGrantReq{})
			as.NotNil(err)
			as.Equal(err.Error(), "mock-failed")
		})

	})

	t.Run("response is failed", func(t *testing.T) {
		cli := AppNoPermission.Ins()
		moduleCli := cli.Admin

		t.Run("", func(t *testing.T) {

			_, _, err := moduleCli.AdminResetPassword(ctx, &lark.AdminResetPasswordReq{})
			as.NotNil(err)
			as.True(lark.GetErrorCode(err) > 0, fmt.Sprintf("need get lark err, but get %s", err))
		})

		t.Run("", func(t *testing.T) {

			_, _, err := moduleCli.GetAdminDeptStats(ctx, &lark.GetAdminDeptStatsReq{})
			as.NotNil(err)
			as.True(lark.GetErrorCode(err) > 0, fmt.Sprintf("need get lark err, but get %s", err))
		})

		t.Run("", func(t *testing.T) {

			_, _, err := moduleCli.GetAdminUserStats(ctx, &lark.GetAdminUserStatsReq{})
			as.NotNil(err)
			as.True(lark.GetErrorCode(err) > 0, fmt.Sprintf("need get lark err, but get %s", err))
		})

		t.Run("", func(t *testing.T) {

			_, _, err := moduleCli.UploadAdminBadgeImage(ctx, &lark.UploadAdminBadgeImageReq{})
			as.NotNil(err)
			as.True(lark.GetErrorCode(err) > 0, fmt.Sprintf("need get lark err, but get %s", err))
		})

		t.Run("", func(t *testing.T) {

			_, _, err := moduleCli.CreateAdminBadge(ctx, &lark.CreateAdminBadgeReq{})
			as.NotNil(err)
			as.True(lark.GetErrorCode(err) > 0, fmt.Sprintf("need get lark err, but get %s", err))
		})

		t.Run("", func(t *testing.T) {

			_, _, err := moduleCli.UpdateAdminBadge(ctx, &lark.UpdateAdminBadgeReq{
				BadgeID: "x",
			})
			as.NotNil(err)
			as.True(lark.GetErrorCode(err) > 0, fmt.Sprintf("need get lark err, but get %s", err))
		})

		t.Run("", func(t *testing.T) {

			_, _, err := moduleCli.GetAdminBadgeList(ctx, &lark.GetAdminBadgeListReq{})
			as.NotNil(err)
			as.True(lark.GetErrorCode(err) > 0, fmt.Sprintf("need get lark err, but get %s", err))
		})

		t.Run("", func(t *testing.T) {

			_, _, err := moduleCli.GetAdminBadge(ctx, &lark.GetAdminBadgeReq{
				BadgeID: "x",
			})
			as.NotNil(err)
			as.True(lark.GetErrorCode(err) > 0, fmt.Sprintf("need get lark err, but get %s", err))
		})

		t.Run("", func(t *testing.T) {

			_, _, err := moduleCli.CreateAdminBadgeGrant(ctx, &lark.CreateAdminBadgeGrantReq{
				BadgeID: "x",
			})
			as.NotNil(err)
			as.True(lark.GetErrorCode(err) > 0, fmt.Sprintf("need get lark err, but get %s", err))
		})

		t.Run("", func(t *testing.T) {

			_, _, err := moduleCli.UpdateAdminBadgeGrant(ctx, &lark.UpdateAdminBadgeGrantReq{
				BadgeID: "x",
				GrantID: "x",
			})
			as.NotNil(err)
			as.True(lark.GetErrorCode(err) > 0, fmt.Sprintf("need get lark err, but get %s", err))
		})

		t.Run("", func(t *testing.T) {

			_, _, err := moduleCli.GetAdminBadgeGrantList(ctx, &lark.GetAdminBadgeGrantListReq{
				BadgeID: "x",
			})
			as.NotNil(err)
			as.True(lark.GetErrorCode(err) > 0, fmt.Sprintf("need get lark err, but get %s", err))
		})

		t.Run("", func(t *testing.T) {

			_, _, err := moduleCli.GetAdminBadgeGrant(ctx, &lark.GetAdminBadgeGrantReq{
				BadgeID: "x",
				GrantID: "x",
			})
			as.NotNil(err)
			as.True(lark.GetErrorCode(err) > 0, fmt.Sprintf("need get lark err, but get %s", err))
		})

		t.Run("", func(t *testing.T) {

			_, _, err := moduleCli.DeleteAdminBadgeGrant(ctx, &lark.DeleteAdminBadgeGrantReq{
				BadgeID: "x",
				GrantID: "x",
			})
			as.NotNil(err)
			as.True(lark.GetErrorCode(err) > 0, fmt.Sprintf("need get lark err, but get %s", err))
		})

	})

	t.Run("fake request is failed", func(t *testing.T) {
		cli := AppAllPermission.Ins()
		moduleCli := cli.Admin
		cli.Mock().MockRawRequest(func(ctx context.Context, req *lark.RawRequestReq, resp interface{}) (response *lark.Response, err error) {
			return nil, fmt.Errorf("fake raw request")
		})

		t.Run("", func(t *testing.T) {

			_, _, err := moduleCli.AdminResetPassword(ctx, &lark.AdminResetPasswordReq{})
			as.NotNil(err)
			as.Equal("fake raw request", err.Error())
		})

		t.Run("", func(t *testing.T) {

			_, _, err := moduleCli.GetAdminDeptStats(ctx, &lark.GetAdminDeptStatsReq{})
			as.NotNil(err)
			as.Equal("fake raw request", err.Error())
		})

		t.Run("", func(t *testing.T) {

			_, _, err := moduleCli.GetAdminUserStats(ctx, &lark.GetAdminUserStatsReq{})
			as.NotNil(err)
			as.Equal("fake raw request", err.Error())
		})

		t.Run("", func(t *testing.T) {

			_, _, err := moduleCli.UploadAdminBadgeImage(ctx, &lark.UploadAdminBadgeImageReq{})
			as.NotNil(err)
			as.Equal("fake raw request", err.Error())
		})

		t.Run("", func(t *testing.T) {

			_, _, err := moduleCli.CreateAdminBadge(ctx, &lark.CreateAdminBadgeReq{})
			as.NotNil(err)
			as.Equal("fake raw request", err.Error())
		})

		t.Run("", func(t *testing.T) {

			_, _, err := moduleCli.UpdateAdminBadge(ctx, &lark.UpdateAdminBadgeReq{
				BadgeID: "x",
			})
			as.NotNil(err)
			as.Equal("fake raw request", err.Error())
		})

		t.Run("", func(t *testing.T) {

			_, _, err := moduleCli.GetAdminBadgeList(ctx, &lark.GetAdminBadgeListReq{})
			as.NotNil(err)
			as.Equal("fake raw request", err.Error())
		})

		t.Run("", func(t *testing.T) {

			_, _, err := moduleCli.GetAdminBadge(ctx, &lark.GetAdminBadgeReq{
				BadgeID: "x",
			})
			as.NotNil(err)
			as.Equal("fake raw request", err.Error())
		})

		t.Run("", func(t *testing.T) {

			_, _, err := moduleCli.CreateAdminBadgeGrant(ctx, &lark.CreateAdminBadgeGrantReq{
				BadgeID: "x",
			})
			as.NotNil(err)
			as.Equal("fake raw request", err.Error())
		})

		t.Run("", func(t *testing.T) {

			_, _, err := moduleCli.UpdateAdminBadgeGrant(ctx, &lark.UpdateAdminBadgeGrantReq{
				BadgeID: "x",
				GrantID: "x",
			})
			as.NotNil(err)
			as.Equal("fake raw request", err.Error())
		})

		t.Run("", func(t *testing.T) {

			_, _, err := moduleCli.GetAdminBadgeGrantList(ctx, &lark.GetAdminBadgeGrantListReq{
				BadgeID: "x",
			})
			as.NotNil(err)
			as.Equal("fake raw request", err.Error())
		})

		t.Run("", func(t *testing.T) {

			_, _, err := moduleCli.GetAdminBadgeGrant(ctx, &lark.GetAdminBadgeGrantReq{
				BadgeID: "x",
				GrantID: "x",
			})
			as.NotNil(err)
			as.Equal("fake raw request", err.Error())
		})

		t.Run("", func(t *testing.T) {

			_, _, err := moduleCli.DeleteAdminBadgeGrant(ctx, &lark.DeleteAdminBadgeGrantReq{
				BadgeID: "x",
				GrantID: "x",
			})
			as.NotNil(err)
			as.Equal("fake raw request", err.Error())
		})

	})
}
