mirror of
https://github.com/ToolJet/ToolJet
synced 2026-04-30 09:57:19 +00:00
* feat: move plugins to root * modify tsconfig * add .gitignore * delete old plugins file * add parcel * docker compose volume mount * add gcs * add typescript to plugins folder * gcs to ts * add dynamodb * add elastic search * add firestore * add gsheets * add graphql * add mongodb * mssql * add mysql * add postgresql * add redis * add s3 * add slack * add stripe * remove plugin related packages from pkgjson * add lib folder * add gitignore * remove typescript generated files * remove generated file * remove generated files * add twilio * add dist to docker compose cache binding * add dist prefix * cleanup - 1 * delete dist * rename to index.ts + add jest config * add it.todo in tests * test fixes * test file changes * fix type checks * add @tooljet/plugins to server package json * esm vs commonjs bug, reduce got to 11.8.2 from 12.0.0 * docker file npm package version fix * add typesense * cleaup - 2 * add sendgrid * add lerna build and clean script for all packages + tsconfig * cleanup -3 * add plugins build step * add missing plugins build step in npm run build * add mssql, mysql & postgres as singleton classes * add db connection to cache only if datasourceId is available * client: add data source schema/manifest files * add query operations files * logic for wrapping form with schema * add script to create index file * add @tooljet/plugins to frontend folder * cleanup 1 -frontend * cleanup - 2 // frontend // data queries * add client and index to gitignore * update gitignore * fix lint & test * update ci * fix unit, e2e * cleanup -3 * fix test * fix tests * fix indent * try npm ci * fix tests * fix typo * fix * rename file for server entry * heroku fix * add main and types entry points in pkg json * move common to root * cleanup - 4: remove redundant $ sign prefix * cleanup - 4: remove redundant $ sign prefix * update options in-sync before DOM is painted * change type cloud to cloud storage * update readme * update ci.yml * update ci yml * add pkg-lock.json * rename index.ts to server.ts * update lock files * add server package.lock * remove unused import * revert commit: add minio * add root dep * import server.ts * remove plugins build step * add npm shrinkwrap * update version - plugins * add new version - 0.0.8 * upgrade version * move to symlinked package * add lock file * feat: add icon inside package * add plugin creation docs * Remove seed * move icons to plugins folder * install pg dep * add react to packages * add seed cmd * revert change * add plugins build in lint, e2e, unit * e2e, lint use npm ci * update dockerfile for plugins * try combining release with web * limit memory on release * try executing seed script post transpile * try executing seed from server directory * update seed execution * add minio * add correct type * add minio to pkg json * remove old file * fix provider key * add python installable + npm ^7.2.0 (#1752) * add python installable + npm ^7.2.0 * add py to prod file * pin npm version to 7.20.0 * pin npm version to 7.20.0 * split into multi stage build and remove python for buildx * copy plugins from buider stage * update dependencies * add freetds dependency * update server dockerfile * update client dockerfile * update dev dockerfile and compose file * fix entrypoint * fix server dev dockerfile * update docker-compose * remove npm install on root dir on docker build * fix heroku script * make lerna prod dependency to enable prod builds * remove redundant env setup Co-authored-by: Akshay Sasidharan <akshaysasidharan93@gmail.com> Co-authored-by: navaneeth <navaneethpk@outlook.com>
220 lines
7.7 KiB
TypeScript
220 lines
7.7 KiB
TypeScript
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
import * as request from 'supertest';
|
|
import { BadRequestException, INestApplication } from '@nestjs/common';
|
|
import { authHeaderForUser, clearDB, createUser, createNestAppInstance } from '../test.helper';
|
|
|
|
describe('organization users controller', () => {
|
|
let app: INestApplication;
|
|
|
|
beforeEach(async () => {
|
|
await clearDB();
|
|
});
|
|
|
|
beforeAll(async () => {
|
|
app = await createNestAppInstance();
|
|
});
|
|
|
|
it('should allow only admin to be able to invite new users', async () => {
|
|
// setup a pre existing user of different organization
|
|
await createUser(app, {
|
|
email: 'someUser@tooljet.io',
|
|
groups: ['admin', 'all_users'],
|
|
});
|
|
|
|
// setup organization and user setup to test against
|
|
const adminUserData = await createUser(app, {
|
|
email: 'admin@tooljet.io',
|
|
groups: ['admin', 'all_users'],
|
|
});
|
|
|
|
const organization = adminUserData.organization;
|
|
|
|
const developerUserData = await createUser(app, {
|
|
email: 'developer@tooljet.io',
|
|
groups: ['developer', 'all_users'],
|
|
organization,
|
|
});
|
|
|
|
const viewerUserData = await createUser(app, {
|
|
email: 'viewer@tooljet.io',
|
|
groups: ['viewer', 'all_users'],
|
|
organization,
|
|
});
|
|
|
|
await request(app.getHttpServer())
|
|
.post(`/api/organization_users/`)
|
|
.set('Authorization', authHeaderForUser(adminUserData.user))
|
|
.send({ email: 'test@tooljet.io', groups: ['Viewer', 'all_users'] })
|
|
.expect(201);
|
|
|
|
await request(app.getHttpServer())
|
|
.post(`/api/organization_users/`)
|
|
.set('Authorization', authHeaderForUser(developerUserData.user))
|
|
.send({ email: 'test2@tooljet.io', groups: ['Viewer', 'all_users'] })
|
|
.expect(403);
|
|
|
|
await request(app.getHttpServer())
|
|
.post(`/api/organization_users/`)
|
|
.set('Authorization', authHeaderForUser(viewerUserData.user))
|
|
.send({ email: 'test3@tooljet.io', groups: ['Viewer', 'all_users'] })
|
|
.expect(403);
|
|
});
|
|
|
|
describe('POST /api/organization_users/:id/archive', () => {
|
|
it('should allow only authenticated users to archive org users', async () => {
|
|
await request(app.getHttpServer()).post('/api/organization_users/random-id/archive/').expect(401);
|
|
});
|
|
|
|
it('should throw error when trying to remove last active admin', async () => {
|
|
const adminUserData = await createUser(app, {
|
|
email: 'admin@tooljet.io',
|
|
groups: ['admin', 'all_users'],
|
|
status: 'active',
|
|
});
|
|
const organization = adminUserData.organization;
|
|
const anotherAdminUserData = await createUser(app, {
|
|
email: 'another-admin@tooljet.io',
|
|
groups: ['admin', 'all_users'],
|
|
status: 'active',
|
|
organization,
|
|
});
|
|
|
|
const _archivedAdmin = await createUser(app, {
|
|
email: 'archived-admin@tooljet.io',
|
|
groups: ['admin', 'all_users'],
|
|
status: 'archived',
|
|
organization,
|
|
});
|
|
|
|
await request(app.getHttpServer())
|
|
.post(`/api/organization_users/${anotherAdminUserData.orgUser.id}/archive/`)
|
|
.set('Authorization', authHeaderForUser(adminUserData.user))
|
|
.expect(201);
|
|
|
|
const response = await request(app.getHttpServer())
|
|
.post(`/api/organization_users/${adminUserData.orgUser.id}/archive/`)
|
|
.set('Authorization', authHeaderForUser(adminUserData.user));
|
|
|
|
expect(response.statusCode).toEqual(400);
|
|
expect(response.body.message).toEqual('Atleast one active admin is required.');
|
|
});
|
|
|
|
it('should allow only admin users to archive org users', async () => {
|
|
const adminUserData = await createUser(app, {
|
|
email: 'admin@tooljet.io',
|
|
groups: ['admin', 'all_users'],
|
|
status: 'active',
|
|
});
|
|
const organization = adminUserData.organization;
|
|
const developerUserData = await createUser(app, {
|
|
email: 'developer@tooljet.io',
|
|
groups: ['developer', 'all_users'],
|
|
organization,
|
|
});
|
|
const viewerUserData = await createUser(app, {
|
|
email: 'viewer@tooljet.io',
|
|
groups: ['viewer', 'all_users'],
|
|
organization,
|
|
});
|
|
|
|
await request(app.getHttpServer())
|
|
.post(`/api/organization_users/${viewerUserData.orgUser.id}/archive/`)
|
|
.set('Authorization', authHeaderForUser(developerUserData.user))
|
|
.expect(403);
|
|
|
|
await viewerUserData.orgUser.reload();
|
|
expect(viewerUserData.orgUser.status).toBe('invited');
|
|
|
|
await request(app.getHttpServer())
|
|
.post(`/api/organization_users/${viewerUserData.orgUser.id}/archive/`)
|
|
.set('Authorization', authHeaderForUser(adminUserData.user))
|
|
.expect(201);
|
|
|
|
await viewerUserData.orgUser.reload();
|
|
expect(viewerUserData.orgUser.status).toBe('archived');
|
|
});
|
|
});
|
|
|
|
describe('POST /api/organization_users/:id/unarchive', () => {
|
|
it('should allow only authenticated users to unarchive org users', async () => {
|
|
await request(app.getHttpServer()).post('/api/organization_users/random-id/unarchive/').expect(401);
|
|
});
|
|
|
|
it('should allow only admin users to unarchive org users', async () => {
|
|
const adminUserData = await createUser(app, {
|
|
email: 'admin@tooljet.io',
|
|
status: 'active',
|
|
groups: ['admin', 'all_users'],
|
|
});
|
|
const organization = adminUserData.organization;
|
|
const developerUserData = await createUser(app, {
|
|
email: 'developer@tooljet.io',
|
|
status: 'active',
|
|
groups: ['developer', 'all_users'],
|
|
organization,
|
|
});
|
|
const viewerUserData = await createUser(app, {
|
|
email: 'viewer@tooljet.io',
|
|
status: 'archived',
|
|
invitationToken: 'old-token',
|
|
password: 'old-password',
|
|
groups: ['viewer', 'all_users'],
|
|
organization,
|
|
});
|
|
|
|
await request(app.getHttpServer())
|
|
.post(`/api/organization_users/${viewerUserData.orgUser.id}/unarchive/`)
|
|
.set('Authorization', authHeaderForUser(developerUserData.user))
|
|
.expect(403);
|
|
|
|
await viewerUserData.orgUser.reload();
|
|
expect(viewerUserData.orgUser.status).toBe('archived');
|
|
|
|
await request(app.getHttpServer())
|
|
.post(`/api/organization_users/${viewerUserData.orgUser.id}/unarchive/`)
|
|
.set('Authorization', authHeaderForUser(developerUserData.user))
|
|
.expect(403);
|
|
|
|
await viewerUserData.orgUser.reload();
|
|
expect(viewerUserData.orgUser.status).toBe('archived');
|
|
|
|
await request(app.getHttpServer())
|
|
.post(`/api/organization_users/${viewerUserData.orgUser.id}/unarchive/`)
|
|
.set('Authorization', authHeaderForUser(adminUserData.user))
|
|
.expect(201);
|
|
|
|
await viewerUserData.orgUser.reload();
|
|
await viewerUserData.user.reload();
|
|
expect(viewerUserData.orgUser.status).toBe('invited');
|
|
expect(viewerUserData.user.invitationToken).not.toBe('old-token');
|
|
expect(viewerUserData.user.password).not.toBe('old-password');
|
|
});
|
|
|
|
it('should allow unarchive if user is already archived', async () => {
|
|
const adminUserData = await createUser(app, {
|
|
email: 'admin@tooljet.io',
|
|
status: 'active',
|
|
groups: ['admin', 'all_users'],
|
|
});
|
|
const organization = adminUserData.organization;
|
|
const developerUserData = await createUser(app, {
|
|
email: 'developer@tooljet.io',
|
|
status: 'active',
|
|
groups: ['developer', 'all_users'],
|
|
organization,
|
|
});
|
|
|
|
await request(app.getHttpServer())
|
|
.post(`/api/organization_users/${developerUserData.orgUser.id}/unarchive/`)
|
|
.set('Authorization', authHeaderForUser(adminUserData.user))
|
|
.expect(201);
|
|
|
|
await developerUserData.orgUser.reload();
|
|
expect(developerUserData.orgUser.status).toBe('active');
|
|
});
|
|
});
|
|
|
|
afterAll(async () => {
|
|
await app.close();
|
|
});
|
|
});
|