create steps

This commit is contained in:
Takeshi Kimata
2024-02-29 20:47:46 +09:00
parent b36e8f3c7f
commit 22c951db07
8 changed files with 189 additions and 26 deletions

View 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');
},
};

View 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");
},
};

View File

@@ -48,7 +48,8 @@ function defineCase(sequelize, DataTypes) {
});
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;

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

View File

@@ -1,10 +1,12 @@
const express = require("express");
const router = express.Router();
const defineCase = require("../../models/cases");
const defineStep = require("../../models/steps");
const { DataTypes } = require("sequelize");
module.exports = function (sequelize) {
const Case = defineCase(sequelize, DataTypes);
const Step = defineStep(sequelize, DataTypes);
router.get("/", async (req, res) => {
const { caseId, folderId } = req.query;
@@ -14,7 +16,10 @@ module.exports = function (sequelize) {
}
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);
}

View File

@@ -1,44 +1,44 @@
'use strict';
"use strict";
module.exports = {
up: async (queryInterface, Sequelize) => {
// Add projects table records
await queryInterface.bulkInsert('Projects', [
await queryInterface.bulkInsert("Projects", [
{
name: 'Project 1',
detail: 'Details of Project 1',
name: "Project 1",
detail: "Details of Project 1",
createdAt: new Date(),
updatedAt: new Date(),
},
{
name: 'Project 2',
name: "Project 2",
createdAt: new Date(),
updatedAt: new Date(),
},
{
name: 'Project 3',
name: "Project 3",
createdAt: new Date(),
updatedAt: new Date(),
},
]);
// Add folders table records
await queryInterface.bulkInsert('folders', [
await queryInterface.bulkInsert("folders", [
{
name: 'Folder 1',
detail: 'Details of Folder 1',
name: "Folder 1",
detail: "Details of Folder 1",
projectId: 1,
createdAt: new Date(),
updatedAt: new Date(),
},
{
name: 'Folder 2',
name: "Folder 2",
projectId: 1,
createdAt: new Date(),
updatedAt: new Date(),
},
{
name: 'Folder 3',
name: "Folder 3",
projectId: 1,
createdAt: new Date(),
updatedAt: new Date(),
@@ -46,9 +46,9 @@ module.exports = {
]);
// Add runs table records
await queryInterface.bulkInsert('runs', [
await queryInterface.bulkInsert("runs", [
{
name: 'Run 1',
name: "Run 1",
projectId: 1,
configurations: null,
description: null,
@@ -57,7 +57,7 @@ module.exports = {
updatedAt: new Date(),
},
{
name: 'Run 2',
name: "Run 2",
projectId: 1,
configurations: null,
description: null,
@@ -66,7 +66,7 @@ module.exports = {
updatedAt: new Date(),
},
{
name: 'Run 3',
name: "Run 3",
projectId: 1,
configurations: null,
description: null,
@@ -77,36 +77,74 @@ module.exports = {
]);
// Add cases table records
await queryInterface.bulkInsert('cases', [
await queryInterface.bulkInsert("cases", [
{
title: 'Sample Case 1',
title: "Sample Case 1",
state: 1,
priority: 1,
type: 1,
automationStatus: 1,
description: 'Sample description for case 1',
description: "Sample description for case 1",
template: 1,
preConditions: 'Sample pre-conditions for case 1',
expectedResults: 'Sample expected results for case 1',
preConditions: "Sample pre-conditions for case 1",
expectedResults: "Sample expected results for case 1",
folderId: 1,
createdAt: new Date(),
updatedAt: new Date(),
},
{
title: 'Sample Case 2',
title: "Sample Case 2",
state: 1,
priority: 1,
type: 1,
automationStatus: 1,
description: 'Sample description for case 2',
description: "Sample description for case 2",
template: 1,
preConditions: 'Sample pre-conditions for case 2',
expectedResults: 'Sample expected results for case 2',
preConditions: "Sample pre-conditions for case 2",
expectedResults: "Sample expected results for case 2",
folderId: 1,
createdAt: 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) => {

View File

@@ -103,6 +103,7 @@ export default function Page({
async function fetchDataEffect() {
try {
const data = await fetchCase(url);
console.log(data)
setTestCase(data);
} catch (error) {
console.error("Error in effect:", error.message);