refactor: Use internal namespace for the existing API
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
const createFlowMock = async (flow) => {
|
||||
const data = {
|
||||
id: flow.id,
|
||||
active: flow.active,
|
||||
name: flow.name,
|
||||
status: flow.status,
|
||||
createdAt: flow.createdAt.getTime(),
|
||||
updatedAt: flow.updatedAt.getTime(),
|
||||
};
|
||||
|
||||
return {
|
||||
data: data,
|
||||
meta: {
|
||||
count: 1,
|
||||
currentPage: null,
|
||||
isArray: false,
|
||||
totalPages: null,
|
||||
type: 'Flow',
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
export default createFlowMock;
|
||||
@@ -0,0 +1,26 @@
|
||||
const createStepMock = async (step) => {
|
||||
const data = {
|
||||
id: step.id,
|
||||
type: step.type || 'action',
|
||||
key: step.key || null,
|
||||
appKey: step.appKey || null,
|
||||
iconUrl: step.iconUrl || null,
|
||||
webhookUrl: step.webhookUrl || null,
|
||||
status: step.status || 'incomplete',
|
||||
position: step.position,
|
||||
parameters: step.parameters || {},
|
||||
};
|
||||
|
||||
return {
|
||||
data,
|
||||
meta: {
|
||||
type: 'Step',
|
||||
count: 1,
|
||||
isArray: false,
|
||||
currentPage: null,
|
||||
totalPages: null,
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
export default createStepMock;
|
||||
@@ -0,0 +1,38 @@
|
||||
const duplicateFlowMock = async (flow, steps = []) => {
|
||||
const data = {
|
||||
active: flow.active,
|
||||
id: flow.id,
|
||||
name: flow.name,
|
||||
status: flow.active ? 'published' : 'draft',
|
||||
createdAt: flow.createdAt.getTime(),
|
||||
updatedAt: flow.updatedAt.getTime(),
|
||||
};
|
||||
|
||||
if (steps.length) {
|
||||
data.steps = steps.map((step) => ({
|
||||
appKey: step.appKey,
|
||||
iconUrl: step.iconUrl,
|
||||
id: step.id,
|
||||
key: step.key,
|
||||
name: step.name,
|
||||
parameters: step.parameters,
|
||||
position: step.position,
|
||||
status: step.status,
|
||||
type: step.type,
|
||||
webhookUrl: step.webhookUrl,
|
||||
}));
|
||||
}
|
||||
|
||||
return {
|
||||
data: data,
|
||||
meta: {
|
||||
count: 1,
|
||||
currentPage: null,
|
||||
isArray: false,
|
||||
totalPages: null,
|
||||
type: 'Flow',
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
export default duplicateFlowMock;
|
||||
@@ -0,0 +1,41 @@
|
||||
import { expect } from 'vitest';
|
||||
|
||||
const exportFlowMock = async (flow, steps = []) => {
|
||||
const data = {
|
||||
id: expect.any(String),
|
||||
name: flow.name,
|
||||
};
|
||||
|
||||
if (steps.length) {
|
||||
data.steps = steps.map((step) => {
|
||||
const computedStep = {
|
||||
id: expect.any(String),
|
||||
key: step.key,
|
||||
name: step.name,
|
||||
appKey: step.appKey,
|
||||
type: step.type,
|
||||
parameters: expect.any(Object),
|
||||
position: step.position,
|
||||
};
|
||||
|
||||
if (step.type === 'trigger') {
|
||||
computedStep.webhookPath = expect.stringContaining('/webhooks/flows/');
|
||||
}
|
||||
|
||||
return computedStep;
|
||||
});
|
||||
}
|
||||
|
||||
return {
|
||||
data: data,
|
||||
meta: {
|
||||
count: 1,
|
||||
currentPage: null,
|
||||
isArray: false,
|
||||
totalPages: null,
|
||||
type: 'Object',
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
export default exportFlowMock;
|
||||
@@ -0,0 +1,38 @@
|
||||
const getFlowMock = async (flow, steps = []) => {
|
||||
const data = {
|
||||
active: flow.active,
|
||||
id: flow.id,
|
||||
name: flow.name,
|
||||
status: flow.active ? 'published' : 'draft',
|
||||
createdAt: flow.createdAt.getTime(),
|
||||
updatedAt: flow.updatedAt.getTime(),
|
||||
};
|
||||
|
||||
if (steps.length) {
|
||||
data.steps = steps.map((step) => ({
|
||||
appKey: step.appKey,
|
||||
iconUrl: step.iconUrl,
|
||||
id: step.id,
|
||||
key: step.key,
|
||||
name: step.name,
|
||||
parameters: step.parameters,
|
||||
position: step.position,
|
||||
status: step.status,
|
||||
type: step.type,
|
||||
webhookUrl: step.webhookUrl,
|
||||
}));
|
||||
}
|
||||
|
||||
return {
|
||||
data: data,
|
||||
meta: {
|
||||
count: 1,
|
||||
currentPage: null,
|
||||
isArray: false,
|
||||
totalPages: null,
|
||||
type: 'Flow',
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
export default getFlowMock;
|
||||
@@ -0,0 +1,40 @@
|
||||
const getFlowsMock = async (flows, steps, currentUserId) => {
|
||||
const data = flows.map((flow) => {
|
||||
const flowSteps = steps.filter((step) => step.flowId === flow.id);
|
||||
|
||||
return {
|
||||
active: flow.active,
|
||||
id: flow.id,
|
||||
name: flow.name,
|
||||
status: flow.active ? 'published' : 'draft',
|
||||
createdAt: flow.createdAt.getTime(),
|
||||
updatedAt: flow.updatedAt.getTime(),
|
||||
isOwner: flow.userId === currentUserId,
|
||||
steps: flowSteps.map((step) => ({
|
||||
appKey: step.appKey,
|
||||
iconUrl: step.iconUrl,
|
||||
id: step.id,
|
||||
key: step.key,
|
||||
name: step.name,
|
||||
parameters: step.parameters,
|
||||
position: step.position,
|
||||
status: step.status,
|
||||
type: step.type,
|
||||
webhookUrl: step.webhookUrl,
|
||||
})),
|
||||
};
|
||||
});
|
||||
|
||||
return {
|
||||
data: data,
|
||||
meta: {
|
||||
count: data.length,
|
||||
currentPage: 1,
|
||||
isArray: true,
|
||||
totalPages: 1,
|
||||
type: 'Flow',
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
export default getFlowsMock;
|
||||
@@ -0,0 +1,21 @@
|
||||
const getFlowMock = async (folder) => {
|
||||
const data = {
|
||||
id: folder.id,
|
||||
name: folder.name,
|
||||
createdAt: folder.createdAt.getTime(),
|
||||
updatedAt: folder.updatedAt.getTime(),
|
||||
};
|
||||
|
||||
return {
|
||||
data: data,
|
||||
meta: {
|
||||
count: 1,
|
||||
currentPage: null,
|
||||
isArray: false,
|
||||
totalPages: null,
|
||||
type: 'Folder',
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
export default getFlowMock;
|
||||
@@ -0,0 +1,35 @@
|
||||
import { expect } from 'vitest';
|
||||
|
||||
const importFlowMock = async (flow, steps = []) => {
|
||||
const data = {
|
||||
name: flow.name,
|
||||
status: flow.active ? 'published' : 'draft',
|
||||
active: flow.active,
|
||||
};
|
||||
|
||||
if (steps.length) {
|
||||
data.steps = steps.map((step) => ({
|
||||
appKey: step.appKey,
|
||||
iconUrl: step.iconUrl,
|
||||
key: step.key,
|
||||
name: step.name,
|
||||
parameters: expect.any(Object),
|
||||
position: step.position,
|
||||
status: 'incomplete',
|
||||
type: step.type,
|
||||
}));
|
||||
}
|
||||
|
||||
return {
|
||||
data: data,
|
||||
meta: {
|
||||
count: 1,
|
||||
currentPage: null,
|
||||
isArray: false,
|
||||
totalPages: null,
|
||||
type: 'Flow',
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
export default importFlowMock;
|
||||
@@ -0,0 +1,29 @@
|
||||
const updateFlowFolderMock = async (flow, folder) => {
|
||||
const data = {
|
||||
active: flow.active,
|
||||
id: flow.id,
|
||||
name: flow.name,
|
||||
status: flow.active ? 'published' : 'draft',
|
||||
createdAt: flow.createdAt.getTime(),
|
||||
updatedAt: flow.updatedAt.getTime(),
|
||||
folder: {
|
||||
id: folder.id,
|
||||
name: folder.name,
|
||||
createdAt: folder.createdAt.getTime(),
|
||||
updatedAt: folder.updatedAt.getTime(),
|
||||
},
|
||||
};
|
||||
|
||||
return {
|
||||
data: data,
|
||||
meta: {
|
||||
count: 1,
|
||||
currentPage: null,
|
||||
isArray: false,
|
||||
totalPages: null,
|
||||
type: 'Flow',
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
export default updateFlowFolderMock;
|
||||
@@ -0,0 +1,38 @@
|
||||
const updateFlowStatusMock = async (flow, steps = []) => {
|
||||
const data = {
|
||||
active: flow.active,
|
||||
id: flow.id,
|
||||
name: flow.name,
|
||||
status: flow.active ? 'published' : 'draft',
|
||||
createdAt: flow.createdAt.getTime(),
|
||||
updatedAt: flow.updatedAt.getTime(),
|
||||
};
|
||||
|
||||
if (steps.length) {
|
||||
data.steps = steps.map((step) => ({
|
||||
appKey: step.appKey,
|
||||
iconUrl: step.iconUrl,
|
||||
id: step.id,
|
||||
key: step.key,
|
||||
name: step.name,
|
||||
parameters: step.parameters,
|
||||
position: step.position,
|
||||
status: step.status,
|
||||
type: step.type,
|
||||
webhookUrl: step.webhookUrl,
|
||||
}));
|
||||
}
|
||||
|
||||
return {
|
||||
data: data,
|
||||
meta: {
|
||||
count: 1,
|
||||
currentPage: null,
|
||||
isArray: false,
|
||||
totalPages: null,
|
||||
type: 'Flow',
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
export default updateFlowStatusMock;
|
||||
Reference in New Issue
Block a user