github.com/kaleido-io/firefly@v0.0.0-20210622132723-8b4b6aacb971/kat/src/test/ethereum/payments/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 testPaymentArgumentValidation = async () => {
    20  
    21  describe('Payment definitions - argument validation', async () => {
    22  
    23    it('Attempting to get a payment definition that does not exist should raise an error', async () => {
    24      const result = await request(app)
    25        .get('/api/v1/payments/definitions/missing')
    26        .expect(404);
    27      assert.deepStrictEqual(result.body, { error: 'Payment definition not found' });
    28    });
    29  
    30    it('Attempting to add a payment definition without a name should raise an error', async () => {
    31      const result = await request(app)
    32        .post('/api/v1/payments/definitions')
    33        .send({
    34          author: '0x0000000000000000000000000000000000000001'
    35        })
    36        .expect(400);
    37      assert.deepStrictEqual(result.body, { error: 'Missing or invalid payment definition name' });
    38    });
    39  
    40    it('Attempting to add a payment definition without an author should raise an error', async () => {
    41      const result = await request(app)
    42        .post('/api/v1/payments/definitions')
    43        .send({
    44          name: 'My payment definition'
    45        })
    46        .expect(400);
    47      assert.deepStrictEqual(result.body, { error: 'Missing or invalid payment definition author' });
    48    });
    49  
    50    it('Attempting to add a payment definition with an invalid description schema should raise an error', async () => {
    51      const result = await request(app)
    52        .post('/api/v1/payments/definitions')
    53        .send({
    54          name: 'My payment definition',
    55          author: '0x0000000000000000000000000000000000000001',
    56          descriptionSchema: 'INVALID'
    57        })
    58        .expect(400);
    59      assert.deepStrictEqual(result.body, { error: 'Invalid description schema' });
    60    });
    61  
    62  });
    63  };