mirror of
https://github.com/ToolJet/ToolJet
synced 2026-04-26 07:57:17 +00:00
* github actions for PR and push to develop branch * test workflow * move to workflows folder * add setup node action * modify build * specify npm version * config unit test * specify host postgres * specify container to run on * add postgresql dependency * add specify ws adapter for test * add e2e test * fix linting * only log errors on tests * update eslint config * fix linting * run e2e test in silent mode * fix library app spec * dont send email on test env * fix org scope * mock env vars * remove reset modules * force colors * explicitly close db connection * add eslint rule for floating promises * update workflow * fix floating promise * fix lint * update workflow * run on all push and pulls * update lint check files * simplify workflow * increase js heap size on env * separate lint and build Co-authored-by: arpitnath <arpitnath42@gmail.com>
89 lines
2.8 KiB
TypeScript
89 lines
2.8 KiB
TypeScript
import * as request from 'supertest';
|
|
import { INestApplication } from '@nestjs/common';
|
|
import { authHeaderForUser, clearDB, createUser, createNestAppInstance } 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 response = await request(app.getHttpServer())
|
|
.post('/api/library_apps')
|
|
.send({ identifier: 'github-contributors' })
|
|
.set('Authorization', authHeaderForUser(nonAdminUserData.user));
|
|
|
|
expect(response.statusCode).toBe(403);
|
|
|
|
response = await request(app.getHttpServer())
|
|
.post('/api/library_apps')
|
|
.send({ identifier: 'github-contributors' })
|
|
.set('Authorization', authHeaderForUser(adminUserData.user));
|
|
|
|
expect(response.statusCode).toBe(201);
|
|
expect(response.body.name).toBe('GitHub Contributor Leaderboard');
|
|
});
|
|
|
|
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 response = await request(app.getHttpServer())
|
|
.post('/api/library_apps')
|
|
.send({ identifier: 'non-existent-template' })
|
|
.set('Authorization', authHeaderForUser(adminUserData.user));
|
|
|
|
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 response = await request(app.getHttpServer())
|
|
.get('/api/library_apps')
|
|
.set('Authorization', authHeaderForUser(adminUserData.user));
|
|
|
|
expect(response.statusCode).toBe(200);
|
|
|
|
const templateAppIds = response.body['template_app_manifests'].map((manifest) => manifest.id);
|
|
|
|
expect(new Set(templateAppIds)).toEqual(new Set(['github-contributors', 'customer-dashboard']));
|
|
});
|
|
});
|
|
|
|
afterAll(async () => {
|
|
await app.close();
|
|
});
|
|
});
|