ToolJet/server/test/services/data_queries.service.spec.ts
Muhsin Shah C P dc8f69e4b2
[Feature] Organisation level environment variables 🚀 (#3068)
* Added new page for env vars

* Changed a field name

* Added some backend files
- Entity, Dto, services

* Started working with api endpoints
- implmented create
- added ability

* Added fields validation
- Added env variables into module

* Added update, delete, get apis
- Also implemented delete feature in frontend

* Implemented update operation on frontend
- Solved an api problem

* Added encryption

* Added encryption to update operation
- Exposed env vars to editor
- working on viewer

* Exposed env vars in viewer also
- Resolved a bug

* Updated edit & delete icon sizes

* Added specs
- Resolved issues that occurred while testing

* removed logout code

* Changed api endpoint

* splitted page into 3 different parts, Form & table

* Now, non-admin users can see all org env vars

* Resolved divider missing issue

* Added variable_type field

* Now secret server values will be shown as 'SecureValue'

* Now you can't update variable_type

* Now server will resolve the secret env values

* Resolved variable name issue

* Added unique constraints

* Resolved some frontend bugs

* Changed error text

* Fixed failing specs

* Added group permissions for org env vars

* Added permission checking in the backend

* Implemented permission checking in the frontend

* Edited spec for new changes

* Changed some specs and fixed failing specs

* Resolved failing case that showed up after merging with the latest develop

* Added default admin seed permissions

* Refactored some code

* Changed value to organization_id

* Fixed a bug

* Resolved a failing case

* Resolved PR changes
- Changed permission name
- Changed column type to enum
- Fixed some errors
- Refactored the code

* minor code change

* added scope

* Fixed: hide table when 0 no of vars available

* Fixed table dark theme issues

* Fixed encryption switch style

* Fixed failing cases and updated a spec

* Added %% for environment variables

* Added code to resolve single variable

* Fixed multi-variable usage

* resolved an issue

* removed extra divider

* Suggestions will also show up for %% too

* now, suggestions dropdown will only show env variables results

* env vars suggestions will not be included  in js search results

* You can't resolve env variables from js code
- Also, we can't resolve js code from env variable enclosures

* added an info text

* Resolved variables issue

* fixed Viewer issue

* Resolved a bug
- client variable was not working on query preview and run actions

* Update error message while using server variable on canvas

* Revert "Update error message while using server variable on canvas"

This reverts commit 081e1c9e29.

* Resolved all PR changes
- removed prefix 'environmentVariable'
- redefined variable evaluation
- removed environmentVariable object from inspector
- fixed a small bug

* Fixed a server side issue

Co-authored-by: Sherfin Shamsudeen <sherfin94@gmail.com>
2022-07-01 16:20:37 +05:30

116 lines
3.9 KiB
TypeScript

import { Test, TestingModule } from '@nestjs/testing';
import { AppModule } from '../../src/app.module';
import { DataQueriesModule } from '../../src/modules/data_queries/data_queries.module';
import { DataSourcesModule } from '../../src/modules/data_sources/data_sources.module';
import { DataQueriesService } from '../../src/services/data_queries.service';
describe('DataQueriesService', () => {
let service: DataQueriesService;
beforeAll(async () => {
const module: TestingModule = await Test.createTestingModule({
imports: [DataSourcesModule, DataQueriesModule, AppModule],
providers: [],
}).compile();
service = module.get<DataQueriesService>(DataQueriesService);
});
it('should be able to parse query options without dynamic variables', async () => {
const queryOptions = { foo: 'bar' };
const options = {};
const parsedOptions = await service.parseQueryOptions(queryOptions, options, null);
expect(parsedOptions['foo']).toBe('bar');
});
it('should be able to parse query options with whole value as a dynamic variable', async () => {
const queryOptions = { foo: '{{bar}}' };
const options = { '{{bar}}': 'bar' };
const parsedOptions = await service.parseQueryOptions(queryOptions, options, null);
expect(parsedOptions['foo']).toBe('bar');
});
it('should be able to parse query options with one dynamic variable', async () => {
const queryOptions = { foo: 'is a {{bar}}' };
const options = { '{{bar}}': 'bar' };
const parsedOptions = await service.parseQueryOptions(queryOptions, options, null);
expect(parsedOptions['foo']).toBe('is a bar');
});
it('should be able to parse query options with whole value as a dynamic variable that contains js code', async () => {
const queryOptions = { foo: '{{bar * 100 + parseInt("500")}}' };
const options = { '{{bar * 100 + parseInt("500")}}': 20 };
const parsedOptions = await service.parseQueryOptions(queryOptions, options, null);
expect(parsedOptions['foo']).toBe(20);
});
it('should be able to parse query options with the value containing more than one dynamic variable', async () => {
const queryOptions = { email: '{{sam}}@{{example.com}}' };
const options = {
'{{sam}}': 'sam',
'{{example.com}}': 'example.com',
};
const parsedOptions = await service.parseQueryOptions(queryOptions, options, null);
expect(parsedOptions['email']).toBe('sam@example.com');
});
it('should be able to parse query options that has an object', async () => {
const queryOptions = {
user: {
email: '{{email}}',
name: '{{name}}',
},
};
const options = {
'{{email}}': 'sam@example.com',
'{{name}}': 'sam',
};
const parsedOptions = await service.parseQueryOptions(queryOptions, options, null);
expect(parsedOptions['user']['name']).toBe('sam');
expect(parsedOptions['user']['email']).toBe('sam@example.com');
});
it('should be able to parse query options that has an array', async () => {
const queryOptions = {
user: ['{{email}}', '{{name}}'],
};
const options = {
'{{email}}': 'sam@example.com',
'{{name}}': 'sam',
};
const parsedOptions = await service.parseQueryOptions(queryOptions, options, null);
expect(parsedOptions['user']).toContain('sam');
expect(parsedOptions['user']).toContain('sam@example.com');
});
it('should be able to parse query options that has an array of objects', async () => {
const queryOptions = {
user: [{ email: '{{email}}' }, { name: '{{name}}' }],
};
const options = {
'{{email}}': 'sam@example.com',
'{{name}}': 'sam',
};
const parsedOptions = await service.parseQueryOptions(queryOptions, options, null);
expect(parsedOptions['user'][1]['name']).toBe('sam');
expect(parsedOptions['user'][0]['email']).toBe('sam@example.com');
});
});