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';
|
||||
|
||||
type ConfigParams = {
|
||||
key?: string;
|
||||
value?: IJSONObject;
|
||||
};
|
||||
|
||||
export const createConfig = async (params: ConfigParams = {}) => {
|
||||
export const createConfig = async (params = {}) => {
|
||||
const configData = {
|
||||
key: params?.key || faker.lorem.word(),
|
||||
value: params?.value || { data: 'sampleConfig' },
|
@@ -1,8 +1,7 @@
|
||||
import Connection from '../../src/models/connection';
|
||||
import appConfig from '../../src/config/app';
|
||||
import { AES } from 'crypto-js';
|
||||
|
||||
export const createConnection = async (params: Partial<Connection> = {}) => {
|
||||
export const createConnection = async (params = {}) => {
|
||||
params.key = params?.key || 'deepl';
|
||||
|
||||
const formattedData = params.formattedData || {
|
@@ -1,10 +1,7 @@
|
||||
import ExecutionStep from '../../src/models/execution-step';
|
||||
import { createExecution } from './execution';
|
||||
import { createStep } from './step';
|
||||
|
||||
export const createExecutionStep = async (
|
||||
params: Partial<ExecutionStep> = {}
|
||||
) => {
|
||||
export const createExecutionStep = async (params = {}) => {
|
||||
params.executionId = params?.executionId || (await createExecution()).id;
|
||||
params.stepId = params?.stepId || (await createStep()).id;
|
||||
params.status = params?.status || 'success';
|
@@ -1,7 +1,6 @@
|
||||
import Execution from '../../src/models/execution';
|
||||
import { createFlow } from './flow';
|
||||
|
||||
export const createExecution = async (params: Partial<Execution> = {}) => {
|
||||
export const createExecution = async (params = {}) => {
|
||||
params.flowId = params?.flowId || (await createFlow()).id;
|
||||
params.testRun = params?.testRun || false;
|
||||
params.createdAt = params?.createdAt || new Date().toISOString();
|
@@ -1,7 +1,6 @@
|
||||
import Flow from '../../src/models/flow';
|
||||
import { createUser } from './user';
|
||||
|
||||
export const createFlow = async (params: Partial<Flow> = {}) => {
|
||||
export const createFlow = async (params = {}) => {
|
||||
params.userId = params?.userId || (await createUser()).id;
|
||||
params.name = params?.name || 'Name your flow!';
|
||||
params.createdAt = params?.createdAt || new Date().toISOString();
|
@@ -1,7 +1,6 @@
|
||||
import Permission from '../../src/models/permission';
|
||||
import { createRole } from './role';
|
||||
|
||||
export const createPermission = async (params: Partial<Permission> = {}) => {
|
||||
export const createPermission = async (params = {}) => {
|
||||
params.roleId = params?.roleId || (await createRole()).id;
|
||||
params.action = params?.action || 'read';
|
||||
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';
|
||||
|
||||
export const createStep = async (params: Partial<Step> = {}) => {
|
||||
export const createStep = async (params = {}) => {
|
||||
params.flowId = params?.flowId || (await createFlow()).id;
|
||||
params.type = params?.type || 'action';
|
||||
|
@@ -1,8 +1,7 @@
|
||||
import { createRole } from './role';
|
||||
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.fullName = params?.fullName || faker.person.fullName();
|
||||
params.email = params?.email || faker.internet.email();
|
Reference in New Issue
Block a user