Skip to content

Commit

Permalink
Merge pull request #22 from YizYah/console
Browse files Browse the repository at this point in the history
fix(mocksessionfromqueryset): added console log for error of not matc…
  • Loading branch information
YizYah authored Jul 25, 2021
2 parents 8a49999 + 53da979 commit 673972d
Showing 1 changed file with 28 additions and 17 deletions.
45 changes: 28 additions & 17 deletions src/custom/session/mockSessionFromQuerySet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,28 @@ const mockDatabaseInfo = {
PASSWORD: 'thisIsAfakeDatabase',
};


const queryInfo = (params: any, query: string): string => {
let paramsString = JSON.stringify(params);
const MAX_LENGTH = 150;
if (paramsString.length > MAX_LENGTH) paramsString = paramsString.substring(0, MAX_LENGTH) + '...';
return `
query:
-----------------
${query.trim()}
-----------------
params: ${paramsString}
`

}
const errorMessageContentsQueryMatched = (params: any, query: string): string =>
`your query was matched in your QuerySpec. But your params were not matched:
${queryInfo(params, query)}`;
const errorMessageContentsQueryNotMatched = (params: any, query: string): string =>
`the query set provided does not contain the given query:
${queryInfo(params, query)}`;


function mockSessionFromQuerySet(querySet: QuerySpec[]): Session {
const driver = neo4j.driver(
mockDatabaseInfo.URI,
Expand All @@ -33,26 +55,15 @@ function mockSessionFromQuerySet(querySet: QuerySpec[]): Session {
});

if (output !== '') return output;
const errorMessageMatchedQuery = errorMessageContentsQueryMatched(params, query);
if (queryMatched) {
let paramsString = JSON.stringify(params)
const MAX_LENGTH = 150
if (paramsString.length > MAX_LENGTH) paramsString = paramsString.substring(0, MAX_LENGTH) + '...'
throw new Error(`your query was matched in your QuerySpec. But your params were not matched.
query:
-----------------
${query.trim()}
-----------------
params: ${paramsString}
`)
console.log(errorMessageMatchedQuery)
throw new Error(errorMessageMatchedQuery)
}

throw new Error(`the query set provided does not contain the given query:
-----------------
${query.trim()}
-----------------
`);
const errorMessageNoMatchedQuery = errorMessageContentsQueryNotMatched(params, query)
console.log(errorMessageNoMatchedQuery)
throw new Error(errorMessageNoMatchedQuery);
};

const mockBeginTransaction = () => {
Expand Down

0 comments on commit 673972d

Please sign in to comment.