Skip to content
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

Merged
merged 12 commits into from
Sep 8, 2022
Merged

Feat/streams api #658

merged 12 commits into from
Sep 8, 2022

Conversation

sogunshola
Copy link
Contributor


name: 'Pull request'
about: A new pull request

New Pull Request

Checklist

  • I am not disclosing a vulnerability.
  • My code is conform the code style
  • I have made corresponding changes to the documentation
  • I have updated Typescript definitions when needed

Issue Description

Related issue: #FILL_THIS_OUT

Solution Description

add package that integrates stream API
@changeset-bot
Copy link

changeset-bot bot commented Sep 8, 2022

🦋 Changeset detected

Latest commit: 28ee0da

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 9 packages
Name Type
@moralisweb3/api-utils Minor
@moralisweb3/core Minor
moralis Minor
@moralisweb3/streams Minor
@moralisweb3/auth Minor
@moralisweb3/evm-utils Minor
@moralisweb3/sol-utils Minor
@moralisweb3/evm-api Minor
@moralisweb3/sol-api Minor

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

Comment on lines 28 to 38
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);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

readonly attribute is missing.

Comment on lines 10 to 22
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));
Copy link
Collaborator

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:

Comment on lines 9 to 27
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,
}),
);
Copy link
Collaborator

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.

Comment on lines 10 to 22
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));
Copy link
Collaborator

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.

Copy link
Contributor Author

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

Copy link
Collaborator

@b4rtaz b4rtaz Sep 8, 2022

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.

Comment on lines 7 to 24
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,
}),
);
Copy link
Collaborator

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.

Comment on lines 7 to 19
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));
Copy link
Collaborator

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.

Comment on lines 9 to 27
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,
}),
);
Copy link
Collaborator

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;
Copy link
Collaborator

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.

Copy link
Contributor Author

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?

Copy link
Collaborator

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.

Comment on lines 20 to 26
"@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"
Copy link
Collaborator

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.

Copy link
Collaborator

@b4rtaz b4rtaz left a 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.

@sogunshola
Copy link
Contributor Author

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

@sogunshola sogunshola merged commit 9cc480d into main Sep 8, 2022
@sogunshola sogunshola deleted the feat/streams-api branch September 8, 2022 13:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants