Skip to content
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

Vamc 15446 spike vamc police data page #1753

Merged
merged 21 commits into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
9 changes: 6 additions & 3 deletions src/platform/testing/e2e/cypress/plugins/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,16 @@ module.exports = on => {
return dir;
},
downloadFile,
deleteFileOrFolder(fileOrFolderName) {
if (fs.existsSync(fileOrFolderName)) {
fs.rmSync(fileOrFolderName, {
deleteFileOrDir(fileOrDirName) {
if (fs.existsSync(fileOrDirName)) {
fs.rmSync(fileOrDirName, {
recursive: true,
});
}
return null;
},
fileOrDirExists(fileOrDirName) {
return fs.existsSync(fileOrDirName);
},
});
};
8 changes: 6 additions & 2 deletions src/platform/testing/e2e/cypress/support/commands/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ import 'cy-mobile-commands';
import 'cypress-wait-until';
import 'cypress-downloadfile/lib/downloadFileCommand';

Cypress.Commands.add('deleteFileOrFolder', folderOrFileName => {
return cy.task('deleteFileOrFolder', folderOrFileName);
Cypress.Commands.add('deleteFileOrDir', fileOrDirName => {
return cy.task('deleteFileOrDir', fileOrDirName);
});

Cypress.Commands.add('fileOrDirExists', fileOrDirName => {
return cy.task('fileOrDirExists', fileOrDirName);
});
20 changes: 5 additions & 15 deletions src/site/stages/build/drupal/static-data-files/generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,10 @@ const pullDataFileContentFromCurls = async (
_buildOptions,
_onlyPublishedContent,
) => {
const curlFiles = dataFiles.filter(isQueryTypeCurl);
return Promise.all(curlFiles.map(dataFile => processCurlDataFile(dataFile)));
const curlDataFiles = dataFiles.filter(isQueryTypeCurl);
return Promise.all(
curlDataFiles.map(dataFile => processCurlDataFile(dataFile)),
);
};

const pullGraphQLDataFileContentFromDrupal = async (
Expand Down Expand Up @@ -219,24 +221,12 @@ const pullDataFileContentFromDrupal = async (
);
};

const pullDataFileContentFromCurl = async (
dataFiles,
buildOptions,
onlyPublishedContent,
) => {
return pullDataFileContentFromCurls(
dataFiles,
buildOptions,
onlyPublishedContent,
);
};

const pullDataFileContent = async (
dataFiles,
buildOptions,
onlyPublishedContent,
) => {
const curls = await pullDataFileContentFromCurl(
const curls = await pullDataFileContentFromCurls(
dataFiles,
buildOptions,
onlyPublishedContent,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
const { curly } = require('node-libcurl');
const { Curl } = require('node-libcurl');
const fs = require('fs');
const csv = require('csvtojson');
const path = require('path');
const { logDrupal: log } = require('../../utilities-drupal');

const query = inputs => async () => {
if (!Array.isArray(inputs)) {
Expand All @@ -14,25 +13,46 @@
throw new Error('inputs must be an array of strings');
}
if (/https?|file:\/\//.test(input)) {
const { data } = await curly.get(input);
const curl = new Curl();
curl.setOpt(Curl.option.URL, input);
if (input.endsWith('cms.va.gov')) {
eselkin marked this conversation as resolved.
Show resolved Hide resolved
curl.setOpt(Curl.option.PROXY, '127.0.0.1:2001');
}
curl.setOpt(Curl.option.CUSTOMREQUEST, 'GET');

const data = await new Promise((resolve, reject) => {
curl.on('end', (statusCode, body) => {
resolve(body);
});
curl.on('error', err => {
reject(err);
});
curl.perform();
});

outputData.push(data);
}
}
return outputData;
};

const postProcess = async queryResult => {
const processedJSON = { data: { statistics: {}, contacts: {} } };
const processedJSON = {
data: {
statistics: {},
contacts: {},
},
};
const [contact, events] = queryResult;
const contactFile = path.join(__dirname, 'pre-contact-police.csv');
const eventsFile = path.join(__dirname, 'pre-events-police.csv');
// Unfortunately there's no Buffer or file-string support in csvtojson, there's read and process per-line, but this is more efficient.
fs.writeFileSync(contactFile, contact, { append: false });
fs.writeFileSync(eventsFile, events, { append: false });
const jsonContact = await csv().fromFile(contactFile);
const jsonEvents = await csv().fromFile(eventsFile);
log(jsonContact);
log(jsonEvents);
// eslint-disable-next-line no-unused-vars
eselkin marked this conversation as resolved.
Show resolved Hide resolved
const contactsJson = await csv().fromFile(contactFile);
Dismissed Show dismissed Hide dismissed
// eslint-disable-next-line no-unused-vars
eselkin marked this conversation as resolved.
Show resolved Hide resolved
const eventsJson = await csv().fromFile(eventsFile);
Dismissed Show dismissed Hide dismissed
// TODO: Process jsonEvents and Join data with contact info for a Facility Police Page content
return processedJSON;
};
Expand Down
14 changes: 11 additions & 3 deletions src/site/tests/static-files/static-files-exist.cypress.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ describe('Static Data Files Test', () => {
/* This is not a visual test -- no accessibility involvement */
/* eslint-disable @department-of-veterans-affairs/axe-check-required */
eselkin marked this conversation as resolved.
Show resolved Hide resolved
it('has the EHR JSON static file', () => {
cy.deleteFileOrFolder('../cypress/downloads/vamc-ehr.json');
cy.deleteFileOrDir('../cypress/downloads/vamc-ehr.json');
cy.fileOrDirExists('cypress/downloads/vamc-ehr.json').should('eq', false);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👏

cy.downloadFile(
'http://localhost:3002/data/cms/vamc-ehr.json',
'../cypress/downloads',
Expand All @@ -12,9 +13,12 @@ describe('Static Data Files Test', () => {
cy.readFile('cypress/downloads/vamc-ehr.json').should('exist');
});
it('has the Supplemental Status JSON static file', () => {
cy.deleteFileOrFolder(
cy.deleteFileOrDir(
'../cypress/downloads/vamc-facility-supplemental-status.json',
);
cy.fileOrDirExists(
'cypress/downloads/vamc-facility-supplemental-status.json',
).should('eq', false);
cy.downloadFile(
'http://localhost:3002/data/cms/vamc-facility-supplemental-status.json',
'../cypress/downloads',
Expand All @@ -25,7 +29,11 @@ describe('Static Data Files Test', () => {
).should('exist');
});
it('has the VAMC Police JSON static file', () => {
cy.deleteFileOrFolder('../cypress/downloads/vamc-police.json');
cy.deleteFileOrDir('../cypress/downloads/vamc-police.json');
cy.fileOrDirExists('cypress/downloads/vamc-police.json').should(
'eq',
false,
);
cy.downloadFile(
'http://localhost:3002/data/cms/vamc-police.json',
'../cypress/downloads',
Expand Down
Loading