Skip to content
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

Fix user-management:reset command #3403

Merged
merged 4 commits into from
Jun 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/cli/src/databases/entities/User.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ export class User {
@BeforeInsert()
@BeforeUpdate()
preUpsertHook(): void {
this.email = this.email?.toLowerCase();
this.email = this.email?.toLowerCase() ?? null;
this.updatedAt = new Date();
}

Expand Down
44 changes: 44 additions & 0 deletions packages/cli/test/integration/commands/reset.cmd.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { execSync } from 'child_process';

import express from 'express';
import path from 'path';

import { Db } from '../../../src';
import * as utils from '../shared/utils';
import type { Role } from '../../../src/databases/entities/Role';
import * as testDb from '../shared/testDb';
import { randomEmail, randomName, randomValidPassword } from '../shared/random';

let app: express.Application;
let testDbName = '';
let globalOwnerRole: Role;

beforeAll(async () => {
app = utils.initTestServer({ endpointGroups: ['owner'], applyAuth: true });
const initResult = await testDb.init();
testDbName = initResult.testDbName;

globalOwnerRole = await testDb.getGlobalOwnerRole();
});

afterAll(async () => {
await testDb.terminate(testDbName);
});

test('user-management:reset should reset DB to default user state', async () => {
await testDb.createUser({ globalRole: globalOwnerRole });

const command = [path.join('bin', 'n8n'), 'user-management:reset'].join(' ');

execSync(command);

const user = await Db.collections.User.findOne();

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();
});