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

test: get user achievements function #795

Merged
merged 3 commits into from
Aug 7, 2024
Merged

Conversation

NueloSE
Copy link
Contributor

@NueloSE NueloSE commented Aug 2, 2024

test

Please add the labels corresponding to the type of changes your PR introduces:

  • Testing

Resolves: #773

Summary by CodeRabbit

  • Bug Fixes

    • Removed the getUserAchievementByCategory function, streamlining the API's approach to user achievements.
  • Tests

    • Introduced a comprehensive test suite for the getUserAchievements functionality, validating various scenarios such as successful data retrieval and handling of invalid formats.
    • Enhanced test coverage ensures the function performs correctly in different situations and edge cases.

Copy link

vercel bot commented Aug 2, 2024

@NueloSE is attempting to deploy a commit to the StarknetID Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Contributor

coderabbitai bot commented Aug 2, 2024

Walkthrough

This change introduces a robust test suite for the getUserAchievements function within the apiService module. The tests cover a variety of scenarios for fetching user achievement data, including successful retrieval, handling default values, and managing errors or unexpected formats. This implementation improves test coverage and ensures reliable performance across diverse conditions.

Changes

Files Change Summary
tests/services/apiService.test.js Added a new test suite for getUserAchievements, including test cases for successful fetches, default data, invalid formats, and null/undefined handling. The getUserAchievementByCategory function was removed from the main service, impacting its test coverage.

Assessment against linked issues

Objective Addressed Explanation
Create test cases for getUserAchievements (773)
Validate API call handling for edge cases (773)
Create test cases for getUserAchievementByCategory (773) Test cases for this function have not been added.

Possibly related issues


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@NueloSE NueloSE marked this pull request as draft August 2, 2024 16:07
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Outside diff range, codebase verification and nitpick comments (2)
tests/services/apiService.test.js (2)

3255-3255: Fix the typo in the test description.

The test description contains a typo: "retun" should be "return".

