-
Notifications
You must be signed in to change notification settings - Fork 260
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: update streams to reflect api changes
- Loading branch information
Showing
15 changed files
with
308 additions
and
107 deletions.
There are no files selected for viewing
This file contains 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,5 @@ | ||
--- | ||
'@moralisweb3/streams': patch | ||
--- | ||
|
||
Update types and endpoints for Moralis.Streams to reflect the api changes. Some types have changes, `Moralis.Streams.retry` now accepts an id and is fixed. And return types from webhooks have been updated. |
This file contains 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,35 @@ | ||
import { MockScenarios } from '../../MockScenarios'; | ||
import { createPaginatedWebhookResponse } from './response/webhookResponse'; | ||
|
||
export const mockGetHistory = MockScenarios.create( | ||
{ | ||
method: 'get', | ||
name: 'mockGetHistory', | ||
url: `/history`, | ||
getParams: (req) => ({ | ||
limit: req.url.searchParams.get('limit'), | ||
cursor: req.url.searchParams.get('cursor'), | ||
}), | ||
}, | ||
[ | ||
{ | ||
condition: { | ||
limit: '20', | ||
}, | ||
response: createPaginatedWebhookResponse(Array(20).fill('id-1'), 20), | ||
}, | ||
{ | ||
condition: { | ||
limit: '5', | ||
}, | ||
response: createPaginatedWebhookResponse(Array(5).fill('id-2'), 20, 'cursor'), | ||
}, | ||
{ | ||
condition: { | ||
limit: '5', | ||
cursor: 'cursor', | ||
}, | ||
response: createPaginatedWebhookResponse(Array(5).fill('id-3'), 20, 'cursor-2'), | ||
}, | ||
], | ||
); |
32 changes: 32 additions & 0 deletions
32
packages/integration/mockRequests/streamApi/replayHistory.ts
This file contains 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,32 @@ | ||
import { MockScenarios } from '../../MockScenarios'; | ||
import { createErrorResponse } from './response/errorResponse'; | ||
import { createWebhookResponse } from './response/webhookResponse'; | ||
|
||
export const mockReplayHistory = MockScenarios.create( | ||
{ | ||
method: 'post', | ||
name: 'mockReplayHistory', | ||
url: `/history/replay/:streamId/:id`, | ||
getParams: (req) => ({ | ||
streamId: req.params.streamId, | ||
id: req.params.id, | ||
}), | ||
}, | ||
[ | ||
{ | ||
condition: { | ||
id: 'id-1', | ||
streamId: 'stream-1', | ||
}, | ||
response: createWebhookResponse('stream-1'), | ||
}, | ||
{ | ||
condition: { | ||
id: 'not-found', | ||
streamId: 'stream-1', | ||
}, | ||
responseStatus: 404, | ||
response: createErrorResponse('History not found'), | ||
}, | ||
], | ||
); |
82 changes: 82 additions & 0 deletions
82
packages/integration/mockRequests/streamApi/response/webhookResponse.ts
This file contains 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,82 @@ | ||
const defaultWebhookResponse = { | ||
id: 'string', | ||
date: '2022-10-12T09:23:13.895Z', | ||
payload: { | ||
block: { | ||
number: 'string', | ||
hash: 'string', | ||
timestamp: 'string', | ||
}, | ||
chainId: 'string', | ||
logs: [ | ||
{ | ||
logIndex: 'string', | ||
transactionHash: 'string', | ||
address: 'string', | ||
data: 'string', | ||
topic0: 'string', | ||
topic1: 'string', | ||
topic2: 'string', | ||
topic3: 'string', | ||
}, | ||
], | ||
txs: [ | ||
{ | ||
hash: 'string', | ||
gas: 'string', | ||
gasPrice: 'string', | ||
nonce: 'string', | ||
input: 'string', | ||
transactionIndex: 'string', | ||
fromAddress: 'string', | ||
toAddress: 'string', | ||
value: 'string', | ||
type: 'string', | ||
v: 'string', | ||
r: 'string', | ||
s: 'string', | ||
receiptCumulativeGasUsed: 'string', | ||
receiptGasUsed: 'string', | ||
receiptContractAddress: 'string', | ||
receiptRoot: 'string', | ||
receiptStatus: 'string', | ||
}, | ||
], | ||
txsInternal: [ | ||
{ | ||
from: 'string', | ||
to: 'string', | ||
value: 'string', | ||
transactionHash: 'string', | ||
gas: 'string', | ||
}, | ||
], | ||
abi: [{}], | ||
retries: 0, | ||
confirmed: true, | ||
tag: 'string', | ||
streamId: 'string', | ||
}, | ||
tinyPayload: { | ||
chainId: 'string', | ||
confirmed: true, | ||
block: 'string', | ||
records: 0, | ||
retries: 0, | ||
}, | ||
errorMessage: 'string', | ||
webhookUrl: 'string', | ||
streamId: 'string', | ||
tag: 'string', | ||
}; | ||
|
||
export const createWebhookResponse = (id: string) => ({ | ||
...defaultWebhookResponse, | ||
id, | ||
}); | ||
|
||
export const createPaginatedWebhookResponse = (ids: string[], total: number, cursor?: string) => ({ | ||
result: ids.map((id) => ({ ...defaultWebhookResponse, id })), | ||
total, | ||
cursor, | ||
}); |
This file contains 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
This file contains 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,57 @@ | ||
import { MoralisStreams } from '@moralisweb3/streams'; | ||
import { cleanStreamsApi, setupStreamApi } from './setup'; | ||
|
||
describe('getHistory', () => { | ||
let StreamApi: MoralisStreams; | ||
|
||
beforeAll(() => { | ||
StreamApi = setupStreamApi(); | ||
}); | ||
|
||
afterAll(() => { | ||
cleanStreamsApi(); | ||
}); | ||
|
||
it('should get all streams', async () => { | ||
const result = await StreamApi.getHistory({ | ||
limit: 20, | ||
}); | ||
|
||
expect(result).toBeDefined(); | ||
expect(result.result).toBeDefined(); | ||
expect(result.pagination.total).toEqual(20); | ||
expect(result.result.length).toEqual(20); | ||
expect(result.result[0].id).toEqual('id-1'); | ||
}); | ||
|
||
it('should get a cursor', async () => { | ||
const result = await StreamApi.getHistory({ | ||
limit: 5, | ||
}); | ||
|
||
expect(result).toBeDefined(); | ||
expect(result.result).toBeDefined(); | ||
expect(result.pagination.total).toEqual(20); | ||
expect(result.result.length).toEqual(5); | ||
expect(result.result[0].id).toEqual('id-2'); | ||
expect(result.pagination.cursor).toEqual('cursor'); | ||
expect(result.next).toBeDefined(); | ||
expect(result.hasNext).toBeTruthy(); | ||
}); | ||
|
||
it('should use a provided cursor', async () => { | ||
const result = await StreamApi.getHistory({ | ||
limit: 5, | ||
cursor: 'cursor', | ||
}); | ||
|
||
expect(result).toBeDefined(); | ||
expect(result.result).toBeDefined(); | ||
expect(result.pagination.total).toEqual(20); | ||
expect(result.result.length).toEqual(5); | ||
expect(result.result[0].id).toEqual('id-3'); | ||
expect(result.pagination.cursor).toEqual('cursor-2'); | ||
expect(result.next).toBeDefined(); | ||
expect(result.hasNext).toBeTruthy(); | ||
}); | ||
}); |
This file contains 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,35 @@ | ||
import { MoralisStreams } from '@moralisweb3/streams'; | ||
import { cleanStreamsApi, setupStreamApi } from './setup'; | ||
|
||
describe('replayHistory', () => { | ||
let StreamApi: MoralisStreams; | ||
|
||
beforeAll(() => { | ||
StreamApi = setupStreamApi(); | ||
}); | ||
|
||
afterAll(() => { | ||
cleanStreamsApi(); | ||
}); | ||
|
||
describe('evm', () => { | ||
it('should trigger replay history succesfully', async () => { | ||
const result = await StreamApi.retry({ | ||
id: 'id-1', | ||
streamId: 'stream-1', | ||
}); | ||
|
||
expect(result).toBeDefined(); | ||
expect(result.result.id).toBe('stream-1'); | ||
}); | ||
|
||
it('should throw an error when no history is found', async () => { | ||
expect( | ||
StreamApi.retry({ | ||
id: 'not-found', | ||
streamId: 'stream-1', | ||
}), | ||
).rejects.toThrowError('[C0006] Request failed, Not Found(404): History not found'); | ||
}); | ||
}); | ||
}); |
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.