feat: Implement rest API endpoint to remove current user

This commit is contained in:
Faruk AYDIN
2024-09-03 15:50:44 +03:00
parent c524277665
commit f8c25ae508
4 changed files with 64 additions and 0 deletions

View File

@@ -0,0 +1,5 @@
export default async (request, response) => {
await request.currentUser.softRemove();
response.status(204).end();
};

View File

@@ -0,0 +1,21 @@
import { describe, it, beforeEach } from 'vitest';
import request from 'supertest';
import app from '../../../../app.js';
import createAuthTokenByUserId from '../../../../helpers/create-auth-token-by-user-id.js';
import { createUser } from '../../../../../test/factories/user.js';
describe('DELETE /api/v1/users/:userId', () => {
let currentUser, token;
beforeEach(async () => {
currentUser = await createUser();
token = await createAuthTokenByUserId(currentUser.id);
});
it('should remove user and return 204 no content', async () => {
await request(app)
.delete(`/api/v1/users/${currentUser.id}`)
.set('Authorization', token)
.expect(204);
});
});