// 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_OKR_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.OKR

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

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

	})

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

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

			cli.Mock().MockOKRCreateOKRPeriod(func(ctx context.Context, request *lark.CreateOKRPeriodReq, options ...lark.MethodOptionFunc) (*lark.CreateOKRPeriodResp, *lark.Response, error) {
				return nil, nil, fmt.Errorf("mock-failed")
			})
			defer cli.Mock().UnMockOKRCreateOKRPeriod()

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

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

			cli.Mock().MockOKRUpdateOKRPeriod(func(ctx context.Context, request *lark.UpdateOKRPeriodReq, options ...lark.MethodOptionFunc) (*lark.UpdateOKRPeriodResp, *lark.Response, error) {
				return nil, nil, fmt.Errorf("mock-failed")
			})
			defer cli.Mock().UnMockOKRUpdateOKRPeriod()

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

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

			cli.Mock().MockOKRGetOKRPeriodList(func(ctx context.Context, request *lark.GetOKRPeriodListReq, options ...lark.MethodOptionFunc) (*lark.GetOKRPeriodListResp, *lark.Response, error) {
				return nil, nil, fmt.Errorf("mock-failed")
			})
			defer cli.Mock().UnMockOKRGetOKRPeriodList()

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

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

			cli.Mock().MockOKRGetOKRPeriodRuleList(func(ctx context.Context, request *lark.GetOKRPeriodRuleListReq, options ...lark.MethodOptionFunc) (*lark.GetOKRPeriodRuleListResp, *lark.Response, error) {
				return nil, nil, fmt.Errorf("mock-failed")
			})
			defer cli.Mock().UnMockOKRGetOKRPeriodRuleList()

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

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

			cli.Mock().MockOKRBatchGetOKR(func(ctx context.Context, request *lark.BatchGetOKRReq, options ...lark.MethodOptionFunc) (*lark.BatchGetOKRResp, *lark.Response, error) {
				return nil, nil, fmt.Errorf("mock-failed")
			})
			defer cli.Mock().UnMockOKRBatchGetOKR()

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

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

			cli.Mock().MockOKRGetUserOKRList(func(ctx context.Context, request *lark.GetUserOKRListReq, options ...lark.MethodOptionFunc) (*lark.GetUserOKRListResp, *lark.Response, error) {
				return nil, nil, fmt.Errorf("mock-failed")
			})
			defer cli.Mock().UnMockOKRGetUserOKRList()

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

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

			cli.Mock().MockOKRDeleteOKRProgressRecord(func(ctx context.Context, request *lark.DeleteOKRProgressRecordReq, options ...lark.MethodOptionFunc) (*lark.DeleteOKRProgressRecordResp, *lark.Response, error) {
				return nil, nil, fmt.Errorf("mock-failed")
			})
			defer cli.Mock().UnMockOKRDeleteOKRProgressRecord()

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

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

			cli.Mock().MockOKRUpdateOKRProgressRecord(func(ctx context.Context, request *lark.UpdateOKRProgressRecordReq, options ...lark.MethodOptionFunc) (*lark.UpdateOKRProgressRecordResp, *lark.Response, error) {
				return nil, nil, fmt.Errorf("mock-failed")
			})
			defer cli.Mock().UnMockOKRUpdateOKRProgressRecord()

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

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

			cli.Mock().MockOKRGetOKRProgressRecord(func(ctx context.Context, request *lark.GetOKRProgressRecordReq, options ...lark.MethodOptionFunc) (*lark.GetOKRProgressRecordResp, *lark.Response, error) {
				return nil, nil, fmt.Errorf("mock-failed")
			})
			defer cli.Mock().UnMockOKRGetOKRProgressRecord()

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

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

			cli.Mock().MockOKRCreateOKRProgressRecord(func(ctx context.Context, request *lark.CreateOKRProgressRecordReq, options ...lark.MethodOptionFunc) (*lark.CreateOKRProgressRecordResp, *lark.Response, error) {
				return nil, nil, fmt.Errorf("mock-failed")
			})
			defer cli.Mock().UnMockOKRCreateOKRProgressRecord()

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

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

			cli.Mock().MockOKRUploadOKRImage(func(ctx context.Context, request *lark.UploadOKRImageReq, options ...lark.MethodOptionFunc) (*lark.UploadOKRImageResp, *lark.Response, error) {
				return nil, nil, fmt.Errorf("mock-failed")
			})
			defer cli.Mock().UnMockOKRUploadOKRImage()

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

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

			cli.Mock().MockOKRGetOKRReview(func(ctx context.Context, request *lark.GetOKRReviewReq, options ...lark.MethodOptionFunc) (*lark.GetOKRReviewResp, *lark.Response, error) {
				return nil, nil, fmt.Errorf("mock-failed")
			})
			defer cli.Mock().UnMockOKRGetOKRReview()

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

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

			cli.Mock().MockOKRGetOKRMetricSourceList(func(ctx context.Context, request *lark.GetOKRMetricSourceListReq, options ...lark.MethodOptionFunc) (*lark.GetOKRMetricSourceListResp, *lark.Response, error) {
				return nil, nil, fmt.Errorf("mock-failed")
			})
			defer cli.Mock().UnMockOKRGetOKRMetricSourceList()

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

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

			cli.Mock().MockOKRGetOKRMetricSourceTableList(func(ctx context.Context, request *lark.GetOKRMetricSourceTableListReq, options ...lark.MethodOptionFunc) (*lark.GetOKRMetricSourceTableListResp, *lark.Response, error) {
				return nil, nil, fmt.Errorf("mock-failed")
			})
			defer cli.Mock().UnMockOKRGetOKRMetricSourceTableList()

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

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

			cli.Mock().MockOKRBatchUpdateOKRMetricSourceTableItem(func(ctx context.Context, request *lark.BatchUpdateOKRMetricSourceTableItemReq, options ...lark.MethodOptionFunc) (*lark.BatchUpdateOKRMetricSourceTableItemResp, *lark.Response, error) {
				return nil, nil, fmt.Errorf("mock-failed")
			})
			defer cli.Mock().UnMockOKRBatchUpdateOKRMetricSourceTableItem()

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

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

			cli.Mock().MockOKRUpdateOKRMetricSourceTableItem(func(ctx context.Context, request *lark.UpdateOKRMetricSourceTableItemReq, options ...lark.MethodOptionFunc) (*lark.UpdateOKRMetricSourceTableItemResp, *lark.Response, error) {
				return nil, nil, fmt.Errorf("mock-failed")
			})
			defer cli.Mock().UnMockOKRUpdateOKRMetricSourceTableItem()

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

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

			cli.Mock().MockOKRGetOKRMetricSourceTableItem(func(ctx context.Context, request *lark.GetOKRMetricSourceTableItemReq, options ...lark.MethodOptionFunc) (*lark.GetOKRMetricSourceTableItemResp, *lark.Response, error) {
				return nil, nil, fmt.Errorf("mock-failed")
			})
			defer cli.Mock().UnMockOKRGetOKRMetricSourceTableItem()

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

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

			cli.Mock().MockOKRGetOKRMetricSourceTableItemList(func(ctx context.Context, request *lark.GetOKRMetricSourceTableItemListReq, options ...lark.MethodOptionFunc) (*lark.GetOKRMetricSourceTableItemListResp, *lark.Response, error) {
				return nil, nil, fmt.Errorf("mock-failed")
			})
			defer cli.Mock().UnMockOKRGetOKRMetricSourceTableItemList()

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

	})

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

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

			_, _, err := moduleCli.CreateOKRPeriod(ctx, &lark.CreateOKRPeriodReq{})
			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.UpdateOKRPeriod(ctx, &lark.UpdateOKRPeriodReq{
				PeriodID: "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.GetOKRPeriodList(ctx, &lark.GetOKRPeriodListReq{})
			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.GetOKRPeriodRuleList(ctx, &lark.GetOKRPeriodRuleListReq{})
			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.BatchGetOKR(ctx, &lark.BatchGetOKRReq{})
			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.GetUserOKRList(ctx, &lark.GetUserOKRListReq{
				UserID: "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.DeleteOKRProgressRecord(ctx, &lark.DeleteOKRProgressRecordReq{
				ProgressID: "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.UpdateOKRProgressRecord(ctx, &lark.UpdateOKRProgressRecordReq{
				ProgressID: "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.GetOKRProgressRecord(ctx, &lark.GetOKRProgressRecordReq{
				ProgressID: "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.CreateOKRProgressRecord(ctx, &lark.CreateOKRProgressRecordReq{})
			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.UploadOKRImage(ctx, &lark.UploadOKRImageReq{})
			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.GetOKRReview(ctx, &lark.GetOKRReviewReq{})
			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.GetOKRMetricSourceList(ctx, &lark.GetOKRMetricSourceListReq{})
			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.GetOKRMetricSourceTableList(ctx, &lark.GetOKRMetricSourceTableListReq{
				MetricSourceID: "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.BatchUpdateOKRMetricSourceTableItem(ctx, &lark.BatchUpdateOKRMetricSourceTableItemReq{
				MetricSourceID: "x",
				MetricTableID:  "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.UpdateOKRMetricSourceTableItem(ctx, &lark.UpdateOKRMetricSourceTableItemReq{
				MetricSourceID: "x",
				MetricTableID:  "x",
				MetricItemID:   "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.GetOKRMetricSourceTableItem(ctx, &lark.GetOKRMetricSourceTableItemReq{
				MetricSourceID: "x",
				MetricTableID:  "x",
				MetricItemID:   "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.GetOKRMetricSourceTableItemList(ctx, &lark.GetOKRMetricSourceTableItemListReq{
				MetricSourceID: "x",
				MetricTableID:  "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.OKR
		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.CreateOKRPeriod(ctx, &lark.CreateOKRPeriodReq{})
			as.NotNil(err)
			as.Equal("fake raw request", err.Error())
		})

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

			_, _, err := moduleCli.UpdateOKRPeriod(ctx, &lark.UpdateOKRPeriodReq{
				PeriodID: "x",
			})
			as.NotNil(err)
			as.Equal("fake raw request", err.Error())
		})

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

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

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

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

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

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

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

			_, _, err := moduleCli.GetUserOKRList(ctx, &lark.GetUserOKRListReq{
				UserID: "x",
			})
			as.NotNil(err)
			as.Equal("fake raw request", err.Error())
		})

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

			_, _, err := moduleCli.DeleteOKRProgressRecord(ctx, &lark.DeleteOKRProgressRecordReq{
				ProgressID: "x",
			})
			as.NotNil(err)
			as.Equal("fake raw request", err.Error())
		})

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

			_, _, err := moduleCli.UpdateOKRProgressRecord(ctx, &lark.UpdateOKRProgressRecordReq{
				ProgressID: "x",
			})
			as.NotNil(err)
			as.Equal("fake raw request", err.Error())
		})

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

			_, _, err := moduleCli.GetOKRProgressRecord(ctx, &lark.GetOKRProgressRecordReq{
				ProgressID: "x",
			})
			as.NotNil(err)
			as.Equal("fake raw request", err.Error())
		})

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

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

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

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

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

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

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

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

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

			_, _, err := moduleCli.GetOKRMetricSourceTableList(ctx, &lark.GetOKRMetricSourceTableListReq{
				MetricSourceID: "x",
			})
			as.NotNil(err)
			as.Equal("fake raw request", err.Error())
		})

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

			_, _, err := moduleCli.BatchUpdateOKRMetricSourceTableItem(ctx, &lark.BatchUpdateOKRMetricSourceTableItemReq{
				MetricSourceID: "x",
				MetricTableID:  "x",
			})
			as.NotNil(err)
			as.Equal("fake raw request", err.Error())
		})

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

			_, _, err := moduleCli.UpdateOKRMetricSourceTableItem(ctx, &lark.UpdateOKRMetricSourceTableItemReq{
				MetricSourceID: "x",
				MetricTableID:  "x",
				MetricItemID:   "x",
			})
			as.NotNil(err)
			as.Equal("fake raw request", err.Error())
		})

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

			_, _, err := moduleCli.GetOKRMetricSourceTableItem(ctx, &lark.GetOKRMetricSourceTableItemReq{
				MetricSourceID: "x",
				MetricTableID:  "x",
				MetricItemID:   "x",
			})
			as.NotNil(err)
			as.Equal("fake raw request", err.Error())
		})

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

			_, _, err := moduleCli.GetOKRMetricSourceTableItemList(ctx, &lark.GetOKRMetricSourceTableItemListReq{
				MetricSourceID: "x",
				MetricTableID:  "x",
			})
			as.NotNil(err)
			as.Equal("fake raw request", err.Error())
		})

	})
}
