github.com/kaleido-io/firefly@v0.0.0-20210622132723-8b4b6aacb971/kat/src/test/corda/members/argument-validation.ts (about)

     1  // Copyright © 2021 Kaleido, Inc.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  import { app } from '../../common';
    16  import request from 'supertest';
    17  import assert from 'assert';
    18  
    19  export const testMembersArgumentValidation = async () => {
    20  
    21  describe('Members - argument validation', async () => {
    22  
    23    it('Attempting to add a member without an address should raise an error', async () => {
    24      const result = await request(app)
    25        .put('/api/v1/members')
    26        .send({
    27          name: 'Member A',
    28          app2appDestination: 'kld://app2app',
    29          docExchangeDestination: 'kld://docexchange'
    30        })
    31        .expect(400);
    32      assert.deepStrictEqual(result.body, { error: 'Missing member address' });
    33    });
    34  
    35    it('Attempting to add a member without a name should raise an error', async () => {
    36      const result = await request(app)
    37        .put('/api/v1/members')
    38        .send({
    39          address: '0x0000000000000000000000000000000000000001',
    40          app2appDestination: 'kld://app2app',
    41          docExchangeDestination: 'kld://docexchange'
    42        })
    43        .expect(400);
    44      assert.deepStrictEqual(result.body, { error: 'Missing member name' });
    45    });
    46  
    47    it('Attempting to add a member without a assetTrailInstanceID should raise an error', async () => {
    48      const result = await request(app)
    49        .put('/api/v1/members')
    50        .send({
    51          name: 'Member A',
    52          address: '0x0000000000000000000000000000000000000001',
    53          app2appDestination: 'kld://app2app',
    54          docExchangeDestination: 'kld://docexchange'
    55        })
    56        .expect(400);
    57      assert.deepStrictEqual(result.body, { error: 'Missing member assetTrailInstanceID' });
    58    });
    59  
    60    it('Attempting to add a member without a docExchangeDestination should raise an error', async () => {
    61      const result = await request(app)
    62        .put('/api/v1/members')
    63        .send({
    64          name: 'Member A',
    65          address: '0x0000000000000000000000000000000000000001',
    66          app2appDestination: 'kld://app2app',
    67          assetTrailInstanceID: 'asset-instance-a'
    68        })
    69        .expect(400);
    70      assert.deepStrictEqual(result.body, { error: 'Missing member docExchangeDestination' });
    71    });
    72  
    73    it('Attempting to add a member without a app2appDestination should raise an error', async () => {
    74      const result = await request(app)
    75        .put('/api/v1/members')
    76        .send({
    77          name: 'Member A',
    78          address: '0x0000000000000000000000000000000000000001',
    79          assetTrailInstanceID: 'asset-instance-a',
    80          docExchangeDestination: 'kld://docexchange'
    81        })
    82        .expect(400);
    83      assert.deepStrictEqual(result.body, { error: 'Missing member app2appDestination' });
    84    });
    85  
    86    it('Attempting to get a member that does not exist should raise an error', async () => {
    87      const result = await request(app)
    88        .get('/api/v1/members/0x0000000000000000000000000000000000000099')
    89        .expect(404);
    90      assert.deepStrictEqual(result.body, { error: 'Member not found' });
    91    });
    92  
    93  });
    94  };