create steps
This commit is contained in:
34
backend/migrations/20240229095914-create-steps.js
Normal file
34
backend/migrations/20240229095914-create-steps.js
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
/** @type {import('sequelize-cli').Migration} */
|
||||||
|
module.exports = {
|
||||||
|
up: async (queryInterface, Sequelize) => {
|
||||||
|
await queryInterface.createTable('steps', {
|
||||||
|
id: {
|
||||||
|
type: Sequelize.INTEGER,
|
||||||
|
primaryKey: true,
|
||||||
|
autoIncrement: true,
|
||||||
|
},
|
||||||
|
step: {
|
||||||
|
type: Sequelize.STRING,
|
||||||
|
allowNull: false,
|
||||||
|
},
|
||||||
|
result: {
|
||||||
|
type: Sequelize.STRING,
|
||||||
|
allowNull: false,
|
||||||
|
},
|
||||||
|
createdAt: {
|
||||||
|
type: Sequelize.DATE,
|
||||||
|
allowNull: false,
|
||||||
|
},
|
||||||
|
updatedAt: {
|
||||||
|
type: Sequelize.DATE,
|
||||||
|
allowNull: false,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
down: async (queryInterface, Sequelize) => {
|
||||||
|
await queryInterface.dropTable('steps');
|
||||||
|
},
|
||||||
|
};
|
||||||
48
backend/migrations/20240229100158-create-cases-steps.js
Normal file
48
backend/migrations/20240229100158-create-cases-steps.js
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
"use strict";
|
||||||
|
|
||||||
|
/** @type {import('sequelize-cli').Migration} */
|
||||||
|
module.exports = {
|
||||||
|
up: async (queryInterface, Sequelize) => {
|
||||||
|
await queryInterface.createTable("cases_steps", {
|
||||||
|
id: {
|
||||||
|
type: Sequelize.INTEGER,
|
||||||
|
primaryKey: true,
|
||||||
|
autoIncrement: true,
|
||||||
|
},
|
||||||
|
caseId: {
|
||||||
|
type: Sequelize.INTEGER,
|
||||||
|
references: {
|
||||||
|
model: "cases",
|
||||||
|
key: "id",
|
||||||
|
},
|
||||||
|
onUpdate: "CASCADE",
|
||||||
|
onDelete: "CASCADE",
|
||||||
|
},
|
||||||
|
stepId: {
|
||||||
|
type: Sequelize.INTEGER,
|
||||||
|
references: {
|
||||||
|
model: "steps",
|
||||||
|
key: "id",
|
||||||
|
},
|
||||||
|
onUpdate: "CASCADE",
|
||||||
|
onDelete: "CASCADE",
|
||||||
|
},
|
||||||
|
createdAt: {
|
||||||
|
type: Sequelize.DATE,
|
||||||
|
allowNull: false,
|
||||||
|
},
|
||||||
|
updatedAt: {
|
||||||
|
type: Sequelize.DATE,
|
||||||
|
allowNull: false,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
await queryInterface.addIndex("cases_steps", ["caseId", "stepId"], {
|
||||||
|
unique: true,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
down: async (queryInterface, Sequelize) => {
|
||||||
|
await queryInterface.dropTable("cases_steps");
|
||||||
|
},
|
||||||
|
};
|
||||||
@@ -48,7 +48,8 @@ function defineCase(sequelize, DataTypes) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
Case.associate = (models) => {
|
Case.associate = (models) => {
|
||||||
Case.belongsTo(models.folder, { foreignKey: 'folderId', onDelete: 'CASCADE' });
|
Case.belongsTo(models.Folder, { foreignKey: 'folderId', onDelete: 'CASCADE' });
|
||||||
|
Case.belongsToMany(models.Step, { through: 'Case_Step' });
|
||||||
};
|
};
|
||||||
|
|
||||||
return Case;
|
return Case;
|
||||||
|
|||||||
16
backend/models/casestep.js
Normal file
16
backend/models/casestep.js
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
function defineCaseStep(sequelize, DataTypes) {
|
||||||
|
const CaseStep = sequelize.define("CaseStep", {
|
||||||
|
caseId: {
|
||||||
|
type: DataTypes.INTEGER,
|
||||||
|
allowNull: false,
|
||||||
|
},
|
||||||
|
stepId: {
|
||||||
|
type: DataTypes.INTEGER,
|
||||||
|
allowNull: false,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
return CaseStep;
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = defineCaseStep;
|
||||||
20
backend/models/steps.js
Normal file
20
backend/models/steps.js
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
function defineStep(sequelize, DataTypes) {
|
||||||
|
const Step = sequelize.define("Step", {
|
||||||
|
step: {
|
||||||
|
type: DataTypes.STRING,
|
||||||
|
allowNull: false,
|
||||||
|
},
|
||||||
|
result: {
|
||||||
|
type: DataTypes.STRING,
|
||||||
|
allowNull: false,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
Step.associate = (models) => {
|
||||||
|
Step.belongsToMany(models.Case, { through: "Case_Step" });
|
||||||
|
};
|
||||||
|
|
||||||
|
return Step;
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = defineStep;
|
||||||
@@ -1,10 +1,12 @@
|
|||||||
const express = require("express");
|
const express = require("express");
|
||||||
const router = express.Router();
|
const router = express.Router();
|
||||||
const defineCase = require("../../models/cases");
|
const defineCase = require("../../models/cases");
|
||||||
|
const defineStep = require("../../models/steps");
|
||||||
const { DataTypes } = require("sequelize");
|
const { DataTypes } = require("sequelize");
|
||||||
|
|
||||||
module.exports = function (sequelize) {
|
module.exports = function (sequelize) {
|
||||||
const Case = defineCase(sequelize, DataTypes);
|
const Case = defineCase(sequelize, DataTypes);
|
||||||
|
const Step = defineStep(sequelize, DataTypes);
|
||||||
|
|
||||||
router.get("/", async (req, res) => {
|
router.get("/", async (req, res) => {
|
||||||
const { caseId, folderId } = req.query;
|
const { caseId, folderId } = req.query;
|
||||||
@@ -14,7 +16,10 @@ module.exports = function (sequelize) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (caseId) {
|
if (caseId) {
|
||||||
const testcase = await Case.findByPk(caseId);
|
// Include steps if requested using caseId
|
||||||
|
const testcase = await Case.findByPk(caseId, {
|
||||||
|
include: Step,
|
||||||
|
});
|
||||||
return res.json(testcase);
|
return res.json(testcase);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,44 +1,44 @@
|
|||||||
'use strict';
|
"use strict";
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
up: async (queryInterface, Sequelize) => {
|
up: async (queryInterface, Sequelize) => {
|
||||||
// Add projects table records
|
// Add projects table records
|
||||||
await queryInterface.bulkInsert('Projects', [
|
await queryInterface.bulkInsert("Projects", [
|
||||||
{
|
{
|
||||||
name: 'Project 1',
|
name: "Project 1",
|
||||||
detail: 'Details of Project 1',
|
detail: "Details of Project 1",
|
||||||
createdAt: new Date(),
|
createdAt: new Date(),
|
||||||
updatedAt: new Date(),
|
updatedAt: new Date(),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'Project 2',
|
name: "Project 2",
|
||||||
createdAt: new Date(),
|
createdAt: new Date(),
|
||||||
updatedAt: new Date(),
|
updatedAt: new Date(),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'Project 3',
|
name: "Project 3",
|
||||||
createdAt: new Date(),
|
createdAt: new Date(),
|
||||||
updatedAt: new Date(),
|
updatedAt: new Date(),
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// Add folders table records
|
// Add folders table records
|
||||||
await queryInterface.bulkInsert('folders', [
|
await queryInterface.bulkInsert("folders", [
|
||||||
{
|
{
|
||||||
name: 'Folder 1',
|
name: "Folder 1",
|
||||||
detail: 'Details of Folder 1',
|
detail: "Details of Folder 1",
|
||||||
projectId: 1,
|
projectId: 1,
|
||||||
createdAt: new Date(),
|
createdAt: new Date(),
|
||||||
updatedAt: new Date(),
|
updatedAt: new Date(),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'Folder 2',
|
name: "Folder 2",
|
||||||
projectId: 1,
|
projectId: 1,
|
||||||
createdAt: new Date(),
|
createdAt: new Date(),
|
||||||
updatedAt: new Date(),
|
updatedAt: new Date(),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'Folder 3',
|
name: "Folder 3",
|
||||||
projectId: 1,
|
projectId: 1,
|
||||||
createdAt: new Date(),
|
createdAt: new Date(),
|
||||||
updatedAt: new Date(),
|
updatedAt: new Date(),
|
||||||
@@ -46,9 +46,9 @@ module.exports = {
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
// Add runs table records
|
// Add runs table records
|
||||||
await queryInterface.bulkInsert('runs', [
|
await queryInterface.bulkInsert("runs", [
|
||||||
{
|
{
|
||||||
name: 'Run 1',
|
name: "Run 1",
|
||||||
projectId: 1,
|
projectId: 1,
|
||||||
configurations: null,
|
configurations: null,
|
||||||
description: null,
|
description: null,
|
||||||
@@ -57,7 +57,7 @@ module.exports = {
|
|||||||
updatedAt: new Date(),
|
updatedAt: new Date(),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'Run 2',
|
name: "Run 2",
|
||||||
projectId: 1,
|
projectId: 1,
|
||||||
configurations: null,
|
configurations: null,
|
||||||
description: null,
|
description: null,
|
||||||
@@ -66,7 +66,7 @@ module.exports = {
|
|||||||
updatedAt: new Date(),
|
updatedAt: new Date(),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'Run 3',
|
name: "Run 3",
|
||||||
projectId: 1,
|
projectId: 1,
|
||||||
configurations: null,
|
configurations: null,
|
||||||
description: null,
|
description: null,
|
||||||
@@ -77,36 +77,74 @@ module.exports = {
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
// Add cases table records
|
// Add cases table records
|
||||||
await queryInterface.bulkInsert('cases', [
|
await queryInterface.bulkInsert("cases", [
|
||||||
{
|
{
|
||||||
title: 'Sample Case 1',
|
title: "Sample Case 1",
|
||||||
state: 1,
|
state: 1,
|
||||||
priority: 1,
|
priority: 1,
|
||||||
type: 1,
|
type: 1,
|
||||||
automationStatus: 1,
|
automationStatus: 1,
|
||||||
description: 'Sample description for case 1',
|
description: "Sample description for case 1",
|
||||||
template: 1,
|
template: 1,
|
||||||
preConditions: 'Sample pre-conditions for case 1',
|
preConditions: "Sample pre-conditions for case 1",
|
||||||
expectedResults: 'Sample expected results for case 1',
|
expectedResults: "Sample expected results for case 1",
|
||||||
folderId: 1,
|
folderId: 1,
|
||||||
createdAt: new Date(),
|
createdAt: new Date(),
|
||||||
updatedAt: new Date(),
|
updatedAt: new Date(),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: 'Sample Case 2',
|
title: "Sample Case 2",
|
||||||
state: 1,
|
state: 1,
|
||||||
priority: 1,
|
priority: 1,
|
||||||
type: 1,
|
type: 1,
|
||||||
automationStatus: 1,
|
automationStatus: 1,
|
||||||
description: 'Sample description for case 2',
|
description: "Sample description for case 2",
|
||||||
template: 1,
|
template: 1,
|
||||||
preConditions: 'Sample pre-conditions for case 2',
|
preConditions: "Sample pre-conditions for case 2",
|
||||||
expectedResults: 'Sample expected results for case 2',
|
expectedResults: "Sample expected results for case 2",
|
||||||
folderId: 1,
|
folderId: 1,
|
||||||
createdAt: new Date(),
|
createdAt: new Date(),
|
||||||
updatedAt: new Date(),
|
updatedAt: new Date(),
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
// Add steps table records
|
||||||
|
await queryInterface.bulkInsert("steps", [
|
||||||
|
{
|
||||||
|
step: "Sample Step 1",
|
||||||
|
result: "Sample Result 1",
|
||||||
|
createdAt: new Date(),
|
||||||
|
updatedAt: new Date(),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
step: "Sample Step 2",
|
||||||
|
result: "Sample Result 2",
|
||||||
|
createdAt: new Date(),
|
||||||
|
updatedAt: new Date(),
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
|
||||||
|
// Add case-step join table
|
||||||
|
await queryInterface.bulkInsert("cases_steps", [
|
||||||
|
{
|
||||||
|
caseId: 1,
|
||||||
|
stepId: 1,
|
||||||
|
createdAt: new Date(),
|
||||||
|
updatedAt: new Date(),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
caseId: 1,
|
||||||
|
stepId: 2,
|
||||||
|
createdAt: new Date(),
|
||||||
|
updatedAt: new Date(),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
caseId: 2,
|
||||||
|
stepId: 2,
|
||||||
|
createdAt: new Date(),
|
||||||
|
updatedAt: new Date(),
|
||||||
|
},
|
||||||
|
]);
|
||||||
},
|
},
|
||||||
|
|
||||||
down: async (queryInterface, Sequelize) => {
|
down: async (queryInterface, Sequelize) => {
|
||||||
|
|||||||
@@ -103,6 +103,7 @@ export default function Page({
|
|||||||
async function fetchDataEffect() {
|
async function fetchDataEffect() {
|
||||||
try {
|
try {
|
||||||
const data = await fetchCase(url);
|
const data = await fetchCase(url);
|
||||||
|
console.log(data)
|
||||||
setTestCase(data);
|
setTestCase(data);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error in effect:", error.message);
|
console.error("Error in effect:", error.message);
|
||||||
|
|||||||
Reference in New Issue
Block a user