test(core): Move unit tests closer to testable components (no-changelog) (#10287)

This commit is contained in:
Tomi Turtiainen
2024-08-05 12:12:25 +03:00
committed by GitHub
parent 8131d66f8c
commit afa43e75f6
80 changed files with 95 additions and 105 deletions

View File

@@ -0,0 +1,36 @@
import { User } from '@db/entities/User';
describe('User Entity', () => {
describe('JSON.stringify', () => {
it('should not serialize sensitive data', () => {
const user = Object.assign(new User(), {
email: 'test@example.com',
firstName: 'Don',
lastName: 'Joe',
password: '123456789',
apiKey: '123',
});
expect(JSON.stringify(user)).toEqual(
'{"email":"test@example.com","firstName":"Don","lastName":"Joe"}',
);
});
});
describe('createPersonalProjectName', () => {
test.each([
['Nathan', 'Nathaniel', 'nathan@nathaniel.n8n', 'Nathan Nathaniel <nathan@nathaniel.n8n>'],
[undefined, 'Nathaniel', 'nathan@nathaniel.n8n', '<nathan@nathaniel.n8n>'],
['Nathan', undefined, 'nathan@nathaniel.n8n', '<nathan@nathaniel.n8n>'],
[undefined, undefined, 'nathan@nathaniel.n8n', '<nathan@nathaniel.n8n>'],
[undefined, undefined, undefined, 'Unnamed Project'],
['Nathan', 'Nathaniel', undefined, 'Unnamed Project'],
])(
'given fistName: %s, lastName: %s and email: %s this gives the projectName: "%s"',
async (firstName, lastName, email, projectName) => {
const user = new User();
Object.assign(user, { firstName, lastName, email });
expect(user.createPersonalProjectName()).toBe(projectName);
},
);
});
});