-
Notifications
You must be signed in to change notification settings - Fork 257
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
Feat/streams api #658
Feat/streams api #658
Conversation
add package that integrates stream API
…into feat/streams-api
🦋 Changeset detectedLatest commit: 28ee0da The changes in this PR will be included in the next version bump. This PR includes changesets to release 9 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
public add = this.endpoints.createFetcher(createStream); | ||
|
||
public update = this.endpoints.createFetcher(updateStream); | ||
|
||
public getAll = this.endpoints.createPaginatedFetcher(getStreams); | ||
|
||
public delete = this.endpoints.createFetcher(deleteStream); | ||
|
||
public setSettings = this.endpoints.createFetcher(setSettings); | ||
|
||
private _readSettings = this.endpoints.createFetcher(readSettings); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
readonly
attribute is missing.
const apiKey = req.headers.get('x-api-key'); | ||
|
||
if (apiKey !== MOCK_API_KEY) { | ||
return res(ctx.status(401)); | ||
} | ||
|
||
const value = mockCreateStreamOutput; | ||
|
||
if (!value) { | ||
return res(ctx.status(404)); | ||
} | ||
|
||
return res(ctx.status(200), ctx.json(value)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should create mocks based on a real API response. Check this file:
That allows us to create better integration tests:
const id = req.params.id as string; | ||
const apiKey = req.headers.get('x-api-key'); | ||
|
||
if (apiKey !== MOCK_API_KEY) { | ||
return res(ctx.status(401)); | ||
} | ||
|
||
const value = mockDeleteStreamOutput[id]; | ||
|
||
if (!value) { | ||
return res(ctx.status(404)); | ||
} | ||
|
||
return res( | ||
ctx.status(200), | ||
ctx.json({ | ||
chainId: value, | ||
}), | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs a real response mock.
const apiKey = req.headers.get('x-api-key'); | ||
|
||
if (apiKey !== MOCK_API_KEY) { | ||
return res(ctx.status(401)); | ||
} | ||
|
||
const value = mockGetSettingsOutput; | ||
|
||
if (!value) { | ||
return res(ctx.status(404)); | ||
} | ||
|
||
return res(ctx.status(200), ctx.json(value)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs a real response mock.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
{
"secretKey": "top_secret",
"region": "us-east-1"
}
is a real response for this endpoint
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see.
const value = mockGetSettingsOutput;
if (!value) {
This condition is always false.
const apiKey = req.headers.get('x-api-key'); | ||
|
||
if (apiKey !== MOCK_API_KEY) { | ||
return res(ctx.status(401)); | ||
} | ||
|
||
const value = mockGetStreamsOutput; | ||
|
||
if (!value) { | ||
return res(ctx.status(404)); | ||
} | ||
|
||
return res( | ||
ctx.status(200), | ||
ctx.json({ | ||
total: value, | ||
}), | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs a real response mock.
const apiKey = req.headers.get('x-api-key'); | ||
|
||
if (apiKey !== MOCK_API_KEY) { | ||
return res(ctx.status(401)); | ||
} | ||
|
||
const value = mockSetSettingsOutput; | ||
|
||
if (!value) { | ||
return res(ctx.status(404)); | ||
} | ||
|
||
return res(ctx.status(200), ctx.json(value)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs a real response mock.
const id = req.params.id as string; | ||
const apiKey = req.headers.get('x-api-key'); | ||
|
||
if (apiKey !== MOCK_API_KEY) { | ||
return res(ctx.status(401)); | ||
} | ||
|
||
const value = mockUpdateStreamOutput[id]; | ||
|
||
if (!value) { | ||
return res(ctx.status(404)); | ||
} | ||
|
||
return res( | ||
ctx.status(200), | ||
ctx.json({ | ||
chainId: value, | ||
}), | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs a real response mock.
@@ -13,6 +13,7 @@ export interface PaginatedResult<ApiResult> { | |||
page_size: number; | |||
cursor: string; | |||
result: ApiResult; | |||
data: ApiResult; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should request the API squad to normalize this property? Here should be also result
as everywhere.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, to have consistency across Moralis Apis. @ErnoW what do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is the best option. Otherwise we should modify the PaginatedEndpoint interface. The current state is wrong. We don't have result
and data
in the same type as the definition says.
packages/moralis/package.json
Outdated
"@moralisweb3/auth": "^2.2.0", | ||
"@moralisweb3/core": "^2.2.0", | ||
"@moralisweb3/api-utils": "^2.2.0", | ||
"@moralisweb3/evm-api": "^2.2.0", | ||
"@moralisweb3/evm-utils": "^2.2.0", | ||
"@moralisweb3/sol-api": "^2.2.0", | ||
"@moralisweb3/sol-utils": "^2.2.0" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an unwanted change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still I see unnecessary conditions in tests like:
const value = mockCreateStreamOutput;
if (!value) {
return res(ctx.status(404));
}
Also, we need to clarify the result/data
problem.
True. Removing unncessary condiitions now |
name: 'Pull request'
about: A new pull request
New Pull Request
Checklist
Issue Description
Related issue: #
FILL_THIS_OUT
Solution Description