|
| 1 | +import * as pluginOne from './pluginOne'; |
| 2 | +import * as pluginTwo from './pluginTwo'; |
| 3 | +import { ArweaveKit } from '../../src/lib/wallet'; |
| 4 | + |
| 5 | +describe('Plugins', () => { |
| 6 | + it('should use plugins', () => { |
| 7 | + const arweaveKit = ArweaveKit.use({ |
| 8 | + name: 'pluginOne', |
| 9 | + plugin: pluginOne, |
| 10 | + }).use({ name: 'pluginTwo', plugin: pluginTwo }); |
| 11 | + |
| 12 | + expect(arweaveKit.pluginOne.hello()).toBe('PluginOne'); |
| 13 | + expect(arweaveKit.pluginTwo.hello()).toBe('PluginTwo'); |
| 14 | + }); |
| 15 | + |
| 16 | + it('should throw error when same named plugins used', () => { |
| 17 | + try { |
| 18 | + const arweaveKit = ArweaveKit.use({ |
| 19 | + name: 'pluginThree', |
| 20 | + plugin: pluginOne, |
| 21 | + }).use({ name: 'pluginThree', plugin: pluginTwo }); |
| 22 | + |
| 23 | + // if not thrown error fail the test |
| 24 | + fail('must throw error'); |
| 25 | + } catch (error: any) { |
| 26 | + expect(error.message).toBe( |
| 27 | + 'Plugin name already exists, please change plugin name.' |
| 28 | + ); |
| 29 | + } |
| 30 | + }); |
| 31 | + |
| 32 | + it('should throw error when empty name used for plugin', () => { |
| 33 | + try { |
| 34 | + const arweaveKit = ArweaveKit.use({ |
| 35 | + name: '', |
| 36 | + plugin: pluginOne, |
| 37 | + }); |
| 38 | + |
| 39 | + // if not thrown error fail the test |
| 40 | + fail('must throw error'); |
| 41 | + } catch (error: any) { |
| 42 | + expect(error.message).toBe('Please provide a valid plugin name.'); |
| 43 | + } |
| 44 | + }); |
| 45 | + |
| 46 | + it('should contain all functions with plugins', () => { |
| 47 | + const arweaveKit = ArweaveKit.use({ |
| 48 | + name: 'pluginFour', |
| 49 | + plugin: pluginOne, |
| 50 | + }); |
| 51 | + |
| 52 | + const functionNames = [ |
| 53 | + 'pluginFour', |
| 54 | + 'initArweave', |
| 55 | + 'createWallet', |
| 56 | + 'getAddress', |
| 57 | + 'getBalance', |
| 58 | + ]; |
| 59 | + functionNames.forEach((functionName) => { |
| 60 | + expect(!!(arweaveKit as any)[functionName]).toBeTruthy(); |
| 61 | + }); |
| 62 | + }); |
| 63 | +}); |
0 commit comments