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: ✨ add TaskStatusEnum #116

Merged
merged 2 commits into from
Dec 11, 2024
Merged

Conversation

zhumeisongsong
Copy link
Owner

@zhumeisongsong zhumeisongsong commented Dec 11, 2024

Related #99

Summary by CodeRabbit

  • New Features

    • Introduced a new enumeration for task statuses: TODO, IN_PROGRESS, and DONE.
    • Enhanced module interface by exporting the task-status enumeration.
  • Tests

    • Added a test suite to validate the functionality and immutability of the TaskStatus enum.

Copy link

coderabbitai bot commented Dec 11, 2024

Walkthrough

The changes introduce a new enumeration, TaskStatusEnum, defining task statuses (TODO, IN_PROGRESS, and DONE) in TypeScript. This enumeration is exported from the index.ts file, enhancing the module's interface. Additionally, a corresponding test suite is added to validate the functionality and integrity of the TaskStatus enum, ensuring it behaves as expected and remains immutable.

Changes

File Path Change Summary
libs/tasks/domain/src/index.ts Added export statement for task-status.enum: export * from './lib/value-objects/task-status.enum';
libs/tasks/domain/src/lib/value-objects/task-status.enum.ts Introduced TaskStatusEnum constant and TaskStatus type for task statuses.
libs/tasks/domain/src/lib/value-objects/task-status.enum.spec.ts Added test suite for TaskStatus enum with four test cases validating statuses and immutability.

Poem

In a burrow deep, where tasks do play,
A new enum hops in, brightening the day.
With statuses clear, like stars up above,
TODO, IN_PROGRESS, and DONE we love!
Tests now ensure they never stray,
Hooray for the changes, hip-hip-hooray! 🐇✨


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>, please review it.
    • 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @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 using 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 generate docstrings to generate docstrings for this PR. (Experiment)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

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.

Copy link

@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 and nitpick comments (3)
libs/tasks/domain/src/lib/value-objects/task-status.enum.ts (1)

1-7: Consider adding JSDoc documentation

Adding JSDoc comments would improve IDE support and make the enum's purpose clearer:

+/**
+ * Represents the possible states of a task in the system.
+ * @enum {string}
+ */
 export const TaskStatusEnum = {
   TODO: 'TODO',
   IN_PROGRESS: 'IN_PROGRESS',
   DONE: 'DONE',
 } as const;

+/** Type representing valid task status values */
 export type TaskStatus = (typeof TaskStatusEnum)[keyof typeof TaskStatusEnum];
libs/tasks/domain/src/lib/value-objects/task-status.enum.spec.ts (2)

16-19: Improve immutability test implementation

The current immutability test could be clearer and avoid the static analysis warning:

 it('should be immutable', () => {
   // @ts-expect-error - Testing immutability
-  expect(() => TaskStatus.TODO = 'SOMETHING_ELSE').toThrow();
+  const attemptMutation = () => {
+    // @ts-expect-error - Testing immutability
+    TaskStatus.TODO = 'SOMETHING_ELSE';
+  };
+  expect(attemptMutation).toThrow();
 });
🧰 Tools
🪛 Biome (1.9.4)

[error] 18-18: The assignment should not be in an expression.

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.

(lint/suspicious/noAssignInExpressions)


3-20: Consider adding type safety tests

The test suite could benefit from additional tests that verify type constraints:

it('should not allow invalid status values', () => {
  // @ts-expect-error - Testing type safety
  const invalidStatus: TaskStatus = 'INVALID_STATUS';
  
  // Verify type narrowing works
  const isValidStatus = (status: string): status is TaskStatus =>
    Object.values(TaskStatusEnum).includes(status as TaskStatus);
    
  expect(isValidStatus('INVALID_STATUS')).toBe(false);
  expect(isValidStatus(TaskStatusEnum.TODO)).toBe(true);
});
🧰 Tools
🪛 Biome (1.9.4)

[error] 18-18: The assignment should not be in an expression.

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.

(lint/suspicious/noAssignInExpressions)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 8a3b013 and 4c2737f.

