|
| 1 | +import { Rpc } from '../modules/rpc/rpc'; |
| 2 | +import { RpcApiKey } from '../modules/rpc/rpc-api-key'; |
| 3 | +import { getConfig } from './helpers/helper'; |
| 4 | + |
| 5 | +describe('Rpc Module tests', () => { |
| 6 | + let rpc: Rpc; |
| 7 | + let apiKeyId: number; |
| 8 | + |
| 9 | + beforeAll(() => { |
| 10 | + rpc = new Rpc(getConfig()); |
| 11 | + }); |
| 12 | + |
| 13 | + test('Create new API key', async () => { |
| 14 | + const apiKeyData = { |
| 15 | + name: 'Test API Key', |
| 16 | + description: 'Test Description', |
| 17 | + }; |
| 18 | + const apiKey = await rpc.createApiKey(apiKeyData); |
| 19 | + |
| 20 | + expect(apiKey).toBeInstanceOf(RpcApiKey); |
| 21 | + expect(apiKey.name).toEqual(apiKeyData.name); |
| 22 | + expect(apiKey.description).toEqual(apiKeyData.description); |
| 23 | + expect(apiKey.uuid).toBeTruthy(); |
| 24 | + expect(apiKey.id).toBeTruthy(); |
| 25 | + |
| 26 | + apiKeyId = apiKey.id; |
| 27 | + }); |
| 28 | + |
| 29 | + test('List API keys', async () => { |
| 30 | + const { items } = await rpc.listApiKeys(); |
| 31 | + |
| 32 | + expect(items.length).toBeGreaterThanOrEqual(0); |
| 33 | + items.forEach((apiKey) => { |
| 34 | + expect(apiKey).toBeInstanceOf(RpcApiKey); |
| 35 | + expect(apiKey.name).toBeTruthy(); |
| 36 | + expect(apiKey.uuid).toBeTruthy(); |
| 37 | + expect(apiKey.id).toBeTruthy(); |
| 38 | + }); |
| 39 | + }); |
| 40 | + |
| 41 | + test('Get specific API key', async () => { |
| 42 | + const apiKey = await rpc.apiKey(apiKeyId).get(); |
| 43 | + |
| 44 | + expect(apiKey).toBeInstanceOf(RpcApiKey); |
| 45 | + expect(apiKey.id).toEqual(apiKeyId); |
| 46 | + }); |
| 47 | + |
| 48 | + test('List endpoints', async () => { |
| 49 | + const endpoints = await rpc.listEndpoints(); |
| 50 | + |
| 51 | + expect(Array.isArray(endpoints)).toBeTruthy(); |
| 52 | + expect(endpoints.length).toBeGreaterThanOrEqual(0); |
| 53 | + |
| 54 | + endpoints.forEach((endpoint) => { |
| 55 | + expect(endpoint).toMatchObject({ |
| 56 | + id: expect.any(Number), |
| 57 | + name: expect.any(String), |
| 58 | + imageUrl: expect.any(String), |
| 59 | + type: expect.any(String), |
| 60 | + version: expect.any(String), |
| 61 | + networkName: expect.any(String), |
| 62 | + networkId: expect.any(Number), |
| 63 | + }); |
| 64 | + }); |
| 65 | + }); |
| 66 | +}); |
0 commit comments