Skip to content

Commit

Permalink
Initialize US with data for E2E tests (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
bt4R9 authored Oct 30, 2023
1 parent dc585ba commit 36dc880
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
6 changes: 6 additions & 0 deletions scripts/preflight.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,11 @@ if [ "$USE_DEMO_DATA" = "1" ]; then
echo "Finish setting up demo data"
fi

if [ "$USE_E2E_MOCK_DATA" = "1" ]; then
echo "Start setting up e2e data"
node /opt/app/dist/server/db/scripts/e2e/init-united-storage-data.js
echo "Finish setting up e2e data"
fi

supervisorctl start node
supervisorctl start nginx
27 changes: 27 additions & 0 deletions src/db/scripts/e2e/init-united-storage-data.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
require('dotenv').config();
require('../../../index');
import * as fs from 'fs';
import {db} from '../../index';

const E2E_WORKBOOK_ID = '1540491943966934028';
const PATH_TO_DATA = `/opt/e2e-data/us-e2e-data`;

(async function () {
try {
await db.ready();

const result = await db.primary.raw(
`SELECT COUNT(*) AS count FROM workbooks WHERE workbook_id = ${E2E_WORKBOOK_ID};`,
);

if (result && result.rows && result.rows[0] && result.rows[0].count === '0') {
const sqlData = fs.readFileSync(PATH_TO_DATA, 'utf8').toString().trim();
await db.primary.raw(sqlData);
}

process.exit(0);
} catch (err) {
console.error(err);
process.exit(1);
}
})();

0 comments on commit 36dc880

Please sign in to comment.