Skip to content

Commit

Permalink
feat(#492): Elastic cache fixes and xml ingest bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
tholulomo committed Jul 2, 2024
1 parent 19d80ee commit 5e99329
Show file tree
Hide file tree
Showing 12 changed files with 387 additions and 117 deletions.
8 changes: 3 additions & 5 deletions resfulservice/spec/controllers/adminController.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ describe('Admin Controllers Unit Tests:', function () {
expect(result.message).to.equal('search query params is missing');
});

it.skip('should return a list of filtered dataset properties', async function () {
it('should return a list of filtered dataset properties', async function () {
req.query = { search: 'Loss' };
sinon.stub(DatasetProperty, 'find').returns(fetchedDatasetProperties);
const result = await getDatasetProperties(req, res, next);
Expand All @@ -80,7 +80,7 @@ describe('Admin Controllers Unit Tests:', function () {
env: { DOCKER_HUB_ADDRESS: 'https://hub.docker.com' }
};

it.skip('should return a list of tags', async function () {
it('should return a list of tags', async function () {
axiosStub.resolves({ status: 200, data: mockDeployment });

sinon.stub(latency, 'latencyCalculator').returns(true);
Expand Down Expand Up @@ -168,12 +168,10 @@ describe('Admin Controllers Unit Tests:', function () {
});

context('deleteElasticSearchIndex', () => {
it.skip('should delete an ElasticSearch index and return a 200 status', async function () {
it('should delete an ElasticSearch index and return a 200 status', async function () {
req.params.type = 'testType';
const responseMock = { acknowledged: true };

sinon.stub(res, 'status').returnsThis();
sinon.stub(res, 'json').returnsThis();
sinon.stub(elasticSearch, 'deleteIndex').resolves(responseMock);

await deleteElasticSearchIndex(req, res, next);
Expand Down
17 changes: 17 additions & 0 deletions resfulservice/spec/controllers/curationController.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,18 @@ describe('Curation Controller', function () {
});
});

context('getControlSampleId', () => {
it('should return a 500 server error when database throws an error', async function () {
const nextSpy = sinon.spy();
sinon.stub(res, 'status').returnsThis();
sinon.stub(res, 'json').returnsThis();
sinon.stub(DatasetId, 'findOne').throws();

await XlsxController.getControlSampleId(req, res, nextSpy);
sinon.assert.calledOnce(nextSpy);
});
});

context('bulkXlsxCurations', () => {
it('should return a 400 error if zip file is not uploaded', async function () {
req.files.uploadfile = wrongXlsxFile;
Expand Down Expand Up @@ -972,7 +984,9 @@ describe('Curation Controller', function () {
});
sinon.stub(XmlData, 'findOne').returns(mockXmlData);
sinon.stub(XmlData, 'findOneAndDelete').returns(mockXmlData);
sinon.stub(XmlData, 'countDocuments').returns(0);
sinon.stub(FsFile, 'findOneAndDelete').returns(true);
sinon.stub(latency, 'latencyCalculator').returns(true);
sinon.stub(DatasetId, 'findOneAndUpdate').returns(mockDatasetId);
const result = await XlsxController.deleteXlsxCurations(req, res, next);

Expand All @@ -993,8 +1007,10 @@ describe('Curation Controller', function () {
sinon
.stub(XlsxObject, 'findOneAndDelete')
.returns(fetchedCuratedXlsxObject);
sinon.stub(XlsxObject, 'countDocuments').returns(0);
sinon.stub(DatasetId, 'findOneAndUpdate').returns(mockDatasetId);
sinon.stub(FileController, 'deleteFile').returns(true);
sinon.stub(latency, 'latencyCalculator').returns(true);
const result = await XlsxController.deleteXlsxCurations(req, res, next);

expect(result).to.be.an('Object');
Expand All @@ -1012,6 +1028,7 @@ describe('Curation Controller', function () {
});
sinon.stub(DatasetId, 'findOneAndDelete').returns(mockDatasetId);
sinon.stub(XlsxObject, 'deleteMany').returns(true);
sinon.stub(latency, 'latencyCalculator').returns(true);
const result = await XlsxController.deleteXlsxCurations(req, res, next);

expect(result).to.be.an('Object');
Expand Down
11 changes: 6 additions & 5 deletions resfulservice/spec/controllers/favouritesController.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ describe('Favourites Controllers Unit Tests:', function () {

it('should return error when chart is not added to favorites and throws error', async () => {
req.body = { chart: 'chart1' };
req.user = { _id: 'testuser' };
req.user = { _id: '60d5ec4f8e621e2d4c3d1c85' };
const error = new Error();
const nextSpy = sinon.spy();
sinon.stub(latency, 'latencyCalculator').returns(true);
Expand Down Expand Up @@ -82,9 +82,9 @@ describe('Favourites Controllers Unit Tests:', function () {
});
});

context.skip('getFavoriteCharts', () => {
context('getFavoriteCharts', () => {
it('should return success and empty chart list when no favorite charts', async () => {
req.user = { _id: 'testuser' };
req.user = { _id: '60d5ec4f8e621e2d4c3d1c85' };

sinon.stub(FavoriteChart, 'findOne').returns(null);
sinon.stub(latency, 'latencyCalculator').returns(true);
Expand All @@ -95,13 +95,14 @@ describe('Favourites Controllers Unit Tests:', function () {
});
});

it.skip('should return success and list of user favorite charts', async () => {
req.user = { _id: 'testuser' };
it('should return success and list of user favorite charts', async () => {
req.user = { _id: '60d5ec4f8e621e2d4c3d1c85' };

sinon.stub(FavoriteChart, 'findOne').returns(mockFavoriteChart);
sinon
.stub(elasticSearch, 'loadAllCharts')
.returns(mockElasticSearchChartsResult);
sinon.stub(FavoriteChart, 'findOneAndUpdate').returns(true);
sinon.stub(latency, 'latencyCalculator').returns(true);
const result = await getFavoriteCharts(req, res, next);
expect(result).to.be.an('Object');
Expand Down
74 changes: 58 additions & 16 deletions resfulservice/spec/graphql/resolver/xml.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,20 @@ const mockXmlData = {

const mockXmlDataList = [
{
id: '64394c8032bc6325505af6f9',
title: 'L183_53_Portschke_2003.xml',
entityState: 'EditedValid',
sequence: 183
id: '6622848a808bdbee354f96d3',
title: 'L311_S10_Lou_2009.xml',
status: 'Not Approved',
isNewCuration: false,
sequence: 311,
user: '65b8ec85c3d3b2ed82fe4029'
},
{
id: '64394e7232bc6325505af6fa',
title: 'L184_53_Paidoaen33_2003.xml',
entityState: 'EditedValid',
sequence: 184
},
{
id: '64394ed032bc6325505af6fb',
title: 'L185_53_Chrysla33_2003.xml',
entityState: 'EditedValid',
sequence: 185
id: '65cf719860df704a1ca74428',
title: 'E0_S1_Uthdev_2003.xml',
status: 'Approved',
isNewCuration: true,
sequence: null,
user: '65b8ec85c3d3b2ed82fe4029'
}
];

Expand Down Expand Up @@ -66,6 +64,28 @@ describe('XmlData Resolver Unit Tests:', function () {

expect(result).to.have.property('xmlData');
expect(result.xmlData).to.be.an('Array');

expect(result.xmlData[0]).to.have.property('id', mockXmlDataList[0].id);
expect(result.xmlData[0]).to.have.property(
'title',
mockXmlDataList[0].title
);
expect(result.xmlData[0]).to.have.property(
'status',
mockXmlDataList[0].status
);
expect(result.xmlData[0]).to.have.property(
'isNewCuration',
mockXmlDataList[0].isNewCuration
);
expect(result.xmlData[0]).to.have.property(
'sequence',
mockXmlDataList[0].sequence
);
expect(result.xmlData[0]).to.have.property(
'user',
mockXmlDataList[0].user
);
});

it('should return paginated lists of columns', async () => {
Expand All @@ -80,6 +100,28 @@ describe('XmlData Resolver Unit Tests:', function () {

expect(result).to.have.property('xmlData');
expect(result.xmlData).to.be.an('Array');

expect(result.xmlData[1]).to.have.property('id', mockXmlDataList[1].id);
expect(result.xmlData[1]).to.have.property(
'title',
mockXmlDataList[1].title
);
expect(result.xmlData[1]).to.have.property(
'status',
mockXmlDataList[1].status
);
expect(result.xmlData[1]).to.have.property(
'isNewCuration',
mockXmlDataList[1].isNewCuration
);
expect(result.xmlData[1]).to.have.property(
'sequence',
mockXmlDataList[1].sequence
);
expect(result.xmlData[1]).to.have.property(
'user',
mockXmlDataList[1].user
);
});

it('should throw a 500, server error', async () => {
Expand Down Expand Up @@ -115,7 +157,7 @@ describe('XmlData Resolver Unit Tests:', function () {
expect(result).to.have.property('status', 'Not Approved');
});

it.skip('should return a curated sample data', async () => {
it('should return a curated sample data', async () => {
sinon.stub(CuratedSamples, 'findOne').returns(fetchedCuratedXlsxObject);
sinon.stub(XlsxFileManager, 'xmlGenerator').returns(mockXmlData.xml_str);
const result = await xmlViewer(
Expand All @@ -126,7 +168,7 @@ describe('XmlData Resolver Unit Tests:', function () {

expect(result).to.have.property('xmlString');
expect(result).to.have.property('title');
expect(result).to.have.property('status', 'Approved');
expect(result).to.have.property('status', 'Not Approved');
});

it('should return a 404 not found error for curatedsample data', async () => {
Expand Down
3 changes: 2 additions & 1 deletion resfulservice/spec/mocks/curationMock.js
Original file line number Diff line number Diff line change
Expand Up @@ -2725,9 +2725,10 @@ const mockCuratedXlsxObject = {
}
},
MICROSTRUCTURE: {
Imagefile: [
ImageFile: [
{
Description: '40000x magnification',
File: '/api/files/socialist_scallop_germaine-2023-09-27T15:18:58.422Z-real_permittivity.csv?isStore=true',
MicroscopyType: 'TEM',
Type: 'grayscale',
Dimension: {
Expand Down
79 changes: 36 additions & 43 deletions resfulservice/spec/mocks/taskMock.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,54 +165,47 @@ const mockElasticSearchSameDateResult = {
};

const mockFavoriteChart = {
chartIds: ['chart1'],
chartIds: [
'http://nanomine.org/viz/1eeea9b71ebb10b7',
'http://nanomine.org/viz/1dfd29527da82466'
],
user: 'testuser'
};

const mockElasticSearchChartsResult = {
data: [
{
_index: 'charts',
_type: '_doc',
_id: 'jDWFKYcBURBt_YNUTQdw',
_score: 1,
_source: {
description:
'Experiments often report multiple modalities of materials characterization. Provenance metadata for characterization results, linked to the article DOI, are stored in the knowledge graph and include the type of characterization and equipment used. This interactive radial plot links pairs of characterization methods based on the number of DOIs shared by each pair. Highlighting a segment reveals the other methods linked to the selection and displays the percent overlap in a tooltip.',
identifier: 'http://nanomine.org/viz/1eeea9b71ebb10b7',
label:
'Which Characterization Methods Are Typically Performed Together?',
thumbnail: 'http://nanomine.org/viz/1eeea9b71ebb10b7_depiction'
}
},
{
_index: 'charts',
_type: '_doc',
_id: 'kTWFKYcBURBt_YNUTQeg',
_score: 1,
_source: {
description:
'This geographic display shows the locations of partner universities developing MaterialsMine with grant funding provided by the NSF CSSI program. The topoJSON map is referenced from the vega-datasets Github repository. Hover over a point to show a tooltip with the university and city!',
identifier: 'http://nanomine.org/viz/330733156368f4cd',
label: 'MaterialsMine on a Map',
thumbnail: 'http://nanomine.org/viz/330733156368f4cd_depiction'
}
},
{
_index: 'charts',
_type: '_doc',
_id: 'mDWFKYcBURBt_YNUTQfb',
_score: 1,
_source: {
description:
'These linked histograms show the distribution of samples in NanoMine, with a focus on mechanical properties data. The histograms enable dynamic crossfiltering, where selection of a range in one chart highlights corresponding samples from accompanying charts that fall within the specified interval of the selected chart. Hold down Shift to pan and zoom within a histogram, and double-click to reset.',
identifier: 'http://nanomine.org/viz/1dfd29527da82466',
label: 'Mechanical Properties with Crossfiltering',
thumbnail: 'http://nanomine.org/viz/1dfd29527da82466_depiction'
}
data: {
hits: {
hits: [
{
_index: 'charts',
_type: '_doc',
_id: 'jDWFKYcBURBt_YNUTQdw',
_score: 1,
_source: {
description:
'Experiments often report multiple modalities of materials characterization. Provenance metadata for characterization results, linked to the article DOI, are stored in the knowledge graph and include the type of characterization and equipment used. This interactive radial plot links pairs of characterization methods based on the number of DOIs shared by each pair. Highlighting a segment reveals the other methods linked to the selection and displays the percent overlap in a tooltip.',
identifier: 'http://nanomine.org/viz/1eeea9b71ebb10b7',
label:
'Which Characterization Methods Are Typically Performed Together?',
thumbnail: 'http://nanomine.org/viz/1eeea9b71ebb10b7_depiction'
}
},
{
_index: 'charts',
_type: '_doc',
_id: 'kTWFKYcBURBt_YNUTQeg',
_score: 1,
_source: {
description:
'This geographic display shows the locations of partner universities developing MaterialsMine with grant funding provided by the NSF CSSI program. The topoJSON map is referenced from the vega-datasets Github repository. Hover over a point to show a tooltip with the university and city!',
identifier: 'http://nanomine.org/viz/330733156368f4cd',
label: 'MaterialsMine on a Map',
thumbnail: 'http://nanomine.org/viz/330733156368f4cd_depiction'
}
}
]
}
],
total: 2
}
};

const fetchedCuration = {
Expand Down
Loading

0 comments on commit 5e99329

Please sign in to comment.