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

refactor(healthcare): convert ava tests to mocha #1148

Merged
4 changes: 2 additions & 2 deletions healthcare/datasets/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
"node": ">=6.0.0"
},
"scripts": {
"test": "ava -T 1m --verbose system-test/*.test.js"
"test": "mocha system-test/*.test.js --timeout=60000"
},
"devDependencies": {
"@google-cloud/nodejs-repo-tools": "^3.0.0",
"ava": "^0.25.0"
"mocha": "^5.2.0"
},
"dependencies": {
"googleapis": "^37.0.0",
Expand Down
65 changes: 33 additions & 32 deletions healthcare/datasets/system-test/datasets.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,65 +15,66 @@

'use strict';

const path = require(`path`);
const test = require(`ava`);
const tools = require(`@google-cloud/nodejs-repo-tools`);
const uuid = require(`uuid`);
const path = require('path');
const assert = require('assert');
const tools = require('@google-cloud/nodejs-repo-tools');
const uuid = require('uuid');

const cmd = `node datasets.js`;
const cwd = path.join(__dirname, `..`);
const cmd = 'node datasets.js';
const cwd = path.join(__dirname, '..');
const datasetId = `dataset-${uuid.v4()}`.replace(/-/gi, '_');
const destinationDatasetId = `destination-${uuid.v4()}`.replace(/-/gi, '_');
const keeplistTags = 'PatientID';

test.before(tools.checkCredentials);
test.after.always(async () => {
before(tools.checkCredentials);
after(async () => {
try {
await tools.runAsync(`${cmd} deleteDataset ${destinationDatasetId}`, cwd);
// eslint-disable-next-line no-empty
} catch (err) {} // Ignore error
});

test.serial(`should create a dataset`, async t => {
it('should create a dataset', async () => {
const output = await tools.runAsync(`${cmd} createDataset ${datasetId}`, cwd);
t.is(output, `Created dataset: ${datasetId}`);
assert.strictEqual(output, `Created dataset: ${datasetId}`);
});

test.serial(`should get a dataset`, async t => {
it('should get a dataset', async () => {
const output = await tools.runAsync(`${cmd} getDataset ${datasetId}`, cwd);
t.regex(output, /name/);
t.regex(output, /timeZone/);
assert.strictEqual(new RegExp(/name/).test(output), true);
assert.strictEqual(new RegExp(/timeZone/).test(output), true);
});

test.serial(`should patch a dataset`, async t => {
it('should patch a dataset', async () => {
const patchTimeZone = 'GMT';
const output = await tools.runAsync(
`${cmd} patchDataset ${datasetId} ${patchTimeZone}`,
cwd
);
t.is(output, `Dataset ${datasetId} patched with time zone ${patchTimeZone}`);
assert.strictEqual(
output,
`Dataset ${datasetId} patched with time zone ${patchTimeZone}`
);
});

test.serial(`should list datasets`, async t => {
it('should list datasets', async () => {
const output = await tools.runAsync(`${cmd} listDatasets`, cwd);
t.regex(output, /datasets/);
assert.strictEqual(new RegExp(/datasets/).test(output), true);
});

test.serial(
`should de-identify data in a dataset and write to a new dataset`,
async t => {
const output = await tools.runAsync(
`${cmd} deidentifyDataset ${datasetId} ${destinationDatasetId} ${keeplistTags}`,
cwd
);
t.is(
output,
`De-identified data written from dataset
it('should de-identify data in a dataset and write to a new dataset', async () => {
const output = await tools.runAsync(
`${cmd} deidentifyDataset ${datasetId} ${destinationDatasetId} ${keeplistTags}`,
cwd
);
assert.strictEqual(
output,
`De-identified data written from dataset
${datasetId} to dataset ${destinationDatasetId}`
);
}
);
);
});

test.serial(`should delete a dataset`, async t => {
it('should delete a dataset', async () => {
const output = await tools.runAsync(`${cmd} deleteDataset ${datasetId}`, cwd);
t.is(output, `Deleted dataset: ${datasetId}`);
assert.strictEqual(output, `Deleted dataset: ${datasetId}`);
});
4 changes: 2 additions & 2 deletions healthcare/dicom/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
"node": ">=6.0.0"
},
"scripts": {
"test": "ava -T 1m --verbose system-test/*.test.js"
"test": "mocha system-test/*.test.js --timeout=60000"
},
"devDependencies": {
"@google-cloud/nodejs-repo-tools": "^3.0.0",
"ava": "^0.25.0"
"mocha": "^5.2.0"
},
"dependencies": {
"googleapis": "^37.0.0",
Expand Down
67 changes: 36 additions & 31 deletions healthcare/dicom/system-test/dicom_stores.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@

'use strict';

const path = require(`path`);
const test = require(`ava`);
const tools = require(`@google-cloud/nodejs-repo-tools`);
const uuid = require(`uuid`);
const path = require('path');
const assert = require('assert');
const tools = require('@google-cloud/nodejs-repo-tools');
const uuid = require('uuid');

const cmdDataset = `node datasets.js`;
const cmd = `node dicom_stores.js`;
const cwdDatasets = path.join(__dirname, `../../datasets`);
const cwd = path.join(__dirname, `..`);
const cmdDataset = 'node datasets.js';
const cmd = 'node dicom_stores.js';
const cwdDatasets = path.join(__dirname, '../../datasets');
const cwd = path.join(__dirname, '..');
const datasetId = `nodejs-docs-samples-test-${uuid.v4()}`.replace(/-/gi, '_');
const dicomStoreId = `nodejs-docs-samples-test-dicom-store${uuid.v4()}`.replace(
/-/gi,
Expand All @@ -35,19 +35,15 @@ const pubsubTopic = `nodejs-docs-samples-test-pubsub${uuid.v4()}`.replace(
);

const bucketName = process.env.GCLOUD_STORAGE_BUCKET;

const dcmFileName = `IM-0002-0001-JPEG-BASELINE.dcm`;
const gcsUri = bucketName + '/' + dcmFileName;

test.before(tools.checkCredentials);
test.before(async () => {
return tools
.runAsync(`${cmdDataset} createDataset ${datasetId}`, cwdDatasets)
.then(results => {
console.log(results);
return results;
});
before(async () => {
tools.checkCredentials();
await tools.runAsync(`${cmdDataset} createDataset ${datasetId}`, cwdDatasets);
});
test.after.always(async () => {
after(async () => {
try {
await tools.runAsync(
`${cmdDataset} deleteDataset ${datasetId}`,
Expand All @@ -56,58 +52,67 @@ test.after.always(async () => {
} catch (err) {} // Ignore error
});

test.serial(`should create a DICOM store`, async t => {
it('should create a DICOM store', async () => {
const output = await tools.runAsync(
`${cmd} createDicomStore ${datasetId} ${dicomStoreId}`,
cwd
);
t.regex(output, /Created DICOM store/);
assert.strictEqual(new RegExp(/Created DICOM store/).test(output), true);
});

test.serial(`should get a DICOM store`, async t => {
it('should get a DICOM store', async () => {
const output = await tools.runAsync(
`${cmd} getDicomStore ${datasetId} ${dicomStoreId}`,
cwd
);
t.regex(output, /Got DICOM store/);
assert.strictEqual(new RegExp(/Got DICOM store/).test(output), true);
});

test.serial(`should patch a DICOM store`, async t => {
it('should patch a DICOM store', async () => {
const output = await tools.runAsync(
`${cmd} patchDicomStore ${datasetId} ${dicomStoreId} ${pubsubTopic}`,
cwd
);
t.regex(output, /Patched DICOM store with Cloud Pub\/Sub topic/);
assert.strictEqual(
new RegExp(/Patched DICOM store with Cloud Pub\/Sub topic/).test(output),
true
);
});

test.serial(`should list DICOM stores`, async t => {
it('should list DICOM stores', async () => {
const output = await tools.runAsync(
`${cmd} listDicomStores ${datasetId}`,
cwd
);
t.regex(output, /DICOM stores/);
assert.strictEqual(new RegExp(/DICOM stores/).test(output), true);
});

test.serial(`should export a DICOM instance`, async t => {
it('should export a DICOM instance', async () => {
const output = await tools.runAsync(
`${cmd} exportDicomInstanceGcs ${datasetId} ${dicomStoreId} ${bucketName}`,
cwd
);
t.regex(output, /Exported DICOM instances to bucket/);
assert.strictEqual(
new RegExp(/Exported DICOM instances to bucket/).test(output),
true
);
});

test.serial(`should import a DICOM object from GCS`, async t => {
it('should import a DICOM object from GCS', async () => {
const output = await tools.runAsync(
`${cmd} importDicomObject ${datasetId} ${dicomStoreId} ${gcsUri}`,
cwd
);
t.regex(output, /Imported DICOM objects from bucket/);
assert.strictEqual(
new RegExp(/Imported DICOM objects from bucket/).test(output),
true
);
});

test(`should delete a DICOM store`, async t => {
it('should delete a DICOM store', async () => {
const output = await tools.runAsync(
`${cmd} deleteDicomStore ${datasetId} ${dicomStoreId}`,
cwd
);
t.regex(output, /Deleted DICOM store/);
assert.strictEqual(new RegExp(/Deleted DICOM store/).test(output), true);
});
53 changes: 24 additions & 29 deletions healthcare/dicom/system-test/dicomweb.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,38 +15,33 @@

'use strict';

const path = require(`path`);
const test = require(`ava`);
const tools = require(`@google-cloud/nodejs-repo-tools`);
const uuid = require(`uuid`);
const path = require('path');
const assert = require('assert');
const tools = require('@google-cloud/nodejs-repo-tools');
const uuid = require('uuid');

const cmdDataset = `node datasets.js`;
const cmdDicomStore = `node dicom_stores.js`;
const cmd = `node dicomweb.js`;
const cwdDatasets = path.join(__dirname, `../../datasets`);
const cwd = path.join(__dirname, `..`);
const cmdDataset = 'node datasets.js';
const cmdDicomStore = 'node dicom_stores.js';
const cmd = 'node dicomweb.js';
const cwdDatasets = path.join(__dirname, '../../datasets');
const cwd = path.join(__dirname, '..');
const datasetId = `nodejs-docs-samples-test-${uuid.v4()}`.replace(/-/gi, '_');
const dicomStoreId = `nodejs-docs-samples-test-dicom-store${uuid.v4()}`.replace(
/-/gi,
'_'
);

const dcmFile = `resources/IM-0002-0001-JPEG-BASELINE-edited.dcm`;
const boundary = `DICOMwebBoundary`;
const dcmFile = 'resources/IM-0002-0001-JPEG-BASELINE-edited.dcm';
const boundary = 'DICOMwebBoundary';
// The studyUid is not assigned by the server and is part of the metadata
// of dcmFile.
const studyUid = `1.2.840.113619.2.176.3596.3364818.7819.1259708454.105`;
const studyUid = '1.2.840.113619.2.176.3596.3364818.7819.1259708454.105';

test.before(tools.checkCredentials);
test.before(async () => {
return tools
.runAsync(`${cmdDataset} createDataset ${datasetId}`, cwdDatasets)
.then(results => {
console.log(results);
return results;
});
before(async () => {
tools.checkCredentials();
await tools.runAsync(`${cmdDataset} createDataset ${datasetId}`, cwdDatasets);
});
test.after.always(async () => {
after(async () => {
try {
await tools.runAsync(
`${cmdDataset} deleteDataset ${datasetId}`,
Expand All @@ -55,7 +50,7 @@ test.after.always(async () => {
} catch (err) {} // Ignore error
});

test.serial(`should store a DICOM instance`, async t => {
it('should store a DICOM instance', async () => {
await tools.runAsync(
`${cmdDicomStore} createDicomStore ${datasetId} ${dicomStoreId}`,
cwd
Expand All @@ -64,31 +59,31 @@ test.serial(`should store a DICOM instance`, async t => {
`${cmd} dicomWebStoreInstance ${datasetId} ${dicomStoreId} ${dcmFile} ${boundary}`,
cwd
);
t.regex(output, /Stored instance/);
assert.strictEqual(new RegExp(/Stored instance/).test(output), true);
});

test.serial(`should search DICOM instances`, async t => {
it('should search DICOM instances', async () => {
const output = await tools.runAsync(
`${cmd} dicomWebSearchInstances ${datasetId} ${dicomStoreId}`,
cwd
);
t.regex(output, /Instances/);
assert.strictEqual(new RegExp(/Instances/).test(output), true);
});

test.serial(`should retrieve a DICOM study`, async t => {
it('should retrieve a DICOM study', async () => {
const output = await tools.runAsync(
`${cmd} dicomWebRetrieveStudy ${datasetId} ${dicomStoreId} ${studyUid}`,
cwd
);
t.regex(output, /Retrieved study/);
assert.strictEqual(new RegExp(/Retrieved study/).test(output), true);
});

test.serial(`should delete a DICOM study`, async t => {
it('should delete a DICOM study', async () => {
const output = await tools.runAsync(
`${cmd} dicomWebDeleteStudy ${datasetId} ${dicomStoreId} ${studyUid}`,
cwd
);
t.regex(output, /Deleted study/);
assert.strictEqual(new RegExp(/Deleted study/).test(output), true);

// Clean up
await tools.runAsync(
Expand Down
4 changes: 2 additions & 2 deletions healthcare/fhir/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
"node": ">=6.0.0"
},
"scripts": {
"test": "ava -T 1m --verbose system-test/*.test.js"
"test": "mocha system-test/*.test.js --timeout=60000"
},
"devDependencies": {
"@google-cloud/nodejs-repo-tools": "^3.0.0",
"ava": "^0.25.0"
"mocha": "^5.2.0"
},
"dependencies": {
"googleapis": "^37.0.0",
Expand Down
Loading