34261/backend/src/db/seeders/20231127130745-sample-data.js
2025-09-20 21:20:53 +00:00

828 lines
20 KiB
JavaScript

const db = require('../models');
const Users = db.users;
const Steps = db.steps;
const Projects = db.projects;
const TestCases = db.test_cases;
const Organizations = db.organizations;
const Results = db.results;
const StepsData = [
{
description: 'Open the application and navigate to login page',
type: 'playback',
// type code here for "relation_one" field
// type code here for "relation_one" field
},
{
description: 'Enter valid username and password',
type: 'record',
// type code here for "relation_one" field
// type code here for "relation_one" field
},
{
description: 'Click on the login button',
type: 'playback',
// type code here for "relation_one" field
// type code here for "relation_one" field
},
{
description: 'Verify the dashboard is displayed',
type: 'code',
// type code here for "relation_one" field
// type code here for "relation_one" field
},
{
description: 'Log out from the application',
type: 'playback',
// type code here for "relation_one" field
// type code here for "relation_one" field
},
];
const ProjectsData = [
{
name: 'E-commerce Platform',
// type code here for "relation_many" field
// type code here for "relation_one" field
// type code here for "relation_one" field
},
{
name: 'Mobile Banking App',
// type code here for "relation_many" field
// type code here for "relation_one" field
// type code here for "relation_one" field
},
{
name: 'Healthcare Management System',
// type code here for "relation_many" field
// type code here for "relation_one" field
// type code here for "relation_one" field
},
{
name: 'Social Media Analytics',
// type code here for "relation_many" field
// type code here for "relation_one" field
// type code here for "relation_one" field
},
{
name: 'IoT Device Integration',
// type code here for "relation_many" field
// type code here for "relation_one" field
// type code here for "relation_one" field
},
];
const TestCasesData = [
{
title: 'Login Functionality Test',
// type code here for "relation_one" field
// type code here for "relation_many" field
// type code here for "relation_many" field
// type code here for "relation_one" field
},
{
title: 'Payment Gateway Integration Test',
// type code here for "relation_one" field
// type code here for "relation_many" field
// type code here for "relation_many" field
// type code here for "relation_one" field
},
{
title: 'User Registration Test',
// type code here for "relation_one" field
// type code here for "relation_many" field
// type code here for "relation_many" field
// type code here for "relation_one" field
},
{
title: 'Data Export Test',
// type code here for "relation_one" field
// type code here for "relation_many" field
// type code here for "relation_many" field
// type code here for "relation_one" field
},
{
title: 'API Response Validation Test',
// type code here for "relation_one" field
// type code here for "relation_many" field
// type code here for "relation_many" field
// type code here for "relation_one" field
},
];
const OrganizationsData = [
{
name: 'Wilhelm Wundt',
},
{
name: 'Lynn Margulis',
},
{
name: 'Francis Crick',
},
{
name: 'Edwin Hubble',
},
{
name: 'Claude Levi-Strauss',
},
];
const ResultsData = [
{
execution_time: new Date('2023-10-01T10:00:00Z'),
status: 'skipped',
// type code here for "relation_one" field
// type code here for "relation_one" field
},
{
execution_time: new Date('2023-10-02T11:30:00Z'),
status: 'failed',
// type code here for "relation_one" field
// type code here for "relation_one" field
},
{
execution_time: new Date('2023-10-03T09:15:00Z'),
status: 'passed',
// type code here for "relation_one" field
// type code here for "relation_one" field
},
{
execution_time: new Date('2023-10-04T14:45:00Z'),
status: 'skipped',
// type code here for "relation_one" field
// type code here for "relation_one" field
},
{
execution_time: new Date('2023-10-05T16:20:00Z'),
status: 'skipped',
// type code here for "relation_one" field
// type code here for "relation_one" field
},
];
async function associateStepWithTest_case() {
const relatedTest_case0 = await TestCases.findOne({
offset: Math.floor(Math.random() * (await TestCases.count())),
});
const Step0 = await Steps.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Step0?.setTest_case) {
await Step0.setTest_case(relatedTest_case0);
}
const relatedTest_case1 = await TestCases.findOne({
offset: Math.floor(Math.random() * (await TestCases.count())),
});
const Step1 = await Steps.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Step1?.setTest_case) {
await Step1.setTest_case(relatedTest_case1);
}
const relatedTest_case2 = await TestCases.findOne({
offset: Math.floor(Math.random() * (await TestCases.count())),
});
const Step2 = await Steps.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Step2?.setTest_case) {
await Step2.setTest_case(relatedTest_case2);
}
const relatedTest_case3 = await TestCases.findOne({
offset: Math.floor(Math.random() * (await TestCases.count())),
});
const Step3 = await Steps.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (Step3?.setTest_case) {
await Step3.setTest_case(relatedTest_case3);
}
const relatedTest_case4 = await TestCases.findOne({
offset: Math.floor(Math.random() * (await TestCases.count())),
});
const Step4 = await Steps.findOne({
order: [['id', 'ASC']],
offset: 4,
});
if (Step4?.setTest_case) {
await Step4.setTest_case(relatedTest_case4);
}
}
async function associateStepWithOrganization() {
const relatedOrganization0 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const Step0 = await Steps.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Step0?.setOrganization) {
await Step0.setOrganization(relatedOrganization0);
}
const relatedOrganization1 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const Step1 = await Steps.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Step1?.setOrganization) {
await Step1.setOrganization(relatedOrganization1);
}
const relatedOrganization2 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const Step2 = await Steps.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Step2?.setOrganization) {
await Step2.setOrganization(relatedOrganization2);
}
const relatedOrganization3 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const Step3 = await Steps.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (Step3?.setOrganization) {
await Step3.setOrganization(relatedOrganization3);
}
const relatedOrganization4 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const Step4 = await Steps.findOne({
order: [['id', 'ASC']],
offset: 4,
});
if (Step4?.setOrganization) {
await Step4.setOrganization(relatedOrganization4);
}
}
// Similar logic for "relation_many"
async function associateUserWithOrganization() {
const relatedOrganization0 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const User0 = await Users.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (User0?.setOrganization) {
await User0.setOrganization(relatedOrganization0);
}
const relatedOrganization1 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const User1 = await Users.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (User1?.setOrganization) {
await User1.setOrganization(relatedOrganization1);
}
const relatedOrganization2 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const User2 = await Users.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (User2?.setOrganization) {
await User2.setOrganization(relatedOrganization2);
}
const relatedOrganization3 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const User3 = await Users.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (User3?.setOrganization) {
await User3.setOrganization(relatedOrganization3);
}
const relatedOrganization4 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const User4 = await Users.findOne({
order: [['id', 'ASC']],
offset: 4,
});
if (User4?.setOrganization) {
await User4.setOrganization(relatedOrganization4);
}
}
// Similar logic for "relation_many"
async function associateProjectWithProject_owner() {
const relatedProject_owner0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Project0 = await Projects.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Project0?.setProject_owner) {
await Project0.setProject_owner(relatedProject_owner0);
}
const relatedProject_owner1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Project1 = await Projects.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Project1?.setProject_owner) {
await Project1.setProject_owner(relatedProject_owner1);
}
const relatedProject_owner2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Project2 = await Projects.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Project2?.setProject_owner) {
await Project2.setProject_owner(relatedProject_owner2);
}
const relatedProject_owner3 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Project3 = await Projects.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (Project3?.setProject_owner) {
await Project3.setProject_owner(relatedProject_owner3);
}
const relatedProject_owner4 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Project4 = await Projects.findOne({
order: [['id', 'ASC']],
offset: 4,
});
if (Project4?.setProject_owner) {
await Project4.setProject_owner(relatedProject_owner4);
}
}
async function associateProjectWithOrganization() {
const relatedOrganization0 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const Project0 = await Projects.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Project0?.setOrganization) {
await Project0.setOrganization(relatedOrganization0);
}
const relatedOrganization1 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const Project1 = await Projects.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Project1?.setOrganization) {
await Project1.setOrganization(relatedOrganization1);
}
const relatedOrganization2 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const Project2 = await Projects.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Project2?.setOrganization) {
await Project2.setOrganization(relatedOrganization2);
}
const relatedOrganization3 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const Project3 = await Projects.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (Project3?.setOrganization) {
await Project3.setOrganization(relatedOrganization3);
}
const relatedOrganization4 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const Project4 = await Projects.findOne({
order: [['id', 'ASC']],
offset: 4,
});
if (Project4?.setOrganization) {
await Project4.setOrganization(relatedOrganization4);
}
}
async function associateTestCaseWithProject() {
const relatedProject0 = await Projects.findOne({
offset: Math.floor(Math.random() * (await Projects.count())),
});
const TestCase0 = await TestCases.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (TestCase0?.setProject) {
await TestCase0.setProject(relatedProject0);
}
const relatedProject1 = await Projects.findOne({
offset: Math.floor(Math.random() * (await Projects.count())),
});
const TestCase1 = await TestCases.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (TestCase1?.setProject) {
await TestCase1.setProject(relatedProject1);
}
const relatedProject2 = await Projects.findOne({
offset: Math.floor(Math.random() * (await Projects.count())),
});
const TestCase2 = await TestCases.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (TestCase2?.setProject) {
await TestCase2.setProject(relatedProject2);
}
const relatedProject3 = await Projects.findOne({
offset: Math.floor(Math.random() * (await Projects.count())),
});
const TestCase3 = await TestCases.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (TestCase3?.setProject) {
await TestCase3.setProject(relatedProject3);
}
const relatedProject4 = await Projects.findOne({
offset: Math.floor(Math.random() * (await Projects.count())),
});
const TestCase4 = await TestCases.findOne({
order: [['id', 'ASC']],
offset: 4,
});
if (TestCase4?.setProject) {
await TestCase4.setProject(relatedProject4);
}
}
// Similar logic for "relation_many"
// Similar logic for "relation_many"
async function associateTestCaseWithOrganization() {
const relatedOrganization0 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const TestCase0 = await TestCases.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (TestCase0?.setOrganization) {
await TestCase0.setOrganization(relatedOrganization0);
}
const relatedOrganization1 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const TestCase1 = await TestCases.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (TestCase1?.setOrganization) {
await TestCase1.setOrganization(relatedOrganization1);
}
const relatedOrganization2 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const TestCase2 = await TestCases.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (TestCase2?.setOrganization) {
await TestCase2.setOrganization(relatedOrganization2);
}
const relatedOrganization3 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const TestCase3 = await TestCases.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (TestCase3?.setOrganization) {
await TestCase3.setOrganization(relatedOrganization3);
}
const relatedOrganization4 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const TestCase4 = await TestCases.findOne({
order: [['id', 'ASC']],
offset: 4,
});
if (TestCase4?.setOrganization) {
await TestCase4.setOrganization(relatedOrganization4);
}
}
async function associateResultWithTest_case() {
const relatedTest_case0 = await TestCases.findOne({
offset: Math.floor(Math.random() * (await TestCases.count())),
});
const Result0 = await Results.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Result0?.setTest_case) {
await Result0.setTest_case(relatedTest_case0);
}
const relatedTest_case1 = await TestCases.findOne({
offset: Math.floor(Math.random() * (await TestCases.count())),
});
const Result1 = await Results.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Result1?.setTest_case) {
await Result1.setTest_case(relatedTest_case1);
}
const relatedTest_case2 = await TestCases.findOne({
offset: Math.floor(Math.random() * (await TestCases.count())),
});
const Result2 = await Results.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Result2?.setTest_case) {
await Result2.setTest_case(relatedTest_case2);
}
const relatedTest_case3 = await TestCases.findOne({
offset: Math.floor(Math.random() * (await TestCases.count())),
});
const Result3 = await Results.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (Result3?.setTest_case) {
await Result3.setTest_case(relatedTest_case3);
}
const relatedTest_case4 = await TestCases.findOne({
offset: Math.floor(Math.random() * (await TestCases.count())),
});
const Result4 = await Results.findOne({
order: [['id', 'ASC']],
offset: 4,
});
if (Result4?.setTest_case) {
await Result4.setTest_case(relatedTest_case4);
}
}
async function associateResultWithOrganization() {
const relatedOrganization0 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const Result0 = await Results.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Result0?.setOrganization) {
await Result0.setOrganization(relatedOrganization0);
}
const relatedOrganization1 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const Result1 = await Results.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Result1?.setOrganization) {
await Result1.setOrganization(relatedOrganization1);
}
const relatedOrganization2 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const Result2 = await Results.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Result2?.setOrganization) {
await Result2.setOrganization(relatedOrganization2);
}
const relatedOrganization3 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const Result3 = await Results.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (Result3?.setOrganization) {
await Result3.setOrganization(relatedOrganization3);
}
const relatedOrganization4 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const Result4 = await Results.findOne({
order: [['id', 'ASC']],
offset: 4,
});
if (Result4?.setOrganization) {
await Result4.setOrganization(relatedOrganization4);
}
}
module.exports = {
up: async (queryInterface, Sequelize) => {
await Steps.bulkCreate(StepsData);
await Projects.bulkCreate(ProjectsData);
await TestCases.bulkCreate(TestCasesData);
await Organizations.bulkCreate(OrganizationsData);
await Results.bulkCreate(ResultsData);
await Promise.all([
await associateStepWithTest_case(),
await associateStepWithOrganization(),
// Similar logic for "relation_many"
await associateUserWithOrganization(),
// Similar logic for "relation_many"
await associateProjectWithProject_owner(),
await associateProjectWithOrganization(),
await associateTestCaseWithProject(),
// Similar logic for "relation_many"
// Similar logic for "relation_many"
await associateTestCaseWithOrganization(),
await associateResultWithTest_case(),
await associateResultWithOrganization(),
]);
},
down: async (queryInterface, Sequelize) => {
await queryInterface.bulkDelete('steps', null, {});
await queryInterface.bulkDelete('projects', null, {});
await queryInterface.bulkDelete('test_cases', null, {});
await queryInterface.bulkDelete('organizations', null, {});
await queryInterface.bulkDelete('results', null, {});
},
};