ToolJet/server/test/controllers/library_apps.e2e-spec.ts
Akshay f86c6f53d0
Release v2.20.0: New Templates (#7805)
* [docs] SAML (#7577)

* added saml doc

* added saml in 2.19

* minor changes

* minor updates

* update new quickstart guide link on canvas (#7733)

* Template: Supply chain management (#7453)

* add setup to create template from new exports

Co-authored-by: abhinabaadhikari <abhinabaadhikari2014@gmail.com>

* Add new templates and update an existing template (#7765)

* Add new templates and update an existing template

* Add two more templates

* fix lead management system template definition

* fix lead management system template definition - handle null values

* Template: Supply chain management (#7453)

* add setup to create template from new exports

Co-authored-by: abhinabaadhikari <abhinabaadhikari2014@gmail.com>

* Add new templates and update an existing template (#7765)

* Add new templates and update an existing template

* Add two more templates

* fix lead management system template definition

* fix lead management system template definition - handle null values

* bump to v2.20.0

* fix e2e test

* fix app name

* handle template import based on the tooljet version

---------

Co-authored-by: Kavin Venkatachalam <50441969+kavinvenkatachalam@users.noreply.github.com>
Co-authored-by: Shubhendra Singh Chauhan <withshubh@gmail.com>
Co-authored-by: Karan Rathod <karan.altcampus@gmail.com>
Co-authored-by: abhinabaadhikari <abhinabaadhikari2014@gmail.com>
Co-authored-by: Abhinaba Adhikari <79746925+abhinabaadhikari@users.noreply.github.com>
2023-10-12 11:56:29 +05:30

106 lines
3.6 KiB
TypeScript

import * as request from 'supertest';
import { INestApplication } from '@nestjs/common';
import { clearDB, createUser, createNestAppInstance, authenticateUser } from '../test.helper';
describe('library apps controller', () => {
let app: INestApplication;
beforeEach(async () => {
await clearDB();
});
beforeAll(async () => {
app = await createNestAppInstance();
});
describe('POST /api/library_apps', () => {
it('should be able to create app if user has app create permission', async () => {
const adminUserData = await createUser(app, {
email: 'admin@tooljet.io',
groups: ['all_users', 'admin'],
});
const organization = adminUserData.organization;
const nonAdminUserData = await createUser(app, {
email: 'developer@tooljet.io',
groups: ['all_users'],
organization,
});
let loggedUser = await authenticateUser(app);
adminUserData['tokenCookie'] = loggedUser.tokenCookie;
loggedUser = await authenticateUser(app, 'developer@tooljet.io');
nonAdminUserData['tokenCookie'] = loggedUser.tokenCookie;
let response = await request(app.getHttpServer())
.post('/api/library_apps')
.send({ identifier: 'github-contributors' })
.set('tj-workspace-id', nonAdminUserData.user.defaultOrganizationId)
.set('Cookie', nonAdminUserData['tokenCookie']);
expect(response.statusCode).toBe(403);
response = await request(app.getHttpServer())
.post('/api/library_apps')
.send({ identifier: 'supply-chain-management' })
.set('tj-workspace-id', adminUserData.user.defaultOrganizationId)
.set('Cookie', adminUserData['tokenCookie']);
expect(response.statusCode).toBe(201);
expect(response.body.app[0].name).toContain('Supply Chain Management');
});
it('should return error if template identifier is not found', async () => {
const adminUserData = await createUser(app, {
email: 'admin@tooljet.io',
groups: ['all_users', 'admin'],
});
const loggedUser = await authenticateUser(app);
adminUserData['tokenCookie'] = loggedUser.tokenCookie;
const response = await request(app.getHttpServer())
.post('/api/library_apps')
.send({ identifier: 'non-existent-template' })
.set('tj-workspace-id', adminUserData.user.defaultOrganizationId)
.set('Cookie', adminUserData['tokenCookie']);
const { timestamp, ...restBody } = response.body;
expect(timestamp).toBeDefined();
expect(restBody).toEqual({
message: 'App definition not found',
path: '/api/library_apps',
statusCode: 400,
});
});
});
describe('GET /api/library_apps', () => {
it('should be get app manifests', async () => {
const adminUserData = await createUser(app, {
email: 'admin@tooljet.io',
groups: ['all_users', 'admin'],
});
const loggedUser = await authenticateUser(app);
adminUserData['tokenCookie'] = loggedUser.tokenCookie;
const response = await request(app.getHttpServer())
.get('/api/library_apps')
.set('tj-workspace-id', adminUserData.user.defaultOrganizationId)
.set('Cookie', adminUserData['tokenCookie']);
expect(response.statusCode).toBe(200);
const templateAppIds = response.body['template_app_manifests'].map((manifest) => manifest.id);
expect(new Set(templateAppIds)).toContain('github-contributors');
expect(new Set(templateAppIds)).toContain('customer-dashboard');
});
});
afterAll(async () => {
await app.close();
});
});