// 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_Lingo_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.Lingo

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

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

	})

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

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

			cli.Mock().MockLingoCreateLingoDraft(func(ctx context.Context, request *lark.CreateLingoDraftReq, options ...lark.MethodOptionFunc) (*lark.CreateLingoDraftResp, *lark.Response, error) {
				return nil, nil, fmt.Errorf("mock-failed")
			})
			defer cli.Mock().UnMockLingoCreateLingoDraft()

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

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

			cli.Mock().MockLingoUpdateLingoDraft(func(ctx context.Context, request *lark.UpdateLingoDraftReq, options ...lark.MethodOptionFunc) (*lark.UpdateLingoDraftResp, *lark.Response, error) {
				return nil, nil, fmt.Errorf("mock-failed")
			})
			defer cli.Mock().UnMockLingoUpdateLingoDraft()

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

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

			cli.Mock().MockLingoDeleteLingoEntity(func(ctx context.Context, request *lark.DeleteLingoEntityReq, options ...lark.MethodOptionFunc) (*lark.DeleteLingoEntityResp, *lark.Response, error) {
				return nil, nil, fmt.Errorf("mock-failed")
			})
			defer cli.Mock().UnMockLingoDeleteLingoEntity()

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

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

			cli.Mock().MockLingoCreateLingoEntity(func(ctx context.Context, request *lark.CreateLingoEntityReq, options ...lark.MethodOptionFunc) (*lark.CreateLingoEntityResp, *lark.Response, error) {
				return nil, nil, fmt.Errorf("mock-failed")
			})
			defer cli.Mock().UnMockLingoCreateLingoEntity()

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

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

			cli.Mock().MockLingoUpdateLingoEntity(func(ctx context.Context, request *lark.UpdateLingoEntityReq, options ...lark.MethodOptionFunc) (*lark.UpdateLingoEntityResp, *lark.Response, error) {
				return nil, nil, fmt.Errorf("mock-failed")
			})
			defer cli.Mock().UnMockLingoUpdateLingoEntity()

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

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

			cli.Mock().MockLingoGetLingoEntity(func(ctx context.Context, request *lark.GetLingoEntityReq, options ...lark.MethodOptionFunc) (*lark.GetLingoEntityResp, *lark.Response, error) {
				return nil, nil, fmt.Errorf("mock-failed")
			})
			defer cli.Mock().UnMockLingoGetLingoEntity()

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

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

			cli.Mock().MockLingoGetLingoEntityList(func(ctx context.Context, request *lark.GetLingoEntityListReq, options ...lark.MethodOptionFunc) (*lark.GetLingoEntityListResp, *lark.Response, error) {
				return nil, nil, fmt.Errorf("mock-failed")
			})
			defer cli.Mock().UnMockLingoGetLingoEntityList()

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

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

			cli.Mock().MockLingoMatchLingoEntity(func(ctx context.Context, request *lark.MatchLingoEntityReq, options ...lark.MethodOptionFunc) (*lark.MatchLingoEntityResp, *lark.Response, error) {
				return nil, nil, fmt.Errorf("mock-failed")
			})
			defer cli.Mock().UnMockLingoMatchLingoEntity()

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

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

			cli.Mock().MockLingoSearchLingoEntity(func(ctx context.Context, request *lark.SearchLingoEntityReq, options ...lark.MethodOptionFunc) (*lark.SearchLingoEntityResp, *lark.Response, error) {
				return nil, nil, fmt.Errorf("mock-failed")
			})
			defer cli.Mock().UnMockLingoSearchLingoEntity()

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

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

			cli.Mock().MockLingoHighlightLingoEntity(func(ctx context.Context, request *lark.HighlightLingoEntityReq, options ...lark.MethodOptionFunc) (*lark.HighlightLingoEntityResp, *lark.Response, error) {
				return nil, nil, fmt.Errorf("mock-failed")
			})
			defer cli.Mock().UnMockLingoHighlightLingoEntity()

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

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

			cli.Mock().MockLingoExtractLingoEntity(func(ctx context.Context, request *lark.ExtractLingoEntityReq, options ...lark.MethodOptionFunc) (*lark.ExtractLingoEntityResp, *lark.Response, error) {
				return nil, nil, fmt.Errorf("mock-failed")
			})
			defer cli.Mock().UnMockLingoExtractLingoEntity()

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

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

			cli.Mock().MockLingoGetLingoClassificationList(func(ctx context.Context, request *lark.GetLingoClassificationListReq, options ...lark.MethodOptionFunc) (*lark.GetLingoClassificationListResp, *lark.Response, error) {
				return nil, nil, fmt.Errorf("mock-failed")
			})
			defer cli.Mock().UnMockLingoGetLingoClassificationList()

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

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

			cli.Mock().MockLingoGetLingoRepoList(func(ctx context.Context, request *lark.GetLingoRepoListReq, options ...lark.MethodOptionFunc) (*lark.GetLingoRepoListResp, *lark.Response, error) {
				return nil, nil, fmt.Errorf("mock-failed")
			})
			defer cli.Mock().UnMockLingoGetLingoRepoList()

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

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

			cli.Mock().MockLingoUploadLingoFile(func(ctx context.Context, request *lark.UploadLingoFileReq, options ...lark.MethodOptionFunc) (*lark.UploadLingoFileResp, *lark.Response, error) {
				return nil, nil, fmt.Errorf("mock-failed")
			})
			defer cli.Mock().UnMockLingoUploadLingoFile()

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

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

			cli.Mock().MockLingoDownloadLingoFile(func(ctx context.Context, request *lark.DownloadLingoFileReq, options ...lark.MethodOptionFunc) (*lark.DownloadLingoFileResp, *lark.Response, error) {
				return nil, nil, fmt.Errorf("mock-failed")
			})
			defer cli.Mock().UnMockLingoDownloadLingoFile()

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

	})

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

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

			_, _, err := moduleCli.CreateLingoDraft(ctx, &lark.CreateLingoDraftReq{})
			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.UpdateLingoDraft(ctx, &lark.UpdateLingoDraftReq{
				DraftID: "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.DeleteLingoEntity(ctx, &lark.DeleteLingoEntityReq{
				EntityID: "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.CreateLingoEntity(ctx, &lark.CreateLingoEntityReq{})
			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.UpdateLingoEntity(ctx, &lark.UpdateLingoEntityReq{
				EntityID: "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.GetLingoEntity(ctx, &lark.GetLingoEntityReq{
				EntityID: "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.GetLingoEntityList(ctx, &lark.GetLingoEntityListReq{})
			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.MatchLingoEntity(ctx, &lark.MatchLingoEntityReq{})
			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.SearchLingoEntity(ctx, &lark.SearchLingoEntityReq{})
			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.HighlightLingoEntity(ctx, &lark.HighlightLingoEntityReq{})
			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.ExtractLingoEntity(ctx, &lark.ExtractLingoEntityReq{})
			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.GetLingoClassificationList(ctx, &lark.GetLingoClassificationListReq{})
			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.GetLingoRepoList(ctx, &lark.GetLingoRepoListReq{})
			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.UploadLingoFile(ctx, &lark.UploadLingoFileReq{})
			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.DownloadLingoFile(ctx, &lark.DownloadLingoFileReq{
				FileToken: "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.Lingo
		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.CreateLingoDraft(ctx, &lark.CreateLingoDraftReq{})
			as.NotNil(err)
			as.Equal("fake raw request", err.Error())
		})

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

			_, _, err := moduleCli.UpdateLingoDraft(ctx, &lark.UpdateLingoDraftReq{
				DraftID: "x",
			})
			as.NotNil(err)
			as.Equal("fake raw request", err.Error())
		})

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

			_, _, err := moduleCli.DeleteLingoEntity(ctx, &lark.DeleteLingoEntityReq{
				EntityID: "x",
			})
			as.NotNil(err)
			as.Equal("fake raw request", err.Error())
		})

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

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

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

			_, _, err := moduleCli.UpdateLingoEntity(ctx, &lark.UpdateLingoEntityReq{
				EntityID: "x",
			})
			as.NotNil(err)
			as.Equal("fake raw request", err.Error())
		})

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

			_, _, err := moduleCli.GetLingoEntity(ctx, &lark.GetLingoEntityReq{
				EntityID: "x",
			})
			as.NotNil(err)
			as.Equal("fake raw request", err.Error())
		})

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

			_, _, err := moduleCli.DownloadLingoFile(ctx, &lark.DownloadLingoFileReq{
				FileToken: "x",
			})
			as.NotNil(err)
			as.Equal("fake raw request", err.Error())
		})

	})
}
