Introduce prettier

This commit is contained in:
Takeshi Kimata
2024-05-19 21:04:45 +09:00
parent cbb5993276
commit 75eeebefda
89 changed files with 872 additions and 944 deletions

7
.prettierrc Normal file
View File

@@ -0,0 +1,7 @@
{
"printWidth": 120,
"tabWidth": 2,
"singleQuote": true,
"trailingComma": "es5",
"endOfLine": "auto"
}

7
.vscode/settings.json vendored Normal file
View File

@@ -0,0 +1,7 @@
{
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true,
"prettier.useEditorConfig": false,
"prettier.useTabs": false,
"prettier.configPath": ".prettierrc"
}

View File

@@ -1,14 +1,14 @@
const express = require("express");
const express = require('express');
const path = require('path');
const { Sequelize } = require("sequelize");
const { Sequelize } = require('sequelize');
const app = express();
// enable frontend access
const cors = require("cors");
const cors = require('cors');
const frontendOrigin = process.env.FRONTEND_ORIGIN || 'http://localhost:3000';
const corsOptions = {
origin: frontendOrigin,
methods: "GET,HEAD,PUT,PATCH,POST,DELETE",
methods: 'GET,HEAD,PUT,PATCH,POST,DELETE',
};
app.use(cors(corsOptions));
@@ -16,103 +16,103 @@ app.use(cors(corsOptions));
app.use(express.json());
// Specify the directory to serve static files
app.use(express.static(path.join(__dirname, "public")));
app.use(express.static(path.join(__dirname, 'public')));
// init sequalize
const sequelize = new Sequelize({
dialect: "sqlite",
storage: "database.sqlite",
dialect: 'sqlite',
storage: 'database.sqlite',
});
// "/"
const indexRoute = require("./routes/index");
app.use("/", indexRoute);
const indexRoute = require('./routes/index');
app.use('/', indexRoute);
// "auth"
const signUpRoute = require("./routes/auth/signup")(sequelize);
const signInRoute = require("./routes/auth/signin")(sequelize);
app.use("/auth", signUpRoute);
app.use("/auth", signInRoute);
const signUpRoute = require('./routes/auth/signup')(sequelize);
const signInRoute = require('./routes/auth/signin')(sequelize);
app.use('/auth', signUpRoute);
app.use('/auth', signInRoute);
// "/projects"
const projectsIndexRoute = require("./routes/projects/index")(sequelize);
const projectsShowRoute = require("./routes/projects/show")(sequelize);
const projectsNewRoute = require("./routes/projects/new")(sequelize);
const projectsEditRoute = require("./routes/projects/edit")(sequelize);
const projectsDeleteRoute = require("./routes/projects/delete")(sequelize);
app.use("/projects", projectsIndexRoute);
app.use("/projects", projectsShowRoute);
app.use("/projects", projectsNewRoute);
app.use("/projects", projectsEditRoute);
app.use("/projects", projectsDeleteRoute);
const projectsIndexRoute = require('./routes/projects/index')(sequelize);
const projectsShowRoute = require('./routes/projects/show')(sequelize);
const projectsNewRoute = require('./routes/projects/new')(sequelize);
const projectsEditRoute = require('./routes/projects/edit')(sequelize);
const projectsDeleteRoute = require('./routes/projects/delete')(sequelize);
app.use('/projects', projectsIndexRoute);
app.use('/projects', projectsShowRoute);
app.use('/projects', projectsNewRoute);
app.use('/projects', projectsEditRoute);
app.use('/projects', projectsDeleteRoute);
// "/folders"
const foldersIndexRoute = require("./routes/folders/index")(sequelize);
const foldersNewRoute = require("./routes/folders/new")(sequelize);
const foldersEditRoute = require("./routes/folders/edit")(sequelize);
const foldersDeleteRoute = require("./routes/folders/delete")(sequelize);
app.use("/folders", foldersIndexRoute);
app.use("/folders", foldersNewRoute);
app.use("/folders", foldersEditRoute);
app.use("/folders", foldersDeleteRoute);
const foldersIndexRoute = require('./routes/folders/index')(sequelize);
const foldersNewRoute = require('./routes/folders/new')(sequelize);
const foldersEditRoute = require('./routes/folders/edit')(sequelize);
const foldersDeleteRoute = require('./routes/folders/delete')(sequelize);
app.use('/folders', foldersIndexRoute);
app.use('/folders', foldersNewRoute);
app.use('/folders', foldersEditRoute);
app.use('/folders', foldersDeleteRoute);
// "/cases"
const casesIndexRoute = require("./routes/cases/index")(sequelize);
const casesShowRoute = require("./routes/cases/show")(sequelize);
const casesNewRoute = require("./routes/cases/new")(sequelize);
const casesEditRoute = require("./routes/cases/edit")(sequelize);
const casesDeleteRoute = require("./routes/cases/delete")(sequelize);
const casesBulkDeleteRoute = require("./routes/cases/bulkDelete")(sequelize);
app.use("/cases", casesIndexRoute);
app.use("/cases", casesShowRoute);
app.use("/cases", casesNewRoute);
app.use("/cases", casesEditRoute);
app.use("/cases", casesDeleteRoute);
app.use("/cases", casesBulkDeleteRoute);
const casesIndexRoute = require('./routes/cases/index')(sequelize);
const casesShowRoute = require('./routes/cases/show')(sequelize);
const casesNewRoute = require('./routes/cases/new')(sequelize);
const casesEditRoute = require('./routes/cases/edit')(sequelize);
const casesDeleteRoute = require('./routes/cases/delete')(sequelize);
const casesBulkDeleteRoute = require('./routes/cases/bulkDelete')(sequelize);
app.use('/cases', casesIndexRoute);
app.use('/cases', casesShowRoute);
app.use('/cases', casesNewRoute);
app.use('/cases', casesEditRoute);
app.use('/cases', casesDeleteRoute);
app.use('/cases', casesBulkDeleteRoute);
// "/steps"
const stepsNewRoute = require("./routes/steps/new")(sequelize);
const stepsDeleteRoute = require("./routes/steps/delete")(sequelize);
app.use("/steps", stepsNewRoute);
app.use("/steps", stepsDeleteRoute);
const stepsNewRoute = require('./routes/steps/new')(sequelize);
const stepsDeleteRoute = require('./routes/steps/delete')(sequelize);
app.use('/steps', stepsNewRoute);
app.use('/steps', stepsDeleteRoute);
// "/attachments"
const attachmentsNewRoute = require("./routes/attachments/new")(sequelize);
const attachmentsDeleteRoute = require("./routes/attachments/delete")(sequelize);
const attachmentsDownloadRoute = require("./routes/attachments/download")(sequelize);
app.use("/attachments", attachmentsNewRoute);
app.use("/attachments", attachmentsDeleteRoute);
app.use("/attachments", attachmentsDownloadRoute);
const attachmentsNewRoute = require('./routes/attachments/new')(sequelize);
const attachmentsDeleteRoute = require('./routes/attachments/delete')(sequelize);
const attachmentsDownloadRoute = require('./routes/attachments/download')(sequelize);
app.use('/attachments', attachmentsNewRoute);
app.use('/attachments', attachmentsDeleteRoute);
app.use('/attachments', attachmentsDownloadRoute);
// "/runs"
const runsIndexRoute = require("./routes/runs/index")(sequelize);
const runsShowRoute = require("./routes/runs/show")(sequelize);
const runsNewRoute = require("./routes/runs/new")(sequelize);
const runsEditRoute = require("./routes/runs/edit")(sequelize);
const runDeleteRoute = require("./routes/runs/delete")(sequelize);
app.use("/runs", runsIndexRoute);
app.use("/runs", runsShowRoute);
app.use("/runs", runsNewRoute);
app.use("/runs", runsEditRoute);
app.use("/runs", runDeleteRoute);
const runsIndexRoute = require('./routes/runs/index')(sequelize);
const runsShowRoute = require('./routes/runs/show')(sequelize);
const runsNewRoute = require('./routes/runs/new')(sequelize);
const runsEditRoute = require('./routes/runs/edit')(sequelize);
const runDeleteRoute = require('./routes/runs/delete')(sequelize);
app.use('/runs', runsIndexRoute);
app.use('/runs', runsShowRoute);
app.use('/runs', runsNewRoute);
app.use('/runs', runsEditRoute);
app.use('/runs', runDeleteRoute);
// "/runcases"
const runCaseIndexRoute = require("./routes/runcases/index")(sequelize);
const runCaseNewRoute = require("./routes/runcases/new")(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", runCaseNewRoute);
app.use("/runcases", runCaseEditRoute);
app.use("/runcases", runCaseBuldNewRoute);
app.use("/runcases", runCaseDeleteRoute);
app.use("/runcases", runCaseBulkDeleteRoute);
const runCaseIndexRoute = require('./routes/runcases/index')(sequelize);
const runCaseNewRoute = require('./routes/runcases/new')(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', runCaseNewRoute);
app.use('/runcases', runCaseEditRoute);
app.use('/runcases', runCaseBuldNewRoute);
app.use('/runcases', runCaseDeleteRoute);
app.use('/runcases', runCaseBulkDeleteRoute);
// "/home"
const homeIndexRoute = require("./routes/home/index")(sequelize);
app.use("/home", homeIndexRoute);
const homeIndexRoute = require('./routes/home/index')(sequelize);
app.use('/home', homeIndexRoute);
const PORT = process.env.PORT || 3001;
app.listen(PORT, () => {

View File

@@ -44,5 +44,5 @@ module.exports = {
async down(queryInterface, Sequelize) {
await queryInterface.dropTable('folders');
}
},
};

View File

@@ -37,16 +37,16 @@ module.exports = {
},
createdAt: {
allowNull: false,
type: Sequelize.DATE
type: Sequelize.DATE,
},
updatedAt: {
allowNull: false,
type: Sequelize.DATE
}
type: Sequelize.DATE,
},
});
},
async down(queryInterface, Sequelize) {
await queryInterface.dropTable('runs');
}
},
};

View File

@@ -57,16 +57,16 @@ module.exports = {
},
createdAt: {
allowNull: false,
type: Sequelize.DATE
type: Sequelize.DATE,
},
updatedAt: {
allowNull: false,
type: Sequelize.DATE
}
type: Sequelize.DATE,
},
});
},
async down(queryInterface, Sequelize) {
await queryInterface.dropTable('cases');
}
},
};

View File

