mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 10:02:05 +00:00
test: Add more tests for expression extensions (no-changelog) (#12598)
This commit is contained in:
committed by
GitHub
parent
a0b7cac3a5
commit
bfe3c5611a
@@ -3,21 +3,39 @@
|
||||
*/
|
||||
import { DateTime } from 'luxon';
|
||||
|
||||
import { ExpressionExtensionError } from '@/errors';
|
||||
|
||||
import { evaluate } from './Helpers';
|
||||
import { ExpressionExtensionError } from '../../src/errors';
|
||||
|
||||
describe('Data Transformation Functions', () => {
|
||||
describe('String Data Transformation Functions', () => {
|
||||
test('.isEmpty() should work correctly on a string that is not empty', () => {
|
||||
expect(evaluate('={{"NotBlank".isEmpty()}}')).toEqual(false);
|
||||
describe('.isEmpty', () => {
|
||||
test('should work correctly on a string that is not empty', () => {
|
||||
expect(evaluate('={{"NotBlank".isEmpty()}}')).toEqual(false);
|
||||
});
|
||||
|
||||
test('should work correctly on a string that is empty', () => {
|
||||
expect(evaluate('={{"".isEmpty()}}')).toEqual(true);
|
||||
});
|
||||
});
|
||||
|
||||
test('.isEmpty() should work correctly on a string that is empty', () => {
|
||||
expect(evaluate('={{"".isEmpty()}}')).toEqual(true);
|
||||
describe('.isNotEmpty', () => {
|
||||
test('should work correctly on a string that is not empty', () => {
|
||||
expect(evaluate('={{"NotBlank".isNotEmpty()}}')).toEqual(true);
|
||||
});
|
||||
|
||||
test('should work correctly on a string that is empty', () => {
|
||||
expect(evaluate('={{"".isNotEmpty()}}')).toEqual(false);
|
||||
});
|
||||
});
|
||||
|
||||
test('.length should return the string length', () => {
|
||||
expect(evaluate('={{"String".length()}}')).toEqual(6);
|
||||
});
|
||||
|
||||
describe('.hash()', () => {
|
||||
test.each([
|
||||
['base64', 'MTIzNDU='],
|
||||
['md5', '827ccb0eea8a706c4c34a16891f84e7b'],
|
||||
['sha1', '8cb2237d0679ca88db6464eac60da96345513964'],
|
||||
['sha224', 'a7470858e79c282bc2f6adfd831b132672dfd1224c1e78cbf5bcd057'],
|
||||
@@ -38,6 +56,10 @@ describe('Data Transformation Functions', () => {
|
||||
expect(evaluate(`={{ "12345".hash("${hashFn}") }}`)).toEqual(hashValue);
|
||||
expect(evaluate(`={{ "12345".hash("${hashFn.toLowerCase()}") }}`)).toEqual(hashValue);
|
||||
});
|
||||
|
||||
test('should throw on invalid algorithm', () => {
|
||||
expect(() => evaluate('={{ "12345".hash("invalid") }}')).toThrow('Unknown algorithm');
|
||||
});
|
||||
});
|
||||
|
||||
test('.urlDecode should work correctly on a string', () => {
|
||||
@@ -64,10 +86,18 @@ describe('Data Transformation Functions', () => {
|
||||
expect(evaluate('={{ "TEST".toLowerCase() }}')).toEqual('test');
|
||||
});
|
||||
|
||||
test('.toDate should work correctly on a date string', () => {
|
||||
expect(evaluate('={{ "2022-09-01T19:42:28.164Z".toDate() }}')).toEqual(
|
||||
new Date('2022-09-01T19:42:28.164Z'),
|
||||
);
|
||||
describe('.toDate', () => {
|
||||
test('should work correctly on a date string', () => {
|
||||
expect(evaluate('={{ "2022-09-01T19:42:28.164Z".toDate() }}')).toEqual(
|
||||
new Date('2022-09-01T19:42:28.164Z'),
|
||||
);
|
||||
});
|
||||
|
||||
test('should throw on invalid date', () => {
|
||||
expect(() => evaluate('={{ "2022-09-32T19:42:28.164Z".toDate() }}')).toThrow(
|
||||
'cannot convert to date',
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
test('.toFloat should work correctly on a string', () => {
|
||||
|
||||
Reference in New Issue
Block a user