feat: Convert factories files to JS
This commit is contained in:
@@ -1,12 +1,6 @@
|
|||||||
import { IJSONObject } from '@automatisch/types';
|
|
||||||
import { faker } from '@faker-js/faker';
|
import { faker } from '@faker-js/faker';
|
||||||
|
|
||||||
type ConfigParams = {
|
export const createConfig = async (params = {}) => {
|
||||||
key?: string;
|
|
||||||
value?: IJSONObject;
|
|
||||||
};
|
|
||||||
|
|
||||||
export const createConfig = async (params: ConfigParams = {}) => {
|
|
||||||
const configData = {
|
const configData = {
|
||||||
key: params?.key || faker.lorem.word(),
|
key: params?.key || faker.lorem.word(),
|
||||||
value: params?.value || { data: 'sampleConfig' },
|
value: params?.value || { data: 'sampleConfig' },
|
@@ -1,8 +1,7 @@
|
|||||||
import Connection from '../../src/models/connection';
|
|
||||||
import appConfig from '../../src/config/app';
|
import appConfig from '../../src/config/app';
|
||||||
import { AES } from 'crypto-js';
|
import { AES } from 'crypto-js';
|
||||||
|
|
||||||
export const createConnection = async (params: Partial<Connection> = {}) => {
|
export const createConnection = async (params = {}) => {
|
||||||
params.key = params?.key || 'deepl';
|
params.key = params?.key || 'deepl';
|
||||||
|
|
||||||
const formattedData = params.formattedData || {
|
const formattedData = params.formattedData || {
|
@@ -1,10 +1,7 @@
|
|||||||
import ExecutionStep from '../../src/models/execution-step';
|
|
||||||
import { createExecution } from './execution';
|
import { createExecution } from './execution';
|
||||||
import { createStep } from './step';
|
import { createStep } from './step';
|
||||||
|
|
||||||
export const createExecutionStep = async (
|
export const createExecutionStep = async (params = {}) => {
|
||||||
params: Partial<ExecutionStep> = {}
|
|
||||||
) => {
|
|
||||||
params.executionId = params?.executionId || (await createExecution()).id;
|
params.executionId = params?.executionId || (await createExecution()).id;
|
||||||
params.stepId = params?.stepId || (await createStep()).id;
|
params.stepId = params?.stepId || (await createStep()).id;
|
||||||
params.status = params?.status || 'success';
|
params.status = params?.status || 'success';
|
@@ -1,7 +1,6 @@
|
|||||||
import Execution from '../../src/models/execution';
|
|
||||||
import { createFlow } from './flow';
|
import { createFlow } from './flow';
|
||||||
|
|
||||||
export const createExecution = async (params: Partial<Execution> = {}) => {
|
export const createExecution = async (params = {}) => {
|
||||||
params.flowId = params?.flowId || (await createFlow()).id;
|
params.flowId = params?.flowId || (await createFlow()).id;
|
||||||
params.testRun = params?.testRun || false;
|
params.testRun = params?.testRun || false;
|
||||||
params.createdAt = params?.createdAt || new Date().toISOString();
|
params.createdAt = params?.createdAt || new Date().toISOString();
|
@@ -1,7 +1,6 @@
|
|||||||
import Flow from '../../src/models/flow';
|
|
||||||
import { createUser } from './user';
|
import { createUser } from './user';
|
||||||
|
|
||||||
export const createFlow = async (params: Partial<Flow> = {}) => {
|
export const createFlow = async (params = {}) => {
|
||||||
params.userId = params?.userId || (await createUser()).id;
|
params.userId = params?.userId || (await createUser()).id;
|
||||||
params.name = params?.name || 'Name your flow!';
|
params.name = params?.name || 'Name your flow!';
|
||||||
params.createdAt = params?.createdAt || new Date().toISOString();
|
params.createdAt = params?.createdAt || new Date().toISOString();
|
@@ -1,7 +1,6 @@
|
|||||||
import Permission from '../../src/models/permission';
|
|
||||||
import { createRole } from './role';
|
import { createRole } from './role';
|
||||||
|
|
||||||
export const createPermission = async (params: Partial<Permission> = {}) => {
|
export const createPermission = async (params = {}) => {
|
||||||
params.roleId = params?.roleId || (await createRole()).id;
|
params.roleId = params?.roleId || (await createRole()).id;
|
||||||
params.action = params?.action || 'read';
|
params.action = params?.action || 'read';
|
||||||
params.subject = params?.subject || 'User';
|
params.subject = params?.subject || 'User';
|
8
packages/backend/test/factories/role.js
Normal file
8
packages/backend/test/factories/role.js
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
export const createRole = async (params = {}) => {
|
||||||
|
params.name = params?.name || 'Viewer';
|
||||||
|
params.key = params?.key || 'viewer';
|
||||||
|
|
||||||
|
const [role] = await global.knex.table('roles').insert(params).returning('*');
|
||||||
|
|
||||||
|
return role;
|
||||||
|
};
|
@@ -1,15 +0,0 @@
|
|||||||
import { IRole } from '@automatisch/types';
|
|
||||||
|
|
||||||
type RoleParams = {
|
|
||||||
name?: string;
|
|
||||||
key?: string;
|
|
||||||
};
|
|
||||||
|
|
||||||
export const createRole = async (params: RoleParams = {}): Promise<IRole> => {
|
|
||||||
params.name = params?.name || 'Viewer';
|
|
||||||
params.key = params?.key || 'viewer';
|
|
||||||
|
|
||||||
const [role] = await knex.table('roles').insert(params).returning('*');
|
|
||||||
|
|
||||||
return role;
|
|
||||||
};
|
|
@@ -1,7 +1,6 @@
|
|||||||
import Step from '../../src/models/step';
|
|
||||||
import { createFlow } from './flow';
|
import { createFlow } from './flow';
|
||||||
|
|
||||||
export const createStep = async (params: Partial<Step> = {}) => {
|
export const createStep = async (params = {}) => {
|
||||||
params.flowId = params?.flowId || (await createFlow()).id;
|
params.flowId = params?.flowId || (await createFlow()).id;
|
||||||
params.type = params?.type || 'action';
|
params.type = params?.type || 'action';
|
||||||
|
|
@@ -1,8 +1,7 @@
|
|||||||
import { createRole } from './role';
|
import { createRole } from './role';
|
||||||
import { faker } from '@faker-js/faker';
|
import { faker } from '@faker-js/faker';
|
||||||
import User from '../../src/models/user';
|
|
||||||
|
|
||||||
export const createUser = async (params: Partial<User> = {}) => {
|
export const createUser = async (params = {}) => {
|
||||||
params.roleId = params?.roleId || (await createRole()).id;
|
params.roleId = params?.roleId || (await createRole()).id;
|
||||||
params.fullName = params?.fullName || faker.person.fullName();
|
params.fullName = params?.fullName || faker.person.fullName();
|
||||||
params.email = params?.email || faker.internet.email();
|
params.email = params?.email || faker.internet.email();
|
Reference in New Issue
Block a user