mirror of
https://github.com/ToolJet/ToolJet
synced 2026-05-13 12:08:52 +00:00
* feat: add user avatar
* update: @nest/platform-express from 8.0.0 to 8.4.4
* add avatar_id in login response
* add user avatar upload in frontend
* align cross divider with layout icons'
* generate nest model - extensions
* Add extensions module
* Add extension to datasouce
* add not implemented check
* create extension
* refactor
* cleanup
* fix tests
* reduce the avatar size on homepage
* poc: run js code from string
* resolve conflicts
* fix conflicts
* add globals
* add new route
* add icon, manifest file upload
* complete user flow
* add flow for data queries
* add dynamic manifest instead of local datasource types
* add version attr
* remove unused code
* add version
* rename extension(s) -> plugins(s)
* add test connection method
* feat: add marketplace listing page
* Add install plugin cmd + missing attrs {name, repo, desc} to plugin
* add missing icon
* - Add npm workspaces for marketplace monorepo
- Added cassandra datasource plugin
- Created upload to s3 script
- Created plugins.json entry file
* install plugin from s3 bucket
* cleanup
* update pkg locks
* fix icon render
* cleanup
* marketplace changes
* ui changes
* operations file load fix + revert vm2
* update module from string to 3.2.1
* load plugins.json from local file instead of remote
* install plugin from local file if not production environment
* add sqlite
* feat: add plivo api plugin
* exp: add heroku 22 stack
* update assets include path
* Revert "exp: add heroku 22 stack"
This reverts commit a8926b36e1.
* add integrations link
* Add casl ability for plugin
* load host from env else fallback to default
* update imports
* remove sqlite
* typo
* add marketplace flag to cli command
* move ts and ncc to devDep
* add hygen templates for marketplace
* cli tree-node path fix
* template indent fix
* TOOLJET_URL -> MARKETPLACE_TOOLJET_URL
* add tests
* refactor: move to plugins.helper for get-service helper utility
* fix; typo
* update package-lock.json
* review changes
* remove a href
* remove bg color + redirect issue due to href
* add test url
* fix crash on search
* remove extra slash
* feat: allow plugin to be installed from github repository
* remove unwanted args from cli command
* add repo attr while save
* feat: add feature toggle for marketplace feature
* fix: make default config as false
* chore: remove hyperlink
* fix: failing build
* chore: update s3 url to point to prod
* fix failing test
* fix test
* fix: test case
* update module from string pkg
* update env
* fix test
* fix test
* add readme file
* Update README.md
Co-authored-by: Akshay Sasidharan <akshaysasidharan93@gmail.com>
665 lines
20 KiB
TypeScript
665 lines
20 KiB
TypeScript
import * as request from 'supertest';
|
|
import { INestApplication } from '@nestjs/common';
|
|
import {
|
|
authHeaderForUser,
|
|
clearDB,
|
|
createApplication,
|
|
createUser,
|
|
createNestAppInstance,
|
|
createDataQuery,
|
|
createDataSource,
|
|
createAppGroupPermission,
|
|
createApplicationVersion,
|
|
} from '../test.helper';
|
|
import { getManager, getRepository } from 'typeorm';
|
|
import { GroupPermission } from 'src/entities/group_permission.entity';
|
|
import { AppGroupPermission } from 'src/entities/app_group_permission.entity';
|
|
|
|
describe('data queries controller', () => {
|
|
let app: INestApplication;
|
|
|
|
beforeEach(async () => {
|
|
await clearDB();
|
|
});
|
|
|
|
beforeAll(async () => {
|
|
app = await createNestAppInstance();
|
|
});
|
|
|
|
it('should be able to update queries of an app only if group is admin or group has app update permission', async () => {
|
|
const adminUserData = await createUser(app, {
|
|
email: 'admin@tooljet.io',
|
|
groups: ['all_users', 'admin'],
|
|
});
|
|
const developerUserData = await createUser(app, {
|
|
email: 'developer@tooljet.io',
|
|
groups: ['all_users', 'developer'],
|
|
organization: adminUserData.organization,
|
|
});
|
|
const viewerUserData = await createUser(app, {
|
|
email: 'viewer@tooljet.io',
|
|
groups: ['all_users', 'viewer'],
|
|
organization: adminUserData.organization,
|
|
});
|
|
const anotherOrgAdminUserData = await createUser(app, {
|
|
email: 'another@tooljet.io',
|
|
groups: ['all_users', 'admin'],
|
|
});
|
|
|
|
const application = await createApplication(app, {
|
|
name: 'name',
|
|
user: adminUserData.user,
|
|
});
|
|
|
|
// setup app permissions for developer
|
|
const developerUserGroup = await getRepository(GroupPermission).findOneOrFail({
|
|
where: {
|
|
group: 'developer',
|
|
},
|
|
});
|
|
await createAppGroupPermission(app, application, developerUserGroup.id, {
|
|
read: true,
|
|
update: true,
|
|
delete: false,
|
|
});
|
|
|
|
// setup app permissions for viewer
|
|
const viewerUserGroup = await getRepository(GroupPermission).findOneOrFail({
|
|
where: {
|
|
group: 'viewer',
|
|
},
|
|
});
|
|
await createAppGroupPermission(app, application, viewerUserGroup.id, {
|
|
read: true,
|
|
update: false,
|
|
delete: false,
|
|
});
|
|
|
|
const dataQuery = await createDataQuery(app, {
|
|
application,
|
|
kind: 'restapi',
|
|
options: {
|
|
method: 'get',
|
|
url: 'https://api.github.com/repos/tooljet/tooljet/stargazers',
|
|
url_params: [],
|
|
headers: [],
|
|
body: [],
|
|
},
|
|
});
|
|
|
|
for (const userData of [adminUserData, developerUserData]) {
|
|
const newOptions = { method: userData.user.email };
|
|
const response = await request(app.getHttpServer())
|
|
.patch(`/api/data_queries/${dataQuery.id}`)
|
|
.set('Authorization', authHeaderForUser(userData.user))
|
|
.send({
|
|
options: newOptions,
|
|
});
|
|
|
|
expect(response.statusCode).toBe(200);
|
|
await dataQuery.reload();
|
|
expect(dataQuery.options.method).toBe(newOptions.method);
|
|
}
|
|
|
|
// Should not update if viewer or if user of another org
|
|
for (const userData of [anotherOrgAdminUserData, viewerUserData]) {
|
|
const oldOptions = dataQuery.options;
|
|
const response = await request(app.getHttpServer())
|
|
.patch(`/api/data_queries/${dataQuery.id}`)
|
|
.set('Authorization', authHeaderForUser(userData.user))
|
|
.send({
|
|
options: { method: '' },
|
|
});
|
|
|
|
expect(response.statusCode).toBe(403);
|
|
await dataQuery.reload();
|
|
expect(dataQuery.options.method).toBe(oldOptions.method);
|
|
}
|
|
});
|
|
|
|
it('should be able to delete queries of an app only if admin/developer of same organization', async () => {
|
|
const adminUserData = await createUser(app, {
|
|
email: 'admin@tooljet.io',
|
|
groups: ['all_users', 'admin'],
|
|
});
|
|
const developerUserData = await createUser(app, {
|
|
email: 'developer@tooljet.io',
|
|
groups: ['all_users', 'developer'],
|
|
organization: adminUserData.organization,
|
|
});
|
|
const viewerUserData = await createUser(app, {
|
|
email: 'viewer@tooljet.io',
|
|
groups: ['all_users', 'viewer'],
|
|
organization: adminUserData.organization,
|
|
});
|
|
const anotherOrgAdminUserData = await createUser(app, {
|
|
email: 'another@tooljet.io',
|
|
groups: ['all_users', 'admin'],
|
|
});
|
|
const application = await createApplication(app, {
|
|
name: 'name',
|
|
user: adminUserData.user,
|
|
});
|
|
|
|
// setup app permissions for developer
|
|
const developerUserGroup = await getRepository(GroupPermission).findOneOrFail({
|
|
where: {
|
|
group: 'developer',
|
|
},
|
|
});
|
|
await createAppGroupPermission(app, application, developerUserGroup.id, {
|
|
read: true,
|
|
update: true,
|
|
delete: false,
|
|
});
|
|
|
|
for (const userData of [adminUserData, developerUserData]) {
|
|
const dataQuery = await createDataQuery(app, {
|
|
application,
|
|
kind: 'restapi',
|
|
options: {
|
|
method: 'get',
|
|
url: 'https://api.github.com/repos/tooljet/tooljet/stargazers',
|
|
url_params: [],
|
|
headers: [],
|
|
body: [],
|
|
},
|
|
});
|
|
const newOptions = { method: userData.user.email };
|
|
|
|
const response = await request(app.getHttpServer())
|
|
.delete(`/api/data_queries/${dataQuery.id}`)
|
|
.set('Authorization', authHeaderForUser(userData.user))
|
|
.send({
|
|
options: newOptions,
|
|
});
|
|
|
|
expect(response.statusCode).toBe(200);
|
|
}
|
|
|
|
// Should not update if viewer or if user of another org
|
|
for (const userData of [anotherOrgAdminUserData, viewerUserData]) {
|
|
const dataQuery = await createDataQuery(app, {
|
|
application,
|
|
kind: 'restapi',
|
|
options: {
|
|
method: 'get',
|
|
url: 'https://api.github.com/repos/tooljet/tooljet/stargazers',
|
|
url_params: [],
|
|
headers: [],
|
|
body: [],
|
|
},
|
|
});
|
|
const oldOptions = dataQuery.options;
|
|
|
|
const response = await request(app.getHttpServer())
|
|
.delete(`/api/data_queries/${dataQuery.id}`)
|
|
.set('Authorization', authHeaderForUser(userData.user))
|
|
.send({
|
|
options: { method: '' },
|
|
});
|
|
|
|
expect(response.statusCode).toBe(403);
|
|
await dataQuery.reload();
|
|
expect(dataQuery.options.method).toBe(oldOptions.method);
|
|
}
|
|
});
|
|
|
|
it('should be able to get queries only if the user has app read permission and belongs to the same organization', async () => {
|
|
const adminUserData = await createUser(app, {
|
|
email: 'admin@tooljet.io',
|
|
groups: ['all_users', 'admin'],
|
|
});
|
|
const developerUserData = await createUser(app, {
|
|
email: 'developer@tooljet.io',
|
|
groups: ['all_users', 'developer'],
|
|
organization: adminUserData.organization,
|
|
});
|
|
const viewerUserData = await createUser(app, {
|
|
email: 'viewer@tooljet.io',
|
|
groups: ['all_users', 'viewer'],
|
|
organization: adminUserData.organization,
|
|
});
|
|
const application = await createApplication(app, {
|
|
name: 'name',
|
|
user: adminUserData.user,
|
|
});
|
|
const anotherOrgAdminUserData = await createUser(app, {
|
|
email: 'another@tooljet.io',
|
|
groups: ['all_users', 'admin'],
|
|
});
|
|
|
|
const allUserGroup = await getManager().findOneOrFail(GroupPermission, {
|
|
where: { group: 'all_users', organization: adminUserData.organization },
|
|
});
|
|
await getManager().update(
|
|
AppGroupPermission,
|
|
{ app: application, groupPermissionId: allUserGroup },
|
|
{ read: true }
|
|
);
|
|
|
|
// setup app permissions for developer
|
|
const developerUserGroup = await getRepository(GroupPermission).findOneOrFail({
|
|
where: {
|
|
group: 'developer',
|
|
},
|
|
});
|
|
await createAppGroupPermission(app, application, developerUserGroup.id, {
|
|
read: true,
|
|
update: true,
|
|
delete: false,
|
|
});
|
|
|
|
await createDataQuery(app, {
|
|
application,
|
|
kind: 'restapi',
|
|
options: { method: 'get' },
|
|
});
|
|
|
|
for (const userData of [adminUserData, developerUserData]) {
|
|
const response = await request(app.getHttpServer())
|
|
.get(`/api/data_queries?app_id=${application.id}`)
|
|
.set('Authorization', authHeaderForUser(userData.user));
|
|
|
|
expect(response.statusCode).toBe(200);
|
|
expect(response.body.data_queries.length).toBe(1);
|
|
}
|
|
|
|
let response = await request(app.getHttpServer())
|
|
.get(`/api/data_queries?app_id=${application.id}`)
|
|
.set('Authorization', authHeaderForUser(viewerUserData.user));
|
|
|
|
expect(response.statusCode).toBe(200);
|
|
|
|
// Forbidden if user of another organization
|
|
response = await request(app.getHttpServer())
|
|
.get(`/api/data_queries?app_id=${application.id}`)
|
|
.set('Authorization', authHeaderForUser(anotherOrgAdminUserData.user));
|
|
|
|
expect(response.statusCode).toBe(403);
|
|
});
|
|
|
|
it('should be able to search queries with application version id', async () => {
|
|
const adminUserData = await createUser(app, {
|
|
email: 'admin@tooljet.io',
|
|
groups: ['all_users', 'admin'],
|
|
});
|
|
const application = await createApplication(app, {
|
|
name: 'name',
|
|
user: adminUserData.user,
|
|
});
|
|
const appVersion = await createApplicationVersion(app, application);
|
|
await createDataQuery(app, {
|
|
application,
|
|
kind: 'restapi',
|
|
options: { method: 'get' },
|
|
appVersion,
|
|
});
|
|
|
|
let response = await request(app.getHttpServer())
|
|
.get(`/api/data_queries?app_id=${application.id}&app_version_id=${appVersion.id}`)
|
|
.set('Authorization', authHeaderForUser(adminUserData.user));
|
|
|
|
expect(response.statusCode).toBe(200);
|
|
expect(response.body.data_queries.length).toBe(1);
|
|
|
|
response = await request(app.getHttpServer())
|
|
.get(`/api/data_queries?app_id=${application.id}&app_version_id=62929ad6-11ae-4655-bb3e-2d2465b58950`)
|
|
.set('Authorization', authHeaderForUser(adminUserData.user));
|
|
|
|
expect(response.statusCode).toBe(200);
|
|
expect(response.body.data_queries.length).toBe(0);
|
|
});
|
|
|
|
it('should be able to create queries for an app only if the user has admin group or update permission', async () => {
|
|
const adminUserData = await createUser(app, {
|
|
email: 'admin@tooljet.io',
|
|
groups: ['all_users', 'admin'],
|
|
});
|
|
const developerUserData = await createUser(app, {
|
|
email: 'developer@tooljet.io',
|
|
groups: ['all_users', 'developer'],
|
|
organization: adminUserData.organization,
|
|
});
|
|
const viewerUserData = await createUser(app, {
|
|
email: 'viewer@tooljet.io',
|
|
groups: ['all_users', 'viewer'],
|
|
organization: adminUserData.organization,
|
|
});
|
|
const application = await createApplication(app, {
|
|
name: 'name',
|
|
user: adminUserData.user,
|
|
});
|
|
const applicationVersion = await createApplicationVersion(app, application);
|
|
const anotherOrgAdminUserData = await createUser(app, {
|
|
email: 'another@tooljet.io',
|
|
groups: ['all_users', 'admin'],
|
|
});
|
|
|
|
// setup app permissions for developer
|
|
const developerUserGroup = await getRepository(GroupPermission).findOneOrFail({
|
|
where: {
|
|
group: 'developer',
|
|
},
|
|
});
|
|
await createAppGroupPermission(app, application, developerUserGroup.id, {
|
|
read: true,
|
|
update: true,
|
|
delete: false,
|
|
});
|
|
|
|
const requestBody = {
|
|
name: 'get query',
|
|
app_id: application.id,
|
|
kind: 'restapi',
|
|
options: { method: 'get' },
|
|
app_version_id: applicationVersion.id,
|
|
};
|
|
|
|
for (const userData of [adminUserData, developerUserData]) {
|
|
const response = await request(app.getHttpServer())
|
|
.post(`/api/data_queries`)
|
|
.set('Authorization', authHeaderForUser(userData.user))
|
|
.send(requestBody);
|
|
|
|
expect(response.statusCode).toBe(201);
|
|
expect(response.body.id).toBeDefined();
|
|
expect(response.body.app_id).toBe(application.id);
|
|
expect(response.body.app_version_id).toBe(applicationVersion.id);
|
|
expect(response.body.options).toBeDefined();
|
|
expect(response.body.kind).toBe('restapi');
|
|
expect(response.body.created_at).toBeDefined();
|
|
expect(response.body.updated_at).toBeDefined();
|
|
}
|
|
|
|
// Forbidden if a viewer or a user of another organization
|
|
for (const userData of [anotherOrgAdminUserData, viewerUserData]) {
|
|
const response = await request(app.getHttpServer())
|
|
.post(`/api/data_queries`)
|
|
.set('Authorization', authHeaderForUser(userData.user))
|
|
.send(requestBody);
|
|
|
|
expect(response.statusCode).toBe(403);
|
|
}
|
|
});
|
|
|
|
it('should not be able to create queries if datasource belongs to another app', async () => {
|
|
const adminUserData = await createUser(app, {
|
|
email: 'admin@tooljet.io',
|
|
groups: ['all_users', 'admin'],
|
|
});
|
|
const application = await createApplication(app, {
|
|
name: 'name',
|
|
user: adminUserData.user,
|
|
});
|
|
const anotherApplication = await createApplication(app, {
|
|
name: 'name',
|
|
user: adminUserData.user,
|
|
});
|
|
const dataSource = await createDataSource(app, {
|
|
name: 'name',
|
|
kind: 'postgres',
|
|
application: application,
|
|
user: adminUserData.user,
|
|
});
|
|
|
|
const applicationVersion = await createApplicationVersion(app, application);
|
|
|
|
let queryParams = {
|
|
name: 'get query',
|
|
app_id: application.id,
|
|
data_source_id: dataSource.id,
|
|
kind: 'restapi',
|
|
options: { method: 'get' },
|
|
app_version_id: applicationVersion.id,
|
|
};
|
|
|
|
// Create query if data source belongs to same app
|
|
let response = await request(app.getHttpServer())
|
|
.post(`/api/data_queries`)
|
|
.set('Authorization', authHeaderForUser(adminUserData.user))
|
|
.send(queryParams);
|
|
|
|
expect(response.statusCode).toBe(201);
|
|
|
|
queryParams = {
|
|
name: 'get query',
|
|
app_id: anotherApplication.id,
|
|
data_source_id: dataSource.id,
|
|
kind: 'restapi',
|
|
options: { method: 'get' },
|
|
app_version_id: applicationVersion.id,
|
|
};
|
|
|
|
// Forbidden if data source belongs to another app
|
|
response = await request(app.getHttpServer())
|
|
.post(`/api/data_queries`)
|
|
.set('Authorization', authHeaderForUser(adminUserData.user))
|
|
.send(queryParams);
|
|
|
|
expect(response.statusCode).toBe(403);
|
|
});
|
|
|
|
it('should be able to get queries sorted created wise', async () => {
|
|
const adminUserData = await createUser(app, {
|
|
email: 'admin@tooljet.io',
|
|
groups: ['all_users', 'admin'],
|
|
});
|
|
|
|
const application = await createApplication(app, {
|
|
name: 'name',
|
|
user: adminUserData.user,
|
|
});
|
|
|
|
const dataSource = await createDataSource(app, {
|
|
name: 'name',
|
|
kind: 'postgres',
|
|
application: application,
|
|
user: adminUserData.user,
|
|
});
|
|
|
|
const appVersion = await createApplicationVersion(app, application);
|
|
|
|
const options = {
|
|
method: 'get',
|
|
url: null,
|
|
url_params: [['', '']],
|
|
headers: [['', '']],
|
|
body: [['', '']],
|
|
json_body: null,
|
|
body_toggle: false,
|
|
};
|
|
|
|
const createdQueries = [];
|
|
const totalQueries = 15;
|
|
|
|
for (let i = 1; i <= totalQueries; i++) {
|
|
const queryParams = {
|
|
name: `restapi${i}`,
|
|
app_id: application.id,
|
|
data_source_id: dataSource.id,
|
|
kind: 'restapi',
|
|
options,
|
|
plugin_id: null,
|
|
app_version_id: appVersion.id,
|
|
};
|
|
|
|
const response = await request(app.getHttpServer())
|
|
.post(`/api/data_queries`)
|
|
.set('Authorization', authHeaderForUser(adminUserData.user))
|
|
.send(queryParams);
|
|
|
|
response.body['plugin'] = null;
|
|
createdQueries.push(response.body);
|
|
}
|
|
|
|
// Latest query should be on top
|
|
createdQueries.reverse();
|
|
|
|
const response = await request(app.getHttpServer())
|
|
.get(`/api/data_queries?app_id=${application.id}&app_version_id=${appVersion.id}`)
|
|
.set('Authorization', authHeaderForUser(adminUserData.user));
|
|
|
|
expect(response.statusCode).toBe(200);
|
|
expect(response.body.data_queries.length).toBe(totalQueries);
|
|
expect(createdQueries).toMatchObject(response.body.data_queries);
|
|
});
|
|
|
|
it('should be able to run queries of an app if the user belongs to the same organization', async () => {
|
|
const adminUserData = await createUser(app, {
|
|
email: 'admin@tooljet.io',
|
|
groups: ['all_users', 'admin'],
|
|
});
|
|
const developerUserData = await createUser(app, {
|
|
email: 'developer@tooljet.io',
|
|
groups: ['all_users', 'developer'],
|
|
organization: adminUserData.organization,
|
|
});
|
|
const viewerUserData = await createUser(app, {
|
|
email: 'viewer@tooljet.io',
|
|
groups: ['all_users', 'viewer'],
|
|
organization: adminUserData.organization,
|
|
});
|
|
const application = await createApplication(app, {
|
|
name: 'name',
|
|
user: adminUserData.user,
|
|
});
|
|
|
|
const dataQuery = await createDataQuery(app, {
|
|
application,
|
|
kind: 'restapi',
|
|
options: {
|
|
method: 'get',
|
|
url: 'https://api.github.com/repos/tooljet/tooljet/stargazers',
|
|
url_params: [],
|
|
headers: [],
|
|
body: [],
|
|
},
|
|
});
|
|
|
|
// setup app permissions for developer
|
|
const developerUserGroup = await getRepository(GroupPermission).findOneOrFail({
|
|
where: {
|
|
group: 'developer',
|
|
},
|
|
});
|
|
await createAppGroupPermission(app, application, developerUserGroup.id, {
|
|
read: true,
|
|
update: true,
|
|
delete: false,
|
|
});
|
|
|
|
// setup app permissions for viewer
|
|
const viewerUserGroup = await getRepository(GroupPermission).findOneOrFail({
|
|
where: {
|
|
group: 'viewer',
|
|
},
|
|
});
|
|
await createAppGroupPermission(app, application, viewerUserGroup.id, {
|
|
read: true,
|
|
update: false,
|
|
delete: false,
|
|
});
|
|
|
|
for (const userData of [adminUserData, developerUserData, viewerUserData]) {
|
|
const response = await request(app.getHttpServer())
|
|
.post(`/api/data_queries/${dataQuery.id}/run`)
|
|
.set('Authorization', authHeaderForUser(userData.user));
|
|
|
|
expect(response.statusCode).toBe(201);
|
|
expect(response.body.data.length).toBe(30);
|
|
}
|
|
});
|
|
|
|
it('should not be able to run queries of an app if the user belongs to another organization', async () => {
|
|
const adminUserData = await createUser(app, {
|
|
email: 'admin@tooljet.io',
|
|
groups: ['all_users', 'admin'],
|
|
});
|
|
const anotherOrgAdminUserData = await createUser(app, {
|
|
email: 'another@tooljet.io',
|
|
groups: ['all_users', 'admin'],
|
|
});
|
|
const application = await createApplication(app, {
|
|
name: 'name',
|
|
user: adminUserData.user,
|
|
});
|
|
|
|
const dataQuery = await createDataQuery(app, {
|
|
application,
|
|
kind: 'restapi',
|
|
options: {
|
|
method: 'get',
|
|
url: 'https://api.github.com/repos/tooljet/tooljet/stargazers',
|
|
url_params: [],
|
|
headers: [],
|
|
body: [],
|
|
},
|
|
});
|
|
|
|
const response = await request(app.getHttpServer())
|
|
.post(`/api/data_queries/${dataQuery.id}/run`)
|
|
.set('Authorization', authHeaderForUser(anotherOrgAdminUserData.user));
|
|
|
|
expect(response.statusCode).toBe(403);
|
|
});
|
|
|
|
it('should be able to run queries of an app if a public app ( even if an unauthenticated user )', async () => {
|
|
const adminUserData = await createUser(app, {
|
|
email: 'admin@tooljet.io',
|
|
groups: ['all_users', 'admin'],
|
|
});
|
|
const application = await createApplication(app, {
|
|
name: 'name',
|
|
user: adminUserData.user,
|
|
isPublic: true,
|
|
});
|
|
const dataQuery = await createDataQuery(app, {
|
|
application,
|
|
kind: 'restapi',
|
|
options: {
|
|
method: 'get',
|
|
url: 'https://api.github.com/repos/tooljet/tooljet/stargazers',
|
|
url_params: [],
|
|
headers: [],
|
|
body: [],
|
|
},
|
|
});
|
|
|
|
const response = await request(app.getHttpServer()).post(`/api/data_queries/${dataQuery.id}/run`);
|
|
|
|
expect(response.statusCode).toBe(201);
|
|
expect(response.body.data.length).toBe(30);
|
|
});
|
|
|
|
it('should not be able to run queries if app not not public and user is not authenticated', async () => {
|
|
const adminUserData = await createUser(app, {
|
|
email: 'admin@tooljet.io',
|
|
groups: ['all_users', 'admin'],
|
|
});
|
|
const application = await createApplication(app, {
|
|
name: 'name',
|
|
user: adminUserData.user,
|
|
isPublic: false,
|
|
});
|
|
const dataQuery = await createDataQuery(app, {
|
|
application,
|
|
kind: 'restapi',
|
|
options: {
|
|
method: 'get',
|
|
url: 'https://api.github.com/repos/tooljet/tooljet/stargazers',
|
|
url_params: [],
|
|
headers: [],
|
|
body: [],
|
|
},
|
|
});
|
|
|
|
const response = await request(app.getHttpServer()).post(`/api/data_queries/${dataQuery.id}/run`);
|
|
|
|
expect(response.statusCode).toBe(401);
|
|
});
|
|
|
|
afterAll(async () => {
|
|
await app.close();
|
|
});
|
|
});
|