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';
|
2023-02-21 10:21:56 -08:00
|
|
|
import { mockInstance } from '../shared/utils';
|
|
|
|
import { InternalHooks } from '@/InternalHooks';
|
|
|
|
import { LoadNodesAndCredentials } from '@/LoadNodesAndCredentials';
|
|
|
|
import { NodeTypes } from '@/NodeTypes';
|
2022-06-03 08:44:34 -07:00
|
|
|
|
|
|
|
let globalOwnerRole: Role;
|
|
|
|
|
|
|
|
beforeAll(async () => {
|
2023-02-21 10:21:56 -08:00
|
|
|
mockInstance(InternalHooks);
|
|
|
|
mockInstance(LoadNodesAndCredentials);
|
|
|
|
mockInstance(NodeTypes);
|
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
|
|
|
});
|
|
|
|
|
2023-05-24 00:45:37 -07:00
|
|
|
// eslint-disable-next-line n8n-local-rules/no-skipped-tests
|
2023-03-10 07:53:05 -08:00
|
|
|
test.skip('user-management:reset should reset DB to default user state', async () => {
|
2022-06-03 08:44:34 -07:00
|
|
|
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
|
|
|
});
|