github.com/kaleido-io/firefly@v0.0.0-20210622132723-8b4b6aacb971/kat/src/test/ethereum/lib/settings.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 assert from 'assert'; 17 import request from 'supertest'; 18 import { ISettings } from '../../../lib/interfaces'; 19 20 export const testSettings = async () => { 21 22 describe('Settings', () => { 23 it('Checks that settings can be retrieved', async () => { 24 const getSettingsResponse = await request(app) 25 .get('/api/v1/settings') 26 .expect(200); 27 const settings: ISettings = getSettingsResponse.body; 28 assert.deepStrictEqual(settings.clientEvents, [ 'asset-instance-submitted' ]); 29 }); 30 31 it('Checks that settings can be updated', async () => { 32 const result = await request(app) 33 .put('/api/v1/settings') 34 .send({ 35 key: 'clientEvents', 36 value: ['asset-instance-property-set'] 37 }) 38 .expect(200); 39 assert.deepStrictEqual(result.body.status, 'success'); 40 41 const getSettingsResponse = await request(app) 42 .get('/api/v1/settings') 43 .expect(200); 44 const settings: ISettings = getSettingsResponse.body; 45 assert.deepStrictEqual(settings.clientEvents, [ 'asset-instance-property-set' ]); 46 }); 47 48 it('Fails when attempting to add an invalid setting', async () => { 49 const result = await request(app) 50 .put('/api/v1/settings') 51 .send({ 52 key: 'clientEvents', 53 value: ['invalid'] 54 }) 55 .expect(400); 56 assert.deepStrictEqual(result.body, { error: 'Invalid Settings' }); 57 }); 58 }); 59 };