-
Notifications
You must be signed in to change notification settings - Fork 91
feat: Create new data access to allow for in-memory transactions. #1386
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
47 commits
Select commit
Hold shift + click to select a range
776bb7d
feat: create pay before persist request flow
aimensahnoun d53c930
Merge branch 'master' of github.com:RequestNetwork/requestNetwork int…
aimensahnoun fc5e671
feat: add preparePaymentRequest
aimensahnoun 4c41cdf
feat: add requestPayment to `createRequest` return
aimensahnoun e9d51c7
docs: document `persistRequest` method
aimensahnoun c2ec1c2
test: add creation and persistance tests for in-memory requests
aimensahnoun 399217c
test: update transactiom-manager tests to check only relavant parts o…
aimensahnoun 12631ac
test: updating request-client tests to check object containing simila…
aimensahnoun dee30bd
Merge branch 'master' into 1380-pay-before-persist
MantisClone a32f05c
Merge branch 'master' of github.com:RequestNetwork/requestNetwork int…
aimensahnoun 0964179
Merge branch '1380-pay-before-persist' of github.com:RequestNetwork/r…
aimensahnoun 6dffdfd
refactor: merge in memory variables into one object `inMemoryInfo`
aimensahnoun d3d9368
test: move `spyPersistTransaction` back to beforeEach
aimensahnoun a56c1aa
Merge branch 'master' of github.com:RequestNetwork/requestNetwork int…
aimensahnoun af2afa8
test: add logs to failing test
aimensahnoun 186b163
test: add more logs to test
aimensahnoun 8e91696
test: revert skip persistence
aimensahnoun 613e6c3
test: add persistence back
aimensahnoun 10ed848
test: add more logs to failing test
aimensahnoun 638d730
test: increase failAtCall
aimensahnoun d4b611f
test: increase timeout
aimensahnoun 0900c53
test: uncomment workflows
aimensahnoun 91f0cc6
test: lower fail at call
aimensahnoun 3dc465c
Revert to fail at call 6
MantisClone 6df24aa
Revert debug log messages and extended timeout
MantisClone 7ec1197
Throw error on unhandled request
MantisClone 6b3513b
Add debug logging related to msw server
MantisClone 8027e49
Print as strings
MantisClone 0f0fe60
Fix debug logs
MantisClone 6172c07
Try resetting handlers after each test
MantisClone ffc7559
Remove debug logs. Call `resetHandlers()` afterEach test
MantisClone e45294e
feat: skip refreshing if `skipePersistence` is active
aimensahnoun 915b0a1
feat: emit confirmation on no-persist-http-data-access
aimensahnoun cf5884d
test: fix `in-memory request` tests
aimensahnoun 8f50530
test: revert test changes
aimensahnoun e2dac67
fix: fix test
aimensahnoun 55ec0b4
test: move in-memory reuqests to their own file
aimensahnoun 8027739
test: move spyPersistTransatction to before all
aimensahnoun c3b08ad
refactor: update error message to be more clear
aimensahnoun 11b3121
clarify error message
MantisClone ab44ab4
fix: skipPersistence doc
MantisClone 7b71180
test: update test with updated error message
aimensahnoun a5d9668
fix: fix typo
aimensahnoun 422e9e0
refactor: move `preparePaymentRequest` to the bottom of file
aimensahnoun 3ccf360
refactor: rename `preparePaymentRequest` and `paymentRequest`
aimensahnoun 157530f
chore: remove await from mockServer.close
aimensahnoun 487dffe
chore: add warning to useMockStorage about overriding skipPersistence
aimensahnoun File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
test: move in-memory reuqests to their own file
- Loading branch information
commit 55ec0b4077f6b4d8fbacbe4fbb98f088854c534d
There are no files selected for viewing
131 changes: 131 additions & 0 deletions
131
packages/request-client.js/test/in-memory-request.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,131 @@ | ||
| import { RequestNetwork } from '../src/index'; | ||
| import * as TestData from './data-test'; | ||
|
|
||
| import { http, HttpResponse } from 'msw'; | ||
| import { setupServer, SetupServer } from 'msw/node'; | ||
| import config from '../src/http-config-defaults'; | ||
|
|
||
| describe('handle in-memory request', () => { | ||
| let requestNetwork: RequestNetwork; | ||
| let spyPersistTransaction: jest.Mock; | ||
| let mockServer: SetupServer; | ||
|
|
||
| beforeAll(() => { | ||
| spyPersistTransaction = jest.fn(); | ||
|
|
||
| mockServer = setupServer( | ||
| http.post('*/persistTransaction', ({ request }) => { | ||
| if (!request.headers.get(config.requestClientVersionHeader)) { | ||
| throw new Error('Missing version header'); | ||
| } | ||
| return HttpResponse.json(spyPersistTransaction()); | ||
| }), | ||
| http.get('*/getTransactionsByChannelId', () => | ||
| HttpResponse.json({ | ||
| result: { transactions: [TestData.timestampedTransactionWithoutPaymentInfo] }, | ||
| }), | ||
| ), | ||
| http.post('*/ipfsAdd', () => HttpResponse.json({})), | ||
| http.get('*/getConfirmedTransaction', () => HttpResponse.json({ result: {} })), | ||
| ); | ||
| mockServer.listen({ onUnhandledRequest: 'bypass' }); | ||
|
|
||
| mockServer.events.on('request:unhandled', (error) => { | ||
| console.error('Found an unhandled %s request to %s', error.request.method, error.request.url); | ||
| }); | ||
| }); | ||
|
|
||
| beforeEach(() => { | ||
| spyPersistTransaction.mockReturnValue({}); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| mockServer.resetHandlers(); | ||
| }); | ||
|
|
||
| afterAll(async () => { | ||
| await mockServer.close(); | ||
MantisClone marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| mockServer.resetHandlers(); | ||
| }); | ||
|
|
||
| const requestCreationParams = { | ||
| paymentNetwork: TestData.declarativePaymentNetworkNoPaymentInfo, | ||
| requestInfo: TestData.parametersWithoutExtensionsData, | ||
| signer: TestData.payee.identity, | ||
| }; | ||
|
|
||
| it('creates a request without persisting it.', async () => { | ||
| requestNetwork = new RequestNetwork({ | ||
| skipPersistence: true, | ||
| signatureProvider: TestData.fakeSignatureProvider, | ||
| }); | ||
|
|
||
| const request = await requestNetwork.createRequest(requestCreationParams); | ||
|
|
||
| expect(request).toBeDefined(); | ||
| expect(request.requestId).toBeDefined(); | ||
| expect(request.inMemoryInfo).toBeDefined(); | ||
| expect(request.inMemoryInfo?.paymentRequest).toBeDefined(); | ||
| expect(request.inMemoryInfo?.topics).toBeDefined(); | ||
| expect(request.inMemoryInfo?.transactionData).toBeDefined(); | ||
| expect(spyPersistTransaction).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it('throws an error when trying to persist a request with skipPersistence as true', async () => { | ||
| requestNetwork = new RequestNetwork({ | ||
| skipPersistence: true, | ||
| signatureProvider: TestData.fakeSignatureProvider, | ||
| }); | ||
|
|
||
| const request = await requestNetwork.createRequest(requestCreationParams); | ||
|
|
||
| expect(request.inMemoryInfo).toBeDefined(); | ||
| expect(request.inMemoryInfo?.paymentRequest).toBeDefined(); | ||
| expect(request.inMemoryInfo?.topics).toBeDefined(); | ||
| expect(request.inMemoryInfo?.transactionData).toBeDefined(); | ||
| expect(request.requestId).toBeDefined(); | ||
|
|
||
| await expect(requestNetwork.persistRequest(request)).rejects.toThrow( | ||
| 'Cannot persist request when skipPersistence is enabled. Create a new instance of RequestNetwork without skipPersistence to persist the request.', | ||
| ); | ||
| }); | ||
|
|
||
| it('throw an error when trying to persist a request without inMemoryInfo', async () => { | ||
| requestNetwork = new RequestNetwork({ | ||
| signatureProvider: TestData.fakeSignatureProvider, | ||
| }); | ||
|
|
||
| const request = await requestNetwork.createRequest(requestCreationParams); | ||
| await request.waitForConfirmation(); | ||
| expect(request.inMemoryInfo).toBeNull(); | ||
|
|
||
| await expect(requestNetwork.persistRequest(request)).rejects.toThrow( | ||
| 'Cannot persist request without inMemoryInfo', | ||
| ); | ||
MantisClone marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }); | ||
|
|
||
| it('persists a previously created in-memory request', async () => { | ||
| requestNetwork = new RequestNetwork({ | ||
| skipPersistence: true, | ||
| signatureProvider: TestData.fakeSignatureProvider, | ||
| }); | ||
|
|
||
| const request = await requestNetwork.createRequest(requestCreationParams); | ||
|
|
||
| expect(request.inMemoryInfo).toBeDefined(); | ||
| expect(request.inMemoryInfo?.paymentRequest).toBeDefined(); | ||
| expect(request.inMemoryInfo?.topics).toBeDefined(); | ||
| expect(request.inMemoryInfo?.transactionData).toBeDefined(); | ||
| expect(request.requestId).toBeDefined(); | ||
|
|
||
| const newRequestNetwork = new RequestNetwork({ | ||
| signatureProvider: TestData.fakeSignatureProvider, | ||
| useMockStorage: true, | ||
| }); | ||
|
|
||
| const persistResult = await newRequestNetwork.persistRequest(request); | ||
|
|
||
| expect(persistResult).toBeDefined(); | ||
| expect(spyPersistTransaction).toHaveBeenCalled(); | ||
| }); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.