- it('should fetch and retun user achievement data', async() => {
+ it('should fetch and return user achievement data', async() => {

3527-3527: Fix the typo in the test description.

The test description contains a typo: "retun" should be "return".

- it('should fetch and retun default user achievement data', async() => {
+ it('should fetch and return default user achievement data', async() => {
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between e2e7bb6 and 762e1e3.

Files selected for processing (1)
  • tests/services/apiService.test.js (2 hunks)
Additional comments not posted (2)
tests/services/apiService.test.js (2)

3798-3810: LGTM!

The test case correctly handles and returns data in an invalid format.


3812-3824: LGTM!

The test case correctly handles null and undefined cases.

@NueloSE
Copy link
Contributor Author

NueloSE commented Aug 5, 2024

Hello @fricoben i have been unable to make any calls to the api for getUserAchievementByCategory. Can i get some aassistance on this??
This is the current forma I am using "https://sepolia.api.starknet.quest/achievements/Argent Explorer NFT?addr=0&category_id=1" and i get a 404 error

@fricoben
Copy link
Contributor

fricoben commented Aug 6, 2024

Hello @fricoben i have been unable to make any calls to the api for getUserAchievementByCategory. Can i get some aassistance on this?? This is the current forma I am using "https://sepolia.api.starknet.quest/achievements/Argent Explorer NFT?addr=0&category_id=1" and i get a 404 error

checking with the back-end team and I'll comeback to you

@fricoben
Copy link
Contributor

fricoben commented Aug 6, 2024

Hello @fricoben i have been unable to make any calls to the api for getUserAchievementByCategory. Can i get some aassistance on this?? This is the current forma I am using "https://sepolia.api.starknet.quest/achievements/Argent Explorer NFT?addr=0&category_id=1" and i get a 404 error

As said on Telegram, the getUserAchievementByCategory function doesn't work anymore so you can delete it from the test and from the code (we don't use it anywhere)

@fricoben fricoben added the ❌ Change request Change requested from reviewer label Aug 6, 2024
@NueloSE NueloSE marked this pull request as ready for review August 6, 2024 15:13
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Outside diff range, codebase verification and nitpick comments (29)
services/apiService.ts (29)

Line range hint 1-9:
Ensure proper error handling for API calls.

The functions fetchLeaderboardToppers and fetchLeaderboardRankings log errors but do not handle them effectively. Consider returning an appropriate error response or throwing an error.

- console.log("Error while fetching leaderboard position", err);
+ throw new Error("Error while fetching leaderboard position: " + err.message);

- console.log("Error while fetching leaderboard ranks", err);
+ throw new Error("Error while fetching leaderboard ranks: " + err.message);

Line range hint 11-13:
Ensure proper error handling for API calls.

The function getBoosts logs errors but does not handle them effectively. Consider returning an appropriate error response or throwing an error.

- console.log("Error while fetching boosts", err);
+ throw new Error("Error while fetching boosts: " + err.message);

Line range hint 15-17:
Ensure proper error handling for API calls.

The function getQuestsInBoost logs errors but does not handle them effectively. Consider returning an appropriate error response or throwing an error.

- console.log("Error while fetching quests in boost", err);
+ throw new Error("Error while fetching quests in boost: " + err.message);

Line range hint 19-21:
Ensure proper error handling for API calls.

The function getBoostById logs errors but does not handle them effectively. Consider returning an appropriate error response or throwing an error.

- console.log("Error while fetching boost data", err);
+ throw new Error("Error while fetching boost data: " + err.message);

Line range hint 23-27:
Ensure proper error handling for API calls.

The function getQuestParticipants logs errors but does not handle them effectively. Consider returning an appropriate error response or throwing an error.

- console.log("Error while fetching total participants", err);
+ throw new Error("Error while fetching total participants: " + err.message);

Line range hint 29-31:
Ensure proper error handling for API calls.

The function getQuestBoostClaimParams logs errors but does not handle them effectively. Consider returning an appropriate error response or throwing an error.

- console.log("Error while fetching claim signature", err);
+ throw new Error("Error while fetching claim signature: " + err.message);

Line range hint 33-35:
Ensure proper error handling for API calls.

The function getPendingBoostClaims logs errors but does not handle them effectively. Consider returning an appropriate error response or throwing an error.

- console.log("Error while fetching pending claims", err);
+ throw new Error("Error while fetching pending claims: " + err.message);

Line range hint 37-41:
Ensure proper error handling for API calls.

The function getCompletedBoosts logs errors but does not handle them effectively. Consider returning an appropriate error response or throwing an error.

- console.log("Error while fetching completed boosts", err);
+ throw new Error("Error while fetching completed boosts: " + err.message);

Line range hint 43-45:
Ensure proper error handling for API calls.

The function getQuests logs errors but does not handle them effectively. Consider returning an appropriate error response or throwing an error.

- console.log("Error while fetching trending quests", err);
+ throw new Error("Error while fetching trending quests: " + err.message);

Line range hint 47-53:
Ensure proper error handling for API calls.

The function getTrendingQuests logs errors but does not handle them effectively. Consider returning an appropriate error response or throwing an error.

- console.log("Error while fetching trending quests", err);
+ throw new Error("Error while fetching trending quests: " + err.message);

Line range hint 55-57:
Ensure proper error handling for API calls.

The function getCompletedQuests logs errors but does not handle them effectively. Consider returning an appropriate error response or throwing an error.

- console.log("Error while fetching completed quests", err);
+ throw new Error("Error while fetching completed quests: " + err.message);

Line range hint 59-61:
Ensure proper error handling for API calls.

The function getBoostedQuests logs errors but does not handle them effectively. Consider returning an appropriate error response or throwing an error.

- console.log("Error while getting boosted quests", err);
+ throw new Error("Error while getting boosted quests: " + err.message);

Line range hint 63-65:
Ensure proper error handling for API calls.

The function getUserAchievements logs errors but does not handle them effectively. Consider returning an appropriate error response or throwing an error.

- console.log("Error while fetching user achievements", err);
+ throw new Error("Error while fetching user achievements: " + err.message);

Line range hint 67-73:
Ensure proper error handling for API calls.

The function verifyUserAchievement logs errors but does not handle them effectively. Consider returning an appropriate error response or throwing an error.

- console.log("Error while verifying user achievement by category", err);
+ throw new Error("Error while verifying user achievement by category: " + err.message);

Line range hint 75-77:
Ensure proper error handling for API calls.

The function fetchBuildings logs errors but does not handle them effectively. Consider returning an appropriate error response or throwing an error.

- console.log("Error while fetching buildings data", err);
+ throw new Error("Error while fetching buildings data: " + err.message);

Line range hint 79-85:
Ensure proper error handling for API calls.

The function getQuizById logs errors but does not handle them effectively. Consider returning an appropriate error response or throwing an error.

- console.log("Error while fetching quiz data by Id", err);
+ throw new Error("Error while fetching quiz data by Id: " + err.message);

Line range hint 87-91:
Ensure proper error handling for API calls.

The function getTasksByQuestId logs errors but does not handle them effectively. Consider returning an appropriate error response or throwing an error.

- console.log("Error while fetching tasks by quest Id", err);
+ throw new Error("Error while fetching tasks by quest Id: " + err.message);

Line range hint 93-95:
Ensure proper error handling for API calls.

The function getDeployedTimeByAddress logs errors but does not handle them effectively. Consider returning an appropriate error response or throwing an error.

- console.log("Error while fetching deployed time by address", err);
+ throw new Error("Error while fetching deployed time by address: " + err.message);

Line range hint 97-101:
Ensure proper error handling for API calls.

The function getEligibleRewards logs errors but does not handle them effectively. Consider returning an appropriate error response or throwing an error.

- console.log("Error while fetching eligible rewards", err);
+ throw new Error("Error while fetching eligible rewards: " + err.message);

Line range hint 103-105:
Ensure proper error handling for API calls.

The function getQuestActivityData logs errors but does not handle them effectively. Consider returning an appropriate error response or throwing an error.

- console.log("Error while fetching quest data", err);
+ throw new Error("Error while fetching quest data: " + err.message);

Line range hint 107-111:
Ensure proper error handling for API calls.

The function getQuestsParticipation logs errors but does not handle them effectively. Consider returning an appropriate error response or throwing an error.

- console.log("Error while fetching quest participation", err);
+ throw new Error("Error while fetching quest participation: " + err.message);

Line range hint 113-115:
Ensure proper error handling for API calls.

The function getUniqueVisitorCount logs errors but does not handle them effectively. Consider returning an appropriate error response or throwing an error.

- console.log("Error while fetching unique visitor count", err);
+ throw new Error("Error while fetching unique visitor count: " + err.message);

Line range hint 117-123:
Ensure proper error handling for API calls.

The function getQuestById logs errors but does not handle them effectively. Consider returning an appropriate error response or throwing an error.

- console.log("Error parsing quest data:", error);
+ throw new Error("Error parsing quest data: " + error.message);

Line range hint 125-131:
Ensure proper error handling for API calls.

The function fetchQuestCategoryData logs errors but does not handle them effectively. Consider returning an appropriate error response or throwing an error.

- console.log("Error parsing quest data:", error);
+ throw new Error("Error parsing quest data: " + error.message);

Line range hint 133-135:
Ensure proper error handling for API calls.

The function updateUniqueVisitors logs errors but does not handle them effectively. Consider returning an appropriate error response or throwing an error.

- console.log("Error while fetching unique visitor count", err);
+ throw new Error("Error while fetching unique visitor count: " + err.message);

Line range hint 137-141:
Ensure proper error handling for API calls.

The function getDerivatesStats logs errors but does not handle them effectively. Consider returning an appropriate error response or throwing an error.

- console.log("Error while fetching derivatives stats", err);
+ throw new Error("Error while fetching derivatives stats: " + err.message);

Line range hint 143-147:
Ensure proper error handling for API calls.

The function getLendingStats logs errors but does not handle them effectively. Consider returning an appropriate error response or throwing an error.

- console.log("Error while fetching lending stats", err);
+ throw new Error("Error while fetching lending stats: " + err.message);

Line range hint 149-153:
Ensure proper error handling for API calls.

The function getPairingStats logs errors but does not handle them effectively. Consider returning an appropriate error response or throwing an error.

- console.log("Error while fetching pairing stats", err);
+ throw new Error("Error while fetching pairing stats: " + err.message);

Line range hint 155-159:
Ensure proper error handling for API calls.

The function getAltProtocolStats logs errors but does not handle them effectively. Consider returning an appropriate error response or throwing an error.

- console.log("Error while fetching alt protocol stats", err);
+ throw new Error("Error while fetching alt protocol stats: " + err.message);
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 762e1e3 and 962720d.

Files selected for processing (2)
  • services/apiService.ts (1 hunks)
  • tests/services/apiService.test.js (4 hunks)
Files skipped from review as they are similar to previous changes (1)
  • tests/services/apiService.test.js

Copy link
Contributor

@fricoben fricoben left a comment

Choose a reason for hiding this comment

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

lgtm

@fricoben fricoben merged commit c1acbf4 into lfglabs-dev:testnet Aug 7, 2024
1 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
❌ Change request Change requested from reviewer
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Testing Functions in @services/apiService 1
2 participants