mirror of
https://github.com/ToolJet/ToolJet
synced 2026-04-26 16:07:18 +00:00
63 lines
1.7 KiB
TypeScript
63 lines
1.7 KiB
TypeScript
import * as request from 'supertest';
|
|
import { INestApplication } from '@nestjs/common';
|
|
import {
|
|
authHeaderForUser,
|
|
clearDB,
|
|
createApplication,
|
|
createUser,
|
|
createNestAppInstance,
|
|
createThread,
|
|
createApplicationVersion,
|
|
} from '../test.helper';
|
|
|
|
describe('thread controller', () => {
|
|
let app: INestApplication;
|
|
|
|
beforeEach(async () => {
|
|
await clearDB();
|
|
});
|
|
|
|
beforeAll(async () => {
|
|
app = await createNestAppInstance();
|
|
});
|
|
|
|
it('should allow only authenticated users to list threads', async () => {
|
|
await request(app.getHttpServer()).get('/api/threads/1234/all').expect(401);
|
|
});
|
|
|
|
it('should list all threads in an application', async () => {
|
|
const userData = await createUser(app, {
|
|
email: 'admin@tooljet.io',
|
|
role: 'admin',
|
|
});
|
|
const application = await createApplication(app, {
|
|
name: 'App',
|
|
user: userData.user,
|
|
});
|
|
const { user } = userData;
|
|
const version = await createApplicationVersion(app, application);
|
|
await createThread(app, {
|
|
appId: application.id,
|
|
x: 100,
|
|
y: 200,
|
|
userId: userData.user.id,
|
|
organizationId: user.organization.id,
|
|
appVersionsId: version.id,
|
|
});
|
|
|
|
const response = await request(app.getHttpServer())
|
|
.get(`/api/threads/${application.id}/all`)
|
|
.query({ appVersionsId: version.id })
|
|
.set('Authorization', authHeaderForUser(user));
|
|
|
|
expect(response.statusCode).toBe(200);
|
|
expect(response.body).toHaveLength(1);
|
|
expect(Object.keys(response.body[0]).sort()).toEqual(
|
|
['id', 'x', 'y', 'appId', 'appVersionsId', 'userId', 'organizationId', 'isResolved', 'user'].sort()
|
|
);
|
|
});
|
|
|
|
afterAll(async () => {
|
|
await app.close();
|
|
});
|
|
});
|