-
Notifications
You must be signed in to change notification settings - Fork 48
[Fix] tariffs undefined values #3645
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
base: dev
Are you sure you want to change the base?
Conversation
WalkthroughThe changes update the pricing page component and its tests in the tariffs admin module. The Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant PricingPageComponent
participant TariffService
User->>PricingPageComponent: Triggers getAllTariffsForService
PricingPageComponent->>TariffService: getAllTariffsForService()
TariffService-->>PricingPageComponent: Returns bags array
PricingPageComponent->>PricingPageComponent: transformBag(bag) for each bag
PricingPageComponent->>PricingPageComponent: Store transformed bags in bags array
User->>PricingPageComponent: Calls onChecked(id, event)
PricingPageComponent->>PricingPageComponent: Find bag by id
alt Bag found
PricingPageComponent->>PricingPageComponent: Update bag.limitIncluded
PricingPageComponent->>PricingPageComponent: Mark form as dirty
else Bag not found
PricingPageComponent->>PricingPageComponent: Return early
end
Poem
✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 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: 0
🧹 Nitpick comments (4)
src/app/ubs/ubs-admin/components/ubs-admin-tariffs/ubs-admin-tariffs-pricing-page/ubs-admin-tariffs-pricing-page.component.spec.ts (1)
581-596
: Add test for case when bag is not foundThe
onChecked
method now has a guard clause that returns early if the bag with the specified ID is not found, but this case isn't tested.Consider adding a test that checks the behavior when a bag ID doesn't exist:
it('onCheck should do nothing if bag with specified ID is not found', () => { const fakeBag: Bag = { id: 1, limitIncluded: false, capacity: 20, price: 100, commission: 10 }; component.bags = [fakeBag]; const nonExistentId = 999; const fakeEvent = { checked: true }; component.onChecked(nonExistentId, fakeEvent); expect(component.bags[0].limitIncluded).toEqual(false); // Should remain unchanged });src/app/ubs/ubs-admin/components/ubs-admin-tariffs/ubs-admin-tariffs-pricing-page/ubs-admin-tariffs-pricing-page.component.ts (3)
243-254
: Improved robustness in onChecked methodGood improvements to the
onChecked
method:
- Added explicit typing for the
id
parameter- Added a guard clause to prevent errors when a bag with specified ID isn't found
- The form is marked as dirty to ensure changes are properly tracked
Consider using a more specific type for the
event
parameter instead ofany
:-onChecked(id: number, event: any): void { +onChecked(id: number, event: { checked: boolean }): void {
358-366
: Good implementation of bag data normalizationThe
transformBag
method effectively normalizes bag objects by ensuring consistent field naming regardless of the input format. It handles both naming conventions (nameUk
/nameEn
vsname
/nameEng
) through fallback values.Consider adding a more specific input type and documentation for clarity:
-transformBag(bag: any): Bag { +/** + * Normalizes bag data by ensuring consistent field naming for multilingual content + * Handles both `nameUk`/`nameEn` and `name`/`nameEng` conventions + */ +transformBag(bag: Partial<Bag>): Bag {
358-379
: Consider adding a unit test for the transformBag methodWhile the component changes look good, there's no specific test for the
transformBag
method itself, which is a key part of fixing the issue with missing fields.Consider adding a dedicated unit test for this important transformation function:
it('should transform bag data correctly with various input formats', () => { // Test case 1: Input with nameUk/nameEn format const input1 = { id: 1, nameUk: 'УкрНазва', nameEn: 'EnglishName', descriptionUk: 'УкрОпис', descriptionEn: 'EnglishDescription', capacity: 20, price: 100 }; // Test case 2: Input with name/nameEng format const input2 = { id: 2, name: 'Назва', nameEng: 'Name', description: 'Опис', descriptionEng: 'Description', capacity: 30, price: 150 }; // Test case 3: Input with mixed or missing fields const input3 = { id: 3, nameUk: 'УкрНазва', nameEng: 'EngName', description: 'Опис', capacity: 40, price: 200 }; const result1 = component.transformBag(input1); const result2 = component.transformBag(input2); const result3 = component.transformBag(input3); // Verify all formats are correctly normalized expect(result1.name).toEqual('УкрНазва'); expect(result1.nameEng).toEqual('EnglishName'); expect(result1.description).toEqual('УкрОпис'); expect(result1.descriptionEng).toEqual('EnglishDescription'); expect(result2.name).toEqual('Назва'); expect(result2.nameEng).toEqual('Name'); expect(result3.name).toEqual('УкрНазва'); expect(result3.nameEng).toEqual('EngName'); expect(result3.description).toEqual('Опис'); expect(result3.descriptionEng).toBeUndefined(); });
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
src/app/ubs/ubs-admin/components/ubs-admin-tariffs/ubs-admin-tariffs-pricing-page/ubs-admin-tariffs-pricing-page.component.spec.ts
(4 hunks)src/app/ubs/ubs-admin/components/ubs-admin-tariffs/ubs-admin-tariffs-pricing-page/ubs-admin-tariffs-pricing-page.component.ts
(2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
src/app/ubs/ubs-admin/components/ubs-admin-tariffs/ubs-admin-tariffs-pricing-page/ubs-admin-tariffs-pricing-page.component.ts (2)
src/app/ubs/ubs-admin/models/tariffs.interface.ts (1)
Bag
(1-25)src/app/ubs/ubs/models/ubs.interface.ts (1)
Bag
(3-12)
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: build (18.x)
🔇 Additional comments (5)
src/app/ubs/ubs-admin/components/ubs-admin-tariffs/ubs-admin-tariffs-pricing-page/ubs-admin-tariffs-pricing-page.component.spec.ts (4)
1-1
: Angular testing utilities properly imported for async testingGood addition of
fakeAsync
andtick
utilities, which are essential for properly testing asynchronous operations in Angular components.
121-131
: Test data properly updated with complete field setThe
fakeBag
object has been updated to include the necessary fields (name
,nameEng
,description
,descriptionEng
) that align with the bag transformation implemented in the component.
543-566
: Properly structured test for asynchronous operationThe test for
getAllTariffsForService
now correctly:
- Uses
fakeAsync
andtick()
to handle async operations- Sets up a complete test response with the expected fields
- Verifies the component state after the observable completes
This ensures the transformations on the bags are properly tested.
581-596
: Testing component state rather than local variablesGood improvement to initialize the component's
bags
array with the test data and then verify the state change within the component rather than in the local variable. This better reflects how the component behaves in actual usage.src/app/ubs/ubs-admin/components/ubs-admin-tariffs/ubs-admin-tariffs-pricing-page/ubs-admin-tariffs-pricing-page.component.ts (1)
373-376
: Properly implemented bag transformation in service response handlingThe
getAllTariffsForService
method now transforms each bag from the API response to ensure consistent field naming before assigning to the component's state. This effectively addresses the issue with missing fields mentioned in the PR objectives.
|
This pull request includes:
name
,description
,nameEng
, anddescriptionEng
fields in the tariffs section by transforming the API response usingtransformBag
.getAllTariffsForService
method to apply the transformation before assigning data tobags
.Summary by CodeRabbit