|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +const { getMetrics } = require('shared'); |
| 4 | +const populateData = require('../services/PopulatedData/populateData'); |
| 5 | +const runnableTestsResolver = require('../resolvers/TestPlanReport/runnableTestsResolver'); |
| 6 | +const finalizedTestResultsResolver = require('../resolvers/TestPlanReport/finalizedTestResultsResolver'); |
| 7 | +const { |
| 8 | + updateTestPlanReportById |
| 9 | +} = require('../models/services/TestPlanReportService'); |
| 10 | +const getGraphQLContext = require('../graphql-context'); |
| 11 | + |
| 12 | +/** @type {import('sequelize-cli').Migration} */ |
| 13 | +module.exports = { |
| 14 | + async up(queryInterface, Sequelize) { |
| 15 | + return queryInterface.sequelize.transaction(async transaction => { |
| 16 | + const context = getGraphQLContext({ req: { transaction } }); |
| 17 | + |
| 18 | + const testPlanReports = await queryInterface.sequelize.query( |
| 19 | + `select distinct on ("TestPlanReport".id) "TestPlanReport".id, metrics |
| 20 | + from "TestPlanReport" |
| 21 | + join public."TestPlanRun" testPlanRun on "TestPlanReport".id = testPlanRun."testPlanReportId" |
| 22 | + where jsonb_array_length(testPlanRun."testResults") > 0;`, |
| 23 | + { |
| 24 | + type: Sequelize.QueryTypes.SELECT, |
| 25 | + transaction |
| 26 | + } |
| 27 | + ); |
| 28 | + |
| 29 | + for (const testPlanReport of testPlanReports) { |
| 30 | + const { testPlanReport: testPlanReportPopulated } = await populateData( |
| 31 | + { testPlanReportId: testPlanReport.id }, |
| 32 | + { context } |
| 33 | + ); |
| 34 | + const runnableTests = runnableTestsResolver( |
| 35 | + testPlanReportPopulated, |
| 36 | + null, |
| 37 | + context |
| 38 | + ); |
| 39 | + const finalizedTestResults = await finalizedTestResultsResolver( |
| 40 | + testPlanReportPopulated, |
| 41 | + null, |
| 42 | + context |
| 43 | + ); |
| 44 | + const metrics = getMetrics({ |
| 45 | + testPlanReport: { |
| 46 | + ...testPlanReportPopulated, |
| 47 | + finalizedTestResults, |
| 48 | + runnableTests |
| 49 | + } |
| 50 | + }); |
| 51 | + await updateTestPlanReportById({ |
| 52 | + id: testPlanReportPopulated.id, |
| 53 | + values: { |
| 54 | + metrics: { |
| 55 | + ...testPlanReportPopulated.metrics, |
| 56 | + ...metrics |
| 57 | + } |
| 58 | + }, |
| 59 | + transaction |
| 60 | + }); |
| 61 | + } |
| 62 | + }); |
| 63 | + } |
| 64 | +}; |
0 commit comments