2022-11-09 06:25:00 -08:00
|
|
|
import * as Db from '@/Db';
|
|
|
|
import { Reset } from '@/commands/user-management/reset';
|
|
|
|
import type { Role } from '@db/entities/Role';
|
2022-06-03 08:44:34 -07:00
|
|
|
import * as testDb from '../shared/testDb';
|
|
|
|
|
|
|
|
let globalOwnerRole: Role;
|
|
|
|
|
|
|
|
beforeAll(async () => {
|
2023-01-13 09:12:22 -08:00
|
|
|
await testDb.init();
|
2022-06-03 08:44:34 -07:00
|
|
|
|
|
|
|
globalOwnerRole = await testDb.getGlobalOwnerRole();
|
|
|
|
});
|
|
|
|
|
2022-06-25 21:03:46 -07:00
|
|
|
beforeEach(async () => {
|
2023-01-13 09:12:22 -08:00
|
|
|
await testDb.truncate(['User']);
|
2022-06-25 21:03:46 -07:00
|
|
|
});
|
|
|
|
|
2022-06-03 08:44:34 -07:00
|
|
|
afterAll(async () => {
|
2023-01-13 09:12:22 -08:00
|
|
|
await testDb.terminate();
|
2022-06-03 08:44:34 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
test('user-management:reset should reset DB to default user state', async () => {
|
|
|
|
await testDb.createUser({ globalRole: globalOwnerRole });
|
|
|
|
|
2022-06-25 21:03:46 -07:00
|
|
|
await Reset.run();
|
2022-06-03 08:44:34 -07:00
|
|
|
|
2023-01-13 09:12:22 -08:00
|
|
|
const user = await Db.collections.User.findOneBy({ globalRoleId: globalOwnerRole.id });
|
2022-06-03 08:44:34 -07:00
|
|
|
|
2022-06-25 21:03:46 -07:00
|
|
|
if (!user) {
|
|
|
|
fail('No owner found after DB reset to default user state');
|
|
|
|
}
|
2022-06-03 08:44:34 -07:00
|
|
|
|
2022-06-25 21:03:46 -07:00
|
|
|
expect(user.email).toBeNull();
|
|
|
|
expect(user.firstName).toBeNull();
|
|
|
|
expect(user.lastName).toBeNull();
|
|
|
|
expect(user.password).toBeNull();
|
|
|
|
expect(user.resetPasswordToken).toBeNull();
|
|
|
|
expect(user.resetPasswordTokenExpiration).toBeNull();
|
|
|
|
expect(user.personalizationAnswers).toBeNull();
|
2022-06-03 08:44:34 -07:00
|
|
|
});
|