mirror of
https://github.com/ToolJet/ToolJet
synced 2026-05-14 20:48:25 +00:00
* eslint-setup: rules for frontend and server * setup pre-commit:hook * frontend:eslint fixes * frontend eslint errors and warning fixed * eslint:fix for ./server * fix server/test: expectatin string lint/error * pre-commit:updated * removed unwanted install cmd from docker file * recommended settings and extension for vscode * husky prepare script added * updated extension recommendations * added prettier as recommended extension * added pre-commit to package.json * remove .prettierrc file * resolve changes * resolve changes
104 lines
3.5 KiB
TypeScript
104 lines
3.5 KiB
TypeScript
import * as request from 'supertest';
|
|
import { INestApplication } from '@nestjs/common';
|
|
import { authHeaderForUser, clearDB, createApplication, createUser, createNestAppInstance } from '../test.helper';
|
|
|
|
describe('app_users controller', () => {
|
|
let app: INestApplication;
|
|
|
|
beforeEach(async () => {
|
|
await clearDB();
|
|
});
|
|
|
|
beforeAll(async () => {
|
|
app = await createNestAppInstance();
|
|
});
|
|
|
|
it('should allow only authenticated users to create new app users', async () => {
|
|
await request(app.getHttpServer()).post('/app_users').expect(401);
|
|
});
|
|
|
|
it('should be able to create a new app user if admin of same organization', async () => {
|
|
const adminUserData = await createUser(app, { email: 'admin@tooljet.io', role: 'admin' });
|
|
const developerUserData = await createUser(app, {
|
|
email: 'dev@tooljet.io',
|
|
role: 'developer',
|
|
organization: adminUserData.organization,
|
|
});
|
|
const application = await createApplication(app, { user: adminUserData.user });
|
|
|
|
const response = await request(app.getHttpServer())
|
|
.post(`/app_users`)
|
|
.set('Authorization', authHeaderForUser(adminUserData.user))
|
|
.send({
|
|
app_id: application.id,
|
|
org_user_id: developerUserData.orgUser.id,
|
|
role: 'admin',
|
|
});
|
|
|
|
expect(response.statusCode).toBe(201);
|
|
});
|
|
|
|
it('should not be able to create new app user if admin of another organization', async () => {
|
|
const adminUserData = await createUser(app, { email: 'admin@tooljet.io', role: 'admin' });
|
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
const developerUserData = await createUser(app, {
|
|
email: 'dev@tooljet.io',
|
|
role: 'developer',
|
|
organization: adminUserData.organization,
|
|
});
|
|
const anotherOrgAdminUserData = await createUser(app, { email: 'another@tooljet.io', role: 'admin' });
|
|
const application = await createApplication(app, { name: 'name', user: adminUserData.user });
|
|
|
|
const response = await request(app.getHttpServer())
|
|
.post(`/app_users`)
|
|
.set('Authorization', authHeaderForUser(anotherOrgAdminUserData.user))
|
|
.send({
|
|
app_id: application.id,
|
|
org_user_id: adminUserData.orgUser.id,
|
|
role: 'admin',
|
|
});
|
|
|
|
expect(response.statusCode).toBe(403);
|
|
});
|
|
|
|
it('should not allow developers and viewers to create app users', async () => {
|
|
const adminUserData = await createUser(app, { email: 'admin@tooljet.io', role: 'admin' });
|
|
const application = await createApplication(app, { name: 'name', user: adminUserData.user });
|
|
|
|
const developerUserData = await createUser(app, {
|
|
email: 'dev@tooljet.io',
|
|
role: 'developer',
|
|
organization: adminUserData.organization,
|
|
});
|
|
const viewerUserData = await createUser(app, {
|
|
email: 'viewer@tooljet.io',
|
|
role: 'viewer',
|
|
organization: adminUserData.organization,
|
|
});
|
|
|
|
let response = await request(app.getHttpServer())
|
|
.post(`/app_users/`)
|
|
.set('Authorization', authHeaderForUser(developerUserData.user))
|
|
.send({
|
|
app_id: application.id,
|
|
org_user_id: viewerUserData.orgUser.id,
|
|
role: 'admin',
|
|
});
|
|
expect(response.statusCode).toBe(403);
|
|
|
|
response = response = await request(app.getHttpServer())
|
|
.post(`/app_users/`)
|
|
.set('Authorization', authHeaderForUser(viewerUserData.user))
|
|
.send({
|
|
app_id: application.id,
|
|
org_user_id: developerUserData.orgUser.id,
|
|
role: 'admin',
|
|
});
|
|
|
|
await application.reload();
|
|
});
|
|
|
|
afterAll(async () => {
|
|
await app.close();
|
|
});
|
|
});
|