2021-12-07 13:25:41 +00:00
|
|
|
import * as request from 'supertest';
|
|
|
|
|
import { INestApplication } from '@nestjs/common';
|
2023-04-06 11:12:58 +00:00
|
|
|
import { clearDB, createUser, createNestAppInstance, authenticateUser } from '../test.helper';
|
2021-12-07 13:25:41 +00:00
|
|
|
|
|
|
|
|
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,
|
|
|
|
|
});
|
|
|
|
|
|
2023-04-06 11:12:58 +00:00
|
|
|
let loggedUser = await authenticateUser(app);
|
|
|
|
|
adminUserData['tokenCookie'] = loggedUser.tokenCookie;
|
|
|
|
|
|
|
|
|
|
loggedUser = await authenticateUser(app, 'developer@tooljet.io');
|
|
|
|
|
nonAdminUserData['tokenCookie'] = loggedUser.tokenCookie;
|
|
|
|
|
|
2021-12-07 13:25:41 +00:00
|
|
|
let response = await request(app.getHttpServer())
|
|
|
|
|
.post('/api/library_apps')
|
|
|
|
|
.send({ identifier: 'github-contributors' })
|
2023-04-06 11:12:58 +00:00
|
|
|
.set('tj-workspace-id', nonAdminUserData.user.defaultOrganizationId)
|
|
|
|
|
.set('Cookie', nonAdminUserData['tokenCookie']);
|
2021-12-07 13:25:41 +00:00
|
|
|
|
|
|
|
|
expect(response.statusCode).toBe(403);
|
|
|
|
|
|
|
|
|
|
response = await request(app.getHttpServer())
|
|
|
|
|
.post('/api/library_apps')
|
|
|
|
|
.send({ identifier: 'github-contributors' })
|
2023-04-06 11:12:58 +00:00
|
|
|
.set('tj-workspace-id', adminUserData.user.defaultOrganizationId)
|
|
|
|
|
.set('Cookie', adminUserData['tokenCookie']);
|
2021-12-07 13:25:41 +00:00
|
|
|
|
|
|
|
|
expect(response.statusCode).toBe(201);
|
2023-06-06 08:42:36 +00:00
|
|
|
expect(response.body.name).toContain('GitHub Contributor Leaderboard');
|
2021-12-07 13:25:41 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should return error if template identifier is not found', async () => {
|
|
|
|
|
const adminUserData = await createUser(app, {
|
|
|
|
|
email: 'admin@tooljet.io',
|
|
|
|
|
groups: ['all_users', 'admin'],
|
|
|
|
|
});
|
|
|
|
|
|
2023-04-06 11:12:58 +00:00
|
|
|
const loggedUser = await authenticateUser(app);
|
|
|
|
|
adminUserData['tokenCookie'] = loggedUser.tokenCookie;
|
|
|
|
|
|
2021-12-07 13:25:41 +00:00
|
|
|
const response = await request(app.getHttpServer())
|
|
|
|
|
.post('/api/library_apps')
|
|
|
|
|
.send({ identifier: 'non-existent-template' })
|
2023-04-06 11:12:58 +00:00
|
|
|
.set('tj-workspace-id', adminUserData.user.defaultOrganizationId)
|
|
|
|
|
.set('Cookie', adminUserData['tokenCookie']);
|
2021-12-07 13:25:41 +00:00
|
|
|
|
2021-12-10 03:13:05 +00:00
|
|
|
const { timestamp, ...restBody } = response.body;
|
|
|
|
|
|
|
|
|
|
expect(timestamp).toBeDefined();
|
|
|
|
|
expect(restBody).toEqual({
|
2021-12-07 13:25:41 +00:00
|
|
|
message: 'App definition not found',
|
2021-12-10 03:13:05 +00:00
|
|
|
path: '/api/library_apps',
|
2021-12-07 13:25:41 +00:00
|
|
|
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'],
|
|
|
|
|
});
|
|
|
|
|
|
2023-04-06 11:12:58 +00:00
|
|
|
const loggedUser = await authenticateUser(app);
|
|
|
|
|
adminUserData['tokenCookie'] = loggedUser.tokenCookie;
|
|
|
|
|
|
2021-12-07 13:25:41 +00:00
|
|
|
const response = await request(app.getHttpServer())
|
|
|
|
|
.get('/api/library_apps')
|
2023-04-06 11:12:58 +00:00
|
|
|
.set('tj-workspace-id', adminUserData.user.defaultOrganizationId)
|
|
|
|
|
.set('Cookie', adminUserData['tokenCookie']);
|
2021-12-07 13:25:41 +00:00
|
|
|
|
|
|
|
|
expect(response.statusCode).toBe(200);
|
|
|
|
|
|
|
|
|
|
const templateAppIds = response.body['template_app_manifests'].map((manifest) => manifest.id);
|
|
|
|
|
|
2022-02-08 04:19:27 +00:00
|
|
|
expect(new Set(templateAppIds)).toContain('github-contributors');
|
|
|
|
|
expect(new Set(templateAppIds)).toContain('customer-dashboard');
|
2021-12-07 13:25:41 +00:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
afterAll(async () => {
|
|
|
|
|
await app.close();
|
|
|
|
|
});
|
|
|
|
|
});
|