Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
RicardoE105 committed Jan 8, 2025
1 parent 50c8497 commit 12ddaf3
Showing 1 changed file with 65 additions and 1 deletion.
66 changes: 65 additions & 1 deletion packages/editor-ui/src/components/WorkflowActivator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,31 @@ import { useWorkflowsStore } from '@/stores/workflows.store';
import { createTestingPinia } from '@pinia/testing';
import { createComponentRenderer } from '@/__tests__/render';
import { mockedStore } from '@/__tests__/utils';
import { EXECUTE_WORKFLOW_TRIGGER_NODE_TYPE } from '@/constants';
import { EXECUTE_WORKFLOW_TRIGGER_NODE_TYPE, WOOCOMMERCE_TRIGGER_NODE_TYPE } from '@/constants';
import { useCredentialsStore } from '@/stores/credentials.store';
import { useToast } from '@/composables/useToast';

const renderComponent = createComponentRenderer(WorkflowActivator);
let mockWorkflowsStore: ReturnType<typeof mockedStore<typeof useWorkflowsStore>>;
let mockCredentialsStore: ReturnType<typeof mockedStore<typeof useCredentialsStore>>;

vi.mock('@/composables/useToast', () => {
const showMessage = vi.fn();
return {
useToast: () => {
return {
showMessage,
};
},
};
});

describe('WorkflowActivator', () => {
beforeEach(() => {
createTestingPinia();

mockWorkflowsStore = mockedStore(useWorkflowsStore);
mockCredentialsStore = mockedStore(useCredentialsStore);
});

afterEach(() => {
Expand Down Expand Up @@ -79,4 +94,53 @@ describe('WorkflowActivator', () => {
);
expect(getByTestId('workflow-activator-status')).toHaveTextContent('Inactive');
});

it('Should show warning toast if the workflow to be activated has free OpenAI credentials', async () => {
const toast = useToast();

mockWorkflowsStore.workflow.usedCredentials = [
{
id: '1',
name: '',
credentialType: '',
currentUserHasAccess: false,
},
];

mockCredentialsStore.state.credentials = {
'1': {
id: '1',
name: 'OpenAI',
type: 'openAiApi',
data: '',
isManaged: true,
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString(),
},
};

mockWorkflowsStore.workflowTriggerNodes = [
{ type: WOOCOMMERCE_TRIGGER_NODE_TYPE, disabled: false } as never,
];

const { rerender } = renderComponent({
props: {
workflowActive: false,
workflowId: '1',
workflowPermissions: { update: true },
},
});

await rerender({ workflowActive: true });

expect(toast.showMessage).toHaveBeenCalledWith(
expect.objectContaining({
title: "You're using free OpenAI API credits",
message:
'To make sure your workflow runs smoothly in the future, replace the free OpenAI API credits with your own API key.',
type: 'warning',
duration: 0,
}),
);
});
});

0 comments on commit 12ddaf3

Please sign in to comment.