github.com/s7techlab/cckit@v0.10.5/examples/insurance/app_test.go (about)

     1  package insurance
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/s7techlab/cckit/examples/insurance/app"
     7  
     8  	. "github.com/onsi/ginkgo"
     9  	. "github.com/onsi/gomega"
    10  	testcc "github.com/s7techlab/cckit/testing"
    11  	expectcc "github.com/s7techlab/cckit/testing/expect"
    12  )
    13  
    14  func TestInsuranceApp(t *testing.T) {
    15  	RegisterFailHandler(Fail)
    16  	RunSpecs(t, "Insurance app suite")
    17  }
    18  
    19  var _ = Describe(`Insurance`, func() {
    20  
    21  	//Create chaincode mock
    22  	cc := testcc.NewMockStub(`insurance`, new(app.SmartContract))
    23  
    24  	Describe("Chaincode initialization ", func() {
    25  		It("Allow to provide contract types attributes  during chaincode creation [init]", func() {
    26  			expectcc.ResponseOk(cc.Init(`init`, &ContractTypesDTO{ContractType1}))
    27  		})
    28  	})
    29  
    30  	Describe("Contract type ", func() {
    31  
    32  		It("Allow to retrieve all contract type, added during chaincode init [contract_type_ls]", func() {
    33  			contractTypes := expectcc.PayloadIs(
    34  				cc.Invoke(`contract_type_ls`), &ContractTypesDTO{}).(ContractTypesDTO)
    35  
    36  			Expect(len(contractTypes)).To(Equal(1))
    37  			Expect(contractTypes[0].ShopType).To(Equal(ContractType1.ShopType))
    38  		})
    39  
    40  		It("Allow to create new contract type [contract_type_create]", func() {
    41  			expectcc.ResponseOk(cc.Invoke(`contract_type_create`, &ContractType2))
    42  
    43  			// get contract type list
    44  			contractTypes := expectcc.PayloadIs(
    45  				cc.Invoke(`contract_type_ls`), &ContractTypesDTO{}).(ContractTypesDTO)
    46  
    47  			//expect now we have 2 contract type
    48  			Expect(len(contractTypes)).To(Equal(2))
    49  		})
    50  
    51  		It("Allow to set active contract type [contract_type_set_active]", func() {
    52  			Expect(ContractType2.Active).To(BeFalse())
    53  
    54  			// active ContractType2
    55  			expectcc.ResponseOk(cc.Invoke(`contract_type_set_active`, &ContractTypeActiveDTO{
    56  				UUID: ContractType2.UUID, Active: true}))
    57  		})
    58  
    59  		It("Allow to retrieve filtered by shop type contract types [contract_type_ls]", func() {
    60  			contractTypes := expectcc.PayloadIs(
    61  				cc.Invoke(`contract_type_ls`, &ShopTypeDTO{ContractType2.ShopType}),
    62  				&ContractTypesDTO{}).(ContractTypesDTO)
    63  
    64  			Expect(len(contractTypes)).To(Equal(1))
    65  			Expect(contractTypes[0].UUID).To(Equal(ContractType2.UUID))
    66  
    67  			// Contract type 2 activated on previous step
    68  			Expect(contractTypes[0].Active).To(BeTrue())
    69  		})
    70  	})
    71  
    72  	Describe("Contract", func() {
    73  
    74  		It("Allow everyone to create contract", func() {
    75  
    76  			// get chaincode invoke response payload and expect returned payload is serialized instance of some structure
    77  			contractCreateResponse := expectcc.PayloadIs(
    78  				cc.Invoke(
    79  					// invoke chaincode function
    80  					`contract_create`,
    81  					// with ContractDTO payload, it will automatically will be marshalled to json
    82  					&Contract1,
    83  				),
    84  				// We expect than payload response is marshalled ContractCreateResponse structure
    85  				&ContractCreateResponse{}).(ContractCreateResponse)
    86  
    87  			Expect(contractCreateResponse.Username).To(Equal(Contract1.Username))
    88  		})
    89  
    90  		It("Allow every one to get user info", func() {
    91  
    92  			// orininally was error https://github.com/IBM/build-blockchain-insurance-app/pull/44
    93  			user := expectcc.PayloadIs(
    94  				cc.Invoke(`user_get_info`, &GetUserDTO{
    95  					Username: Contract1.Username,
    96  				}), &ResponseUserDTO{}).(ResponseUserDTO)
    97  
    98  			Expect(user.LastName).To(Equal(Contract1.LastName))
    99  		})
   100  
   101  	})
   102  
   103  })