2021-09-21 13:48:28 +00:00
|
|
|
/* eslint-disable @typescript-eslint/no-unused-vars */
|
2021-08-12 15:33:52 +00:00
|
|
|
import * as request from 'supertest';
|
|
|
|
|
import { INestApplication } from '@nestjs/common';
|
|
|
|
|
import { authHeaderForUser, clearDB, createUser, createNestAppInstance } from '../test.helper';
|
2021-12-10 03:13:05 +00:00
|
|
|
import { getConnection } from 'typeorm';
|
2021-08-12 15:33:52 +00:00
|
|
|
|
|
|
|
|
describe('users controller', () => {
|
|
|
|
|
let app: INestApplication;
|
|
|
|
|
|
|
|
|
|
beforeEach(async () => {
|
|
|
|
|
await clearDB();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
beforeAll(async () => {
|
|
|
|
|
app = await createNestAppInstance();
|
2021-12-10 03:13:05 +00:00
|
|
|
jest.setTimeout(10000);
|
2021-08-12 15:33:52 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe('update user', () => {
|
|
|
|
|
it('should allow users to update their firstName, lastName and password', async () => {
|
|
|
|
|
const userData = await createUser(app, { email: 'admin@tooljet.io', role: 'admin' });
|
|
|
|
|
const { user } = userData;
|
2021-09-21 13:48:28 +00:00
|
|
|
|
|
|
|
|
const [firstName, lastName] = ['Daenerys', 'Targaryen', 'drogo666'];
|
|
|
|
|
|
2021-08-12 15:33:52 +00:00
|
|
|
const response = await request(app.getHttpServer())
|
2021-10-15 09:05:11 +00:00
|
|
|
.patch('/api/users/update')
|
2021-08-12 15:33:52 +00:00
|
|
|
.set('Authorization', authHeaderForUser(user))
|
2021-09-21 13:48:28 +00:00
|
|
|
.send({ firstName, lastName });
|
|
|
|
|
|
2021-08-12 15:33:52 +00:00
|
|
|
expect(response.statusCode).toBe(200);
|
2021-09-21 13:48:28 +00:00
|
|
|
|
2021-08-12 15:33:52 +00:00
|
|
|
await user.reload();
|
2021-09-21 13:48:28 +00:00
|
|
|
|
|
|
|
|
expect(user.firstName).toEqual(firstName);
|
|
|
|
|
expect(user.lastName).toEqual(lastName);
|
2021-08-12 15:33:52 +00:00
|
|
|
});
|
2021-09-21 13:48:28 +00:00
|
|
|
});
|
2021-08-12 15:33:52 +00:00
|
|
|
|
|
|
|
|
afterAll(async () => {
|
2021-12-10 03:13:05 +00:00
|
|
|
await getConnection().close();
|
2021-08-12 15:33:52 +00:00
|
|
|
await app.close();
|
|
|
|
|
});
|
|
|
|
|
});
|