mirror of
https://github.com/ToolJet/ToolJet
synced 2026-05-02 19:07:29 +00:00
* add: new URL prefix
* fix: working on home page
* add: profile path
* playing with rxjs
* removed context part
* working on path changes
* changing routes
- TODO: replace the workspaceId with actual id
* redo: public apps path
* initial commit
* added authorize API
* remove privileges from auth response
* fixed some api issue
- added subscriptions
* fix: redirect url workspace-id null issue
* fix: switch workspace
* fix: organization list mapping
- menu item paths
* fix: preview url
- editor, viewer permission mapping
* jwt fix
* fix: some url issue
- permission mappings
- workspace login
* fixed some issues
- user invite workspace-id
- org settings menu item default selected item issue
* app viewer fixes
* fixing workspace login issues
* fix
* fixing issues
- tooljet db
- path issues
- refatoring the code
* fix: workspace vars permissions
* fix: multi-page handle
* fix: create app from template
* fix: bulk user upload
* fix: import app
- clone app
- upload profile image
* fix: onboarding
* fix: log out
* fixed multi-workspace logout issue
* fix: launch btn
* fix: oauth2
* fixes
* fix: sso login
* fix: workspace sso login
* fixing sso issues
* fix: moved list of orgs to rxjs
- fixed switching issues
* reverting some changes
* fixed some minor bugs
* fixing sso redirect url issues
* fix: switching network timing issues
* fix: back to workspace-id
* fix: tj-database
- refactored the code - removed org id from some pages
- will get the org id from the service file only
* fix: multi-pages
* fix: infinite loop issue
* fixing workspace switching issue
* fixes
- comment link
- logout & private route redirect url
* fix: wrong uuid error
* fixing subpath
- fixed most of the places
- need to test & fix workspace login, sso, new account
* fix: subpath workspace login
* fix: rxjs handle bug
* Revert "fix: tj-database"
This reverts commit 9632ec2ff0.
* fix: reverted tj-db changes
* fix: subpath sso
* typo fix
* fix: existing session issues
* new: switch workspace page
* fix: modal dark-mode
* added default sso support
* fixes
- subpath workspace switching
- handle wrong routes
* fix: manager user button
- refactored the code
* removed SINGLE Workspace feature
* rebase
* add: change modal text
* fix: added validation
* fixed private app 401 issue
* initial commit
* fix: logged out session multi-tab issue
* refactoring the code
* fix: redirect url issue
* added auth-token in cookies
* Fix: failing e2e specs
* added session API
* fix: backend session guard
* fix: removing user details from local storage
* fix: null wid
* undo and redo
* fix: login page
* fix: viewer login redirection
* fix: login page redirection
* fix: public apps logout issue
* added session storage and scheduler
* added profile api
* fix: sso login
- switch workspace
- login page
- setup admin
* working on fixes
* fix: socket issue
* fix: setup admin api
* connected profile & logout apis
* fix: malfunctioned auth token case
* fix: realtime avatar
* fix: profile avatar
* fix: Realtime cursors avatar
* setting max age for auth token cookie
* add: Go to login page if logout api returns 401
* fix: subpath login
* fix
* fix: app logout [viewer]
* fix: authorize page
* remove expiry from jwt
* fix: integrations route
- session api
* small fix
* fix: updated profile
* fix: workspace login [logged user]
* fix: oauth and another workspace page issue
* fixed app preview logout issue
* subpath fix
* fix: subpath app id
* fix: selected state didnt change for apps page [subpath]
* fix
* add cookie parser to test app
* specs added
* increased user session expiry time
* test: session & new apis
* working on test cases
* fix: onboarding issue
* fixing specs
* fix: test cases
* fix: removing profile api calls
* some fixes
* fixing rebase issues
* fix: global ds issues
* fix: app is crashing
* fix: back to text
* fix: oauth test cases
* fix: test-helper
* fix: onboarding test cases
* fix: tests again
* refactoring the code
* latest develop merging precautions
- fixed a minor null issue
* fix: typo
* fix :menu issues due to the merging
* fix: - clicking on tooljet logo didnt redirect to login page for public apps
- private app preview doesnt load after login
* subpath fixes
* fixed back to issue
* PR changes
* fix: spec fixes for EE
* doc: URL scoped for workspace
---------
Co-authored-by: gsmithun4 <gsmithun4@gmail.com>
Co-authored-by: Shubhendra <withshubh@gmail.com>
500 lines
20 KiB
TypeScript
500 lines
20 KiB
TypeScript
import * as request from 'supertest';
|
|
import { INestApplication } from '@nestjs/common';
|
|
import { Organization } from 'src/entities/organization.entity';
|
|
import { OrganizationUser } from 'src/entities/organization_user.entity';
|
|
import { User } from 'src/entities/user.entity';
|
|
import {
|
|
clearDB,
|
|
createNestAppInstanceWithEnvMock,
|
|
createUser,
|
|
verifyInviteToken,
|
|
setUpAccountFromToken,
|
|
authenticateUser,
|
|
} from '../../test.helper';
|
|
import { Repository } from 'typeorm';
|
|
|
|
describe('Form Onboarding', () => {
|
|
let app: INestApplication;
|
|
let userRepository: Repository<User>;
|
|
let orgRepository: Repository<Organization>;
|
|
let orgUserRepository: Repository<OrganizationUser>;
|
|
let current_user: User;
|
|
let loggedUser: any;
|
|
let loggedOrgUser: any;
|
|
let current_organization: Organization;
|
|
let org_user: User;
|
|
let org_user_organization: Organization;
|
|
let mockConfig;
|
|
|
|
beforeAll(async () => {
|
|
({ app, mockConfig } = await createNestAppInstanceWithEnvMock());
|
|
userRepository = app.get('UserRepository');
|
|
orgRepository = app.get('OrganizationRepository');
|
|
orgUserRepository = app.get('OrganizationUserRepository');
|
|
await clearDB();
|
|
});
|
|
|
|
afterEach(() => {
|
|
jest.resetAllMocks();
|
|
jest.clearAllMocks();
|
|
});
|
|
|
|
describe('Multi Organization Operations', () => {
|
|
beforeEach(async () => {
|
|
jest.spyOn(mockConfig, 'get').mockImplementation((key: string) => {
|
|
switch (key) {
|
|
case 'DISABLE_MULTI_WORKSPACE':
|
|
return 'false';
|
|
default:
|
|
return process.env[key];
|
|
}
|
|
});
|
|
});
|
|
describe('Signup user and invite users', () => {
|
|
describe('Signup first user', () => {
|
|
it('should throw error if the user is trying to signup as first user', async () => {
|
|
const response = await request(app.getHttpServer())
|
|
.post('/api/signup')
|
|
.send({ email: 'admin@tooljet.com', name: 'Admin', password: 'password' });
|
|
|
|
expect(response.statusCode).toBe(403);
|
|
});
|
|
|
|
it('first user should only be sign up through /setup-admin api', async () => {
|
|
const response = await request(app.getHttpServer())
|
|
.post('/api/setup-admin')
|
|
.send({ email: 'firstuser@tooljet.com', name: 'Admin', password: 'password', workspace: 'tooljet' });
|
|
expect(response.statusCode).toBe(201);
|
|
});
|
|
});
|
|
|
|
describe('Signup user', () => {
|
|
it('should signup organization admin', async () => {
|
|
const response = await request(app.getHttpServer())
|
|
.post('/api/signup')
|
|
.send({ email: 'admin@tooljet.com', name: 'Admin', password: 'password' });
|
|
expect(response.statusCode).toBe(201);
|
|
|
|
const user = await userRepository.findOneOrFail({
|
|
where: { email: 'admin@tooljet.com' },
|
|
relations: ['organizationUsers'],
|
|
});
|
|
current_user = user;
|
|
|
|
const organization = await orgRepository.findOneOrFail({
|
|
where: { id: user?.organizationUsers?.[0]?.organizationId },
|
|
});
|
|
current_organization = organization;
|
|
|
|
expect(user.defaultOrganizationId).toBe(user?.organizationUsers?.[0]?.organizationId);
|
|
});
|
|
|
|
it('should verify invitation token of user', async () => {
|
|
const { body } = await verifyInviteToken(app, current_user);
|
|
expect(body?.email).toEqual('admin@tooljet.com');
|
|
expect(body?.name).toEqual('Admin');
|
|
});
|
|
|
|
it('should return user info and setup user account using invitation token (setup-account-from-token)', async () => {
|
|
const { invitationToken } = current_user;
|
|
const payload = {
|
|
token: invitationToken,
|
|
};
|
|
await setUpAccountFromToken(app, current_user, current_organization, payload);
|
|
});
|
|
|
|
it('should allow user to view apps', async () => {
|
|
loggedUser = await authenticateUser(app, current_user.email);
|
|
const response = await request(app.getHttpServer())
|
|
.get(`/api/apps`)
|
|
.set('tj-workspace-id', current_user?.defaultOrganizationId)
|
|
.set('Cookie', loggedUser.tokenCookie);
|
|
|
|
expect(response.statusCode).toBe(200);
|
|
});
|
|
});
|
|
|
|
describe("Invite User that doesn't exist in any organization", () => {
|
|
it('should send invitation link to the user', async () => {
|
|
const response = await request(app.getHttpServer())
|
|
.post('/api/organization_users')
|
|
.send({ email: 'org_user@tooljet.com', first_name: 'test', last_name: 'test' })
|
|
.set('tj-workspace-id', current_user?.defaultOrganizationId)
|
|
.set('Cookie', loggedUser.tokenCookie);
|
|
const { status } = response;
|
|
expect(status).toBe(201);
|
|
});
|
|
|
|
it('should verify token', async () => {
|
|
const user = await userRepository.findOneOrFail({ where: { email: 'org_user@tooljet.com' } });
|
|
org_user = user;
|
|
const { body } = await verifyInviteToken(app, org_user);
|
|
expect(body?.email).toEqual('org_user@tooljet.com');
|
|
expect(body?.name).toEqual('test test');
|
|
});
|
|
|
|
it('should setup org user account using invitation token (setup-account-from-token)', async () => {
|
|
const { invitationToken } = org_user;
|
|
const { invitationToken: orgInviteToken } = await orgUserRepository.findOneOrFail({
|
|
where: { userId: org_user.id },
|
|
});
|
|
const organization = await orgRepository.findOneOrFail({
|
|
where: { id: org_user?.organizationUsers?.[0]?.organizationId },
|
|
});
|
|
|
|
org_user_organization = organization;
|
|
const payload = {
|
|
token: invitationToken,
|
|
organization_token: orgInviteToken,
|
|
password: 'password',
|
|
};
|
|
await setUpAccountFromToken(app, org_user, org_user_organization, payload);
|
|
});
|
|
|
|
it('should allow user to view apps', async () => {
|
|
loggedOrgUser = await authenticateUser(app, org_user.email);
|
|
const response = await request(app.getHttpServer())
|
|
.get(`/api/apps`)
|
|
.set('tj-workspace-id', org_user?.defaultOrganizationId)
|
|
.set('Cookie', loggedOrgUser.tokenCookie);
|
|
|
|
expect(response.statusCode).toBe(200);
|
|
});
|
|
});
|
|
|
|
describe('Invite User that exists in an organization', () => {
|
|
let orgInvitationToken: string;
|
|
let invitedUser: User;
|
|
|
|
it('should send invitation link to the user', async () => {
|
|
const response = await request(app.getHttpServer())
|
|
.post('/api/organization_users')
|
|
.send({ email: 'admin@tooljet.com' })
|
|
.set('tj-workspace-id', org_user?.defaultOrganizationId)
|
|
.set('Cookie', loggedOrgUser.tokenCookie);
|
|
const { status } = response;
|
|
expect(status).toBe(201);
|
|
});
|
|
|
|
it('should verify organization token (verify-organization-token)', async () => {
|
|
const { user, invitationToken } = await orgUserRepository.findOneOrFail({
|
|
where: {
|
|
userId: current_user.id,
|
|
organizationId: org_user_organization.id,
|
|
},
|
|
relations: ['user'],
|
|
});
|
|
orgInvitationToken = invitationToken;
|
|
invitedUser = user;
|
|
|
|
const response = await request(app.getHttpServer()).get(
|
|
`/api/verify-organization-token?token=${invitationToken}`
|
|
);
|
|
const {
|
|
body: { email, name, onboarding_details },
|
|
status,
|
|
} = response;
|
|
|
|
expect(status).toBe(200);
|
|
expect(Object.keys(onboarding_details)).toEqual(['password']);
|
|
await invitedUser.reload();
|
|
expect(invitedUser.status).toBe('active');
|
|
expect(email).toEqual('admin@tooljet.com');
|
|
expect(name).toEqual('Admin');
|
|
});
|
|
|
|
it('should accept invite and add user to the organization (accept-invite)', async () => {
|
|
await request(app.getHttpServer()).post(`/api/accept-invite`).send({ token: orgInvitationToken }).expect(201);
|
|
});
|
|
|
|
it('should allow the new user to view apps', async () => {
|
|
const response = await request(app.getHttpServer())
|
|
.get(`/api/apps`)
|
|
.set('tj-workspace-id', invitedUser?.defaultOrganizationId)
|
|
.set('Cookie', loggedUser.tokenCookie);
|
|
|
|
expect(response.statusCode).toBe(200);
|
|
});
|
|
});
|
|
});
|
|
describe('Signup and invite url should both work unless one of them is consumed', () => {
|
|
describe('Signup url should work even if the user is invited to another organization', () => {
|
|
beforeAll(async () => {
|
|
await clearDB();
|
|
const { user, organization } = await createUser(app, {
|
|
firstName: 'admin',
|
|
lastName: 'admin',
|
|
email: 'admin@tooljet.com',
|
|
status: 'active',
|
|
});
|
|
current_user = user;
|
|
current_organization = organization;
|
|
loggedUser = await authenticateUser(app, user.email);
|
|
});
|
|
it('should signup user', async () => {
|
|
const response = await request(app.getHttpServer())
|
|
.post('/api/signup')
|
|
.send({ email: 'another_user@tooljet.com', name: 'another user', password: 'password' });
|
|
expect(response.statusCode).toBe(201);
|
|
|
|
const user = await userRepository.findOneOrFail({
|
|
where: { email: 'another_user@tooljet.com' },
|
|
relations: ['organizationUsers'],
|
|
});
|
|
org_user = user;
|
|
|
|
const organization = await orgRepository.findOneOrFail({
|
|
where: { id: user?.organizationUsers?.[0]?.organizationId },
|
|
});
|
|
org_user_organization = organization;
|
|
|
|
expect(user.defaultOrganizationId).toBe(user?.organizationUsers?.[0]?.organizationId);
|
|
expect(user.status).toBe('invited');
|
|
expect(user.source).toBe('signup');
|
|
});
|
|
|
|
it('should invite signed up user to another workspace', async () => {
|
|
const response = await request(app.getHttpServer())
|
|
.post('/api/organization_users')
|
|
.send({ email: 'another_user@tooljet.com' })
|
|
.set('tj-workspace-id', current_user?.defaultOrganizationId)
|
|
.set('Cookie', loggedUser.tokenCookie);
|
|
const { status } = response;
|
|
expect(status).toBe(201);
|
|
});
|
|
|
|
it('should verify if signup url is still valid for the invited user', async () => {
|
|
const user = await userRepository.findOneOrFail({ where: { email: 'another_user@tooljet.com' } });
|
|
org_user = user;
|
|
const { body, status } = await verifyInviteToken(app, org_user, true);
|
|
expect(status).toBe(200);
|
|
expect(body?.email).toEqual('another_user@tooljet.com');
|
|
expect(body?.name).toEqual('another user');
|
|
const { invitationToken } = org_user;
|
|
const organization = await orgRepository.findOneOrFail({
|
|
where: { id: org_user?.organizationUsers?.[0]?.organizationId },
|
|
});
|
|
|
|
org_user_organization = organization;
|
|
const payload = {
|
|
token: invitationToken,
|
|
password: 'password',
|
|
};
|
|
await setUpAccountFromToken(app, org_user, org_user_organization, payload);
|
|
});
|
|
});
|
|
|
|
describe('Invite url should work even if the user has signed up earlier', () => {
|
|
beforeAll(async () => {
|
|
await clearDB();
|
|
const { user, organization } = await createUser(app, {
|
|
firstName: 'admin',
|
|
lastName: 'admin',
|
|
email: 'admin@tooljet.com',
|
|
status: 'active',
|
|
});
|
|
current_user = user;
|
|
current_organization = organization;
|
|
loggedUser = await authenticateUser(app, user.email);
|
|
});
|
|
it('should signup user', async () => {
|
|
const response = await request(app.getHttpServer())
|
|
.post('/api/signup')
|
|
.send({ email: 'another_user@tooljet.com', name: 'another user', password: 'password' });
|
|
expect(response.statusCode).toBe(201);
|
|
|
|
const user = await userRepository.findOneOrFail({
|
|
where: { email: 'another_user@tooljet.com' },
|
|
relations: ['organizationUsers'],
|
|
});
|
|
org_user = user;
|
|
|
|
const organization = await orgRepository.findOneOrFail({
|
|
where: { id: user?.organizationUsers?.[0]?.organizationId },
|
|
});
|
|
org_user_organization = organization;
|
|
|
|
expect(user.defaultOrganizationId).toBe(user?.organizationUsers?.[0]?.organizationId);
|
|
expect(user.status).toBe('invited');
|
|
expect(user.source).toBe('signup');
|
|
});
|
|
|
|
it('should invite a user to another workspace', async () => {
|
|
const response = await request(app.getHttpServer())
|
|
.post('/api/organization_users')
|
|
.send({ email: 'another_user@tooljet.com' })
|
|
.set('tj-workspace-id', current_user?.defaultOrganizationId)
|
|
.set('Cookie', loggedUser.tokenCookie);
|
|
const { status } = response;
|
|
expect(status).toBe(201);
|
|
});
|
|
|
|
it('should verify if invite url is still valid for the invited user', async () => {
|
|
const user = await userRepository.findOneOrFail({ where: { email: 'another_user@tooljet.com' } });
|
|
org_user = user;
|
|
const { body, status } = await verifyInviteToken(app, org_user);
|
|
expect(status).toBe(200);
|
|
expect(body?.email).toEqual('another_user@tooljet.com');
|
|
expect(body?.name).toEqual('another user');
|
|
const { invitationToken } = org_user;
|
|
const { invitationToken: orgInviteToken } = await orgUserRepository.findOneOrFail({
|
|
where: { userId: org_user.id },
|
|
});
|
|
const organization = await orgRepository.findOneOrFail({
|
|
where: { id: org_user?.organizationUsers?.[0]?.organizationId },
|
|
});
|
|
|
|
org_user_organization = organization;
|
|
const payload = {
|
|
token: invitationToken,
|
|
password: 'password',
|
|
organizationToken: orgInviteToken,
|
|
};
|
|
await setUpAccountFromToken(app, org_user, org_user_organization, payload);
|
|
});
|
|
});
|
|
|
|
describe('Invite url should work', () => {
|
|
beforeAll(async () => {
|
|
await clearDB();
|
|
const { user, organization } = await createUser(app, {
|
|
firstName: 'admin',
|
|
lastName: 'admin',
|
|
email: 'admin@tooljet.com',
|
|
status: 'active',
|
|
});
|
|
current_user = user;
|
|
current_organization = organization;
|
|
loggedUser = await authenticateUser(app, 'admin@tooljet.com');
|
|
});
|
|
it('should invite user to another workspace', async () => {
|
|
const response = await request(app.getHttpServer())
|
|
.post('/api/organization_users')
|
|
.send({ email: 'another_user@tooljet.com', first_name: 'another', last_name: 'user', password: 'password' })
|
|
.set('tj-workspace-id', current_user?.defaultOrganizationId)
|
|
.set('Cookie', loggedUser.tokenCookie);
|
|
const { status } = response;
|
|
expect(status).toBe(201);
|
|
|
|
const user = await userRepository.findOneOrFail({
|
|
where: { email: 'another_user@tooljet.com' },
|
|
relations: ['organizationUsers'],
|
|
});
|
|
org_user = user;
|
|
|
|
const organization = await orgRepository.findOneOrFail({
|
|
where: { id: user?.organizationUsers?.[0]?.organizationId },
|
|
});
|
|
org_user_organization = organization;
|
|
|
|
expect(user.defaultOrganizationId).toBe(user?.organizationUsers?.[0]?.organizationId);
|
|
expect(user.status).toBe('invited');
|
|
expect(user.source).toBe('invite');
|
|
});
|
|
|
|
it('should not signup the same invited user', async () => {
|
|
const response = await request(app.getHttpServer())
|
|
.post('/api/signup')
|
|
.send({ email: 'another_user@tooljet.com', name: 'another user', password: 'password' });
|
|
expect(response.statusCode).toBe(406);
|
|
});
|
|
|
|
it('should verify if invite url is still valid for the signed up user', async () => {
|
|
const user = await userRepository.findOneOrFail({ where: { email: 'another_user@tooljet.com' } });
|
|
org_user = user;
|
|
const { body, status } = await verifyInviteToken(app, org_user);
|
|
expect(status).toBe(200);
|
|
expect(body?.email).toEqual('another_user@tooljet.com');
|
|
expect(body?.name).toEqual('another user');
|
|
const { invitationToken } = org_user;
|
|
const { invitationToken: orgInviteToken } = await orgUserRepository.findOneOrFail({
|
|
where: { userId: org_user.id },
|
|
});
|
|
const organization = await orgRepository.findOneOrFail({
|
|
where: { id: org_user?.organizationUsers?.[0]?.organizationId },
|
|
});
|
|
|
|
org_user_organization = organization;
|
|
const payload = {
|
|
token: invitationToken,
|
|
password: 'password',
|
|
organizationToken: orgInviteToken,
|
|
};
|
|
await setUpAccountFromToken(app, org_user, org_user_organization, payload);
|
|
});
|
|
});
|
|
|
|
describe('Signup url should work', () => {
|
|
beforeAll(async () => {
|
|
await clearDB();
|
|
const { user, organization } = await createUser(app, {
|
|
firstName: 'admin',
|
|
lastName: 'admin',
|
|
email: 'admin@tooljet.com',
|
|
status: 'active',
|
|
});
|
|
current_user = user;
|
|
current_organization = organization;
|
|
loggedUser = await authenticateUser(app, user.email);
|
|
});
|
|
it('should invite user to another workspace', async () => {
|
|
const response = await request(app.getHttpServer())
|
|
.post('/api/organization_users')
|
|
.send({ email: 'another_user@tooljet.com', first_name: 'another', last_name: 'user', password: 'password' })
|
|
.set('tj-workspace-id', current_user?.defaultOrganizationId)
|
|
.set('Cookie', loggedUser.tokenCookie);
|
|
const { status } = response;
|
|
expect(status).toBe(201);
|
|
|
|
const user = await userRepository.findOneOrFail({
|
|
where: { email: 'another_user@tooljet.com' },
|
|
relations: ['organizationUsers'],
|
|
});
|
|
org_user = user;
|
|
|
|
const organization = await orgRepository.findOneOrFail({
|
|
where: { id: user?.organizationUsers?.[0]?.organizationId },
|
|
});
|
|
org_user_organization = organization;
|
|
|
|
expect(user.defaultOrganizationId).toBe(user?.organizationUsers?.[0]?.organizationId);
|
|
expect(user.status).toBe('invited');
|
|
expect(user.source).toBe('invite');
|
|
});
|
|
|
|
it('should not signup the same invited user', async () => {
|
|
const response = await request(app.getHttpServer())
|
|
.post('/api/signup')
|
|
.set('tj-workspace-id', current_user?.defaultOrganizationId)
|
|
.send({ email: 'another_user@tooljet.com', name: 'another user', password: 'password' });
|
|
expect(response.statusCode).toBe(406);
|
|
});
|
|
|
|
it('should verify if signup url is still valid for the invited user', async () => {
|
|
const user = await userRepository.findOneOrFail({ where: { email: 'another_user@tooljet.com' } });
|
|
org_user = user;
|
|
const { body, status } = await verifyInviteToken(app, org_user, true);
|
|
expect(status).toBe(200);
|
|
expect(body?.email).toEqual('another_user@tooljet.com');
|
|
expect(body?.name).toEqual('another user');
|
|
const { invitationToken } = org_user;
|
|
const organization = await orgRepository.findOneOrFail({
|
|
where: { id: org_user?.organizationUsers?.[0]?.organizationId },
|
|
});
|
|
|
|
org_user_organization = organization;
|
|
const payload = {
|
|
token: invitationToken,
|
|
password: 'password',
|
|
};
|
|
await setUpAccountFromToken(app, org_user, org_user_organization, payload);
|
|
});
|
|
});
|
|
});
|
|
});
|
|
|
|
afterAll(async () => {
|
|
await clearDB();
|
|
await app.close();
|
|
});
|
|
});
|