CLIxIndia-Dev / CLIxIndia-Dev/MiTiRobot
Duplicated code for getting Keyboard Buttons
- Dominant language
- JavaScript
- Stars
- 0
- Forks
- 1
- PR merge metrics
- No merged PRs in 30d
Description
I see this action repeated quite a bit throughout the code:
```
for x in children:
if x.name is not None:
button_list.append(x.name)
buttons.append([KeyboardButton(text=x.name)])
```
It seems like you could make it a method on the `Element` class or just a standalone method (whichever makes more sense), to DRY up the code, and return both the `button_list` and `buttons`. I would also then suggest a set of tests against that method, to test for things like:
* Empty list of children
* Mix of children with `.name` and without `.name`
* Make sure right number of buttons come back, with the right names and object type (for `buttons`)
* Unicode values in `.name` (I assume the `name` comes from the user, and can be anything?)
* Empty name string (you may want to have form validation that prevents this?)...do you want that to show up?
* Newlines in the `name` field, or other weird space characters / tabs / etc.
* Are there any unallowable `name` characters, from Telegram's point of view (do their API docs mention any)? Should guard against those in the code (strip them out or encode them) and verify with a test
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by locating the repeated loop that reads child names and creates KeyboardButton objects, then inspect the Element class and its callers. Extract the shared behavior and add tests covering empty children, named and unnamed children, Unicode and unusual names, correct button counts, and object types; done means callers use the shared method and the tests pass.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- api, backend
- Issue type
- Refactor
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100