ToolJet/server/test/services/data_queries.service.spec.ts
Akshay 7023f72d1d
Feature: User access management 🔥 (#918)
* create migrations for group permissions setup

* define new entities and relationships

* revise migrations

* rename columns

* add migration to populate permission groups for existing users

* Feature: User access permission group usage (#883)

* create migrations for group permissions setup

* define new entities and relationships

* revise migrations

* rename columns

* add migration to populate permission groups for existing users

* revise migrations

* hide roles usage

* setup group permissions for apps and users

* fix defaultChecked

* fix update permission checkbox

* fix casl ability check to have params passed

* fix casl apps abilities to check with app specific permission

* add ability to delete groups

* conditionally render edit and delete options for all and admin users

* fix user role to group migration

* revise group management pages to disallow updating default group

* move manage users and groups to navbar dropdown

* show only addable apps and users on dropdowns

* rename header as profile settings

* scope addable apps and users by organization

* scope viewable apps on homepage

* hide manage groups link from non admins

* make permissions to be used with radio input

* add loading state for add apps/users buttons

* revise unit tests

* revise migrations

* fix e2e tests

* comment out dead code

* fix seeds script

* handle folder count

* captalize error toast

* hide manage users dropdown for non admins

* show fobidden error on blank homepage

* fix folder app count

* fix invalid state set

* make group name clickable for edit instead

* users with edit permission can deploy apps

* not show edit link on homepage if user dont have update permission

* remove unused entity from merge

* remove roles usage from manage org users page

* fix folder count and blank slate on homepage

* disable add buttons if there is no selections

* humanize default groups on view

* make app added onto groups have read permission by default

* not show app menu if user is not admin

* remove admin users from group user addition dropdown

* create default permissions for app cloned

* fix querying index page without page params

* fix admin scoped out from group add

* remove apps from header

* fix invitation url not shown

* scope admin deletion check by org

* scope public apps by organization

* add specs for group permissions e2e

* removed unused entity and add group permissions spec

* remove console logs

* remove unused permission

* scope public app count by org

* remove console log

* refactor manage group permission resources component

* update group permssion in org scope
2021-10-11 20:45:58 +05:30

116 lines
3.8 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);
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);
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);
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);
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);
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);
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);
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);
expect(parsedOptions['user'][1]['name']).toBe('sam');
expect(parsedOptions['user'][0]['email']).toBe('sam@example.com');
});
});