-
Notifications
You must be signed in to change notification settings - Fork 0
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: ✨ WellbeingPromptEntity and DailyPromptRecordEntity #23
Conversation
Caution Review failedThe pull request is closed. WalkthroughThis pull request introduces new components and configurations for two libraries: Changes
Possibly related PRs
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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.
Actionable comments posted: 2
🧹 Outside diff range and nitpick comments (6)
libs/prompt/domain/daily-prompt-record-entity/src/lib/daily-prompt-record-entity.ts (1)
1-7
: Add JSDoc documentation for better maintainabilityPlease add documentation to explain the purpose of this entity and its properties. This will help other developers understand how to use this interface correctly.
+/** + * Represents a daily prompt record for a user. + */ export interface DailyPromptRecordEntity { + /** Unique identifier for the prompt record */ id: string; + /** Reference to the associated prompt */ promptId: string; + /** Reference to the user who received this prompt */ userId: string; + /** Timestamp when the prompt record was created */ createdAt: Date; + /** Timestamp when the user completed the prompt */ completedAt?: Date; }libs/prompt/domain/wellbeing-prompt-entity/src/lib/wellbeing-prompt-entity.ts (2)
1-10
: Export and organize WellbeingCategory typeThe type definition looks good, but consider these improvements:
- Add export statement to make it reusable
- Consider organizing categories alphabetically for better maintenance
-type WellbeingCategory = +export type WellbeingCategory = - | 'physical' - | 'mental' - | 'social' - | 'emotional' - | 'mindfulness' - | 'productivity' - | 'self-care' - | 'gratitude' - | 'creativity'; + | 'creativity' + | 'emotional' + | 'gratitude' + | 'mental' + | 'mindfulness' + | 'physical' + | 'productivity' + | 'self-care' + | 'social';
12-17
: Add documentation and consider validation constraintsThe interface structure is good, but could benefit from:
- JSDoc documentation explaining the entity's purpose and properties
- Consider adding validation constraints using decorators if you're using class-validator
+/** + * Represents a wellbeing prompt entity that contains content and categorization + * for various aspects of personal wellbeing. + */ export interface WellbeingPromptEntity { + /** Unique identifier for the prompt */ id: string; + /** The actual prompt text content */ content: string; + /** Category classifying the type of wellbeing this prompt addresses */ category: WellbeingCategory; + /** Timestamp when this prompt was created */ createdAt: Date; }If you're using class-validator, consider implementing this as a class with validation:
import { IsDate, IsEnum, IsString, IsUUID, MinLength } from 'class-validator'; export class WellbeingPromptEntity { @IsUUID() id: string; @IsString() @MinLength(1) content: string; @IsEnum(WellbeingCategory) category: WellbeingCategory; @IsDate() createdAt: Date; }libs/prompt/domain/wellbeing-prompt-entity/src/lib/wellbeing-prompt-entity.spec.ts (1)
1-1
: Consider using type import for WellbeingPromptEntitySince
WellbeingPromptEntity
appears to be a type/interface, consider using a type import for better clarity and tree-shaking.-import { WellbeingPromptEntity } from './wellbeing-prompt-entity'; +import type { WellbeingPromptEntity } from './wellbeing-prompt-entity';libs/prompt/domain/daily-prompt-record-entity/src/lib/daily-prompt-record-entity.spec.ts (2)
4-18
: Consider enhancing property validation tests.While the basic property checks are good, consider these improvements:
- Add validation for required vs optional properties
- Extract test data to reduce duplication
- Use more efficient property validation
Consider this refactor:
+const createTestRecord = () => ({ + id: '1', + promptId: 'prompt1', + userId: 'user1', + createdAt: new Date(), + completedAt: new Date(), +}); it('should have all required properties', () => { - const record: DailyPromptRecordEntity = { - id: '1', - promptId: 'prompt1', - userId: 'user1', - createdAt: new Date(), - completedAt: new Date(), - }; + const record = createTestRecord(); + const requiredProps = ['id', 'promptId', 'userId', 'createdAt', 'completedAt']; - expect(record).toHaveProperty('id'); - expect(record).toHaveProperty('promptId'); - expect(record).toHaveProperty('userId'); - expect(record).toHaveProperty('createdAt'); - expect(record).toHaveProperty('completedAt'); + requiredProps.forEach(prop => { + expect(record).toHaveProperty(prop); + expect(record[prop]).not.toBeNull(); + expect(record[prop]).not.toBeUndefined(); + }); });
20-34
: Enhance type validation with edge cases and format checks.The type checks are good, but consider adding:
- Edge case testing (null, undefined)
- Format validation for IDs (e.g., UUID)
- Date range constraints
Consider this enhancement:
it('should have correct types for properties', () => { - const record: DailyPromptRecordEntity = { - id: '1', - promptId: 'prompt1', - userId: 'user1', - createdAt: new Date(), - completedAt: new Date(), - }; + const record = createTestRecord(); expect(typeof record.id).toBe('string'); + expect(record.id).toMatch(/^[0-9a-f-]+$/); // UUID format expect(typeof record.promptId).toBe('string'); expect(typeof record.userId).toBe('string'); expect(record.createdAt).toBeInstanceOf(Date); expect(record.completedAt).toBeInstanceOf(Date); + expect(record.completedAt.getTime()).toBeGreaterThanOrEqual(record.createdAt.getTime()); }); +it('should validate date constraints', () => { + const record = createTestRecord(); + const futureDate = new Date(); + futureDate.setFullYear(futureDate.getFullYear() + 1); + + expect(() => ({ + ...record, + completedAt: futureDate + })).toThrow(); // Assuming there's validation in the entity +});
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (21)
libs/prompt/domain/daily-prompt-record-entity/README.md
(1 hunks)libs/prompt/domain/daily-prompt-record-entity/eslint.config.js
(1 hunks)libs/prompt/domain/daily-prompt-record-entity/jest.config.ts
(1 hunks)libs/prompt/domain/daily-prompt-record-entity/project.json
(1 hunks)libs/prompt/domain/daily-prompt-record-entity/src/index.ts
(1 hunks)libs/prompt/domain/daily-prompt-record-entity/src/lib/daily-prompt-record-entity.spec.ts
(1 hunks)libs/prompt/domain/daily-prompt-record-entity/src/lib/daily-prompt-record-entity.ts
(1 hunks)libs/prompt/domain/daily-prompt-record-entity/tsconfig.json
(1 hunks)libs/prompt/domain/daily-prompt-record-entity/tsconfig.lib.json
(1 hunks)libs/prompt/domain/daily-prompt-record-entity/tsconfig.spec.json
(1 hunks)libs/prompt/domain/wellbeing-prompt-entity/README.md
(1 hunks)libs/prompt/domain/wellbeing-prompt-entity/eslint.config.js
(1 hunks)libs/prompt/domain/wellbeing-prompt-entity/jest.config.ts
(1 hunks)libs/prompt/domain/wellbeing-prompt-entity/project.json
(1 hunks)libs/prompt/domain/wellbeing-prompt-entity/src/index.ts
(1 hunks)libs/prompt/domain/wellbeing-prompt-entity/src/lib/wellbeing-prompt-entity.spec.ts
(1 hunks)libs/prompt/domain/wellbeing-prompt-entity/src/lib/wellbeing-prompt-entity.ts
(1 hunks)libs/prompt/domain/wellbeing-prompt-entity/tsconfig.json
(1 hunks)libs/prompt/domain/wellbeing-prompt-entity/tsconfig.lib.json
(1 hunks)libs/prompt/domain/wellbeing-prompt-entity/tsconfig.spec.json
(1 hunks)tsconfig.base.json
(1 hunks)
✅ Files skipped from review due to trivial changes (16)
- libs/prompt/domain/daily-prompt-record-entity/README.md
- libs/prompt/domain/daily-prompt-record-entity/eslint.config.js
- libs/prompt/domain/daily-prompt-record-entity/jest.config.ts
- libs/prompt/domain/daily-prompt-record-entity/project.json
- libs/prompt/domain/daily-prompt-record-entity/src/index.ts
- libs/prompt/domain/daily-prompt-record-entity/tsconfig.json
- libs/prompt/domain/daily-prompt-record-entity/tsconfig.lib.json
- libs/prompt/domain/daily-prompt-record-entity/tsconfig.spec.json
- libs/prompt/domain/wellbeing-prompt-entity/README.md
- libs/prompt/domain/wellbeing-prompt-entity/eslint.config.js
- libs/prompt/domain/wellbeing-prompt-entity/jest.config.ts
- libs/prompt/domain/wellbeing-prompt-entity/project.json
- libs/prompt/domain/wellbeing-prompt-entity/src/index.ts
- libs/prompt/domain/wellbeing-prompt-entity/tsconfig.json
- libs/prompt/domain/wellbeing-prompt-entity/tsconfig.lib.json
- libs/prompt/domain/wellbeing-prompt-entity/tsconfig.spec.json
🔇 Additional comments (6)
libs/prompt/domain/wellbeing-prompt-entity/src/lib/wellbeing-prompt-entity.ts (1)
1-17
: Verify consistency with other domain entities
Let's ensure this implementation follows the same patterns as other domain entities in the codebase.
✅ Verification successful
Implementation is consistent with domain patterns
The WellbeingPromptEntity
follows the same patterns as other domain entities in the codebase:
- Uses interface-based entity definition like
DailyPromptRecordEntity
- Follows consistent naming convention with
-entity
suffix - Has similar basic properties structure including
id
and timestamps - Neither entity uses class-validator decorators, maintaining consistency
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Check patterns used in other domain entities
# Find all domain entity files
echo "Looking for other domain entities..."
fd -e ts -p "domain/.+entity\.ts$"
# Check for validation patterns
echo -e "\nChecking validation patterns..."
rg -l "class-validator" "libs/*/domain"
# Check documentation patterns
echo -e "\nChecking documentation patterns..."
rg "export (interface|class|type)" -A 3 "libs/*/domain"
Length of output: 651
Script:
#!/bin/bash
# Let's examine the daily prompt record entity and compare patterns
cat libs/prompt/domain/daily-prompt-record-entity/src/lib/daily-prompt-record-entity.ts
# Also check for any other interfaces/types in the domain
rg "export (interface|class|type)" -A 3 "libs/prompt/domain/"
# Look for any validation decorators or patterns
rg "class-validator" "libs/prompt/domain/"
Length of output: 1179
tsconfig.base.json (2)
21-25
: LGTM! Path mappings follow consistent structure.
The new path mappings for prompt entities follow the established pattern and are well-organized under the prompt domain.
21-25
: Verify the existence of referenced paths and index files.
Let's ensure the new module paths and their index files are properly set up.
✅ Verification successful
All paths and index files are properly set up
The verification confirms:
- Both directories exist:
daily-prompt-record-entity
andwellbeing-prompt-entity
- Both index files exist and properly export their respective entities
- The exports follow the expected pattern of exporting from their
lib
directories
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Verify the existence of new module paths and their index files
# Check if the directories exist
echo "Checking directories..."
for dir in "libs/prompt/domain/daily-prompt-record-entity" "libs/prompt/domain/wellbeing-prompt-entity"; do
if [ -d "$dir" ]; then
echo "✓ Directory exists: $dir"
else
echo "✗ Missing directory: $dir"
fi
done
# Check if the index files exist and export entities
echo -e "\nChecking index files..."
for file in "libs/prompt/domain/daily-prompt-record-entity/src/index.ts" "libs/prompt/domain/wellbeing-prompt-entity/src/index.ts"; do
if [ -f "$file" ]; then
echo "✓ Index file exists: $file"
echo "Contents of $file:"
cat "$file"
else
echo "✗ Missing index file: $file"
fi
done
Length of output: 1985
libs/prompt/domain/wellbeing-prompt-entity/src/lib/wellbeing-prompt-entity.spec.ts (1)
19-30
:
Fix critical issues in error testing
The current error test has several issues:
- Creating an invalid object with type assertion doesn't trigger runtime validation
- The function doesn't actually throw an error
- The test doesn't verify specific error type or message
Here's a suggested fix:
it('should throw an error if category is invalid', () => {
expect(() => {
// Assuming there's a constructor or factory method
new WellbeingPromptEntity({
id: '2',
content: 'Meditate for 10 minutes.',
category: 'invalid-category',
createdAt: new Date(),
});
}).toThrow('Invalid category. Expected one of: [list of valid categories]');
});
Let's verify if there's a validation mechanism in the entity:
libs/prompt/domain/daily-prompt-record-entity/src/lib/daily-prompt-record-entity.spec.ts (2)
1-3
: LGTM! Clean import and well-structured test suite.
The import statement correctly uses the type
keyword for TypeScript, and the test suite follows Jest naming conventions.
1-35
: Consider adding test cases for error scenarios and business rules.
The test suite would benefit from additional test cases:
- Error scenarios (invalid data)
- Business rule validations (if any)
- Integration with related entities (if applicable)
Let's check for any business rules in the implementation:
Consider organizing tests into logical groups using describe
blocks for different aspects (validation, business rules, error cases).
libs/prompt/domain/daily-prompt-record-entity/src/lib/daily-prompt-record-entity.ts
Outdated
Show resolved
Hide resolved
libs/prompt/domain/wellbeing-prompt-entity/src/lib/wellbeing-prompt-entity.spec.ts
Show resolved
Hide resolved
🎉 This PR is included in version 1.0.0 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
related #22
Summary by CodeRabbit
Release Notes
New Features
DailyPromptRecordEntity
andWellbeingPromptEntity
interfaces for structured data representation.daily-prompt-record-entity
andwellbeing-prompt-entity
libraries, providing usage instructions.Configuration Changes
@prompt/daily-prompt-record-entity
and@prompt/wellbeing-prompt-entity
.Documentation
Bug Fixes
DailyPromptRecordEntity
andWellbeingPromptEntity
test suites.