/* eslint @typescript-eslint/no-non-null-assertion: "off" */ import {newServiceClient, readLayerProfile, ServiceError} from '../node'; import {globalUniverse, layerProfileStr} from './config'; const globalUrl = 'http://localhost:9150'; test('newClient returns instance', () => { const client = newServiceClient(globalUrl); expect(client).toBeTruthy(); }); test('resolveUniverse returns base modeling id', async () => { const client = newServiceClient(globalUrl); const universeId = await client.resolveUniverse('base'); expect(universeId).toBeTruthy(); }); test('loadUniverseFromApi returns base modeling', async () => { const client = newServiceClient(globalUrl); const universeId = await client.resolveUniverse('base'); if (universeId instanceof ServiceError) { expect(false).toBeTruthy(); return; } const universe = await client.loadUniverse(universeId!); expect(universe).toBeTruthy(); if (!universe) { return; } expect(universe.description.length).toBeGreaterThan(0); expect(universe.models.size).toBeGreaterThan(0); expect(universe.models.get('base.object/base')).toBeTruthy(); expect(universe.models.get('base.object/base')!.targetFields.size).toEqual(1); expect(universe.models.get('base.object/base')!.object).toBeTruthy(); }); test('loadUniverseFromApi returns data modeling', async () => { const client = newServiceClient(globalUrl); const universeId = await client.resolveUniverse('data'); if (universeId instanceof ServiceError) { expect(false).toBeTruthy(); return; } const universe = await client.loadUniverse(universeId!); expect(universe).toBeTruthy(); if (!universe) { return; } expect(universe.description.length).toBeGreaterThan(0); expect(universe.models.size).toBeGreaterThan(0); expect(universe.models.get('base.object/data')).toBeTruthy(); expect(universe.models.get('base.object/data')!.targetFields.size).toEqual(1); expect(universe.models.get('data.@data/data')).toBeTruthy(); expect(universe.models.get('data.@integer/data')).toBeTruthy(); expect(universe.models.get('data.@boolean/data')).toBeTruthy(); expect(universe.models.get('data.@string/data')).toBeTruthy(); expect(universe.models.get('data.@string/data')!.object).toBeTruthy(); expect(universe.models.get('data.@string/data')!.abstracts.size).toBeGreaterThan(0); expect(universe.models.get('data.@data/data')!.specials.size).toBeGreaterThan(3); }); test('getLayerProfile works', async () => { const client = newServiceClient(globalUrl); client.token = 'AcTnSLTMXZeD3m9Rj8LfOVZCyGIAAAAA____fwIAYgAAADJwcm9maWxlL2U0ZjkwNTc2MzQzMjgzNWQ2Mjc0Y2NhNjQ0MzUxZjlkL2dldFRva2VuczB1bml2ZXJzZS9jNWZhY2JjOWRjYjljMzlhYzM0Yjk4OWE4ZTc1ZGU2YS9leHBvcnS5QQPEH11r1YaJrgAzRh01909Xyg'; const lp = await client.getLayerProfile('e4f905763432835d6274cca644351f9d'); expect(lp).toBeTruthy(); }); test('getUser works', async () => { const client = newServiceClient(globalUrl); const st = readLayerProfile(layerProfileStr)!; const userId = st.getAccessGroup('main_full')!.tokens[0].userId; const user = (await client.getUser(userId))!; if (user instanceof ServiceError) { expect(false).toBeTruthy(); return; } expect(user.id).toEqual(userId); expect(user.name).toBeTruthy(); }); test('getJSONSchema returns JSON schema', async () => { const client = newServiceClient(globalUrl); const universeJson = await client.getUniverseJSONSchema(globalUniverse); if (universeJson instanceof ServiceError) { expect(false).toBeTruthy(); return; } const universeSchema = JSON.parse(universeJson!); expect(universeSchema['$id']).toEqual(`https://api.vyze.io/service/v1/schema/json/${globalUniverse}`); expect(Object.keys(universeSchema['$defs'])).toHaveLength(4); });