update runCase at once
This commit is contained in:
@@ -22,6 +22,7 @@ app.use(express.static(path.join(__dirname, 'public')));
|
|||||||
const sequelize = new Sequelize({
|
const sequelize = new Sequelize({
|
||||||
dialect: 'sqlite',
|
dialect: 'sqlite',
|
||||||
storage: 'database/database.sqlite',
|
storage: 'database/database.sqlite',
|
||||||
|
logging: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
// "/"
|
// "/"
|
||||||
@@ -98,17 +99,9 @@ app.use('/runs', runDeleteRoute);
|
|||||||
|
|
||||||
// "/runcases"
|
// "/runcases"
|
||||||
const runCaseIndexRoute = require('./routes/runcases/index')(sequelize);
|
const runCaseIndexRoute = require('./routes/runcases/index')(sequelize);
|
||||||
const runCaseNewRoute = require('./routes/runcases/new')(sequelize);
|
|
||||||
const runCaseEditRoute = require('./routes/runcases/edit')(sequelize);
|
const runCaseEditRoute = require('./routes/runcases/edit')(sequelize);
|
||||||
const runCaseBuldNewRoute = require('./routes/runcases/bulkNew')(sequelize);
|
|
||||||
const runCaseDeleteRoute = require('./routes/runcases/delete')(sequelize);
|
|
||||||
const runCaseBulkDeleteRoute = require('./routes/runcases/bulkDelete')(sequelize);
|
|
||||||
app.use('/runcases', runCaseIndexRoute);
|
app.use('/runcases', runCaseIndexRoute);
|
||||||
app.use('/runcases', runCaseNewRoute);
|
|
||||||
app.use('/runcases', runCaseEditRoute);
|
app.use('/runcases', runCaseEditRoute);
|
||||||
app.use('/runcases', runCaseBuldNewRoute);
|
|
||||||
app.use('/runcases', runCaseDeleteRoute);
|
|
||||||
app.use('/runcases', runCaseBulkDeleteRoute);
|
|
||||||
|
|
||||||
// "/members"
|
// "/members"
|
||||||
const membersIndexRoute = require('./routes/members/index')(sequelize);
|
const membersIndexRoute = require('./routes/members/index')(sequelize);
|
||||||
|
|||||||
@@ -1,47 +0,0 @@
|
|||||||
const express = require('express');
|
|
||||||
const router = express.Router();
|
|
||||||
const defineRunCase = require('../../models/runCases');
|
|
||||||
const { DataTypes, Op } = require('sequelize');
|
|
||||||
|
|
||||||
module.exports = function (sequelize) {
|
|
||||||
const RunCase = defineRunCase(sequelize, DataTypes);
|
|
||||||
const { verifySignedIn } = require('../../middleware/auth')(sequelize);
|
|
||||||
const { verifyProjectReporterFromRunId } = require('../../middleware/verifyEditable')(sequelize);
|
|
||||||
|
|
||||||
router.post('/bulkdelete', verifySignedIn, verifyProjectReporterFromRunId, async (req, res) => {
|
|
||||||
const recordsToDelete = req.body;
|
|
||||||
|
|
||||||
// TODO Instead of receiving a combination of runId and caseId from frontend,
|
|
||||||
// receives only an array of caseId and constructs a pair from the query parameter runId
|
|
||||||
try {
|
|
||||||
const existingRunCases = await RunCase.findAll({
|
|
||||||
where: {
|
|
||||||
[Op.or]: recordsToDelete.map((condition) => ({
|
|
||||||
runId: condition.runId,
|
|
||||||
caseId: condition.caseId,
|
|
||||||
})),
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
if (existingRunCases.length === 0) {
|
|
||||||
return res.status(200).send('No records found to delete');
|
|
||||||
}
|
|
||||||
|
|
||||||
await RunCase.destroy({
|
|
||||||
where: {
|
|
||||||
[Op.or]: recordsToDelete.map((condition) => ({
|
|
||||||
runId: condition.runId,
|
|
||||||
caseId: condition.caseId,
|
|
||||||
})),
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
res.status(200).send('Records deleted successfully');
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Error deleting run cases:', error);
|
|
||||||
res.status(500).send('Internal Server Error');
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return router;
|
|
||||||
};
|
|
||||||
@@ -1,49 +0,0 @@
|
|||||||
const express = require('express');
|
|
||||||
const router = express.Router();
|
|
||||||
const defineRunCase = require('../../models/runCases');
|
|
||||||
const { DataTypes, Op } = require('sequelize');
|
|
||||||
|
|
||||||
module.exports = function (sequelize) {
|
|
||||||
const { verifySignedIn } = require('../../middleware/auth')(sequelize);
|
|
||||||
const { verifyProjectReporterFromRunId } = require('../../middleware/verifyEditable')(sequelize);
|
|
||||||
const RunCase = defineRunCase(sequelize, DataTypes);
|
|
||||||
|
|
||||||
router.post('/bulknew', verifySignedIn, verifyProjectReporterFromRunId, async (req, res) => {
|
|
||||||
const recordsToCreate = req.body;
|
|
||||||
|
|
||||||
// TODO Instead of receiving a combination of runId and caseId from frontend,
|
|
||||||
// receives only an array of caseId and constructs a pair from the query parameter runId
|
|
||||||
try {
|
|
||||||
const existingRunCases = await RunCase.findAll({
|
|
||||||
where: {
|
|
||||||
[Op.or]: recordsToCreate.map((record) => ({
|
|
||||||
runId: record.runId,
|
|
||||||
caseId: record.caseId,
|
|
||||||
})),
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
// Filter out records that already exist
|
|
||||||
const recordsToCreateFiltered = recordsToCreate.filter((record) => {
|
|
||||||
return !existingRunCases.some(
|
|
||||||
(existingRecord) => existingRecord.runId == record.runId && existingRecord.caseId == record.caseId
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
const newRunCases = await RunCase.bulkCreate(
|
|
||||||
recordsToCreateFiltered.map((record) => ({
|
|
||||||
runId: record.runId,
|
|
||||||
caseId: record.caseId,
|
|
||||||
status: 0,
|
|
||||||
}))
|
|
||||||
);
|
|
||||||
|
|
||||||
res.json(newRunCases);
|
|
||||||
} catch (error) {
|
|
||||||
console.error(error);
|
|
||||||
res.status(500).send('Internal Server Error');
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return router;
|
|
||||||
};
|
|
||||||
@@ -1,37 +0,0 @@
|
|||||||
const express = require('express');
|
|
||||||
const router = express.Router();
|
|
||||||
const defineRunCase = require('../../models/runCases');
|
|
||||||
const { DataTypes } = require('sequelize');
|
|
||||||
|
|
||||||
module.exports = function (sequelize) {
|
|
||||||
const { verifySignedIn } = require('../../middleware/auth')(sequelize);
|
|
||||||
const { verifyProjectReporterFromRunId } = require('../../middleware/verifyEditable')(sequelize);
|
|
||||||
const RunCase = defineRunCase(sequelize, DataTypes);
|
|
||||||
|
|
||||||
router.delete('/', verifySignedIn, verifyProjectReporterFromRunId, async (req, res) => {
|
|
||||||
const runId = req.query.runId;
|
|
||||||
const caseId = req.query.caseId;
|
|
||||||
|
|
||||||
try {
|
|
||||||
// Get RunCase to be deleted.
|
|
||||||
const deletingRunCase = await RunCase.findOne({
|
|
||||||
where: {
|
|
||||||
runId: runId,
|
|
||||||
caseId: caseId,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!deletingRunCase) {
|
|
||||||
return res.status(404).send('RunCase not found');
|
|
||||||
}
|
|
||||||
|
|
||||||
await deletingRunCase.destroy();
|
|
||||||
res.status(204).send();
|
|
||||||
} catch (error) {
|
|
||||||
console.error(error);
|
|
||||||
res.status(500).send('Internal Server Error');
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return router;
|
|
||||||
};
|
|
||||||
@@ -8,31 +8,68 @@ module.exports = function (sequelize) {
|
|||||||
const { verifyProjectReporterFromRunId } = require('../../middleware/verifyEditable')(sequelize);
|
const { verifyProjectReporterFromRunId } = require('../../middleware/verifyEditable')(sequelize);
|
||||||
const RunCase = defineRunCase(sequelize, DataTypes);
|
const RunCase = defineRunCase(sequelize, DataTypes);
|
||||||
|
|
||||||
router.put('/', verifySignedIn, verifyProjectReporterFromRunId, async (req, res) => {
|
router.post('/update', verifySignedIn, verifyProjectReporterFromRunId, async (req, res) => {
|
||||||
const runId = req.query.runId;
|
const runId = req.query.runId;
|
||||||
const caseId = req.query.caseId;
|
const runCases = req.body;
|
||||||
const status = req.query.status;
|
const t = await sequelize.transaction();
|
||||||
|
|
||||||
|
console.log('############## start edit');
|
||||||
|
console.log(runCases);
|
||||||
|
console.log('############## end edit');
|
||||||
|
|
||||||
|
const createRunCase = async (runCase) => {
|
||||||
|
const newRunCase = await RunCase.create(
|
||||||
|
{
|
||||||
|
runId: runId,
|
||||||
|
caseId: runCase.caseId,
|
||||||
|
status: 0,
|
||||||
|
},
|
||||||
|
{ transaction: t }
|
||||||
|
);
|
||||||
|
return newRunCase;
|
||||||
|
};
|
||||||
|
|
||||||
|
const deleteRunCase = async (runCase) => {
|
||||||
|
await RunCase.destroy({
|
||||||
|
where: { runId: runId, caseId: runCase.caseId },
|
||||||
|
transaction: t,
|
||||||
|
});
|
||||||
|
return null;
|
||||||
|
};
|
||||||
|
|
||||||
|
const updateRunCase = async (runCase) => {
|
||||||
|
await RunCase.update(
|
||||||
|
{
|
||||||
|
status: runCase.status,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
where: { id: runCase.id },
|
||||||
|
transaction: t,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
return step;
|
||||||
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const runCase = await RunCase.findOne({
|
const results = await Promise.all(
|
||||||
where: {
|
runCases.map(async (step) => {
|
||||||
runId: runId,
|
if (step.editState === 'new') {
|
||||||
caseId: caseId,
|
return createRunCase(step);
|
||||||
},
|
} else if (step.editState === 'deleted') {
|
||||||
});
|
return deleteRunCase(step);
|
||||||
|
} else if (step.editState === 'changed') {
|
||||||
|
return updateRunCase(step);
|
||||||
|
} else if (step.editState === 'notChanged') {
|
||||||
|
return step;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
if (!runCase) {
|
await t.commit();
|
||||||
return res.status(404).send('Runcase not found');
|
res.json(results.filter((result) => result !== null));
|
||||||
}
|
|
||||||
|
|
||||||
await runCase.update({
|
|
||||||
runId,
|
|
||||||
caseId,
|
|
||||||
status,
|
|
||||||
});
|
|
||||||
res.json(runCase);
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
|
await t.rollback();
|
||||||
res.status(500).send('Internal Server Error');
|
res.status(500).send('Internal Server Error');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,42 +0,0 @@
|
|||||||
const express = require('express');
|
|
||||||
const router = express.Router();
|
|
||||||
const defineRunCase = require('../../models/runCases');
|
|
||||||
const { DataTypes } = require('sequelize');
|
|
||||||
|
|
||||||
module.exports = function (sequelize) {
|
|
||||||
const { verifySignedIn } = require('../../middleware/auth')(sequelize);
|
|
||||||
const { verifyProjectReporterFromRunId } = require('../../middleware/verifyEditable')(sequelize);
|
|
||||||
const RunCase = defineRunCase(sequelize, DataTypes);
|
|
||||||
|
|
||||||
router.post('/', verifySignedIn, verifyProjectReporterFromRunId, async (req, res) => {
|
|
||||||
const runId = req.query.runId;
|
|
||||||
const caseId = req.query.caseId;
|
|
||||||
|
|
||||||
try {
|
|
||||||
// Check if the record already exists
|
|
||||||
const existingRunCase = await RunCase.findOne({
|
|
||||||
where: {
|
|
||||||
runId: runId,
|
|
||||||
caseId: caseId,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
if (existingRunCase) {
|
|
||||||
return res.status(400).send('Record already exists');
|
|
||||||
}
|
|
||||||
|
|
||||||
const newRunCase = await RunCase.create({
|
|
||||||
runId: runId,
|
|
||||||
caseId: caseId,
|
|
||||||
status: 0,
|
|
||||||
});
|
|
||||||
|
|
||||||
res.json(newRunCase);
|
|
||||||
} catch (error) {
|
|
||||||
console.error(error);
|
|
||||||
res.status(500).send('Internal Server Error');
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return router;
|
|
||||||
};
|
|
||||||
@@ -277,7 +277,8 @@
|
|||||||
"test_case_selection": "Test case selection",
|
"test_case_selection": "Test case selection",
|
||||||
"include_in_run": "Include in run",
|
"include_in_run": "Include in run",
|
||||||
"exclude_from_run": "Exclude from run",
|
"exclude_from_run": "Exclude from run",
|
||||||
"no_cases_found": "No cases found"
|
"no_cases_found": "No cases found",
|
||||||
|
"are_you_sure_leave": "Are you sure you want to leave the page?"
|
||||||
},
|
},
|
||||||
"Members": {
|
"Members": {
|
||||||
"member_management": "Member Management",
|
"member_management": "Member Management",
|
||||||
|
|||||||
@@ -173,7 +173,8 @@
|
|||||||
"case_title": "テストケースタイトル",
|
"case_title": "テストケースタイトル",
|
||||||
"case_description": "テストケース詳細",
|
"case_description": "テストケース詳細",
|
||||||
"create": "作成",
|
"create": "作成",
|
||||||
"please_rnter": "テストケースタイトルを入力してください"
|
"please_rnter": "テストケースタイトルを入力してください",
|
||||||
|
"are_you_sure_leave": "ページを離れてもよろしいですか"
|
||||||
},
|
},
|
||||||
"Case": {
|
"Case": {
|
||||||
"back_to_cases": "テストケース一覧に戻る",
|
"back_to_cases": "テストケース一覧に戻る",
|
||||||
|
|||||||
@@ -22,23 +22,15 @@ import { Save, ArrowLeft, Folder, ChevronDown, CopyPlus, CopyMinus, RotateCw } f
|
|||||||
import RunProgressChart from './RunPregressDonutChart';
|
import RunProgressChart from './RunPregressDonutChart';
|
||||||
import TestCaseSelector from './TestCaseSelector';
|
import TestCaseSelector from './TestCaseSelector';
|
||||||
import { testRunStatus } from '@/config/selection';
|
import { testRunStatus } from '@/config/selection';
|
||||||
import { RunType, RunCaseType, RunCaseInfoType, RunStatusCountType, RunMessages } from '@/types/run';
|
import { RunType, RunCaseType, RunStatusCountType, RunMessages } from '@/types/run';
|
||||||
import { CaseType } from '@/types/case';
|
import { CaseType } from '@/types/case';
|
||||||
import { FolderType } from '@/types/folder';
|
import { FolderType } from '@/types/folder';
|
||||||
import {
|
import { fetchRun, updateRun, fetchRunCases, updateRunCases } from '../runsControl';
|
||||||
fetchRun,
|
|
||||||
updateRun,
|
|
||||||
fetchRunCases,
|
|
||||||
createRunCase,
|
|
||||||
updateRunCase,
|
|
||||||
bulkCreateRunCases,
|
|
||||||
deleteRunCase,
|
|
||||||
bulkDeleteRunCases,
|
|
||||||
} from '../runsControl';
|
|
||||||
import { fetchFolders } from '../../folders/foldersControl';
|
import { fetchFolders } from '../../folders/foldersControl';
|
||||||
import { fetchCases } from '@/utils/caseControl';
|
import { fetchCases } from '@/utils/caseControl';
|
||||||
import { TokenContext } from '@/utils/TokenProvider';
|
import { TokenContext } from '@/utils/TokenProvider';
|
||||||
import { useTheme } from 'next-themes';
|
import { useTheme } from 'next-themes';
|
||||||
|
import { useFormGuard } from '@/utils/formGuard';
|
||||||
|
|
||||||
const defaultTestRun = {
|
const defaultTestRun = {
|
||||||
id: 0,
|
id: 0,
|
||||||
@@ -70,7 +62,9 @@ export default function RunEditor({ projectId, runId, messages, locale }: Props)
|
|||||||
const [testcases, setTestCases] = useState<CaseType[]>([]);
|
const [testcases, setTestCases] = useState<CaseType[]>([]);
|
||||||
const [isNameInvalid, setIsNameInvalid] = useState<boolean>(false);
|
const [isNameInvalid, setIsNameInvalid] = useState<boolean>(false);
|
||||||
const [isUpdating, setIsUpdating] = useState<boolean>(false);
|
const [isUpdating, setIsUpdating] = useState<boolean>(false);
|
||||||
|
const [isDirty, setIsDirty] = useState(false);
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
useFormGuard(isDirty, messages.areYouSureLeave);
|
||||||
|
|
||||||
const fetchRunAndStatusCount = async () => {
|
const fetchRunAndStatusCount = async () => {
|
||||||
const { run, statusCounts } = await fetchRun(context.token.access_token, Number(runId));
|
const { run, statusCounts } = await fetchRun(context.token.access_token, Number(runId));
|
||||||
@@ -102,6 +96,9 @@ export default function RunEditor({ projectId, runId, messages, locale }: Props)
|
|||||||
if (selectedFolder && selectedFolder.id) {
|
if (selectedFolder && selectedFolder.id) {
|
||||||
try {
|
try {
|
||||||
const latestRunCases: RunCaseType[] = await fetchRunCases(context.token.access_token, Number(runId));
|
const latestRunCases: RunCaseType[] = await fetchRunCases(context.token.access_token, Number(runId));
|
||||||
|
latestRunCases.forEach((runCase: RunCaseType) => {
|
||||||
|
runCase.editState = 'notChanged';
|
||||||
|
});
|
||||||
setRunCases(latestRunCases);
|
setRunCases(latestRunCases);
|
||||||
|
|
||||||
const testCasesData: CaseType[] = await fetchCases(context.token.access_token, selectedFolder.id);
|
const testCasesData: CaseType[] = await fetchCases(context.token.access_token, selectedFolder.id);
|
||||||
@@ -130,11 +127,11 @@ export default function RunEditor({ projectId, runId, messages, locale }: Props)
|
|||||||
}, [selectedFolder]);
|
}, [selectedFolder]);
|
||||||
|
|
||||||
const handleChangeStatus = async (changeCaseId: number, status: number) => {
|
const handleChangeStatus = async (changeCaseId: number, status: number) => {
|
||||||
await updateRunCase(context.token.access_token, Number(runId), changeCaseId, status);
|
setIsDirty(true);
|
||||||
setTestCases((prevTestCases) => {
|
setTestCases((prevTestCases) => {
|
||||||
return prevTestCases.map((testCase) => {
|
return prevTestCases.map((testCase) => {
|
||||||
if (testCase.id === changeCaseId) {
|
if (testCase.id === changeCaseId) {
|
||||||
return { ...testCase, runStatus: status };
|
return { ...testCase, runStatus: status, editState: 'changed' };
|
||||||
}
|
}
|
||||||
return testCase;
|
return testCase;
|
||||||
});
|
});
|
||||||
@@ -142,26 +139,28 @@ export default function RunEditor({ projectId, runId, messages, locale }: Props)
|
|||||||
};
|
};
|
||||||
|
|
||||||
const handleIncludeExcludeCase = async (isInclude: boolean, clickedTestCaseId: number) => {
|
const handleIncludeExcludeCase = async (isInclude: boolean, clickedTestCaseId: number) => {
|
||||||
|
setIsDirty(true);
|
||||||
if (isInclude) {
|
if (isInclude) {
|
||||||
const createdRunCase = await createRunCase(context.token.access_token, Number(runId), clickedTestCaseId);
|
const newRunCase: RunCaseType = {
|
||||||
setRunCases((prevRunCases) => {
|
id: 0,
|
||||||
return [...prevRunCases, createdRunCase];
|
runId: Number(runId),
|
||||||
});
|
caseId: clickedTestCaseId,
|
||||||
} else {
|
status: 0,
|
||||||
await deleteRunCase(context.token.access_token, Number(runId), clickedTestCaseId);
|
editState: 'new',
|
||||||
setRunCases((prevRunCases) => {
|
};
|
||||||
return prevRunCases.filter((runCase) => runCase.caseId !== clickedTestCaseId);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
setTestCases((prevTestCases) => {
|
setRunCases([...runCases, newRunCase]);
|
||||||
return prevTestCases.map((testCase) => {
|
} else {
|
||||||
if (testCase.id === clickedTestCaseId) {
|
const deleteRunCase = runCases.find((runCase) => runCase.caseId === clickedTestCaseId);
|
||||||
return { ...testCase, isIncluded: isInclude };
|
if (!deleteRunCase) {
|
||||||
}
|
return;
|
||||||
return testCase;
|
}
|
||||||
});
|
deleteRunCase.editState = 'deleted';
|
||||||
});
|
|
||||||
|
setRunCases((prevRunCases) =>
|
||||||
|
prevRunCases.map((runCase) => (runCase.caseId === deleteRunCase.runId ? deleteRunCase : runCase))
|
||||||
|
);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleBulkIncludeExcludeCases = async (isInclude: boolean) => {
|
const handleBulkIncludeExcludeCases = async (isInclude: boolean) => {
|
||||||
@@ -172,20 +171,49 @@ export default function RunEditor({ projectId, runId, messages, locale }: Props)
|
|||||||
keys = Array.from(selectedKeys).map(Number);
|
keys = Array.from(selectedKeys).map(Number);
|
||||||
}
|
}
|
||||||
|
|
||||||
const runCaseInfo: RunCaseInfoType[] = keys.map((caseId) => ({
|
|
||||||
runId: Number(runId),
|
|
||||||
caseId: caseId,
|
|
||||||
}));
|
|
||||||
if (isInclude) {
|
if (isInclude) {
|
||||||
const createdRunCases = await bulkCreateRunCases(context.token.access_token, Number(runId), runCaseInfo);
|
// TODO fix and add unit test
|
||||||
setRunCases((prevRunCases) => [...prevRunCases, ...createdRunCases]);
|
|
||||||
} else {
|
|
||||||
await bulkDeleteRunCases(context.token.access_token, Number(runId), runCaseInfo);
|
|
||||||
setRunCases((prevRunCases) => {
|
setRunCases((prevRunCases) => {
|
||||||
return prevRunCases.filter((runCase) => {
|
const updatedRunCases = prevRunCases.map((runCase) => {
|
||||||
return !runCaseInfo.some((info) => info.caseId === runCase.caseId);
|
if (keys.includes(runCase.caseId) && runCase.editState === 'deleted') {
|
||||||
|
return { ...runCase, editState: 'changed' };
|
||||||
|
}
|
||||||
|
return runCase;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
keys.forEach((caseId) => {
|
||||||
|
const existingRunCase = prevRunCases.find((runCase) => runCase.caseId === caseId);
|
||||||
|
if (!existingRunCase) {
|
||||||
|
updatedRunCases.push({
|
||||||
|
id: -1,
|
||||||
|
runId: Number(runId),
|
||||||
|
caseId: caseId,
|
||||||
|
status: -1,
|
||||||
|
editState: 'new',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return updatedRunCases;
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
setRunCases((prevRunCases) =>
|
||||||
|
prevRunCases
|
||||||
|
.filter((runCase) => {
|
||||||
|
// If editState is 'new', remove from the array
|
||||||
|
if (keys.includes(runCase.caseId) && runCase.editState === 'new') {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
})
|
||||||
|
.map((runCase) => {
|
||||||
|
// If editState isn't 'new', set editState to 'deleted'.
|
||||||
|
if (keys.includes(runCase.caseId) && runCase.editState !== 'new') {
|
||||||
|
return { ...runCase, editState: 'deleted' };
|
||||||
|
}
|
||||||
|
return runCase;
|
||||||
|
})
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const updatedTestCases = testcases.map((testcase) => {
|
const updatedTestCases = testcases.map((testcase) => {
|
||||||
@@ -227,6 +255,7 @@ export default function RunEditor({ projectId, runId, messages, locale }: Props)
|
|||||||
onPress={async () => {
|
onPress={async () => {
|
||||||
setIsUpdating(true);
|
setIsUpdating(true);
|
||||||
await updateRun(context.token.access_token, testRun);
|
await updateRun(context.token.access_token, testRun);
|
||||||
|
await updateRunCases(context.token.access_token, Number(runId), runCases);
|
||||||
setIsUpdating(false);
|
setIsUpdating(false);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ export default function Page({ params }: { params: { projectId: string; runId: s
|
|||||||
includeInRun: t('include_in_run'),
|
includeInRun: t('include_in_run'),
|
||||||
excludeFromRun: t('exclude_from_run'),
|
excludeFromRun: t('exclude_from_run'),
|
||||||
noCasesFound: t('no_cases_found'),
|
noCasesFound: t('no_cases_found'),
|
||||||
|
areYouSureLeave: t('are_you_sure_leave'),
|
||||||
};
|
};
|
||||||
|
|
||||||
return <RunEditor projectId={params.projectId} runId={params.runId} messages={messages} locale={params.locale} />;
|
return <RunEditor projectId={params.projectId} runId={params.runId} messages={messages} locale={params.locale} />;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import Config from '@/config/config';
|
import Config from '@/config/config';
|
||||||
const apiServer = Config.apiServer;
|
const apiServer = Config.apiServer;
|
||||||
import { RunType, RunCaseInfoType } from '@/types/run';
|
import { RunType, RunCaseType } from '@/types/run';
|
||||||
|
|
||||||
async function fetchRun(jwt: string, runId: number) {
|
async function fetchRun(jwt: string, runId: number) {
|
||||||
const url = `${apiServer}/runs/${runId}`;
|
const url = `${apiServer}/runs/${runId}`;
|
||||||
@@ -150,134 +150,29 @@ async function fetchRunCases(jwt: string, runId: number) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function createRunCase(jwt: string, runId: number, caseId: number) {
|
async function updateRunCases(jwt: string, runId: number, runCases: RunCaseType[]) {
|
||||||
const fetchOptions = {
|
const fetchOptions = {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
Authorization: `Bearer ${jwt}`,
|
Authorization: `Bearer ${jwt}`,
|
||||||
},
|
},
|
||||||
|
body: JSON.stringify(runCases),
|
||||||
};
|
};
|
||||||
|
|
||||||
const url = `${apiServer}/runcases?runId=${runId}&caseId=${caseId}`;
|
console.log(runCases);
|
||||||
|
const url = `${apiServer}/runcases/update?runId=${runId}`;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await fetch(url, fetchOptions);
|
const response = await fetch(url, fetchOptions);
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
throw new Error(`HTTP error! Status: ${response.status}`);
|
throw new Error(`HTTP error! Status: ${response.status}`);
|
||||||
}
|
}
|
||||||
const data = await response.json();
|
return await response.json();
|
||||||
return data;
|
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
console.error('Error creating new runcase:', error);
|
console.error('Error deleting project:', error);
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function updateRunCase(jwt: string, runId: number, caseId: number, status: number) {
|
export { fetchRun, fetchRuns, createRun, updateRun, deleteRun, fetchRunCases, updateRunCases };
|
||||||
const fetchOptions = {
|
|
||||||
method: 'PUT',
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/json',
|
|
||||||
Authorization: `Bearer ${jwt}`,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
const url = `${apiServer}/runcases?runId=${runId}&caseId=${caseId}&status=${status}`;
|
|
||||||
|
|
||||||
try {
|
|
||||||
const response = await fetch(url, fetchOptions);
|
|
||||||
if (!response.ok) {
|
|
||||||
throw new Error(`HTTP error! Status: ${response.status}`);
|
|
||||||
}
|
|
||||||
const data = await response.json();
|
|
||||||
return data;
|
|
||||||
} catch (error: any) {
|
|
||||||
console.error('Error updating runcase:', error);
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function bulkCreateRunCases(jwt: string, runId: number, runCaseInfo: RunCaseInfoType[]) {
|
|
||||||
const fetchOptions = {
|
|
||||||
method: 'POST',
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/json',
|
|
||||||
Authorization: `Bearer ${jwt}`,
|
|
||||||
},
|
|
||||||
body: JSON.stringify(runCaseInfo),
|
|
||||||
};
|
|
||||||
|
|
||||||
const url = `${apiServer}/runcases/bulknew?runId=${runId}`;
|
|
||||||
|
|
||||||
try {
|
|
||||||
const response = await fetch(url, fetchOptions);
|
|
||||||
if (!response.ok) {
|
|
||||||
throw new Error(`HTTP error! Status: ${response.status}`);
|
|
||||||
}
|
|
||||||
const data = await response.json();
|
|
||||||
return data;
|
|
||||||
} catch (error: any) {
|
|
||||||
console.error('Error creating new runcase:', error);
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function deleteRunCase(jwt: string, runId: number, caseId: number) {
|
|
||||||
const fetchOptions = {
|
|
||||||
method: 'DELETE',
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/json',
|
|
||||||
Authorization: `Bearer ${jwt}`,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
const url = `${apiServer}/runcases?runId=${runId}&caseId=${caseId}`;
|
|
||||||
|
|
||||||
try {
|
|
||||||
const response = await fetch(url, fetchOptions);
|
|
||||||
if (!response.ok) {
|
|
||||||
throw new Error(`HTTP error! Status: ${response.status}`);
|
|
||||||
}
|
|
||||||
} catch (error: any) {
|
|
||||||
console.error('Error deleting runcase:', error);
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function bulkDeleteRunCases(jwt: string, runId: number, runCaseInfo: RunCaseInfoType[]) {
|
|
||||||
const fetchOptions = {
|
|
||||||
method: 'POST',
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/json',
|
|
||||||
Authorization: `Bearer ${jwt}`,
|
|
||||||
},
|
|
||||||
body: JSON.stringify(runCaseInfo),
|
|
||||||
};
|
|
||||||
|
|
||||||
const url = `${apiServer}/runcases/bulkdelete?runId=${runId}`;
|
|
||||||
|
|
||||||
try {
|
|
||||||
const response = await fetch(url, fetchOptions);
|
|
||||||
if (!response.ok) {
|
|
||||||
throw new Error(`HTTP error! Status: ${response.status}`);
|
|
||||||
}
|
|
||||||
} catch (error: any) {
|
|
||||||
console.error('Error deleting runcase:', error);
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export {
|
|
||||||
fetchRun,
|
|
||||||
fetchRuns,
|
|
||||||
createRun,
|
|
||||||
updateRun,
|
|
||||||
deleteRun,
|
|
||||||
fetchRunCases,
|
|
||||||
createRunCase,
|
|
||||||
updateRunCase,
|
|
||||||
bulkCreateRunCases,
|
|
||||||
deleteRunCase,
|
|
||||||
bulkDeleteRunCases,
|
|
||||||
};
|
|
||||||
|
|||||||
@@ -14,11 +14,7 @@ type RunCaseType = {
|
|||||||
runId: number;
|
runId: number;
|
||||||
caseId: number;
|
caseId: number;
|
||||||
status: number;
|
status: number;
|
||||||
};
|
editState: 'notChanged' | 'changed' | 'new' | 'deleted';
|
||||||
|
|
||||||
type RunCaseInfoType = {
|
|
||||||
runId: number;
|
|
||||||
caseId: number;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
type RunStatusCountType = {
|
type RunStatusCountType = {
|
||||||
@@ -86,6 +82,7 @@ type RunMessages = {
|
|||||||
includeInRun: string;
|
includeInRun: string;
|
||||||
excludeFromRun: string;
|
excludeFromRun: string;
|
||||||
noCasesFound: string;
|
noCasesFound: string;
|
||||||
|
areYouSureLeave: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export { RunType, RunCaseType, RunCaseInfoType, RunStatusCountType, ProgressSeriesType, RunsMessages, RunMessages };
|
export type { RunType, RunCaseType, RunStatusCountType, ProgressSeriesType, RunsMessages, RunMessages };
|
||||||
|
|||||||
Reference in New Issue
Block a user