github.com/kaleido-io/firefly@v0.0.0-20210622132723-8b4b6aacb971/kat/src/test/ethereum/assets/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 testAssetArgumentValidation = () => {
    20  describe('Asset definitions - argument validation', async () => {
    21    it('Attempting to get an asset definition that does not exist should raise an error', async () => {
    22      const result = await request(app)
    23        .get('/api/v1/assets/definitions/1000000')
    24        .expect(404);
    25      assert.deepStrictEqual(result.body, { error: 'Asset definition not found' });
    26    });
    27  
    28    it('Attempting to add an asset definition without a name should raise an error', async () => {
    29      const result = await request(app)
    30        .post('/api/v1/assets/definitions')
    31        .send({
    32          author: '0x0000000000000000000000000000000000000001',
    33          isContentPrivate: false,
    34          isContentUnique: true
    35        })
    36        .expect(400);
    37      assert.deepStrictEqual(result.body, { error: 'Missing or invalid asset definition name' });
    38    });
    39  
    40    it('Attempting to add an asset definition without an author should raise an error', async () => {
    41      const result = await request(app)
    42        .post('/api/v1/assets/definitions')
    43        .send({
    44          name: 'My asset definition',
    45          isContentPrivate: false,
    46          isContentUnique: true
    47        })
    48        .expect(400);
    49      assert.deepStrictEqual(result.body, { error: 'Missing or invalid asset definition author' });
    50    });
    51  
    52    it('Attempting to add an asset definition with an invalid index schema should raise an error', async () => {
    53      const result = await request(app)
    54        .post('/api/v1/assets/definitions')
    55        .send({
    56          name: 'My asset definition',
    57          author: '0x0000000000000000000000000000000000000001',
    58          isContentPrivate: false,
    59          isContentUnique: true,
    60          indexes: {}
    61        })
    62        .expect(400);
    63      assert.deepStrictEqual(result.body, { error: 'Indexes do not conform to index schema' });
    64    });
    65  
    66    it('Attempting to add an asset definition without indicating if the content should be private or not should raise an error', async () => {
    67      const result = await request(app)
    68        .post('/api/v1/assets/definitions')
    69        .send({
    70          name: 'My asset definition',
    71          author: '0x0000000000000000000000000000000000000001',
    72          isContentUnique: true
    73        })
    74        .expect(400);
    75      assert.deepStrictEqual(result.body, { error: 'Missing asset definition content privacy' });
    76    });
    77  
    78    it('Attempting to add an asset definition with an invalid description schema should raise an error', async () => {
    79      const result = await request(app)
    80        .post('/api/v1/assets/definitions')
    81        .send({
    82          name: 'My asset definition',
    83          author: '0x0000000000000000000000000000000000000001',
    84          descriptionSchema: 'INVALID',
    85          isContentPrivate: false,
    86          isContentUnique: true
    87        })
    88        .expect(400);
    89      assert.deepStrictEqual(result.body, { error: 'Invalid description schema' });
    90    });
    91  
    92    it('Attempting to add an asset definition with an invalid content schema should raise an error', async () => {
    93      const result = await request(app)
    94        .post('/api/v1/assets/definitions')
    95        .send({
    96          name: 'My asset definition',
    97          author: '0x0000000000000000000000000000000000000001',
    98          contentSchema: 'INVALID',
    99          isContentPrivate: false,
   100          isContentUnique: true
   101        })
   102        .expect(400);
   103      assert.deepStrictEqual(result.body, { error: 'Invalid content schema' });
   104    });
   105  
   106  });
   107  
   108  describe('Asset instances - argument validation', async () => {
   109  
   110    it('Attempting to add an asset instance without specifying the author should raise an error', async () => {
   111      const result = await request(app)
   112        .post('/api/v1/assets/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx')
   113        .send({
   114          assetDefinitionID: '',
   115          content: {}
   116        })
   117        .expect(400);
   118      assert.deepStrictEqual(result.body, { error: 'Missing or invalid asset instance author' });
   119    });
   120  
   121    it('Attempting to add an asset instance without specifying the content should raise an error', async () => {
   122      const result = await request(app)
   123        .post('/api/v1/assets/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx')
   124        .send({
   125          author: '0x0000000000000000000000000000000000000001'
   126        })
   127        .expect(400);
   128      assert.deepStrictEqual(result.body, { error: 'Missing or invalid asset content' });
   129    });
   130  
   131  });
   132  };