refactor: Use internal namespace for the existing API

This commit is contained in:
Faruk AYDIN
2025-04-17 19:47:03 +02:00
parent 53f0d80c80
commit cddfbad68a
354 changed files with 2275 additions and 2195 deletions

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;