Account Deletion (#716)

Adds ability to remove user account, wipes personal information and soft-deletes record.
This commit is contained in:
Tom Moor
2018-07-10 21:05:01 -07:00
committed by GitHub
parent f15ac0ee2a
commit 2d6f906b83
37 changed files with 254 additions and 79 deletions

View File

@ -3,6 +3,7 @@ import TestServer from 'fetch-test-server';
import app from '..';
import { flushdb, seed } from '../test/support';
import { buildUser } from '../test/factories';
const server = new TestServer(app.callback());
@ -11,19 +12,60 @@ afterAll(server.close);
describe('#user.info', async () => {
it('should return known user', async () => {
const { user } = await seed();
const user = await buildUser();
const res = await server.post('/api/user.info', {
body: { token: user.getJwtToken() },
});
const body = await res.json();
expect(res.status).toEqual(200);
expect(body).toMatchSnapshot();
expect(body.data.id).toEqual(user.id);
expect(body.data.name).toEqual(user.name);
});
it('should require authentication', async () => {
await seed();
const res = await server.post('/api/user.info');
expect(res.status).toEqual(401);
});
});
describe('#user.delete', async () => {
it('should not allow deleting without confirmation', async () => {
const user = await buildUser();
const res = await server.post('/api/user.delete', {
body: { token: user.getJwtToken() },
});
expect(res.status).toEqual(400);
});
it('should allow deleting last admin if only user', async () => {
const user = await buildUser({ isAdmin: true });
const res = await server.post('/api/user.delete', {
body: { token: user.getJwtToken(), confirmation: true },
});
expect(res.status).toEqual(200);
});
it('should not allow deleting last admin if many users', async () => {
const user = await buildUser({ isAdmin: true });
await buildUser({ teamId: user.teamId, isAdmin: false });
const res = await server.post('/api/user.delete', {
body: { token: user.getJwtToken(), confirmation: true },
});
expect(res.status).toEqual(400);
});
it('should allow deleting user account with confirmation', async () => {
const user = await buildUser();
const res = await server.post('/api/user.delete', {
body: { token: user.getJwtToken(), confirmation: true },
});
expect(res.status).toEqual(200);
});
it('should require authentication', async () => {
const res = await server.post('/api/user.delete');
const body = await res.json();
expect(res.status).toEqual(401);
@ -44,7 +86,6 @@ describe('#user.update', async () => {
});
it('should require authentication', async () => {
await seed();
const res = await server.post('/api/user.update');
const body = await res.json();
@ -67,7 +108,7 @@ describe('#user.promote', async () => {
});
it('should require admin', async () => {
const { user } = await seed();
const user = await buildUser();
const res = await server.post('/api/user.promote', {
body: { token: user.getJwtToken(), id: user.id },
});
@ -96,7 +137,7 @@ describe('#user.demote', async () => {
});
it("shouldn't demote admins if only one available ", async () => {
const { admin } = await seed();
const admin = await buildUser({ isAdmin: true });
const res = await server.post('/api/user.demote', {
body: {
@ -111,7 +152,7 @@ describe('#user.demote', async () => {
});
it('should require admin', async () => {
const { user } = await seed();
const user = await buildUser();
const res = await server.post('/api/user.promote', {
body: { token: user.getJwtToken(), id: user.id },
});
@ -139,8 +180,7 @@ describe('#user.suspend', async () => {
});
it("shouldn't allow suspending the user themselves", async () => {
const { admin } = await seed();
const admin = await buildUser({ isAdmin: true });
const res = await server.post('/api/user.suspend', {
body: {
token: admin.getJwtToken(),
@ -154,7 +194,7 @@ describe('#user.suspend', async () => {
});
it('should require admin', async () => {
const { user } = await seed();
const user = await buildUser();
const res = await server.post('/api/user.suspend', {
body: { token: user.getJwtToken(), id: user.id },
});
@ -187,7 +227,7 @@ describe('#user.activate', async () => {
});
it('should require admin', async () => {
const { user } = await seed();
const user = await buildUser();
const res = await server.post('/api/user.activate', {
body: { token: user.getJwtToken(), id: user.id },
});