neo-forgery
Advanced tools
Comparing version 1.12.1 to 2.0.0
@@ -14,6 +14,10 @@ "use strict"; | ||
fakeSession.run = mockRun; | ||
const mockBeginTransaction = () => { | ||
const mockBeginTransaction = (transactionType) => { | ||
let _isOpen = true; | ||
return { | ||
run: mockRun, | ||
run: async (query, params) => { | ||
const output = await mockRun(query, params); | ||
output.summary.transactionType = transactionType; | ||
return output; | ||
}, | ||
commit: () => { | ||
@@ -20,0 +24,0 @@ _isOpen = false; |
@@ -36,10 +36,2 @@ "use strict"; | ||
let queryMatched = false; | ||
// querySet.map((querySpec: QuerySpec) => { | ||
// if (removeExtraWhite(querySpec.query) === removeExtraWhite(query)) { | ||
// queryMatched = true; | ||
// if (!querySpec.params || isSubset(params, querySpec.params)) { // was: JSON.stringify(querySpec.params) === JSON.stringify(params) | ||
// output = storedToLive(querySpec.output); | ||
// } | ||
// } | ||
// }); | ||
for (let index = 0; index < querySet.length; index++) { | ||
@@ -61,6 +53,10 @@ const querySpec = querySet[index]; | ||
}; | ||
const mockBeginTransaction = () => { | ||
fakeSession._beginTransaction = function mockBeginTransaction(transactionType) { | ||
let _isOpen = true; | ||
return { | ||
run: mockRun, | ||
run: async (query, params) => { | ||
const output = await mockRun(query, params); | ||
output.summary.transactionType = transactionType; | ||
return output; | ||
}, | ||
commit: () => { | ||
@@ -78,5 +74,5 @@ _isOpen = false; | ||
fakeSession.run = mockRun; | ||
fakeSession._beginTransaction = mockBeginTransaction; | ||
// fakeSession._beginTransaction = mockBeginTransaction; | ||
return fakeSession; | ||
} | ||
module.exports = mockSessionFromQuerySet; |
@@ -5,3 +5,3 @@ { | ||
"author": "YizYah", | ||
"version": "1.12.1", | ||
"version": "2.0.0", | ||
"bugs": "https://github.com/YizYah/neo-forgery/issues", | ||
@@ -8,0 +8,0 @@ "engines": { |
@@ -200,3 +200,3 @@ | ||
There are two functions for generating sessions that produce mock outptu. These can be used for confirming that output is what you expect it to be. | ||
There are two functions for generating sessions that produce mock output. These can be used for confirming that output is what you expect it to be. | ||
@@ -251,2 +251,28 @@ ### Generation from a Query Set | ||
### Testing Transactions | ||
Transactions can be called in your test as easily as directly calling `.run()`. | ||
For instance: | ||
```typescript | ||
const session = mockSessionFromQuerySet(querySet) | ||
const output: any = await session.readTransaction((tx: any) => | ||
tx.run(query, params)) | ||
// assert that output is expected | ||
``` | ||
If you want to ensure that a particular transaction type was executed, you can look at `summary.transactionType` in the output. The value of `transactionType` will be either `READ` or `WRITE`. | ||
For instance: | ||
```typescript | ||
const session = mockSessionFromFunction(sessionRunMock) | ||
const output: any = await session.writeTransaction((tx: any) => | ||
tx.run('', { foo: "bar" })) | ||
t.is(output.summary.transactionType, 'WRITE') | ||
``` | ||
### Mock Driver Generation | ||
@@ -253,0 +279,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
51536
528