feat: Add variables feature (#5602)
* feat: add variables db models and migrations * feat: variables api endpoints * feat: add $variables to expressions * test: fix ActiveWorkflowRunner tests failing * test: a different fix for the tests broken by $variables * feat: variables licensing * fix: could create one extra variable than licensed for * feat: Add Variables UI page and $vars global property (#5750) * feat: add support for row slot to datatable * feat: add variables create, read, update, delete * feat: add vars autocomplete * chore: remove alert * feat: add variables autocomplete for code and expressions * feat: add tests for variable components * feat: add variables search and sort * test: update tests for variables view * chore: fix test and linting issue * refactor: review changes * feat: add variable creation telemetry * fix: Improve variables listing and disabled case, fix resource sorting (no-changelog) (#5903) * fix: Improve variables disabled experience and fix sorting * fix: update action box margin * test: update tests for variables row and datatable * fix: Add ee controller to base controller * fix: variables.ee routes not being added * feat: add variables validation * fix: fix vue-fragment bug that breaks everything * chore: Update lock * feat: Add variables input validation and permissions (no-changelog) (#5910) * feat: add input validation * feat: handle variables view for non-instance-owner users * test: update variables tests * fix: fix data-testid pattern * feat: improve overflow styles * test: fix variables row snapshot * feat: update sorting to take newly created variables into account * fix: fix list layout overflow * fix: fix adding variables on page other than 1. fix validation * feat: add docs link * fix: fix default displayName function for resource-list-layout * feat: improve vars expressions ux, cm-tooltip * test: fix datatable test * feat: add MATCH_REGEX validation rule * fix: overhaul how datatable pagination selector works * feat: update completer description * fix: conditionally update usage syntax based on key validation * test: update datatable snapshot * fix: fix variables-row button margins * fix: fix pagination overflow * test: Fix broken test * test: Update snapshot * fix: Remove duplicate declaration * feat: add custom variables icon --------- Co-authored-by: Alex Grozav <alex@grozav.com> Co-authored-by: Omar Ajoue <krynble@gmail.com>
This commit is contained in:
99
packages/editor-ui/src/stores/__tests__/environments.spec.ts
Normal file
99
packages/editor-ui/src/stores/__tests__/environments.spec.ts
Normal file
@@ -0,0 +1,99 @@
|
||||
import { afterAll, beforeAll } from 'vitest';
|
||||
import { setActivePinia, createPinia } from 'pinia';
|
||||
import { setupServer } from '@/__tests__/server';
|
||||
import { useEnvironmentsStore } from '@/stores/environments.ee';
|
||||
import { EnvironmentVariable } from '@/Interface';
|
||||
|
||||
describe('store', () => {
|
||||
let server: ReturnType<typeof setupServer>;
|
||||
const seedRecordsCount = 3;
|
||||
|
||||
beforeAll(() => {
|
||||
server = setupServer();
|
||||
server.createList('variable', seedRecordsCount);
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
setActivePinia(createPinia());
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
server.shutdown();
|
||||
});
|
||||
|
||||
describe('variables', () => {
|
||||
describe('fetchAllVariables()', () => {
|
||||
it('should fetch all credentials', async () => {
|
||||
const environmentsStore = useEnvironmentsStore();
|
||||
await environmentsStore.fetchAllVariables();
|
||||
|
||||
expect(environmentsStore.variables).toHaveLength(seedRecordsCount);
|
||||
});
|
||||
});
|
||||
|
||||
describe('createVariable()', () => {
|
||||
it('should store a new variable', async () => {
|
||||
const variable: Omit<EnvironmentVariable, 'id'> = {
|
||||
key: 'ENV_VAR',
|
||||
value: 'SECRET',
|
||||
};
|
||||
const environmentsStore = useEnvironmentsStore();
|
||||
|
||||
await environmentsStore.fetchAllVariables();
|
||||
const recordsCount = environmentsStore.variables.length;
|
||||
|
||||
expect(environmentsStore.variables).toHaveLength(recordsCount);
|
||||
|
||||
await environmentsStore.createVariable(variable);
|
||||
|
||||
expect(environmentsStore.variables).toHaveLength(recordsCount + 1);
|
||||
expect(environmentsStore.variables[0]).toMatchObject(variable);
|
||||
});
|
||||
});
|
||||
|
||||
describe('updateVariable()', () => {
|
||||
it('should update an existing variable', async () => {
|
||||
const updateValue: Partial<EnvironmentVariable> = {
|
||||
key: 'ENV_VAR',
|
||||
value: 'SECRET',
|
||||
};
|
||||
|
||||
const environmentsStore = useEnvironmentsStore();
|
||||
await environmentsStore.fetchAllVariables();
|
||||
|
||||
await environmentsStore.updateVariable({
|
||||
...environmentsStore.variables[0],
|
||||
...updateValue,
|
||||
});
|
||||
|
||||
expect(environmentsStore.variables[0]).toMatchObject(updateValue);
|
||||
});
|
||||
});
|
||||
|
||||
describe('deleteVariable()', () => {
|
||||
it('should delete an existing variable', async () => {
|
||||
const environmentsStore = useEnvironmentsStore();
|
||||
await environmentsStore.fetchAllVariables();
|
||||
const recordsCount = environmentsStore.variables.length;
|
||||
|
||||
await environmentsStore.deleteVariable(environmentsStore.variables[0]);
|
||||
|
||||
expect(environmentsStore.variables).toHaveLength(recordsCount - 1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('variablesAsObject', () => {
|
||||
it('should return variables as a key-value object', async () => {
|
||||
const environmentsStore = useEnvironmentsStore();
|
||||
await environmentsStore.fetchAllVariables();
|
||||
|
||||
expect(environmentsStore.variablesAsObject).toEqual(
|
||||
environmentsStore.variables.reduce<Record<string, string>>((acc, variable) => {
|
||||
acc[variable.key] = variable.value;
|
||||
return acc;
|
||||
}, {}),
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
38
packages/editor-ui/src/stores/__tests__/usage.test.ts
Normal file
38
packages/editor-ui/src/stores/__tests__/usage.test.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
import { createPinia, setActivePinia } from 'pinia';
|
||||
import { useUsageStore } from '@/stores/usage';
|
||||
|
||||
describe('Usage and plan store', () => {
|
||||
beforeEach(() => {
|
||||
setActivePinia(createPinia());
|
||||
});
|
||||
|
||||
test.each([
|
||||
[5, 3, 0.8, false],
|
||||
[5, 4, 0.8, true],
|
||||
[5, 4, 0.9, false],
|
||||
[10, 5, 0.8, false],
|
||||
[10, 8, 0.8, true],
|
||||
[10, 9, 0.8, true],
|
||||
[-1, 99, 0.8, false],
|
||||
[-1, 99, 0.1, false],
|
||||
])(
|
||||
'should check if workflow usage is close to limit',
|
||||
(limit, value, warningThreshold, expectation) => {
|
||||
const store = useUsageStore();
|
||||
store.setData({
|
||||
usage: {
|
||||
executions: {
|
||||
limit,
|
||||
value,
|
||||
warningThreshold,
|
||||
},
|
||||
},
|
||||
license: {
|
||||
planId: '',
|
||||
planName: '',
|
||||
},
|
||||
});
|
||||
expect(store.isCloseToLimit).toBe(expectation);
|
||||
},
|
||||
);
|
||||
});
|
||||
Reference in New Issue
Block a user