Skip to content

Commit

Permalink
feat: Refactoring ES error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
tholulomo committed Feb 19, 2024
1 parent df3aa53 commit d294fe7
Show file tree
Hide file tree
Showing 4 changed files with 333 additions and 223 deletions.
43 changes: 29 additions & 14 deletions app/tests/unit/components/metamineNU/VisualizationLayout.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,35 @@ describe('VisualizationLayout.vue', () => {
link: { to: '/mm', text: 'Pairwise' },
dense: false
}
const dispatch = jest.spyOn(store, 'dispatch')
const originalFunction = store.dispatch
const dispatch = jest
.spyOn(store, 'dispatch')
.mockImplementationOnce(
async () => await originalFunction('metamineNU/fetchMetamineDataset')
)
.mockImplementationOnce(() => Promise.resolve({ val: 'reload' }))
.mockImplementationOnce(() => Promise.resolve({ val: 'force-cache' }))
.mockImplementationOnce(() => Promise.resolve({ val: 'reload' }))
const commitSpy = jest.spyOn(store, 'commit')
global.fetch = jest
.fn()
.mockImplementationOnce(() =>
Promise.resolve({ json: () => Promise.resolve(mockValues) })
Promise.resolve({
json: () => Promise.resolve(mockValues),
url: 'windows_url/metamine/file_1.csv'
})
)
.mockImplementationOnce(() =>
Promise.resolve({ json: () => Promise.resolve(mockValues2) })
Promise.resolve({
json: () => Promise.resolve(mockValues2),
url: 'windows_url/metamine/file_2.csv'
})
)
.mockImplementationOnce(() =>
Promise.resolve({ json: () => Promise.resolve(mockValues2) })
Promise.resolve({
json: () => Promise.resolve(mockValues2),
url: 'windows_url/metamine/file_3.csv'
})
)
.mockImplementation(() => {})

Expand All @@ -39,8 +56,8 @@ describe('VisualizationLayout.vue', () => {
await jest.resetAllMocks()
})

it.skip('makes a fetch call when mounted ', () => {
expect.assertions(12)
it('makes a fetch call when mounted ', async () => {
expect.assertions(10)
expect(wrapper.exists()).toBe(true)
expect(dispatch).toHaveBeenCalledTimes(2)
expect(commitSpy).toHaveBeenCalledTimes(5)
Expand Down Expand Up @@ -73,16 +90,14 @@ describe('VisualizationLayout.vue', () => {
[],
undefined
)
expect(dispatch).toHaveBeenNthCalledWith(2, 'fetchWrapper', {
url: '/api/files/metamine'
})

expect(fetch).toHaveBeenCalledTimes(1 + mockValues.fetchedNames.length)
// check initial fetch request
expect(fetch).toHaveBeenNthCalledWith(1, '/api/files/metamine')
for (let i = 0; i < mockValues.fetchedNames.length; i++) {
expect(fetch).toHaveBeenNthCalledWith(
i + 2,
`/api/files/metamine/${mockValues.fetchedNames[i].name}`
)
}
expect(global.fetch).toHaveBeenNthCalledWith(1, '/api/files/metamine', {
cache: 'reload'
})
})

it('renders layout properly ', () => {
Expand Down
7 changes: 6 additions & 1 deletion resfulservice/src/controllers/kgWrapperController.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,8 @@ exports.getKnowledge = async (req, res, next) => {
* @returns {*} response.data
*/
exports.getSparql = async (req, res, next) => {
const log = req.logger;
log.info('getSparql(): Function entry');
const whyisPath = req.query.whyisPath;
try {
if (!req.env.KNOWLEDGE_ADDRESS) {
Expand Down Expand Up @@ -206,6 +208,7 @@ exports.getSparql = async (req, res, next) => {
if (response.data && whyisPath !== 'pub') {
req.knowledgeId = req.knowledgeId ?? uuidv4();
await elasticSearch.createKnowledgeGraphDoc(
log,
req.knowledgeId,
req.query.queryString,
response?.data
Expand Down Expand Up @@ -277,7 +280,9 @@ exports.getInstanceFromKnowledgeGraph = async (req, res, next) => {
const view = req?.query?.view;
let url;
if (!view) url = `${req.env.KNOWLEDGE_ADDRESS}/about?uri=${req.query.uri}`;
else { url = `${req.env.KNOWLEDGE_ADDRESS}/about?uri=${req.query.uri}&view=${view}`; }
else {
url = `${req.env.KNOWLEDGE_ADDRESS}/about?uri=${req.query.uri}&view=${view}`;
}
return axios
.get(url, {
responseType: 'arraybuffer'
Expand Down
2 changes: 1 addition & 1 deletion resfulservice/src/middlewares/knowledge-cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ exports.isKnowledgeCached = async (req, res, next) => {
req.logger.info('Middleware.isKnowledgeCached - Function entry');
const query = req.query.query ?? req.body?.query;

const cacheResult = await elasticSearch.searchKnowledgeGraph(query);
const cacheResult = await elasticSearch.searchKnowledgeGraph(req, query);
if (cacheResult.length) {
const {
_id,
Expand Down
Loading

0 comments on commit d294fe7

Please sign in to comment.