-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Delete account route #331
base: master
Are you sure you want to change the base?
Delete account route #331
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
import { EntityRepository, In } from 'typeorm'; | ||
import * as bcrypt from 'bcrypt'; | ||
import FactoryUtils from 'tests/data/FactoryUtils'; | ||
import { Activity } from '../types/internal'; | ||
import { UserModel } from '../models/UserModel'; | ||
import { Uuid } from '../types'; | ||
import { UserAccessType, UserState, Uuid } from '../types'; | ||
import { BaseRepository } from './BaseRepository'; | ||
|
||
@EntityRepository(UserModel) | ||
|
@@ -82,4 +83,23 @@ export class UserRepository extends BaseRepository<UserModel> { | |
}) | ||
.execute(); | ||
} | ||
|
||
public async deleteUser(user: UserModel) { | ||
const clearedSensitiveFields: Partial<UserModel> = { | ||
email: `deleted-user-${FactoryUtils.randomHexString()}@ucsd.edu`, | ||
profilePicture: null, | ||
firstName: 'Deleted', | ||
lastName: 'User', | ||
graduationYear: 0, | ||
major: 'Deleted', | ||
points: 0, | ||
credits: 0, | ||
lastLogin: new Date(0), | ||
bio: null, | ||
accessType: UserAccessType.RESTRICTED, | ||
state: UserState.BLOCKED, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. re: my earlier comment about whether we should use a new |
||
}; | ||
const deletedUser = { ...user, ...clearedSensitiveFields }; | ||
return this.repository.save(deletedUser); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { ControllerFactory } from './controllers'; | ||
import { DatabaseConnection, PortalState, UserFactory } from './data'; | ||
|
||
beforeAll(async () => { | ||
await DatabaseConnection.connect(); | ||
}); | ||
|
||
beforeEach(async () => { | ||
await DatabaseConnection.clear(); | ||
}); | ||
|
||
afterAll(async () => { | ||
await DatabaseConnection.clear(); | ||
await DatabaseConnection.close(); | ||
}); | ||
|
||
describe('Delete user account', () => { | ||
test('Deleted user account cannot log in', async () => { | ||
const conn = await DatabaseConnection.get(); | ||
const account = UserFactory.fake(); | ||
|
||
await new PortalState().createUsers(account).write(); | ||
const userController = await ControllerFactory.user(conn); | ||
|
||
const deletedUserResponse = await userController.deleteAccount(account); | ||
|
||
expect(deletedUserResponse).toStrictEqual({ error: null }); | ||
}); | ||
test('Deleted user account is not viewable to other members', async () => { | ||
}); | ||
test('Deleted user account is still counted for event attendance', async () => { | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: let's make the string values here all uppercased so that visually it's easier to distinguish deleted users and active users in e.g. a list of orders, a database table, etc.