CFE-4 implementation of mock handler structure
This commit is contained in:
153
mocks/handler.js
153
mocks/handler.js
@@ -1,146 +1,13 @@
|
||||
import {
|
||||
GET_PERMISSIONS_LIST,
|
||||
GET_ROLE_MANAGEMENT,
|
||||
GET_SIDEBAR_NOTIFICATION,
|
||||
GET_USER_ROUTE,
|
||||
SET_USER_PASSWORD,
|
||||
EXPERT_MANAGEMENT,
|
||||
GET_PROVINCE_LIST,
|
||||
GET_ROLE_LIST,
|
||||
} from "@/core/data/apiRoutes";
|
||||
import {rest} from "msw";
|
||||
import {userHandler} from "./handlers/user";
|
||||
import {permissionsHandler} from "./handlers/permissions";
|
||||
import {rolesHandler} from "./handlers/roles";
|
||||
import {provincesHandler} from "./handlers/provinces";
|
||||
import {expertsHandler} from "./handlers/experts";
|
||||
|
||||
export const handler = [
|
||||
rest.get(GET_USER_ROUTE, (req, res, ctx) => {
|
||||
return res(ctx.json({
|
||||
data: {
|
||||
id: 10,
|
||||
permissions: [
|
||||
"manage_users"
|
||||
],
|
||||
}
|
||||
}))
|
||||
}),
|
||||
rest.get(GET_SIDEBAR_NOTIFICATION, (req, res, ctx) => {
|
||||
return res(ctx.json({
|
||||
data: []
|
||||
}))
|
||||
}),
|
||||
rest.post(SET_USER_PASSWORD, (req, res, ctx) => {
|
||||
return res(
|
||||
ctx.status(200),
|
||||
);
|
||||
}),
|
||||
rest.get(GET_PERMISSIONS_LIST, (req, res, ctx) => {
|
||||
return res(ctx.json(
|
||||
{
|
||||
data: [
|
||||
{
|
||||
id: 1,
|
||||
name: "manage_passenger_office_navgan",
|
||||
name_fa: "مدیریت کارتابل رییس اداره مسافری استان"
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
name: "manage_province_working_group_navgan",
|
||||
name_fa: "مدیریت کارتابل کارگروه استانی"
|
||||
}
|
||||
]
|
||||
}
|
||||
))
|
||||
}),
|
||||
rest.get(GET_ROLE_MANAGEMENT, (req, res, ctx) => {
|
||||
return res(
|
||||
ctx.json(
|
||||
{
|
||||
data: [
|
||||
{
|
||||
created_at: "2023-10-01T07:20:07.000000Z",
|
||||
guard_name: "api",
|
||||
id: 1,
|
||||
name: "admin",
|
||||
name_fa: "ادمین",
|
||||
permissions: [
|
||||
{
|
||||
id: 1,
|
||||
name: "manage_users",
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
name: "manage_roles",
|
||||
},
|
||||
],
|
||||
updated_at: "2023-10-10T07:38:12.000000Z"
|
||||
},
|
||||
{
|
||||
created_at: "2023-10-01T07:20:07.000000Z",
|
||||
guard_name: "api",
|
||||
id: 2,
|
||||
name: "manager",
|
||||
name_fa: "مدیر",
|
||||
permissions: [
|
||||
{
|
||||
id: 1,
|
||||
name: "manage_users",
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
name: "manage_roles",
|
||||
},
|
||||
],
|
||||
updated_at: "2023-10-10T07:38:12.000000Z"
|
||||
}
|
||||
],
|
||||
meta: {
|
||||
totalRowCount: 2
|
||||
}
|
||||
}
|
||||
),
|
||||
);
|
||||
}),
|
||||
rest.get(GET_PROVINCE_LIST, (req, res, ctx) => {
|
||||
return res(ctx.json({
|
||||
data: [
|
||||
{
|
||||
id: 1,
|
||||
name: "آذربایجان شرقی"
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
name: "اردبیل"
|
||||
}
|
||||
]
|
||||
}))
|
||||
}),
|
||||
rest.get(GET_ROLE_LIST, (req, res, ctx) => {
|
||||
return res(ctx.json({
|
||||
data: [
|
||||
{
|
||||
id: 1,
|
||||
name: "admin",
|
||||
name_fa: "ادمین"
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
name: "manager",
|
||||
name_fa: "مدیر"
|
||||
}
|
||||
]
|
||||
}))
|
||||
}),
|
||||
rest.post(EXPERT_MANAGEMENT, (req, res, ctx) => {
|
||||
return res(
|
||||
ctx.status(200),
|
||||
);
|
||||
}),
|
||||
rest.delete(`${EXPERT_MANAGEMENT}/:id`, (req, res, ctx) => {
|
||||
return res(
|
||||
ctx.status(200),
|
||||
);
|
||||
}),
|
||||
rest.post(`${EXPERT_MANAGEMENT}/:id`, (req, res, ctx) => {
|
||||
return res(
|
||||
ctx.status(200),
|
||||
);
|
||||
}),
|
||||
...userHandler,
|
||||
...permissionsHandler,
|
||||
...rolesHandler,
|
||||
...provincesHandler,
|
||||
...expertsHandler
|
||||
]
|
||||
20
mocks/handlers/experts.js
Normal file
20
mocks/handlers/experts.js
Normal file
@@ -0,0 +1,20 @@
|
||||
import {rest} from "msw";
|
||||
import {ADD_EXPERT, DELETE_EXPERT, UPDATE_EXPERT} from "@/core/data/apiRoutes";
|
||||
|
||||
export const expertsHandler = [
|
||||
rest.post(ADD_EXPERT, (req, res, ctx) => {
|
||||
return res(
|
||||
ctx.status(200),
|
||||
);
|
||||
}),
|
||||
rest.delete(`${DELETE_EXPERT}/:id`, (req, res, ctx) => {
|
||||
return res(
|
||||
ctx.status(200),
|
||||
);
|
||||
}),
|
||||
rest.post(`${UPDATE_EXPERT}/:id`, (req, res, ctx) => {
|
||||
return res(
|
||||
ctx.status(200),
|
||||
);
|
||||
}),
|
||||
]
|
||||
23
mocks/handlers/permissions.js
Normal file
23
mocks/handlers/permissions.js
Normal file
@@ -0,0 +1,23 @@
|
||||
import {rest} from "msw";
|
||||
import {GET_PERMISSIONS_LIST} from "@/core/data/apiRoutes";
|
||||
|
||||
export const permissionsHandler = [
|
||||
rest.get(GET_PERMISSIONS_LIST, (req, res, ctx) => {
|
||||
return res(ctx.json(
|
||||
{
|
||||
data: [
|
||||
{
|
||||
id: 1,
|
||||
name: "manage_passenger_office_navgan",
|
||||
name_fa: "مدیریت کارتابل رییس اداره مسافری استان"
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
name: "manage_province_working_group_navgan",
|
||||
name_fa: "مدیریت کارتابل کارگروه استانی"
|
||||
}
|
||||
]
|
||||
}
|
||||
))
|
||||
})
|
||||
]
|
||||
19
mocks/handlers/provinces.js
Normal file
19
mocks/handlers/provinces.js
Normal file
@@ -0,0 +1,19 @@
|
||||
import {rest} from "msw";
|
||||
import {GET_PROVINCE_LIST} from "@/core/data/apiRoutes";
|
||||
|
||||
export const provincesHandler = [
|
||||
rest.get(GET_PROVINCE_LIST, (req, res, ctx) => {
|
||||
return res(ctx.json({
|
||||
data: [
|
||||
{
|
||||
id: 1,
|
||||
name: "آذربایجان شرقی"
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
name: "اردبیل"
|
||||
}
|
||||
]
|
||||
}))
|
||||
}),
|
||||
]
|
||||
70
mocks/handlers/roles.js
Normal file
70
mocks/handlers/roles.js
Normal file
@@ -0,0 +1,70 @@
|
||||
import {rest} from "msw";
|
||||
import {GET_ROLE_LIST, GET_ROLES} from "@/core/data/apiRoutes";
|
||||
|
||||
export const rolesHandler = [
|
||||
rest.get(GET_ROLES, (req, res, ctx) => {
|
||||
return res(
|
||||
ctx.json(
|
||||
{
|
||||
data: [
|
||||
{
|
||||
created_at: "2023-10-01T07:20:07.000000Z",
|
||||
guard_name: "api",
|
||||
id: 1,
|
||||
name: "admin",
|
||||
name_fa: "ادمین",
|
||||
permissions: [
|
||||
{
|
||||
id: 1,
|
||||
name: "manage_users",
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
name: "manage_roles",
|
||||
},
|
||||
],
|
||||
updated_at: "2023-10-10T07:38:12.000000Z"
|
||||
},
|
||||
{
|
||||
created_at: "2023-10-01T07:20:07.000000Z",
|
||||
guard_name: "api",
|
||||
id: 2,
|
||||
name: "manager",
|
||||
name_fa: "مدیر",
|
||||
permissions: [
|
||||
{
|
||||
id: 1,
|
||||
name: "manage_users",
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
name: "manage_roles",
|
||||
},
|
||||
],
|
||||
updated_at: "2023-10-10T07:38:12.000000Z"
|
||||
}
|
||||
],
|
||||
meta: {
|
||||
totalRowCount: 2
|
||||
}
|
||||
}
|
||||
),
|
||||
);
|
||||
}),
|
||||
rest.get(GET_ROLE_LIST, (req, res, ctx) => {
|
||||
return res(ctx.json({
|
||||
data: [
|
||||
{
|
||||
id: 1,
|
||||
name: "admin",
|
||||
name_fa: "ادمین"
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
name: "manager",
|
||||
name_fa: "مدیر"
|
||||
}
|
||||
]
|
||||
}))
|
||||
}),
|
||||
]
|
||||
25
mocks/handlers/user.js
Normal file
25
mocks/handlers/user.js
Normal file
@@ -0,0 +1,25 @@
|
||||
import {rest} from "msw";
|
||||
import {GET_SIDEBAR_NOTIFICATION, GET_USER, SET_USER_PASSWORD} from "@/core/data/apiRoutes";
|
||||
|
||||
export const userHandler = [
|
||||
rest.get(GET_USER, (req, res, ctx) => {
|
||||
return res(ctx.json({
|
||||
data: {
|
||||
id: 10,
|
||||
permissions: [
|
||||
"manage_users"
|
||||
],
|
||||
}
|
||||
}))
|
||||
}),
|
||||
rest.get(GET_SIDEBAR_NOTIFICATION, (req, res, ctx) => {
|
||||
return res(ctx.json({
|
||||
data: []
|
||||
}))
|
||||
}),
|
||||
rest.post(SET_USER_PASSWORD, (req, res, ctx) => {
|
||||
return res(
|
||||
ctx.status(200),
|
||||
);
|
||||
}),
|
||||
]
|
||||
Reference in New Issue
Block a user