📒 Files selected for processing (3)
  • libs/tasks/domain/src/index.ts (1 hunks)
  • libs/tasks/domain/src/lib/value-objects/task-status.enum.spec.ts (1 hunks)
  • libs/tasks/domain/src/lib/value-objects/task-status.enum.ts (1 hunks)
🧰 Additional context used
🪛 Biome (1.9.4)
libs/tasks/domain/src/lib/value-objects/task-status.enum.spec.ts

[error] 18-18: The assignment should not be in an expression.

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.

(lint/suspicious/noAssignInExpressions)

🔇 Additional comments (2)
libs/tasks/domain/src/index.ts (1)

4-4: LGTM! Export follows consistent pattern

The new export follows the established barrel file pattern and maintains a logical grouping with other domain exports.

libs/tasks/domain/src/lib/value-objects/task-status.enum.ts (1)

1-5: LGTM! Well-implemented immutable enum pattern

The implementation uses TypeScript's const assertion pattern correctly, ensuring type safety and immutability.

Copy link

@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 and nitpick comments (2)
libs/tasks/domain/src/lib/value-objects/task-status.enum.spec.ts (2)

4-14: Consider using test.each for more maintainable tests

While the current tests are correct, they could be more maintainable using Jest's test.each pattern. This would reduce code duplication and make it easier to add new status values in the future.

Here's a suggested refactor:

-  it('should have TODO status', () => {
-    expect(TaskStatusEnum.TODO).toBe('TODO');
-  });
-
-  it('should have IN_PROGRESS status', () => {
-    expect(TaskStatusEnum.IN_PROGRESS).toBe('IN_PROGRESS');
-  });
-
-  it('should have DONE status', () => {
-    expect(TaskStatusEnum.DONE).toBe('DONE');
-  });
+  test.each([
+    ['TODO'],
+    ['IN_PROGRESS'],
+    ['DONE'],
+  ])('should have %s status', (status) => {
+    expect(TaskStatusEnum[status]).toBe(status);
+  });

3-20: Consider adding additional test cases for better coverage

The current test suite covers the basic functionality, but consider adding these test cases for more comprehensive coverage:

  1. Type checking to ensure only valid enum values are assignable
  2. Verification that the enum doesn't contain any unexpected values

Would you like me to provide example implementations for these additional test cases?

🧰 Tools
🪛 Biome (1.9.4)

[error] 18-18: The assignment should not be in an expression.

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.

(lint/suspicious/noAssignInExpressions)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 4c2737f and cbaecea.

📒 Files selected for processing (1)
  • libs/tasks/domain/src/lib/value-objects/task-status.enum.spec.ts (1 hunks)
🧰 Additional context used
🪛 Biome (1.9.4)
libs/tasks/domain/src/lib/value-objects/task-status.enum.spec.ts

[error] 18-18: The assignment should not be in an expression.

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.

(lint/suspicious/noAssignInExpressions)

🔇 Additional comments (3)
libs/tasks/domain/src/lib/value-objects/task-status.enum.spec.ts (3)

1-1: LGTM!

The import statement correctly imports the enum under test.


3-3: LGTM!

The test suite is well-structured with a clear and descriptive name.


16-19: ⚠️ Potential issue

Fix inconsistent enum naming

There's an inconsistency in the enum naming. The import uses TaskStatusEnum but the test uses TaskStatus.

Apply this fix:

   it('should be immutable', () => {
     // @ts-expect-error - Testing immutability
-    expect(() => TaskStatus.TODO = 'SOMETHING_ELSE').toThrow();
+    expect(() => TaskStatusEnum.TODO = 'SOMETHING_ELSE').toThrow();
   });

Likely invalid or redundant comment.

🧰 Tools
🪛 Biome (1.9.4)

[error] 18-18: The assignment should not be in an expression.

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.

(lint/suspicious/noAssignInExpressions)

@zhumeisongsong zhumeisongsong merged commit 01037d4 into main Dec 11, 2024
5 checks passed
@zhumeisongsong zhumeisongsong deleted the feature/add-user-task-status branch December 11, 2024 05:33
Copy link

🎉 This PR is included in version 1.16.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant