Skip to content

Initialize US with data for E2E tests #21

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
})();