@@ -1,9 +1,9 @@
"use strict";
'use strict';
/** @type {import('sequelize-cli').Migration} */
module.exports = {
up: async (queryInterface, Sequelize) => {
await queryInterface.createTable("caseSteps", {
await queryInterface.createTable('caseSteps', {
id: {
type: Sequelize.INTEGER,
primaryKey: true,
@@ -12,20 +12,20 @@ module.exports = {
caseId: {
type: Sequelize.INTEGER,
references: {
model: "cases",
key: "id",
model: 'cases',
key: 'id',
},
onUpdate: "CASCADE",
onDelete: "CASCADE",
onUpdate: 'CASCADE',
onDelete: 'CASCADE',
},
stepId: {
type: Sequelize.INTEGER,
references: {
model: "steps",
key: "id",
model: 'steps',
key: 'id',
},
onUpdate: "CASCADE",
onDelete: "CASCADE",
onUpdate: 'CASCADE',
onDelete: 'CASCADE',
},
stepNo: {
type: Sequelize.INTEGER,
@@ -41,12 +41,12 @@ module.exports = {
},
});
await queryInterface.addIndex("caseSteps", ["caseId", "stepId"], {
await queryInterface.addIndex('caseSteps', ['caseId', 'stepId'], {
unique: true,
});
},
down: async (queryInterface, Sequelize) => {
await queryInterface.dropTable("caseSteps");
await queryInterface.dropTable('caseSteps');
},
};

View File

@@ -23,16 +23,16 @@ module.exports = {
},
createdAt: {
allowNull: false,
type: Sequelize.DATE
type: Sequelize.DATE,
},
updatedAt: {
allowNull: false,
type: Sequelize.DATE
}
type: Sequelize.DATE,
},
});
},
async down(queryInterface, Sequelize) {
await queryInterface.dropTable('attachments');
}
},
};

View File

@@ -1,9 +1,9 @@
"use strict";
'use strict';
/** @type {import('sequelize-cli').Migration} */
module.exports = {
up: async (queryInterface, Sequelize) => {
await queryInterface.createTable("caseAttachments", {
await queryInterface.createTable('caseAttachments', {
id: {
type: Sequelize.INTEGER,
primaryKey: true,
@@ -12,20 +12,20 @@ module.exports = {
caseId: {
type: Sequelize.INTEGER,
references: {
model: "cases",
key: "id",
model: 'cases',
key: 'id',
},
onUpdate: "CASCADE",
onDelete: "CASCADE",
onUpdate: 'CASCADE',
onDelete: 'CASCADE',
},
attachmentId: {
type: Sequelize.INTEGER,
references: {
model: "attachments",
key: "id",
model: 'attachments',
key: 'id',
},
onUpdate: "CASCADE",
onDelete: "CASCADE",
onUpdate: 'CASCADE',
onDelete: 'CASCADE',
},
createdAt: {
type: Sequelize.DATE,
@@ -37,12 +37,12 @@ module.exports = {
},
});
await queryInterface.addIndex("caseAttachments", ["caseId", "attachmentId"], {
await queryInterface.addIndex('caseAttachments', ['caseId', 'attachmentId'], {
unique: true,
});
},
down: async (queryInterface, Sequelize) => {
await queryInterface.dropTable("caseAttachments");
await queryInterface.dropTable('caseAttachments');
},
};

View File

@@ -1,9 +1,9 @@
"use strict";
'use strict';
/** @type {import('sequelize-cli').Migration} */
module.exports = {
up: async (queryInterface, Sequelize) => {
await queryInterface.createTable("runCases", {
await queryInterface.createTable('runCases', {
id: {
type: Sequelize.INTEGER,
primaryKey: true,
@@ -12,20 +12,20 @@ module.exports = {
runId: {
type: Sequelize.INTEGER,
references: {
model: "runs",
key: "id",
model: 'runs',
key: 'id',
},
onUpdate: "CASCADE",
onDelete: "CASCADE",
onUpdate: 'CASCADE',
onDelete: 'CASCADE',
},
caseId: {
type: Sequelize.INTEGER,
references: {
model: "cases",
key: "id",
model: 'cases',
key: 'id',
},
onUpdate: "CASCADE",
onDelete: "CASCADE",
onUpdate: 'CASCADE',
onDelete: 'CASCADE',
},
status: {
type: Sequelize.INTEGER,
@@ -41,12 +41,12 @@ module.exports = {
},
});
await queryInterface.addIndex("runCases", ["runId", "caseId"], {
await queryInterface.addIndex('runCases', ['runId', 'caseId'], {
unique: true,
});
},
down: async (queryInterface, Sequelize) => {
await queryInterface.dropTable("runCases");
await queryInterface.dropTable('runCases');
},
};

View File

@@ -1,9 +1,9 @@
"use strict";
'use strict';
/** @type {import('sequelize-cli').Migration} */
module.exports = {
up: async (queryInterface, Sequelize) => {
await queryInterface.createTable("users", {
await queryInterface.createTable('users', {
id: {
type: Sequelize.INTEGER,
primaryKey: true,
@@ -12,7 +12,7 @@ module.exports = {
email: {
type: Sequelize.STRING,
allowNull: false,
unique: true
unique: true,
},
password: {
type: Sequelize.STRING,
@@ -41,6 +41,6 @@ module.exports = {
},
down: async (queryInterface, Sequelize) => {
await queryInterface.dropTable("users");
await queryInterface.dropTable('users');
},
};

View File

@@ -1,5 +1,5 @@
function defineAttachment(sequelize, DataTypes) {
const Attachment = sequelize.define("Attachment", {
const Attachment = sequelize.define('Attachment', {
title: {
type: DataTypes.STRING,
allowNull: false,
@@ -16,7 +16,7 @@ function defineAttachment(sequelize, DataTypes) {
Attachment.associate = (models) => {
Attachment.belongsToMany(models.Case, {
through: "caseAttachments"
through: 'caseAttachments',
});
};

View File

@@ -1,5 +1,5 @@
function defineCaseAttachment(sequelize, DataTypes) {
const CaseAttachment = sequelize.define("CaseAttachment", {
const CaseAttachment = sequelize.define('CaseAttachment', {
caseId: {
type: DataTypes.INTEGER,
allowNull: false,
@@ -12,12 +12,12 @@ function defineCaseAttachment(sequelize, DataTypes) {
CaseAttachment.associate = (models) => {
CaseAttachment.belongsTo(models.Case, {
foreignKey: "caseId",
onDelete: "CASCADE",
foreignKey: 'caseId',
onDelete: 'CASCADE',
});
CaseAttachment.belongsTo(models.Attachment, {
foreignKey: "attachmentId",
onDelete: "CASCADE",
foreignKey: 'attachmentId',
onDelete: 'CASCADE',
});
};

View File

@@ -1,5 +1,5 @@
function defineCaseStep(sequelize, DataTypes) {
const CaseStep = sequelize.define("CaseStep", {
const CaseStep = sequelize.define('CaseStep', {
caseId: {
type: DataTypes.INTEGER,
allowNull: false,
@@ -16,12 +16,12 @@ function defineCaseStep(sequelize, DataTypes) {
CaseStep.associate = (models) => {
CaseStep.belongsTo(models.Case, {
foreignKey: "caseId",
onDelete: "CASCADE",
foreignKey: 'caseId',
onDelete: 'CASCADE',
});
CaseStep.belongsTo(models.Step, {
foreignKey: "stepId",
onDelete: "CASCADE",
foreignKey: 'stepId',
onDelete: 'CASCADE',
});
};

View File

@@ -1,5 +1,5 @@
function defineCase(sequelize, DataTypes) {
const Case = sequelize.define("Case", {
const Case = sequelize.define('Case', {
title: {
type: DataTypes.STRING,
allowNull: false,
@@ -40,20 +40,20 @@ function defineCase(sequelize, DataTypes) {
type: DataTypes.INTEGER,
allowNull: false,
references: {
model: "folder",
key: "id",
model: 'folder',
key: 'id',
},
onDelete: "CASCADE",
onDelete: 'CASCADE',
},
});
Case.associate = (models) => {
Case.belongsTo(models.Folder, {
foreignKey: "folderId",
onDelete: "CASCADE",
foreignKey: 'folderId',
onDelete: 'CASCADE',
});
Case.belongsToMany(models.Step, {
through: "caseSteps"
through: 'caseSteps',
});
};

View File

@@ -1,5 +1,5 @@
function defineFolder(sequelize, DataTypes) {
const Folder = sequelize.define("Folder", {
const Folder = sequelize.define('Folder', {
name: {
type: DataTypes.STRING,
allowNull: false,
@@ -17,10 +17,10 @@ function defineFolder(sequelize, DataTypes) {
allowNull: false,
references: {
model: 'project',
key: 'id'
key: 'id',
},
onDelete: 'CASCADE',
},
onDelete: 'CASCADE'
}
});
Folder.associate = (models) => {

View File

@@ -1,40 +1,27 @@
"use strict";
'use strict';
const fs = require("fs");
const path = require("path");
const Sequelize = require("sequelize");
const process = require("process");
const fs = require('fs');
const path = require('path');
const Sequelize = require('sequelize');
const process = require('process');
const basename = path.basename(__filename);
const env = process.env.NODE_ENV || "development";
const config = require(__dirname + "/../config/config.json")[env];
const env = process.env.NODE_ENV || 'development';
const config = require(__dirname + '/../config/config.json')[env];
const db = {};
let sequelize;
if (config.use_env_variable) {
sequelize = new Sequelize(process.env[config.use_env_variable], config);
} else {
sequelize = new Sequelize(
config.database,
config.username,
config.password,
config
);
sequelize = new Sequelize(config.database, config.username, config.password, config);
}
fs.readdirSync(__dirname)
.filter((file) => {
return (
file.indexOf(".") !== 0 &&
file !== basename &&
file.slice(-3) === ".js" &&
file.indexOf(".test.js") === -1
);
return file.indexOf('.') !== 0 && file !== basename && file.slice(-3) === '.js' && file.indexOf('.test.js') === -1;
})
.forEach((file) => {
const model = require(path.join(__dirname, file))(
sequelize,
Sequelize.DataTypes
);
const model = require(path.join(__dirname, file))(sequelize, Sequelize.DataTypes);
db[model.name] = model;
});

View File

@@ -1,5 +1,5 @@
function defineProject(sequelize, DataTypes) {
const Project = sequelize.define("Project", {
const Project = sequelize.define('Project', {
name: {
type: DataTypes.STRING,
allowNull: false,
@@ -11,7 +11,7 @@ function defineProject(sequelize, DataTypes) {
});
Project.associate = (models) => {
Project.hasMany(models.Folder, { foreignKey: "projectId" });
Project.hasMany(models.Folder, { foreignKey: 'projectId' });
};
return Project;

View File

@@ -1,5 +1,5 @@
function defineRunCase(sequelize, DataTypes) {
const RunCase = sequelize.define("RunCase", {
const RunCase = sequelize.define('RunCase', {
runId: {
type: DataTypes.INTEGER,
allowNull: false,
@@ -16,12 +16,12 @@ function defineRunCase(sequelize, DataTypes) {
RunCase.associate = (models) => {
RunCase.belongsTo(models.Run, {
foreignKey: "runId",
onDelete: "CASCADE",
foreignKey: 'runId',
onDelete: 'CASCADE',
});
RunCase.belongsTo(models.Case, {
foreignKey: "caseId",
onDelete: "CASCADE",
foreignKey: 'caseId',
onDelete: 'CASCADE',
});
};

View File

@@ -21,10 +21,10 @@ function defineRun(sequelize, DataTypes) {
allowNull: false,
references: {
model: 'project',
key: 'id'
key: 'id',
},
onDelete: 'CASCADE',
},
onDelete: 'CASCADE'
}
});
Run.associate = (models) => {

View File

@@ -1,5 +1,5 @@
function defineStep(sequelize, DataTypes) {
const Step = sequelize.define("Step", {
const Step = sequelize.define('Step', {
step: {
type: DataTypes.STRING,
allowNull: false,
@@ -12,7 +12,7 @@ function defineStep(sequelize, DataTypes) {
Step.associate = (models) => {
Step.belongsToMany(models.Case, {
through: "caseSteps"
through: 'caseSteps',
});
};

View File

@@ -1,5 +1,5 @@
function defineUser(sequelize, DataTypes) {
const User = sequelize.define("User", {
const User = sequelize.define('User', {
email: {
type: DataTypes.STRING,
allowNull: false,

View File

@@ -1,14 +1,14 @@
const express = require("express");
const express = require('express');
const router = express.Router();
const path = require("path");
const fs = require("fs");
const defineAttachment = require("../../models/attachments");
const { DataTypes } = require("sequelize");
const path = require('path');
const fs = require('fs');
const defineAttachment = require('../../models/attachments');
const { DataTypes } = require('sequelize');
module.exports = function (sequelize) {
const Attachment = defineAttachment(sequelize, DataTypes);
router.delete("/:attachmentId", async (req, res) => {
router.delete('/:attachmentId', async (req, res) => {
const attachmentId = req.params.attachmentId;
const t = await sequelize.transaction();
@@ -16,19 +16,19 @@ module.exports = function (sequelize) {
const attachment = await Attachment.findByPk(attachmentId);
if (!attachment) {
await t.rollback();
return res.status(404).send("Attachment not found");
return res.status(404).send('Attachment not found');
}
// delete file from folder
const uploadDir = path.join(__dirname, "../../public/uploads");
const uploadDir = path.join(__dirname, '../../public/uploads');
const url = attachment.path;
const fileName = url.substring(url.lastIndexOf("/") + 1);
const fileName = url.substring(url.lastIndexOf('/') + 1);
const filePath = path.join(uploadDir, fileName);
fs.unlink(filePath, (err) => {
if (err) {
console.error('Error deleting file:', err);
t.rollback();
return res.status(404).send("Attachment not found");
return res.status(404).send('Attachment not found');
}
});
@@ -38,7 +38,7 @@ module.exports = function (sequelize) {
} catch (error) {
console.error(error);
await t.rollback();
res.status(500).send("Internal Server Error");
res.status(500).send('Internal Server Error');
}
});

View File

@@ -1,32 +1,32 @@
const express = require("express");
const express = require('express');
const router = express.Router();
const path = require("path");
const fs = require("fs");
const defineAttachment = require("../../models/attachments");
const { DataTypes } = require("sequelize");
const path = require('path');
const fs = require('fs');
const defineAttachment = require('../../models/attachments');
const { DataTypes } = require('sequelize');
module.exports = function (sequelize) {
const Attachment = defineAttachment(sequelize, DataTypes);
router.get("/download/:attachmentId", async (req, res) => {
router.get('/download/:attachmentId', async (req, res) => {
const attachmentId = req.params.attachmentId;
try {
const attachment = await Attachment.findByPk(attachmentId);
if (!attachment) {
return res.status(404).send("Attachment not found");
return res.status(404).send('Attachment not found');
}
const filename = attachment.path.split("/").pop();
const filename = attachment.path.split('/').pop();
const filePath = path.join(__dirname, `../../public/uploads/${filename}`);
if (!fs.existsSync(filePath)) {
return res.status(404).json({ error: "File not found" });
return res.status(404).json({ error: 'File not found' });
}
res.download(filePath);
} catch (error) {
console.error(error);
res.status(500).send("Internal Server Error");
res.status(500).send('Internal Server Error');
}
});

View File

@@ -1,18 +1,18 @@
const express = require("express");
const express = require('express');
const router = express.Router();
const path = require("path");
const fs = require("fs");
const multer = require("multer");
const defineAttachment = require("../../models/attachments");
const defineCaseAttachment = require("../../models/caseAttachments");
const { DataTypes } = require("sequelize");
const path = require('path');
const fs = require('fs');
const multer = require('multer');
const defineAttachment = require('../../models/attachments');
const defineCaseAttachment = require('../../models/caseAttachments');
const { DataTypes } = require('sequelize');
module.exports = function (sequelize) {
const Attachment = defineAttachment(sequelize, DataTypes);
const CaseAttachment = defineCaseAttachment(sequelize, DataTypes);
// Create uploads folder if it does not exist
const uploadDir = path.join(__dirname, "../../public/uploads");
const uploadDir = path.join(__dirname, '../../public/uploads');
if (!fs.existsSync(uploadDir)) {
fs.mkdirSync(uploadDir, { recursive: true });
}
@@ -46,16 +46,16 @@ module.exports = function (sequelize) {
const upload = multer({ storage });
router.post("/", upload.array("files", 10), async (req, res) => {
router.post('/', upload.array('files', 10), async (req, res) => {
const t = await sequelize.transaction();
try {
const caseId = req.query.parentCaseId;
const files = req.files;
if (files.length === 0) {
return res.status(400).json({ error: "No files uploaded" });
return res.status(400).json({ error: 'No files uploaded' });
}
const host = req.get("host");
const host = req.get('host');
const protocol = req.protocol;
const attachmentsData = files.map((file) => ({
title: file.originalname,
@@ -75,7 +75,7 @@ module.exports = function (sequelize) {
res.json(newAttachments);
} catch (error) {
await t.rollback();
res.status(500).json({ error: "Internal server error" });
res.status(500).json({ error: 'Internal server error' });
}
});

View File

@@ -1,2 +1,2 @@
const roles = [{ uid: "admin" }, { uid: "moderator" }, { uid: "user" }];
const roles = [{ uid: 'admin' }, { uid: 'moderator' }, { uid: 'user' }];
module.exports = roles;

View File

@@ -1,14 +1,14 @@
const express = require("express");
const express = require('express');
const router = express.Router();
const defineUser = require("../../models/users");
const { DataTypes } = require("sequelize");
const defineUser = require('../../models/users');
const { DataTypes } = require('sequelize');
const bcrypt = require('bcrypt');
const jwt = require('jsonwebtoken');
module.exports = function (sequelize) {
const User = defineUser(sequelize, DataTypes);
router.post("/signin", async (req, res) => {
router.post('/signin', async (req, res) => {
try {
const { email, password } = req.body;
const user = await User.findOne({
@@ -17,20 +17,20 @@ module.exports = function (sequelize) {
},
});
if (!user) {
return res.status(401).json({ error: "Authentication failed" });
return res.status(401).json({ error: 'Authentication failed' });
}
const passwordMatch = await bcrypt.compare(password, user.password);
if (!passwordMatch) {
return res.status(401).json({ error: "Authentication failed" });
return res.status(401).json({ error: 'Authentication failed' });
}
const accessToken = jwt.sign({ userId: user.id }, "your-secret-key", {
expiresIn: "1h",
const accessToken = jwt.sign({ userId: user.id }, 'your-secret-key', {
expiresIn: '1h',
});
res.status(200).json({ access_token: accessToken, user });
} catch (error) {
console.error(error);
res.status(500).send("Sign up failed");
res.status(500).send('Sign up failed');
}
});

View File

@@ -1,15 +1,15 @@
const express = require("express");
const express = require('express');
const router = express.Router();
const defineUser = require("../../models/users");
const { DataTypes } = require("sequelize");
const roles = require("./roles");
const bcrypt = require("bcrypt");
const jwt = require("jsonwebtoken");
const defineUser = require('../../models/users');
const { DataTypes } = require('sequelize');
const roles = require('./roles');
const bcrypt = require('bcrypt');
const jwt = require('jsonwebtoken');
module.exports = function (sequelize) {
const User = defineUser(sequelize, DataTypes);
router.post("/signup", async (req, res) => {
router.post('/signup', async (req, res) => {
try {
const { email, password, username, avatarPath } = req.body;
const hashedPassword = await bcrypt.hash(password, 10);
@@ -17,8 +17,8 @@ module.exports = function (sequelize) {
const userCount = await User.count();
const initialRole =
userCount > 0
? roles.findIndex((entry) => entry.uid === "user")
: roles.findIndex((entry) => entry.uid === "admin");
? roles.findIndex((entry) => entry.uid === 'user')
: roles.findIndex((entry) => entry.uid === 'admin');
const user = await User.create({
email,
@@ -28,15 +28,15 @@ module.exports = function (sequelize) {
avatarPath: avatarPath,
});
const accessToken = jwt.sign({ userId: user.id }, "your-secret-key", {
expiresIn: "1h",
const accessToken = jwt.sign({ userId: user.id }, 'your-secret-key', {
expiresIn: '1h',
});
user.password = undefined;
res.status(200).json({ access_token: accessToken, user });
} catch (error) {
console.error(error);
res.status(500).send("Sign up failed");
res.status(500).send('Sign up failed');
}
});

View File

@@ -1,15 +1,15 @@
const express = require("express");
const express = require('express');
const router = express.Router();
const defineCase = require("../../models/cases");
const { DataTypes } = require("sequelize");
const defineCase = require('../../models/cases');
const { DataTypes } = require('sequelize');
module.exports = function (sequelize) {
const Case = defineCase(sequelize, DataTypes);
router.post("/bulkdelete", async (req, res) => {
router.post('/bulkdelete', async (req, res) => {
const { caseIds } = req.body;
if (!caseIds || !Array.isArray(caseIds)) {
return res.status(400).send("Invalid caseIds array");
return res.status(400).send('Invalid caseIds array');
}
try {
@@ -17,7 +17,7 @@ module.exports = function (sequelize) {
res.status(204).send();
} catch (error) {
console.error(error);
res.status(500).send("Internal Server Error");
res.status(500).send('Internal Server Error');
}
});

View File

@@ -1,23 +1,23 @@
const express = require("express");
const express = require('express');
const router = express.Router();
const defineCase = require("../../models/cases");
const { DataTypes } = require("sequelize");
const defineCase = require('../../models/cases');
const { DataTypes } = require('sequelize');
module.exports = function (sequelize) {
const Case = defineCase(sequelize, DataTypes);
router.delete("/:caseId", async (req, res) => {
router.delete('/:caseId', async (req, res) => {
const caseId = req.params.caseId;
try {
const testcase = await Case.findByPk(caseId);
if (!testcase) {
return res.status(404).send("Case not found");
return res.status(404).send('Case not found');
}
await testcase.destroy();
res.status(204).send();
} catch (error) {
console.error(error);
res.status(500).send("Internal Server Error");
res.status(500).send('Internal Server Error');
}
});

View File

@@ -1,20 +1,20 @@
const express = require("express");
const express = require('express');
const router = express.Router();
const defineCase = require("../../models/cases");
const defineStep = require("../../models/steps");
const { DataTypes } = require("sequelize");
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.put("/:caseId", async (req, res) => {
router.put('/:caseId', async (req, res) => {
const caseId = req.params.caseId;
const updateCase = req.body;
try {
const testcase = await Case.findByPk(caseId);
if (!testcase) {
return res.status(404).send("Case not found");
return res.status(404).send('Case not found');
}
// if Case has Steps, update Steps as well
@@ -36,7 +36,7 @@ module.exports = function (sequelize) {
res.json(testcase);
} catch (error) {
console.error(error);
res.status(500).send("Internal Server Error");
res.status(500).send('Internal Server Error');
}
});

View File

@@ -1,16 +1,16 @@
const express = require("express");
const express = require('express');
const router = express.Router();
const defineCase = require("../../models/cases");
const { DataTypes } = require("sequelize");
const defineCase = require('../../models/cases');
const { DataTypes } = require('sequelize');
module.exports = function (sequelize) {
const Case = defineCase(sequelize, DataTypes);
router.get("/", async (req, res) => {
router.get('/', async (req, res) => {
const { folderId } = req.query;
if (!folderId) {
return res.status(400).json({ error: "folderId is required" });
return res.status(400).json({ error: 'folderId is required' });
}
try {
@@ -22,7 +22,7 @@ module.exports = function (sequelize) {
res.json(cases);
} catch (error) {
console.error(error);
res.status(500).send("Internal Server Error");
res.status(500).send('Internal Server Error');
}
});

View File

@@ -1,17 +1,9 @@
const express = require("express");
const express = require('express');
const router = express.Router();
const defineCase = require("../../models/cases");
const { DataTypes } = require("sequelize");
const defineCase = require('../../models/cases');
const { DataTypes } = require('sequelize');
const requiredFields = [
"title",
"state",
"priority",
"type",
"automationStatus",
"template",
"folderId",
];
const requiredFields = ['title', 'state', 'priority', 'type', 'automationStatus', 'template', 'folderId'];
function isEmpty(value) {
if (value === null || value === undefined) {
@@ -24,7 +16,7 @@ function isEmpty(value) {
module.exports = function (sequelize) {
const Case = defineCase(sequelize, DataTypes);
router.post("/", async (req, res) => {
router.post('/', async (req, res) => {
try {
if (
requiredFields.some((field) => {
@@ -32,8 +24,7 @@ module.exports = function (sequelize) {
})
) {
return res.status(400).json({
error:
"Title, state, priority, type, automationStatus, template, and folderId are required",
error: 'Title, state, priority, type, automationStatus, template, and folderId are required',
});
}
@@ -65,7 +56,7 @@ module.exports = function (sequelize) {
res.json(newCase);
} catch (error) {
res.status(500).json({ error: "Internal server error" });
res.status(500).json({ error: 'Internal server error' });
}
});

View File

@@ -1,24 +1,24 @@
const express = require("express");
const express = require('express');
const router = express.Router();
const defineCase = require("../../models/cases");
const defineStep = require("../../models/steps");
const defineAttachment = require("../../models/attachments");
const { DataTypes } = require("sequelize");
const defineCase = require('../../models/cases');
const defineStep = require('../../models/steps');
const defineAttachment = require('../../models/attachments');
const { DataTypes } = require('sequelize');
module.exports = function (sequelize) {
const Case = defineCase(sequelize, DataTypes);
const Step = defineStep(sequelize, DataTypes);
const Attachment = defineAttachment(sequelize, DataTypes);
Case.belongsToMany(Step, { through: "caseSteps" });
Step.belongsToMany(Case, { through: "caseSteps" });
Case.belongsToMany(Attachment, { through: "caseAttachments" });
Attachment.belongsToMany(Case, { through: "caseAttachments" });
Case.belongsToMany(Step, { through: 'caseSteps' });
Step.belongsToMany(Case, { through: 'caseSteps' });
Case.belongsToMany(Attachment, { through: 'caseAttachments' });
Attachment.belongsToMany(Case, { through: 'caseAttachments' });
router.get("/:caseId", async (req, res) => {
router.get('/:caseId', async (req, res) => {
const caseId = req.params.caseId;
if (!caseId) {
return res.status(400).json({ error: "caseId is required" });
return res.status(400).json({ error: 'caseId is required' });
}
try {
@@ -26,7 +26,7 @@ module.exports = function (sequelize) {
include: [
{
model: Step,
through: { attributes: ["stepNo"] },
through: { attributes: ['stepNo'] },
},
{
model: Attachment,
@@ -36,7 +36,7 @@ module.exports = function (sequelize) {
return res.json(testcase);
} catch (error) {
console.error(error);
res.status(500).send("Internal Server Error");
res.status(500).send('Internal Server Error');
}
});

View File

@@ -1,23 +1,23 @@
const express = require("express");
const express = require('express');
const router = express.Router();
const defineFolder = require("../../models/folders");
const { DataTypes } = require("sequelize");
const defineFolder = require('../../models/folders');
const { DataTypes } = require('sequelize');
module.exports = function (sequelize) {
const Folder = defineFolder(sequelize, DataTypes);
router.delete("/:folderId", async (req, res) => {
router.delete('/:folderId', async (req, res) => {
const folderId = req.params.folderId;
try {
const folder = await Folder.findByPk(folderId);
if (!folder) {
return res.status(404).send("Folder not found");
return res.status(404).send('Folder not found');
}
await folder.destroy();
res.status(204).send();
} catch (error) {
console.error(error);
res.status(500).send("Internal Server Error");
res.status(500).send('Internal Server Error');
}
});

View File

@@ -1,18 +1,18 @@
const express = require("express");
const express = require('express');
const router = express.Router();
const defineFolder = require("../../models/folders");
const { DataTypes } = require("sequelize");
const defineFolder = require('../../models/folders');
const { DataTypes } = require('sequelize');
module.exports = function (sequelize) {
const Folder = defineFolder(sequelize, DataTypes);
router.put("/:folderId", async (req, res) => {
router.put('/:folderId', async (req, res) => {
const folderId = req.params.folderId;
const { name, detail, projectId, parentFolderId } = req.body;
try {
const folder = await Folder.findByPk(folderId);
if (!folder) {
return res.status(404).send("Folder not found");
return res.status(404).send('Folder not found');
}
await folder.update({
name,
@@ -23,7 +23,7 @@ module.exports = function (sequelize) {
res.json(folder);
} catch (error) {
console.error(error);
res.status(500).send("Internal Server Error");
res.status(500).send('Internal Server Error');
}
});

View File

@@ -1,12 +1,12 @@
const express = require("express");
const express = require('express');
const router = express.Router();
const defineFolder = require('../../models/folders');
const { DataTypes } = require('sequelize');
module.exports = function (sequelize) {
const Folder = defineFolder(sequelize, DataTypes)
const Folder = defineFolder(sequelize, DataTypes);
router.get("/", async (req, res) => {
router.get('/', async (req, res) => {
const { projectId } = req.query;
if (!projectId) {
@@ -16,13 +16,13 @@ module.exports = function(sequelize) {
try {
const folders = await Folder.findAll({
where: {
projectId: projectId
}
projectId: projectId,
},
});
res.json(folders);
} catch (error) {
console.error(error);
res.status(500).send("Internal Server Error");
res.status(500).send('Internal Server Error');
}
});

View File

@@ -1,18 +1,16 @@
const express = require("express");
const express = require('express');
const router = express.Router();
const defineFolder = require("../../models/folders");
const { DataTypes } = require("sequelize");
const defineFolder = require('../../models/folders');
const { DataTypes } = require('sequelize');
module.exports = function (sequelize) {
const Folder = defineFolder(sequelize, DataTypes);
router.post("/", async (req, res) => {
router.post('/', async (req, res) => {
try {
const { name, detail, projectId, parentFolderId } = req.body;
if (!name || !projectId) {
return res
.status(400)
.json({ error: "Name and projectId are required" });
return res.status(400).json({ error: 'Name and projectId are required' });
}
const newFolder = await Folder.create({
@@ -24,7 +22,7 @@ module.exports = function (sequelize) {
res.json(newFolder);
} catch (error) {
res.status(500).json({ error: "Internal server error" });
res.status(500).json({ error: 'Internal server error' });
}
});

View File

@@ -1,11 +1,11 @@
const express = require("express");
const express = require('express');
const router = express.Router();
const defineProject = require("../../models/projects");
const defineFolder = require("../../models/folders");
const defineCase = require("../../models/cases");
const defineRun = require("../../models/runs");
const defineRunCase = require("../../models/runCases");
const { DataTypes } = require("sequelize");
const defineProject = require('../../models/projects');
const defineFolder = require('../../models/folders');
const defineCase = require('../../models/cases');
const defineRun = require('../../models/runs');
const defineRunCase = require('../../models/runCases');
const { DataTypes } = require('sequelize');
module.exports = function (sequelize) {
const Project = defineProject(sequelize, DataTypes);
@@ -13,16 +13,16 @@ module.exports = function (sequelize) {
const Case = defineCase(sequelize, DataTypes);
const Run = defineRun(sequelize, DataTypes);
const RunCase = defineRunCase(sequelize, DataTypes);
Project.hasMany(Folder, { foreignKey: "projectId" });
Folder.hasMany(Case, { foreignKey: "folderId" });
Project.hasMany(Run, { foreignKey: "projectId" });
Run.hasMany(RunCase, { foreignKey: "runId" });
Project.hasMany(Folder, { foreignKey: 'projectId' });
Folder.hasMany(Case, { foreignKey: 'folderId' });
Project.hasMany(Run, { foreignKey: 'projectId' });
Run.hasMany(RunCase, { foreignKey: 'runId' });
router.get("/:projectId", async (req, res) => {
router.get('/:projectId', async (req, res) => {
const projectId = req.params.projectId;
if (!projectId) {
return res.status(400).json({ error: "projectId is required" });
return res.status(400).json({ error: 'projectId is required' });
}
try {
@@ -36,12 +36,12 @@ module.exports = function (sequelize) {
],
});
if (!project) {
return res.status(404).send("Project not found");
return res.status(404).send('Project not found');
}
res.json(project);
} catch (error) {
console.error(error);
res.status(500).send("Internal Server Error");
res.status(500).send('Internal Server Error');
}
});

View File

@@ -1,23 +1,23 @@
const express = require("express");
const express = require('express');
const router = express.Router();
const defineProject = require("../../models/projects");
const { DataTypes } = require("sequelize");
const defineProject = require('../../models/projects');
const { DataTypes } = require('sequelize');
module.exports = function (sequelize) {
const Project = defineProject(sequelize, DataTypes);
router.delete("/:projectId", async (req, res) => {
router.delete('/:projectId', async (req, res) => {
const projectId = req.params.projectId;
try {
const project = await Project.findByPk(projectId);
if (!project) {
return res.status(404).send("Project not found");
return res.status(404).send('Project not found');
}
await project.destroy();
res.status(204).send();
} catch (error) {
console.error(error);
res.status(500).send("Internal Server Error");
res.status(500).send('Internal Server Error');
}
});

View File

@@ -1,18 +1,18 @@
const express = require("express");
const express = require('express');
const router = express.Router();
const defineProject = require("../../models/projects");
const { DataTypes } = require("sequelize");
const defineProject = require('../../models/projects');
const { DataTypes } = require('sequelize');
module.exports = function (sequelize) {
const Project = defineProject(sequelize, DataTypes);
router.put("/:projectId", async (req, res) => {
router.put('/:projectId', async (req, res) => {
const projectId = req.params.projectId;
const { name, detail } = req.body;
try {
const project = await Project.findByPk(projectId);
if (!project) {
return res.status(404).send("Project not found");
return res.status(404).send('Project not found');
}
await project.update({
name,
@@ -21,7 +21,7 @@ module.exports = function (sequelize) {
res.json(project);
} catch (error) {
console.error(error);
res.status(500).send("Internal Server Error");
res.status(500).send('Internal Server Error');
}
});

View File

@@ -1,18 +1,18 @@
const express = require("express");
const express = require('express');
const router = express.Router();
const defineProject = require('../../models/projects');
const { DataTypes } = require('sequelize');
module.exports = function (sequelize) {
const Project = defineProject(sequelize, DataTypes)
const Project = defineProject(sequelize, DataTypes);
router.get("/", async (req, res) => {
router.get('/', async (req, res) => {
try {
const projects = await Project.findAll();
res.json(projects);
} catch (error) {
console.error(error);
res.status(500).send("Internal Server Error");
res.status(500).send('Internal Server Error');
}
});

View File

@@ -1,12 +1,12 @@
const express = require("express");
const express = require('express');
const router = express.Router();
const defineProject = require("../../models/projects");
const { DataTypes } = require("sequelize");
const defineProject = require('../../models/projects');
const { DataTypes } = require('sequelize');
module.exports = function (sequelize) {
const Project = defineProject(sequelize, DataTypes)
const Project = defineProject(sequelize, DataTypes);
router.post("/", async (req, res) => {
router.post('/', async (req, res) => {
try {
const { name, detail } = req.body;
const newProject = await Project.create({
@@ -16,7 +16,7 @@ module.exports = function (sequelize) {
res.json(newProject);
} catch (error) {
console.error(error);
res.status(500).send("Internal Server Error");
res.status(500).send('Internal Server Error');
}
});

View File

@@ -1,19 +1,19 @@
const express = require("express");
const express = require('express');
const router = express.Router();
const defineProject = require("../../models/projects");
const defineFolder = require("../../models/folders");
const { DataTypes } = require("sequelize");
const defineProject = require('../../models/projects');
const defineFolder = require('../../models/folders');
const { DataTypes } = require('sequelize');
module.exports = function (sequelize) {
const Project = defineProject(sequelize, DataTypes);
const Folder = defineFolder(sequelize, DataTypes);
Project.hasMany(Folder, { foreignKey: "projectId" });
Project.hasMany(Folder, { foreignKey: 'projectId' });
router.get("/:projectId", async (req, res) => {
router.get('/:projectId', async (req, res) => {
const projectId = req.params.projectId;
if (!projectId) {
return res.status(400).json({ error: "projectId is required" });
return res.status(400).json({ error: 'projectId is required' });
}
try {
@@ -25,12 +25,12 @@ module.exports = function (sequelize) {
],
});
if (!project) {
return res.status(404).send("Project not found");
return res.status(404).send('Project not found');
}
res.json(project);
} catch (error) {
console.error(error);
res.status(500).send("Internal Server Error");
res.status(500).send('Internal Server Error');
}
});

View File

@@ -1,12 +1,12 @@
const express = require("express");
const express = require('express');
const router = express.Router();
const defineRunCase = require("../../models/runCases");
const { DataTypes, Op } = require("sequelize");
const defineRunCase = require('../../models/runCases');
const { DataTypes, Op } = require('sequelize');
module.exports = function (sequelize) {
const RunCase = defineRunCase(sequelize, DataTypes);
router.post("/bulkdelete", async (req, res) => {
router.post('/bulkdelete', async (req, res) => {
const recordsToDelete = req.body;
try {
@@ -20,7 +20,7 @@ module.exports = function (sequelize) {
});
if (existingRunCases.length === 0) {
return res.status(200).send("No records found to delete");
return res.status(200).send('No records found to delete');
}
await RunCase.destroy({
@@ -32,10 +32,10 @@ module.exports = function (sequelize) {
},
});
res.status(200).send("Records deleted successfully");
res.status(200).send('Records deleted successfully');
} catch (error) {
console.error("Error deleting run cases:", error);
res.status(500).send("Internal Server Error");
console.error('Error deleting run cases:', error);
res.status(500).send('Internal Server Error');
}
});

View File

@@ -1,12 +1,12 @@
const express = require("express");
const express = require('express');
const router = express.Router();
const defineRunCase = require("../../models/runCases");
const { DataTypes, Op } = require("sequelize");
const defineRunCase = require('../../models/runCases');
const { DataTypes, Op } = require('sequelize');
module.exports = function (sequelize) {
const RunCase = defineRunCase(sequelize, DataTypes);
router.post("/bulknew", async (req, res) => {
router.post('/bulknew', async (req, res) => {
const recordsToCreate = req.body;
try {
@@ -22,9 +22,7 @@ module.exports = function (sequelize) {
// Filter out records that already exist
const recordsToCreateFiltered = recordsToCreate.filter((record) => {
return !existingRunCases.some(
(existingRecord) =>
existingRecord.runId == record.runId &&
existingRecord.caseId == record.caseId
(existingRecord) => existingRecord.runId == record.runId && existingRecord.caseId == record.caseId
);
});
@@ -39,7 +37,7 @@ module.exports = function (sequelize) {
res.json(newRunCases);
} catch (error) {
console.error(error);
res.status(500).send("Internal Server Error");
res.status(500).send('Internal Server Error');
}
});

View File

@@ -1,12 +1,12 @@
const express = require("express");
const express = require('express');
const router = express.Router();
const defineRunCase = require("../../models/runCases");
const { DataTypes } = require("sequelize");
const defineRunCase = require('../../models/runCases');
const { DataTypes } = require('sequelize');
module.exports = function (sequelize) {
const RunCase = defineRunCase(sequelize, DataTypes);
router.delete("/", async (req, res) => {
router.delete('/', async (req, res) => {
const runId = req.query.runId;
const caseId = req.query.caseId;
@@ -20,14 +20,14 @@ module.exports = function (sequelize) {
});
if (!deletingRunCase) {
return res.status(404).send("RunCase not found");
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");
res.status(500).send('Internal Server Error');
}
});

View File

@@ -1,12 +1,12 @@
const express = require("express");
const express = require('express');
const router = express.Router();
const defineRunCase = require("../../models/runCases");
const { DataTypes } = require("sequelize");
const defineRunCase = require('../../models/runCases');
const { DataTypes } = require('sequelize');
module.exports = function (sequelize) {
const RunCase = defineRunCase(sequelize, DataTypes);
router.put("/", async (req, res) => {
router.put('/', async (req, res) => {
const runId = req.query.runId;
const caseId = req.query.caseId;
const status = req.query.status;
@@ -20,7 +20,7 @@ module.exports = function (sequelize) {
});
if (!runCase) {
return res.status(404).send("Runcase not found");
return res.status(404).send('Runcase not found');
}
await runCase.update({
@@ -31,7 +31,7 @@ module.exports = function (sequelize) {
res.json(runCase);
} catch (error) {
console.error(error);
res.status(500).send("Internal Server Error");
res.status(500).send('Internal Server Error');
}
});

View File

@@ -1,12 +1,12 @@
const express = require("express");
const express = require('express');
const router = express.Router();
const defineRunCase = require("../../models/runCases");
const defineRunCase = require('../../models/runCases');
const { DataTypes } = require('sequelize');
module.exports = function (sequelize) {
const RunCase = defineRunCase(sequelize, DataTypes)
const RunCase = defineRunCase(sequelize, DataTypes);
router.get("/", async (req, res) => {
router.get('/', async (req, res) => {
const { runId } = req.query;
if (!runId) {
@@ -16,13 +16,13 @@ module.exports = function(sequelize) {
try {
const runCases = await RunCase.findAll({
where: {
runId: runId
}
runId: runId,
},
});
res.json(runCases);
} catch (error) {
console.error(error);
res.status(500).send("Internal Server Error");
res.status(500).send('Internal Server Error');
}
});

View File

@@ -1,12 +1,12 @@
const express = require("express");
const express = require('express');
const router = express.Router();
const defineRunCase = require("../../models/runCases");
const { DataTypes } = require("sequelize");
const defineRunCase = require('../../models/runCases');
const { DataTypes } = require('sequelize');
module.exports = function (sequelize) {
const RunCase = defineRunCase(sequelize, DataTypes);
router.post("/", async (req, res) => {
router.post('/', async (req, res) => {
const runId = req.query.runId;
const caseId = req.query.caseId;
@@ -15,26 +15,24 @@ module.exports = function (sequelize) {
const existingRunCase = await RunCase.findOne({
where: {
runId: runId,
caseId: caseId
}
caseId: caseId,
},
});
if (existingRunCase) {
return res.status(400).send("Record already exists");
return res.status(400).send('Record already exists');
}
const newRunCase = await RunCase.create(
{
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");
res.status(500).send('Internal Server Error');
}
});

View File

@@ -1,23 +1,23 @@
const express = require("express");
const express = require('express');
const router = express.Router();
const defineRun = require("../../models/runs");
const { DataTypes } = require("sequelize");
const defineRun = require('../../models/runs');
const { DataTypes } = require('sequelize');
module.exports = function (sequelize) {
const Run = defineRun(sequelize, DataTypes);
router.delete("/:runId", async (req, res) => {
router.delete('/:runId', async (req, res) => {
const runId = req.params.runId;
try {
const testrun = await Run.findByPk(runId);
if (!testrun) {
return res.status(404).send("Run not found");
return res.status(404).send('Run not found');
}
await testrun.destroy();
res.status(204).send();
} catch (error) {
console.error(error);
res.status(500).send("Internal Server Error");
res.status(500).send('Internal Server Error');
}
});

View File

@@ -1,18 +1,18 @@
const express = require("express");
const express = require('express');
const router = express.Router();
const defineRun = require("../../models/runs");
const { DataTypes } = require("sequelize");
const defineRun = require('../../models/runs');
const { DataTypes } = require('sequelize');
module.exports = function (sequelize) {
const Run = defineRun(sequelize, DataTypes);
router.put("/:runId", async (req, res) => {
router.put('/:runId', async (req, res) => {
const runId = req.params.runId;
const updateRun = req.body;
try {
const testrun = await Run.findByPk(runId);
if (!testrun) {
return res.status(404).send("Run not found");
return res.status(404).send('Run not found');
}
delete updateRun.Steps;
@@ -20,7 +20,7 @@ module.exports = function (sequelize) {
res.json(testrun);
} catch (error) {
console.error(error);
res.status(500).send("Internal Server Error");
res.status(500).send('Internal Server Error');
}
});

View File

@@ -1,12 +1,12 @@
const express = require("express");
const express = require('express');
const router = express.Router();
const defineRun = require("../../models/runs");
const defineRun = require('../../models/runs');
const { DataTypes } = require('sequelize');
module.exports = function (sequelize) {
const Run = defineRun(sequelize, DataTypes)
const Run = defineRun(sequelize, DataTypes);
router.get("/", async (req, res) => {
router.get('/', async (req, res) => {
const { projectId } = req.query;
if (!projectId) {
@@ -16,13 +16,13 @@ module.exports = function(sequelize) {
try {
const runs = await Run.findAll({
where: {
projectId: projectId
}
projectId: projectId,
},
});
res.json(runs);
} catch (error) {
console.error(error);
res.status(500).send("Internal Server Error");
res.status(500).send('Internal Server Error');
}
});

View File

@@ -1,18 +1,16 @@
const express = require("express");
const express = require('express');
const router = express.Router();
const defineRun = require("../../models/runs");
const { DataTypes } = require("sequelize");
const defineRun = require('../../models/runs');
const { DataTypes } = require('sequelize');
module.exports = function (sequelize) {
const Run = defineRun(sequelize, DataTypes);
router.post("/", async (req, res) => {
router.post('/', async (req, res) => {
try {
const { name, configurations, description, state, projectId } = req.body;
if (!name || !projectId) {
return res
.status(400)
.json({ error: "Name and projectId are required" });
return res.status(400).json({ error: 'Name and projectId are required' });
}
const newRun = await Run.create({
@@ -25,7 +23,7 @@ module.exports = function (sequelize) {
res.json(newRun);
} catch (error) {
res.status(500).json({ error: "Internal server error" });
res.status(500).json({ error: 'Internal server error' });
}
});

View File

@@ -1,39 +1,39 @@
const express = require("express");
const express = require('express');
const router = express.Router();
const defineRun = require("../../models/runs");
const defineRunCase = require("../../models/runCases");
const { DataTypes, literal } = require("sequelize");
const defineRun = require('../../models/runs');
const defineRunCase = require('../../models/runCases');
const { DataTypes, literal } = require('sequelize');
module.exports = function (sequelize) {
const Run = defineRun(sequelize, DataTypes);
const RunCase = defineRunCase(sequelize, DataTypes);
router.get("/:runId", async (req, res) => {
router.get('/:runId', async (req, res) => {
const runId = req.params.runId;
if (!runId) {
return res.status(400).json({ error: "runId is required" });
return res.status(400).json({ error: 'runId is required' });
}
try {
const run = await Run.findByPk(runId);
if (!run) {
return res.status(404).send("Run not found");
return res.status(404).send('Run not found');
}
// Counts test case status belonging to the run
const statusCounts = await RunCase.findAll({
attributes: ["status", [literal("COUNT(*)"), "count"]],
attributes: ['status', [literal('COUNT(*)'), 'count']],
where: {
runId: run.id,
},
group: ["status"],
group: ['status'],
});
res.json({ run, statusCounts });
} catch (error) {
console.error(error);
res.status(500).send("Internal Server Error");
res.status(500).send('Internal Server Error');
}
});

View File

@@ -1,14 +1,14 @@
const express = require("express");
const express = require('express');
const router = express.Router();
const defineStep = require("../../models/steps");
const defineCaseStep = require("../../models/caseSteps");
const { DataTypes, Op } = require("sequelize");
const defineStep = require('../../models/steps');
const defineCaseStep = require('../../models/caseSteps');
const { DataTypes, Op } = require('sequelize');
module.exports = function (sequelize) {
const Step = defineStep(sequelize, DataTypes);
const CaseStep = defineCaseStep(sequelize, DataTypes);
router.delete("/:stepId", async (req, res) => {
router.delete('/:stepId', async (req, res) => {
const stepId = req.params.stepId;
// TODO The caseId should not be specified from the front end, but should be traced from stepId by association.
const caseId = req.query.parentCaseId;
@@ -19,7 +19,7 @@ module.exports = function (sequelize) {
const step = await Step.findByPk(stepId);
if (!step) {
await t.rollback();
return res.status(404).send("Step not found");
return res.status(404).send('Step not found');
}
// Get caseStep to be deleted.
@@ -32,7 +32,7 @@ module.exports = function (sequelize) {
// Decrease stepNo for all caseSteps with greater than the caseStep to be deleted.
await CaseStep.update(
{ stepNo: sequelize.literal("stepNo - 1") },
{ stepNo: sequelize.literal('stepNo - 1') },
{
where: {
CaseId: caseId,
@@ -51,7 +51,7 @@ module.exports = function (sequelize) {
} catch (error) {
console.error(error);
await t.rollback();
res.status(500).send("Internal Server Error");
res.status(500).send('Internal Server Error');
}
});

View File

@@ -1,14 +1,14 @@
const express = require("express");
const express = require('express');
const router = express.Router();
const defineStep = require("../../models/steps");
const defineCaseStep = require("../../models/caseSteps");
const { DataTypes, Op } = require("sequelize");
const defineStep = require('../../models/steps');
const defineCaseStep = require('../../models/caseSteps');
const { DataTypes, Op } = require('sequelize');
module.exports = function (sequelize) {
const Step = defineStep(sequelize, DataTypes);
const CaseStep = defineCaseStep(sequelize, DataTypes);
router.post("/", async (req, res) => {
router.post('/', async (req, res) => {
const newStepNo = req.query.newStepNo;
const caseId = req.query.parentCaseId;
@@ -16,13 +16,13 @@ module.exports = function (sequelize) {
try {
// Update existing stepNo for steps with stepNo greater than or equal to newStepNo
const maxStepNo = await CaseStep.max("stepNo", {
const maxStepNo = await CaseStep.max('stepNo', {
where: { caseId: caseId },
transaction: t,
});
if (maxStepNo >= newStepNo) {
await CaseStep.update(
{ stepNo: sequelize.literal("stepNo + 1") },
{ stepNo: sequelize.literal('stepNo + 1') },
{
where: {
caseId: caseId,
@@ -35,8 +35,8 @@ module.exports = function (sequelize) {
const newStep = await Step.create(
{
step: "",
result: "",
step: '',
result: '',
},
{ transaction: t }
);
@@ -55,7 +55,7 @@ module.exports = function (sequelize) {
} catch (error) {
console.error(error);
await t.rollback();
res.status(500).send("Internal Server Error");
res.status(500).send('Internal Server Error');
}
});

View File

@@ -1,58 +1,58 @@
"use strict";
const path = require("path");
const fs = require("fs");
'use strict';
const path = require('path');
const fs = require('fs');
module.exports = {
up: async (queryInterface, Sequelize) => {
// Add projects table records
await queryInterface.bulkInsert("Projects", [
await queryInterface.bulkInsert('Projects', [
{
name: "TestPlat Test",
name: 'TestPlat Test',
detail: "Test Plat's Manual test",
createdAt: new Date(),
updatedAt: new Date(),
},
{
name: "Iron Muscle App(筋トレアプリ)",
detail: "リリース前総合評価",
name: 'Iron Muscle App(筋トレアプリ)',
detail: 'リリース前総合評価',
createdAt: new Date(),
updatedAt: new Date(),
},
]);
// Add folders table records
await queryInterface.bulkInsert("folders", [
await queryInterface.bulkInsert('folders', [
{
name: "Account",
detail: "",
name: 'Account',
detail: '',
projectId: 1,
createdAt: new Date(),
updatedAt: new Date(),
},
{
name: "Contact",
detail: "",
name: 'Contact',
detail: '',
projectId: 1,
createdAt: new Date(),
updatedAt: new Date(),
},
{
name: "アカウント",
detail: "",
name: 'アカウント',
detail: '',
projectId: 2,
createdAt: new Date(),
updatedAt: new Date(),
},
{
name: "トレーニング記録",
detail: "",
name: 'トレーニング記録',
detail: '',
projectId: 2,
createdAt: new Date(),
updatedAt: new Date(),
},
{
name: "タイムライン",
detail: "",
name: 'タイムライン',
detail: '',
projectId: 2,
createdAt: new Date(),
updatedAt: new Date(),
@@ -60,30 +60,30 @@ module.exports = {
]);
// Add runs table records
await queryInterface.bulkInsert("runs", [
await queryInterface.bulkInsert('runs', [
{
name: "First Test Run",
name: 'First Test Run',
projectId: 1,
configurations: 1,
description: "5/14 - 5/31",
description: '5/14 - 5/31',
state: 4,
createdAt: new Date(),
updatedAt: new Date(),
},
{
name: "総合評価第一回",
name: '総合評価第一回',
projectId: 2,
configurations: 1,
description: "5/14 - 5/31",
description: '5/14 - 5/31',
state: 4,
createdAt: new Date(),
updatedAt: new Date(),
},
{
name: "総合評価第二回",
name: '総合評価第二回',
projectId: 2,
configurations: 1,
description: "6/1 - 6/12",
description: '6/1 - 6/12',
state: 1,
createdAt: new Date(),
updatedAt: new Date(),
@@ -91,171 +91,171 @@ module.exports = {
]);
// Add cases table records
await queryInterface.bulkInsert("cases", [
await queryInterface.bulkInsert('cases', [
{
title: "Signup",
title: 'Signup',
state: 1,
priority: 1,
type: 4,
automationStatus: 1,
description: "User can signup from signup form.",
description: 'User can signup from signup form.',
template: 1,
preConditions: "Not signed in",
expectedResults: "",
preConditions: 'Not signed in',
expectedResults: '',
folderId: 1,
createdAt: new Date(),
updatedAt: new Date(),
},
{
title: "Signin",
title: 'Signin',
state: 1,
priority: 1,
type: 4,
automationStatus: 1,
description: "User can signin from signin form.",
description: 'User can signin from signin form.',
template: 1,
preConditions: "Not signed in",
expectedResults: "",
preConditions: 'Not signed in',
expectedResults: '',
folderId: 1,
createdAt: new Date(),
updatedAt: new Date(),
},
{
title: "Contact",
title: 'Contact',
state: 1,
priority: 1,
type: 4,
automationStatus: 1,
description: "User can send inquiry from 'contact us' form.",
template: 0,
preConditions: "",
expectedResults: "",
preConditions: '',
expectedResults: '',
folderId: 2,
createdAt: new Date(),
updatedAt: new Date(),
},
{
title: "メールアドレスでのアカウント登録",
title: 'メールアドレスでのアカウント登録',
state: 1,
priority: 2,
type: 4,
automationStatus: 1,
description: "メールアドレス、パスワードをフォームに入力してサインアップボタンを押す",
description: 'メールアドレス、パスワードをフォームに入力してサインアップボタンを押す',
template: 0,
preConditions: "未サインイン状態であること。アカウントがないこと。",
expectedResults: "サインアップができ、自動でアカウントページに遷移する",
preConditions: '未サインイン状態であること。アカウントがないこと。',
expectedResults: 'サインアップができ、自動でアカウントページに遷移する',
folderId: 3,
createdAt: new Date(),
updatedAt: new Date(),
},
{
title: "メールアドレスでのサインイン",
title: 'メールアドレスでのサインイン',
state: 1,
priority: 2,
type: 4,
automationStatus: 1,
description: "メールアドレス、パスワードをフォームに入力してサインインボタンを押す",
description: 'メールアドレス、パスワードをフォームに入力してサインインボタンを押す',
template: 0,
preConditions: "未サインイン状態であること",
expectedResults: "サインインができ、自動でアカウントページに遷移する",
preConditions: '未サインイン状態であること',
expectedResults: 'サインインができ、自動でアカウントページに遷移する',
folderId: 3,
createdAt: new Date(),
updatedAt: new Date(),
},
{
title: "ソーシャルアカウントサインイン",
title: 'ソーシャルアカウントサインイン',
state: 1,
priority: 1,
type: 4,
automationStatus: 1,
description: "Googleアカウントで筋トレアプリにサインインできること",
description: 'Googleアカウントで筋トレアプリにサインインできること',
template: 0,
preConditions: "未サインイン状態であること",
expectedResults: "サインインでき、自動でアカウントページに遷移する",
preConditions: '未サインイン状態であること',
expectedResults: 'サインインでき、自動でアカウントページに遷移する',
folderId: 3,
createdAt: new Date(),
updatedAt: new Date(),
},
{
title: "アカウント情報編集",
title: 'アカウント情報編集',
state: 1,
priority: 3,
type: 4,
automationStatus: 1,
description: "ユーザー名、アバター画像を変更できること",
description: 'ユーザー名、アバター画像を変更できること',
template: 0,
preConditions: "アバター画像(.png, .svg, .jpg)を用意する",
expectedResults: "アバター画像を登録できること",
preConditions: 'アバター画像(.png, .svg, .jpg)を用意する',
expectedResults: 'アバター画像を登録できること',
folderId: 3,
createdAt: new Date(),
updatedAt: new Date(),
},
{
title: "アカウント閲覧",
title: 'アカウント閲覧',
state: 1,
priority: 0,
type: 1,
automationStatus: 1,
description: "ほかの人のアカウント情報は見れないこと",
description: 'ほかの人のアカウント情報は見れないこと',
template: 1,
preConditions: "特になし",
expectedResults: "",
preConditions: '特になし',
expectedResults: '',
folderId: 3,
createdAt: new Date(),
updatedAt: new Date(),
},
{
title: "筋トレ記録(部位選択)",
title: '筋トレ記録(部位選択)',
state: 1,
priority: 2,
type: 1,
automationStatus: 1,
description: "部位選択",
description: '部位選択',
template: 1,
preConditions: "特になし",
expectedResults: "筋トレ部位を選択できること",
preConditions: '特になし',
expectedResults: '筋トレ部位を選択できること',
folderId: 4,
createdAt: new Date(),
updatedAt: new Date(),
},
{
title: "筋トレ記録(回数選択)",
title: '筋トレ記録(回数選択)',
state: 1,
priority: 2,
type: 1,
automationStatus: 1,
description: "回数選択",
description: '回数選択',
template: 1,
preConditions: "特になし",
expectedResults: "筋トレ回数を選択できること",
preConditions: '特になし',
expectedResults: '筋トレ回数を選択できること',
folderId: 4,
createdAt: new Date(),
updatedAt: new Date(),
},
{
title: "筋トレ記録 ダイアログのクローズ",
title: '筋トレ記録 ダイアログのクローズ',
state: 1,
priority: 3,
type: 3,
automationStatus: 1,
description: "選択ダイアログの機能性確認",
description: '選択ダイアログの機能性確認',
template: 1,
preConditions: "ダイアログを開く",
expectedResults: "ダイアログの「×」ボタンを押して閉じれること",
preConditions: 'ダイアログを開く',
expectedResults: 'ダイアログの「×」ボタンを押して閉じれること',
folderId: 4,
createdAt: new Date(),
updatedAt: new Date(),
},
{
title: "筋トレ記録 選択ダイアログ",
title: '筋トレ記録 選択ダイアログ',
state: 1,
priority: 3,
type: 3,
automationStatus: 1,
description: "選択ダイアログのレスポンシブ確認",
description: '選択ダイアログのレスポンシブ確認',
template: 1,
preConditions: "スマホでウェブサイトにアクセスする",
expectedResults: "ダイアログの表示がおかしくないこと",
preConditions: 'スマホでウェブサイトにアクセスする',
expectedResults: 'ダイアログの表示がおかしくないこと',
folderId: 4,
createdAt: new Date(),
updatedAt: new Date(),
@@ -263,47 +263,47 @@ module.exports = {
]);
// Add steps table records
await queryInterface.bulkInsert("steps", [
await queryInterface.bulkInsert('steps', [
{
step: "Check accout status",
result: "Never have account",
step: 'Check accout status',
result: 'Never have account',
createdAt: new Date(),
updatedAt: new Date(),
},
{
step: "Enter signup form and then, click 'signup' button.",
result: "Automatically redirect to the account page",
result: 'Automatically redirect to the account page',
createdAt: new Date(),
updatedAt: new Date(),
},
{
step: "Check signin status",
result: "Not signed in",
step: 'Check signin status',
result: 'Not signed in',
createdAt: new Date(),
updatedAt: new Date(),
},
{
step: "Enter signin form and then, click 'signin button.'",
result: "Automatically redirect to the account page",
result: 'Automatically redirect to the account page',
createdAt: new Date(),
updatedAt: new Date(),
},
{
step: "ブラウザのシークレットモードに入る",
result: "開発者モードのLocal Storageを開き、sessionがないことを確認する。",
step: 'ブラウザのシークレットモードに入る',
result: '開発者モードのLocal Storageを開き、sessionがないことを確認する。',
createdAt: new Date(),
updatedAt: new Date(),
},
{
step: "'account/userinfo?userid=xxx'に遷移する",
result: "エラーページにリダイレクトされ、403エラーなこと。",
result: 'エラーページにリダイレクトされ、403エラーなこと。',
createdAt: new Date(),
updatedAt: new Date(),
},
]);
// Add case-step join table
await queryInterface.bulkInsert("caseSteps", [
await queryInterface.bulkInsert('caseSteps', [
{
caseId: 1,
stepId: 1,
@@ -338,7 +338,8 @@ module.exports = {
stepNo: 1,
createdAt: new Date(),
updatedAt: new Date(),
}, {
},
{
caseId: 8,
stepId: 6,
stepNo: 2,
@@ -347,28 +348,28 @@ module.exports = {
},
]);
await queryInterface.bulkInsert("attachments", [
await queryInterface.bulkInsert('attachments', [
{
title: "Selenium logo",
detail: "",
path: "http://localhost:3001/uploads/861px-Selenium_Logo.png",
title: 'Selenium logo',
detail: '',
path: 'http://localhost:3001/uploads/861px-Selenium_Logo.png',
createdAt: new Date(),
updatedAt: new Date(),
},
{
title: "vitest logo",
detail: "",
path: "http://localhost:3001/uploads/logo-shadow.svg",
title: 'vitest logo',
detail: '',
path: 'http://localhost:3001/uploads/logo-shadow.svg',
createdAt: new Date(),
updatedAt: new Date(),
},
]);
// copy sample files to uploads folder
const sampleFolderPath = "public/sample";
const uploadsFolderPath = "public/uploads";
const SeleniumLogoFileName = "861px-Selenium_Logo.png";
const vitestLogoFileName = "logo-shadow.svg";
const sampleFolderPath = 'public/sample';
const uploadsFolderPath = 'public/uploads';
const SeleniumLogoFileName = '861px-Selenium_Logo.png';
const vitestLogoFileName = 'logo-shadow.svg';
if (!fs.existsSync(uploadsFolderPath)) {
fs.mkdirSync(uploadsFolderPath, { recursive: true });
}
@@ -381,17 +382,13 @@ module.exports = {
}
}
);
fs.copyFile(
`${sampleFolderPath}/${vitestLogoFileName}`,
`${uploadsFolderPath}/${vitestLogoFileName}`,
(err) => {
fs.copyFile(`${sampleFolderPath}/${vitestLogoFileName}`, `${uploadsFolderPath}/${vitestLogoFileName}`, (err) => {
if (err) {
console.log(err);
}
}
);
});
await queryInterface.bulkInsert("caseAttachments", [
await queryInterface.bulkInsert('caseAttachments', [
{
caseId: 1,
attachmentId: 1,
@@ -406,7 +403,7 @@ module.exports = {
},
]);
await queryInterface.bulkInsert("runCases", [
await queryInterface.bulkInsert('runCases', [
{
runId: 1,
caseId: 1,

View File

@@ -1,50 +1,42 @@
import { tv } from "tailwind-variants";
import { tv } from 'tailwind-variants';
export const title = tv({
base: "tracking-tight inline font-semibold",
base: 'tracking-tight inline font-semibold',
variants: {
color: {
violet: "from-[#FF1CF7] to-[#b249f8]",
yellow: "from-[#FF705B] to-[#FFB457]",
blue: "from-[#5EA2EF] to-[#0072F5]",
cyan: "from-[#00b7fa] to-[#01cfea]",
green: "from-[#6FEE8D] to-[#17c964]",
pink: "from-[#FF72E1] to-[#F54C7A]",
foreground: "dark:from-[#FFFFFF] dark:to-[#4B4B4B]",
violet: 'from-[#FF1CF7] to-[#b249f8]',
yellow: 'from-[#FF705B] to-[#FFB457]',
blue: 'from-[#5EA2EF] to-[#0072F5]',
cyan: 'from-[#00b7fa] to-[#01cfea]',
green: 'from-[#6FEE8D] to-[#17c964]',
pink: 'from-[#FF72E1] to-[#F54C7A]',
foreground: 'dark:from-[#FFFFFF] dark:to-[#4B4B4B]',
},
size: {
sm: "text-3xl lg:text-4xl",
md: "text-[2.3rem] lg:text-5xl leading-9",
lg: "text-4xl lg:text-6xl",
sm: 'text-3xl lg:text-4xl',
md: 'text-[2.3rem] lg:text-5xl leading-9',
lg: 'text-4xl lg:text-6xl',
},
fullWidth: {
true: "w-full block",
true: 'w-full block',
},
},
defaultVariants: {
size: "md",
size: 'md',
},
compoundVariants: [
{
color: [
"violet",
"yellow",
"blue",
"cyan",
"green",
"pink",
"foreground",
],
class: "bg-clip-text text-transparent bg-gradient-to-b",
color: ['violet', 'yellow', 'blue', 'cyan', 'green', 'pink', 'foreground'],
class: 'bg-clip-text text-transparent bg-gradient-to-b',
},
],
});
export const subtitle = tv({
base: "w-full md:w-1/2 my-2 text-lg lg:text-xl text-default-600 block max-w-full",
base: 'w-full md:w-1/2 my-2 text-lg lg:text-xl text-default-600 block max-w-full',
variants: {
fullWidth: {
true: "!w-full",
true: '!w-full',
},
},
defaultVariants: {

View File

@@ -1,11 +1,11 @@
import { Fira_Code as FontMono, Inter as FontSans } from "next/font/google";
import { Fira_Code as FontMono, Inter as FontSans } from 'next/font/google';
export const fontSans = FontSans({
subsets: ["latin"],
variable: "--font-sans",
subsets: ['latin'],
variable: '--font-sans',
});
export const fontMono = FontMono({
subsets: ["latin"],
variable: "--font-mono",
subsets: ['latin'],
variable: '--font-mono',
});

View File

@@ -1,92 +1,74 @@
const roles = [{ uid: "admin" }, { uid: "moderator" }, { uid: "user" }];
const roles = [{ uid: 'admin' }, { uid: 'moderator' }, { uid: 'user' }];
const categoricalPalette = [
"#fba91e",
"#6ea56c",
"#3ac6e1",
"#feda2f",
"#f15f47",
"#244470",
"#9c80bb",
"#f595a6",
];
const categoricalPalette = ['#fba91e', '#6ea56c', '#3ac6e1', '#feda2f', '#f15f47', '#244470', '#9c80bb', '#f595a6'];
const priorities = [
{ uid: "critical", color: "#bb3e03", chartColor: "#bb3e03" },
{ uid: "high", color: "#ca6702", chartColor: "#ca6702" },
{ uid: "medium", color: "#ee9b00", chartColor: "#ee9b00" },
{ uid: "low", color: "#94d2bd", chartColor: "#94d2bd" },
{ uid: 'critical', color: '#bb3e03', chartColor: '#bb3e03' },
{ uid: 'high', color: '#ca6702', chartColor: '#ca6702' },
{ uid: 'medium', color: '#ee9b00', chartColor: '#ee9b00' },
{ uid: 'low', color: '#94d2bd', chartColor: '#94d2bd' },
];
const testTypes = [
{ uid: "other", chartColor: categoricalPalette[0] },
{ uid: "security", chartColor: categoricalPalette[1] },
{ uid: "performance", chartColor: categoricalPalette[2] },
{ uid: "accessibility", chartColor: categoricalPalette[3] },
{ uid: "functional", chartColor: categoricalPalette[4] },
{ uid: "acceptance", chartColor: categoricalPalette[5] },
{ uid: "usability", chartColor: categoricalPalette[6] },
{ uid: "smokeSanity", chartColor: categoricalPalette[7] },
{ uid: "compatibility", chartColor: categoricalPalette[0] },
{ uid: "destructive", chartColor: categoricalPalette[1] },
{ uid: "regression", chartColor: categoricalPalette[2] },
{ uid: "automated", chartColor: categoricalPalette[3] },
{ uid: "manual", chartColor: categoricalPalette[4] },
{ uid: 'other', chartColor: categoricalPalette[0] },
{ uid: 'security', chartColor: categoricalPalette[1] },
{ uid: 'performance', chartColor: categoricalPalette[2] },
{ uid: 'accessibility', chartColor: categoricalPalette[3] },
{ uid: 'functional', chartColor: categoricalPalette[4] },
{ uid: 'acceptance', chartColor: categoricalPalette[5] },
{ uid: 'usability', chartColor: categoricalPalette[6] },
{ uid: 'smokeSanity', chartColor: categoricalPalette[7] },
{ uid: 'compatibility', chartColor: categoricalPalette[0] },
{ uid: 'destructive', chartColor: categoricalPalette[1] },
{ uid: 'regression', chartColor: categoricalPalette[2] },
{ uid: 'automated', chartColor: categoricalPalette[3] },
{ uid: 'manual', chartColor: categoricalPalette[4] },
];
const automationStatus = [
{ name: "Automated", uid: "automated" },
{ name: "Automation Not Required", uid: "automation-not-required" },
{ name: "Cannot Be Automated", uid: "cannot-be-automated" },
{ name: "Obsolete", uid: "obsolete" },
{ name: 'Automated', uid: 'automated' },
{ name: 'Automation Not Required', uid: 'automation-not-required' },
{ name: 'Cannot Be Automated', uid: 'cannot-be-automated' },
{ name: 'Obsolete', uid: 'obsolete' },
];
const templates = [{ uid: "text" }, { uid: "step" }];
const templates = [{ uid: 'text' }, { uid: 'step' }];
const testRunStatus = [
{ uid: "new" },
{ uid: "inProgress" },
{ uid: "underReview" },
{ uid: "rejected" },
{ uid: "done" },
{ uid: "closed" },
{ uid: 'new' },
{ uid: 'inProgress' },
{ uid: 'underReview' },
{ uid: 'rejected' },
{ uid: 'done' },
{ uid: 'closed' },
];
const testRunCaseStatus = [
{
uid: "untested",
color: "primary",
chartColor: "#3ac6e1",
uid: 'untested',
color: 'primary',
chartColor: '#3ac6e1',
},
{ uid: "passed", color: "success", chartColor: "#6ea56c" },
{ uid: "failed", color: "danger", chartColor: "#f15f47" },
{ uid: "retest", color: "warning", chartColor: "#fba91e" },
{ uid: "skipped", color: "primary", chartColor: "#805aab" },
{ uid: 'passed', color: 'success', chartColor: '#6ea56c' },
{ uid: 'failed', color: 'danger', chartColor: '#f15f47' },
{ uid: 'retest', color: 'warning', chartColor: '#fba91e' },
{ uid: 'skipped', color: 'primary', chartColor: '#805aab' },
];
const avatars = [
"/avatar/bear.png",
"/avatar/cat.png",
"/avatar/cow.png",
"/avatar/dog.png",
"/avatar/giraffe.png",
"/avatar/koala.png",
"/avatar/lion.png",
"/avatar/owl.png",
"/avatar/panda.png",
"/avatar/penguin.png",
"/avatar/rhinoceros.png",
"/avatar/shark.png",
"/avatar/sloth.png",
'/avatar/bear.png',
'/avatar/cat.png',
'/avatar/cow.png',
'/avatar/dog.png',
'/avatar/giraffe.png',
'/avatar/koala.png',
'/avatar/lion.png',
'/avatar/owl.png',
'/avatar/panda.png',
'/avatar/penguin.png',
'/avatar/rhinoceros.png',
'/avatar/shark.png',
'/avatar/sloth.png',
];
export {
roles,
priorities,
testTypes,
automationStatus,
templates,
testRunStatus,
testRunCaseStatus,
avatars,
};
export { roles, priorities, testTypes, automationStatus, templates, testRunStatus, testRunCaseStatus, avatars };

View File

@@ -1,4 +1,4 @@
const createNextIntlPlugin = require("next-intl/plugin");
const createNextIntlPlugin = require('next-intl/plugin');
const withNextIntl = createNextIntlPlugin();
/** @type {import('next').NextConfig} */

View File

@@ -3,4 +3,4 @@ module.exports = {
tailwindcss: {},
autoprefixer: {},
},
}
};

View File

@@ -1,13 +1,13 @@
import { UserType } from "@/types/user";
import { avatars } from "@/config/selection";
import Config from "@/config/config";
import { UserType } from '@/types/user';
import { avatars } from '@/config/selection';
import Config from '@/config/config';
const apiServer = Config.apiServer;
async function signUp(newUser: UserType) {
const fetchOptions = {
method: "POST",
method: 'POST',
headers: {
"Content-Type": "application/json",
'Content-Type': 'application/json',
},
body: JSON.stringify(newUser),
};
@@ -22,16 +22,16 @@ async function signUp(newUser: UserType) {
const token = await response.json();
return token;
} catch (error: any) {
console.error("Error sign up:", error);
console.error('Error sign up:', error);
throw error;
}
}
async function signIn(signInUser: UserType) {
const fetchOptions = {
method: "POST",
method: 'POST',
headers: {
"Content-Type": "application/json",
'Content-Type': 'application/json',
},
body: JSON.stringify(signInUser),
};
@@ -46,7 +46,7 @@ async function signIn(signInUser: UserType) {
const token = await response.json();
return token;
} catch (error: any) {
console.error("Error sign in:", error);
console.error('Error sign in:', error);
throw error;
}
}

View File

@@ -1,24 +1,24 @@
import { expect, test } from "vitest";
import { isValidEmail, isValidPassword } from "./validate";
import { expect, test } from 'vitest';
import { isValidEmail, isValidPassword } from './validate';
test("validate email", () => {
const email1 = "aaa@gmail.com";
test('validate email', () => {
const email1 = 'aaa@gmail.com';
expect(isValidEmail(email1)).toBe(true);
const email2 = "gmail.com";
const email2 = 'gmail.com';
expect(isValidEmail(email2)).toBe(false);
const email23 = "";
const email23 = '';
expect(isValidEmail(email23)).toBe(false);
});
test("validate password", () => {
const pass1 = "aaaaaaaa";
test('validate password', () => {
const pass1 = 'aaaaaaaa';
expect(isValidPassword(pass1)).toBe(true);
const pass2 = "abcdefg";
const pass2 = 'abcdefg';
expect(isValidPassword(pass2)).toBe(false);
const pass3 = "";
const pass3 = '';
expect(isValidPassword(pass3)).toBe(false);
});

View File

@@ -1,6 +1,5 @@
function isValidEmail(email: string) {
const validRegex =
/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/;
const validRegex = /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/;
if (email.match(validRegex)) {
return true;
} else {

View File

@@ -1,8 +1,8 @@
import { expect, test } from "vitest";
import { isImage } from "./isImage";
import { AttachmentType } from "@/types/case";
import { expect, test } from 'vitest';
import { isImage } from './isImage';
import { AttachmentType } from '@/types/case';
test("isImage", () => {
test('isImage', () => {
type CaseAttachmentType = {
createdAt: Date;
updatedAt: Date;
@@ -19,17 +19,17 @@ test("isImage", () => {
const sampleAttachment: AttachmentType = {
id: 1,
title: "",
detail: "",
path: "",
title: '',
detail: '',
path: '',
createdAt: new Date(),
updatedAt: new Date(),
caseAttachments: sampleCaseAttachment,
};
sampleAttachment.path = "public/uploads/abc.png";
sampleAttachment.path = 'public/uploads/abc.png';
expect(isImage(sampleAttachment)).toBe(true);
sampleAttachment.path = "public/uploads/abc.mp3";
sampleAttachment.path = 'public/uploads/abc.mp3';
expect(isImage(sampleAttachment)).toBe(false);
});

View File

@@ -1,14 +1,11 @@
import Config from "@/config/config";
import Config from '@/config/config';
const apiServer = Config.apiServer;
async function fetchDownloadAttachment(
attachmentId: number,
downloadFileName: string
) {
async function fetchDownloadAttachment(attachmentId: number, downloadFileName: string) {
const fetchOptions = {
method: "GET",
method: 'GET',
headers: {
"Content-Type": "application/json",
'Content-Type': 'application/json',
},
};
@@ -23,14 +20,14 @@ async function fetchDownloadAttachment(
const blob = await response.blob();
const downloadUrl = window.URL.createObjectURL(blob);
const link = document.createElement("a");
const link = document.createElement('a');
link.href = downloadUrl;
link.download = downloadFileName;
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
} catch (error: any) {
console.error("Error downloading file:", error);
console.error('Error downloading file:', error);
throw error;
}
}
@@ -39,31 +36,31 @@ async function fetchCreateAttachments(caseId: number, files: File[]) {
try {
const formData = new FormData();
for (let i = 0; i < files.length; i++) {
formData.append("files", files[i]);
formData.append('files', files[i]);
}
const url = `${apiServer}/attachments?parentCaseId=${caseId}`;
const response = await fetch(url, {
method: "POST",
method: 'POST',
body: formData,
});
if (!response.ok) {
throw new Error("Network response was not ok");
throw new Error('Network response was not ok');
}
const responseData = await response.json();
return responseData;
} catch (error: any) {
console.error("Error uploading files:", error);
console.error('Error uploading files:', error);
}
}
async function fetchDeleteAttachment(attachmentId: number) {
const fetchOptions = {
method: "DELETE",
method: 'DELETE',
headers: {
"Content-Type": "application/json",
'Content-Type': 'application/json',
},
};
@@ -75,13 +72,9 @@ async function fetchDeleteAttachment(attachmentId: number) {
throw new Error(`HTTP error! Status: ${response.status}`);
}
} catch (error: any) {
console.error("Error deleting file:", error);
console.error('Error deleting file:', error);
throw error;
}
}
export {
fetchDownloadAttachment,
fetchCreateAttachments,
fetchDeleteAttachment,
};
export { fetchDownloadAttachment, fetchCreateAttachments, fetchDeleteAttachment };

View File

@@ -1,15 +1,15 @@
import { AttachmentType } from "@/types/case";
import { AttachmentType } from '@/types/case';
function isImage(attachmentFile: AttachmentType) {
let path = attachmentFile.path;
let extension = path.substring(path.lastIndexOf(".") + 1).toLowerCase();
let extension = path.substring(path.lastIndexOf('.') + 1).toLowerCase();
if (
extension === "png" ||
extension === "jpg" ||
extension === "jpeg" ||
extension === "gif" ||
extension === "bmp" ||
extension === "svg"
extension === 'png' ||
extension === 'jpg' ||
extension === 'jpeg' ||
extension === 'gif' ||
extension === 'bmp' ||
extension === 'svg'
) {
return true;
} else {

View File

@@ -1,11 +1,11 @@
import Config from "@/config/config";
import Config from '@/config/config';
const apiServer = Config.apiServer;
async function fetchCreateStep(newStepNo: number, parentCaseId: number) {
const fetchOptions = {
method: "POST",
method: 'POST',
headers: {
"Content-Type": "application/json",
'Content-Type': 'application/json',
},
};
@@ -18,16 +18,16 @@ async function fetchCreateStep(newStepNo: number, parentCaseId: number) {
}
return await response.json();
} catch (error: any) {
console.error("Error deleting project:", error);
console.error('Error deleting project:', error);
throw error;
}
}
async function fetchDeleteStep(stepId: number, parentCaseId: number) {
const fetchOptions = {
method: "DELETE",
method: 'DELETE',
headers: {
"Content-Type": "application/json",
'Content-Type': 'application/json',
},
};
@@ -39,12 +39,9 @@ async function fetchDeleteStep(stepId: number, parentCaseId: number) {
throw new Error(`HTTP error! Status: ${response.status}`);
}
} catch (error: any) {
console.error("Error deleting project:", error);
console.error('Error deleting project:', error);
throw error;
}
}
export {
fetchCreateStep,
fetchDeleteStep,
};
export { fetchCreateStep, fetchDeleteStep };

View File

@@ -1,15 +1,15 @@
import Config from "@/config/config";
import Config from '@/config/config';
const apiServer = Config.apiServer;
import { CaseType } from "@/types/case";
import { CaseType } from '@/types/case';
async function fetchCase(caseId: number) {
const url = `${apiServer}/cases/${caseId}`;
try {
const response = await fetch(url, {
method: "GET",
method: 'GET',
headers: {
"Content-Type": "application/json",
'Content-Type': 'application/json',
},
});
@@ -20,7 +20,7 @@ async function fetchCase(caseId: number) {
const data = await response.json();
return data;
} catch (error: any) {
console.error("Error fetching data:", error.message);
console.error('Error fetching data:', error.message);
}
}
@@ -29,9 +29,9 @@ async function fetchCases(folderId: string) {
try {
const response = await fetch(url, {
method: "GET",
method: 'GET',
headers: {
"Content-Type": "application/json",
'Content-Type': 'application/json',
},
});
@@ -42,28 +42,28 @@ async function fetchCases(folderId: string) {
const data = await response.json();
return data;
} catch (error: any) {
console.error("Error fetching data:", error.message);
console.error('Error fetching data:', error.message);
}
}
async function createCase(folderId: string) {
const newCase = {
title: "untitled case",
title: 'untitled case',
state: 0,
priority: 2,
type: 0,
automationStatus: 0,
description: "",
description: '',
template: 0,
preConditions: "",
expectedResults: "",
preConditions: '',
expectedResults: '',
folderId: folderId,
};
const fetchOptions = {
method: "POST",
method: 'POST',
headers: {
"Content-Type": "application/json",
'Content-Type': 'application/json',
},
body: JSON.stringify(newCase),
};
@@ -78,16 +78,16 @@ async function createCase(folderId: string) {
const data = await response.json();
return data;
} catch (error: any) {
console.error("Error creating case:", error);
console.error('Error creating case:', error);
throw error;
}
}
async function updateCase(updateCaseData: CaseType) {
const fetchOptions = {
method: "PUT",
method: 'PUT',
headers: {
"Content-Type": "application/json",
'Content-Type': 'application/json',
},
body: JSON.stringify(updateCaseData),
};
@@ -102,16 +102,16 @@ async function updateCase(updateCaseData: CaseType) {
const data = await response.json();
return data;
} catch (error: any) {
console.error("Error updating project:", error);
console.error('Error updating project:', error);
throw error;
}
}
async function deleteCase(caseId: number) {
const fetchOptions = {
method: "DELETE",
method: 'DELETE',
headers: {
"Content-Type": "application/json",
'Content-Type': 'application/json',
},
};
@@ -123,16 +123,16 @@ async function deleteCase(caseId: number) {
throw new Error(`HTTP error! Status: ${response.status}`);
}
} catch (error: any) {
console.error("Error deleting case:", error);
console.error('Error deleting case:', error);
throw error;
}
}
async function deleteCases(deleteCases: string[]) {
const fetchOptions = {
method: "POST",
method: 'POST',
headers: {
"Content-Type": "application/json",
'Content-Type': 'application/json',
},
body: JSON.stringify({ caseIds: deleteCases }),
};
@@ -145,16 +145,9 @@ async function deleteCases(deleteCases: string[]) {
throw new Error(`HTTP error! Status: ${response.status}`);
}
} catch (error: any) {
console.error("Error deleting cases:", error);
console.error('Error deleting cases:', error);
throw error;
}
}
export {
fetchCase,
fetchCases,
updateCase,
createCase,
deleteCase,
deleteCases,
};
export { fetchCase, fetchCases, updateCase, createCase, deleteCase, deleteCases };

View File

@@ -1,4 +1,4 @@
import Config from "@/config/config";
import Config from '@/config/config';
const apiServer = Config.apiServer;
/**
@@ -8,9 +8,9 @@ async function fetchFolders(projectId: string) {
try {
const url = `${apiServer}/folders?projectId=${projectId}`;
const response = await fetch(url, {
method: "GET",
method: 'GET',
headers: {
"Content-Type": "application/json",
'Content-Type': 'application/json',
},
});
@@ -21,19 +21,14 @@ async function fetchFolders(projectId: string) {
const data = await response.json();
return data;
} catch (error: any) {
console.error("Error fetching data:", error.message);
console.error('Error fetching data:', error.message);
}
}
/**
* Create project
*/
async function createFolder(
name: string,
detail: string,
projectId: strting,
parentFolderId: number
) {
async function createFolder(name: string, detail: string, projectId: strting, parentFolderId: number) {
const newFolderData = {
name: name,
detail: detail,
@@ -42,9 +37,9 @@ async function createFolder(
};
const fetchOptions = {
method: "POST",
method: 'POST',
headers: {
"Content-Type": "application/json",
'Content-Type': 'application/json',
},
body: JSON.stringify(newFolderData),
};
@@ -59,7 +54,7 @@ async function createFolder(
const data = await response.json();
return data;
} catch (error: any) {
console.error("Error creating new project:", error);
console.error('Error creating new project:', error);
throw error;
}
}
@@ -67,13 +62,7 @@ async function createFolder(
/**
* Update folder
*/
async function updateFolder(
folderId: number,
name: string,
detail: string,
projectId: string,
parentFolderId: number
) {
async function updateFolder(folderId: number, name: string, detail: string, projectId: string, parentFolderId: number) {
const updateFolderData = {
name: name,
detail: detail,
@@ -82,9 +71,9 @@ async function updateFolder(
};
const fetchOptions = {
method: "PUT",
method: 'PUT',
headers: {
"Content-Type": "application/json",
'Content-Type': 'application/json',
},
body: JSON.stringify(updateFolderData),
};
@@ -99,7 +88,7 @@ async function updateFolder(
const data = await response.json();
return data;
} catch (error: any) {
console.error("Error updating project:", error);
console.error('Error updating project:', error);
throw error;
}
}
@@ -109,9 +98,9 @@ async function updateFolder(
*/
async function deleteFolder(folderId: number) {
const fetchOptions = {
method: "DELETE",
method: 'DELETE',
headers: {
"Content-Type": "application/json",
'Content-Type': 'application/json',
},
};
@@ -123,7 +112,7 @@ async function deleteFolder(folderId: number) {
throw new Error(`HTTP error! Status: ${response.status}`);
}
} catch (error: any) {
console.error("Error deleting project:", error);
console.error('Error deleting project:', error);
throw error;
}
}

View File

@@ -1,6 +1,6 @@
import { ProjectType } from "@/types/project";
import { testTypes, priorities, testRunCaseStatus } from "@/config/selection";
import { HomeMessages } from "./page";
import { ProjectType } from '@/types/project';
import { testTypes, priorities, testRunCaseStatus } from '@/config/selection';
import { HomeMessages } from './page';
// aggregate folder, case, run mum
function aggregateBasicInfo(project: ProjectType) {
@@ -85,9 +85,4 @@ function aggregateProgress(project: ProjectType, messages: HomeMessages) {
return { series, categories };
}
export {
aggregateBasicInfo,
aggregateTestType,
aggregateTestPriority,
aggregateProgress,
};
export { aggregateBasicInfo, aggregateTestType, aggregateTestPriority, aggregateProgress };

View File

@@ -1,15 +1,15 @@
import Config from "@/config/config";
import Config from '@/config/config';
const apiServer = Config.apiServer;
import { RunType, RunCaseInfoType } from "@/types/run";
import { RunType, RunCaseInfoType } from '@/types/run';
async function fetchRun(runId: string) {
const url = `${apiServer}/runs/${runId}`;
try {
const response = await fetch(url, {
method: "GET",
method: 'GET',
headers: {
"Content-Type": "application/json",
'Content-Type': 'application/json',
},
});
@@ -20,7 +20,7 @@ async function fetchRun(runId: string) {
const data = await response.json();
return data;
} catch (error: any) {
console.error("Error fetching data:", error.message);
console.error('Error fetching data:', error.message);
}
}
@@ -29,9 +29,9 @@ async function fetchRuns(projectId: string) {
try {
const response = await fetch(url, {
method: "GET",
method: 'GET',
headers: {
"Content-Type": "application/json",
'Content-Type': 'application/json',
},
});
@@ -42,23 +42,23 @@ async function fetchRuns(projectId: string) {
const data = await response.json();
return data;
} catch (error: any) {
console.error("Error fetching data:", error.message);
console.error('Error fetching data:', error.message);
}
}
async function createRun(projectId: string) {
const newTestRun = {
name: "untitled run",
name: 'untitled run',
configurations: 0,
description: "",
description: '',
state: 0,
projectId: projectId,
};
const fetchOptions = {
method: "POST",
method: 'POST',
headers: {
"Content-Type": "application/json",
'Content-Type': 'application/json',
},
body: JSON.stringify(newTestRun),
};
@@ -73,16 +73,16 @@ async function createRun(projectId: string) {
const data = await response.json();
return data;
} catch (error: any) {
console.error("Error creating new test run:", error);
console.error('Error creating new test run:', error);
throw error;
}
}
async function updateRun(updateTestRun: RunType) {
const fetchOptions = {
method: "PUT",
method: 'PUT',
headers: {
"Content-Type": "application/json",
'Content-Type': 'application/json',
},
body: JSON.stringify(updateTestRun),
};
@@ -97,16 +97,16 @@ async function updateRun(updateTestRun: RunType) {
const data = await response.json();
return data;
} catch (error: any) {
console.error("Error updating run:", error);
console.error('Error updating run:', error);
throw error;
}
}
async function deleteRun(runId: number) {
const fetchOptions = {
method: "DELETE",
method: 'DELETE',
headers: {
"Content-Type": "application/json",
'Content-Type': 'application/json',
},
};
@@ -118,7 +118,7 @@ async function deleteRun(runId: number) {
throw new Error(`HTTP error! Status: ${response.status}`);
}
} catch (error: any) {
console.error("Error deleting run:", error);
console.error('Error deleting run:', error);
throw error;
}
}
@@ -128,9 +128,9 @@ async function fetchRunCases(runId: string) {
try {
const response = await fetch(url, {
method: "GET",
method: 'GET',
headers: {
"Content-Type": "application/json",
'Content-Type': 'application/json',
},
});
@@ -141,15 +141,15 @@ async function fetchRunCases(runId: string) {
const data = await response.json();
return data;
} catch (error: any) {
console.error("Error fetching data:", error.message);
console.error('Error fetching data:', error.message);
}
}
async function createRunCase(runId: string, caseId: number) {
const fetchOptions = {
method: "POST",
method: 'POST',
headers: {
"Content-Type": "application/json",
'Content-Type': 'application/json',
},
};
@@ -163,16 +163,16 @@ async function createRunCase(runId: string, caseId: number) {
const data = await response.json();
return data;
} catch (error: any) {
console.error("Error creating new runcase:", error);
console.error('Error creating new runcase:', error);
throw error;
}
}
async function updateRunCase(runId: string, caseId: number, status: number) {
const fetchOptions = {
method: "PUT",
method: 'PUT',
headers: {
"Content-Type": "application/json",
'Content-Type': 'application/json',
},
};
@@ -186,16 +186,16 @@ async function updateRunCase(runId: string, caseId: number, status: number) {
const data = await response.json();
return data;
} catch (error: any) {
console.error("Error updating runcase:", error);
console.error('Error updating runcase:', error);
throw error;
}
}
async function bulkCreateRunCases(runCaseInfo: RunCaseInfoType[]) {
const fetchOptions = {
method: "POST",
method: 'POST',
headers: {
"Content-Type": "application/json",
'Content-Type': 'application/json',
},
body: JSON.stringify(runCaseInfo),
};
@@ -210,16 +210,16 @@ async function bulkCreateRunCases(runCaseInfo: RunCaseInfoType[]) {
const data = await response.json();
return data;
} catch (error: any) {
console.error("Error creating new runcase:", error);
console.error('Error creating new runcase:', error);
throw error;
}
}
async function deleteRunCase(runId: string, caseId: number) {
const fetchOptions = {
method: "DELETE",
method: 'DELETE',
headers: {
"Content-Type": "application/json",
'Content-Type': 'application/json',
},
};
@@ -231,16 +231,16 @@ async function deleteRunCase(runId: string, caseId: number) {
throw new Error(`HTTP error! Status: ${response.status}`);
}
} catch (error: any) {
console.error("Error deleting runcase:", error);
console.error('Error deleting runcase:', error);
throw error;
}
}
async function bulkDeleteRunCases(runCaseInfo: RunCaseInfoType[]) {
const fetchOptions = {
method: "POST",
method: 'POST',
headers: {
"Content-Type": "application/json",
'Content-Type': 'application/json',
},
body: JSON.stringify(runCaseInfo),
};
@@ -253,7 +253,7 @@ async function bulkDeleteRunCases(runCaseInfo: RunCaseInfoType[]) {
throw new Error(`HTTP error! Status: ${response.status}`);
}
} catch (error: any) {
console.error("Error deleting runcase:", error);
console.error('Error deleting runcase:', error);
throw error;
}
}

View File

@@ -1,4 +1,4 @@
import Config from "@/config/config";
import Config from '@/config/config';
const apiServer = Config.apiServer;
/**
@@ -9,9 +9,9 @@ async function fetchProjects() {
try {
const response = await fetch(url, {
method: "GET",
method: 'GET',
headers: {
"Content-Type": "application/json",
'Content-Type': 'application/json',
},
});
@@ -22,7 +22,7 @@ async function fetchProjects() {
const data = await response.json();
return data;
} catch (error: any) {
console.error("Error fetching data:", error.message);
console.error('Error fetching data:', error.message);
}
}
@@ -36,9 +36,9 @@ async function createProject(name: string, detail: string) {
};
const fetchOptions = {
method: "POST",
method: 'POST',
headers: {
"Content-Type": "application/json",
'Content-Type': 'application/json',
},
body: JSON.stringify(newProjectData),
};
@@ -53,7 +53,7 @@ async function createProject(name: string, detail: string) {
const data = await response.json();
return data;
} catch (error: any) {
console.error("Error creating new project:", error);
console.error('Error creating new project:', error);
throw error;
}
}
@@ -68,9 +68,9 @@ async function updateProject(projectId: number, name: string, detail: string) {
};
const fetchOptions = {
method: "PUT",
method: 'PUT',
headers: {
"Content-Type": "application/json",
'Content-Type': 'application/json',
},
body: JSON.stringify(updatedProjectData),
};
@@ -85,7 +85,7 @@ async function updateProject(projectId: number, name: string, detail: string) {
const data = await response.json();
return data;
} catch (error: any) {
console.error("Error updating project:", error);
console.error('Error updating project:', error);
throw error;
}
}
@@ -95,9 +95,9 @@ async function updateProject(projectId: number, name: string, detail: string) {
*/
async function deleteProject(projectId: number) {
const fetchOptions = {
method: "DELETE",
method: 'DELETE',
headers: {
"Content-Type": "application/json",
'Content-Type': 'application/json',
},
};
@@ -109,7 +109,7 @@ async function deleteProject(projectId: number) {
throw new Error(`HTTP error! Status: ${response.status}`);
}
} catch (error: any) {
console.error("Error deleting project:", error);
console.error('Error deleting project:', error);
throw error;
}
}

View File

@@ -1,7 +1,7 @@
import { notFound } from "next/navigation";
import { getRequestConfig } from "next-intl/server";
import { notFound } from 'next/navigation';
import { getRequestConfig } from 'next-intl/server';
const locales = ["en", "ja"];
const locales = ['en', 'ja'];
export default getRequestConfig(async ({ locale }) => {
if (!locales.includes(locale as any)) notFound();

View File

@@ -1,12 +1,12 @@
import createMiddleware from "next-intl/middleware";
import { locales, localePrefix } from "./navigation";
import createMiddleware from 'next-intl/middleware';
import { locales, localePrefix } from './navigation';
export default createMiddleware({
defaultLocale: "en",
defaultLocale: 'en',
localePrefix,
locales,
});
export const config = {
matcher: ["/", "/(ja|en)/:path*"],
matcher: ['/', '/(ja|en)/:path*'],
};

View File

@@ -1,10 +1,9 @@
import { createSharedPathnamesNavigation } from "next-intl/navigation";
import { createSharedPathnamesNavigation } from 'next-intl/navigation';
export const locales = ["en", "ja"] as const;
export const localePrefix = "always";
export const locales = ['en', 'ja'] as const;
export const localePrefix = 'always';
export const { Link, redirect, usePathname, useRouter } =
createSharedPathnamesNavigation({ locales, localePrefix });
export const { Link, redirect, usePathname, useRouter } = createSharedPathnamesNavigation({ locales, localePrefix });
export const NextUiLinkClasses =
"data-[focus-visible=true]:outline-focus data-[focus-visible=true]:outline-offset-2 text-medium text-primary hover:underline hover:opacity-80 active:opacity-disabled transition-opacity underline-offset-4 dark:text-white";
'data-[focus-visible=true]:outline-focus data-[focus-visible=true]:outline-offset-2 text-medium text-primary hover:underline hover:opacity-80 active:opacity-disabled transition-opacity underline-offset-4 dark:text-white';

View File

@@ -1,37 +1,37 @@
import { nextui } from "@nextui-org/theme";
import { nextui } from '@nextui-org/theme';
/** @type {import('tailwindcss').Config} */
module.exports = {
content: [
"./pages/**/*.{js,ts,jsx,tsx,mdx}",
"./components/**/*.{js,ts,jsx,tsx,mdx}",
"./app/**/*.{js,ts,jsx,tsx,mdx}",
"./src/app/**/*.{js,ts,jsx,tsx,mdx}",
"./node_modules/@nextui-org/theme/dist/**/*.{js,ts,jsx,tsx}",
'./pages/**/*.{js,ts,jsx,tsx,mdx}',
'./components/**/*.{js,ts,jsx,tsx,mdx}',
'./app/**/*.{js,ts,jsx,tsx,mdx}',
'./src/app/**/*.{js,ts,jsx,tsx,mdx}',
'./node_modules/@nextui-org/theme/dist/**/*.{js,ts,jsx,tsx}',
],
theme: {
extend: {},
},
darkMode: "class",
darkMode: 'class',
plugins: [
nextui({
themes: {
light: {
colors: {
primary: {
DEFAULT: "#030712",
foreground: "#FFFFFF",
DEFAULT: '#030712',
foreground: '#FFFFFF',
},
focus: "#030712",
focus: '#030712',
},
},
dark: {
colors: {
primary: {
DEFAULT: "#1F883D",
foreground: "#FFFFFF",
DEFAULT: '#1F883D',
foreground: '#FFFFFF',
},
focus: "#1F883D",
focus: '#1F883D',
},
},
},

View File

@@ -1,4 +1,4 @@
import { CaseType } from "./case";
import { CaseType } from './case';
export type FolderType = {
id: number;

View File

@@ -1,4 +1,4 @@
import {SVGProps} from "react";
import { SVGProps } from 'react';
export type IconSvgProps = SVGProps<SVGSVGElement> & {
size?: number;

View File

@@ -1,5 +1,5 @@
import { FolderType } from "./folder";
import { RunType } from "./run";
import { FolderType } from './folder';
import { RunType } from './run';
export type ProjectType = {
id: number;

View File

@@ -29,10 +29,10 @@ type RunStatusCountType = {
type ProgressSeriesType = {
name: string;
data: number[];
}
};
type RunsMessages = {
runList: string,
runList: string;
id: string;
name: string;
description: string;
@@ -44,11 +44,11 @@ type RunsMessages = {
};
type RunMessages = {
backToRuns: string,
backToRuns: string;
updating: string;
update: string;
progress: string,
refresh: string,
progress: string;
refresh: string;
id: string;
title: string;
pleaseEnter: string;
@@ -78,12 +78,4 @@ type RunMessages = {
noCasesFound: string;
};
export {
RunType,
RunCaseType,
RunCaseInfoType,
RunStatusCountType,
ProgressSeriesType,
RunsMessages,
RunMessages,
};
export { RunType, RunCaseType, RunCaseInfoType, RunStatusCountType, ProgressSeriesType, RunsMessages, RunMessages };

View File

@@ -1,6 +1,6 @@
'use client'
import { usePathname } from 'next/navigation'
import { useState, useEffect } from "react";
'use client';
import { usePathname } from 'next/navigation';
import { useState, useEffect } from 'react';
type ProjectFolderIds = {
projectId: number | null;
@@ -12,21 +12,19 @@ type ProjectFolderIds = {
* Example: For the path '/projects/1/folders/3/cases', projectId would be 1 and folderId would be 3.
*/
const useGetCurrentIds = (): ProjectFolderIds => {
const pathname = usePathname()
const pathname = usePathname();
const [projectId, setProjectId] = useState<number | null>(null);
const [folderId, setFolderId] = useState<number | null>(null);
useEffect(() => {
const currentPath = pathname;
const pathSegments = currentPath.split("/").filter(Boolean);
const pathSegments = currentPath.split('/').filter(Boolean);
const projectIdIndex = pathSegments.indexOf("projects") + 1;
const folderIdIndex = pathSegments.indexOf("folders") + 1;
const projectIdIndex = pathSegments.indexOf('projects') + 1;
const folderIdIndex = pathSegments.indexOf('folders') + 1;
const newProjectId =
projectIdIndex !== -1 ? parseInt(pathSegments[projectIdIndex], 10) : null;
const newFolderId =
folderIdIndex !== -1 ? parseInt(pathSegments[folderIdIndex], 10) : null;
const newProjectId = projectIdIndex !== -1 ? parseInt(pathSegments[projectIdIndex], 10) : null;
const newFolderId = folderIdIndex !== -1 ? parseInt(pathSegments[folderIdIndex], 10) : null;
setProjectId(newProjectId);
setFolderId(newFolderId);

16
package-lock.json generated
View File

@@ -9,6 +9,7 @@
"version": "1.0.0",
"devDependencies": {
"@vitest/coverage-v8": "^1.6.0",
"prettier": "^3.2.5",
"vitest": "^1.6.0"
}
},
@@ -1504,6 +1505,21 @@
"node": "^10 || ^12 || >=14"
}
},
"node_modules/prettier": {
"version": "3.2.5",
"resolved": "https://registry.npmjs.org/prettier/-/prettier-3.2.5.tgz",
"integrity": "sha512-3/GWa9aOC0YeD7LUfvOG2NiDyhOWRvt1k+rcKhOuYnMY24iiCphgneUfJDyFXd6rZCAnuLBv6UeAULtrhT/F4A==",
"dev": true,
"bin": {
"prettier": "bin/prettier.cjs"
},
"engines": {
"node": ">=14"
},
"funding": {
"url": "https://github.com/prettier/prettier?sponsor=1"
}
},
"node_modules/pretty-format": {
"version": "29.7.0",
"resolved": "https://registry.npmjs.org/pretty-format/-/pretty-format-29.7.0.tgz",

View File

@@ -3,11 +3,13 @@
"version": "1.0.0",
"private": true,
"scripts": {
"format": "prettier --write frontend/**/*.{js,ts,json} backend/**/*.{js,ts,json}",
"test": "vitest",
"coverage": "vitest run --coverage"
},
"devDependencies": {
"@vitest/coverage-v8": "^1.6.0",
"prettier": "^3.2.5",
"vitest": "^1.6.0"
}
}