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

Fix importing a DiceRoll with group rolls, modify test to cover #243

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

aarku
Copy link

@aarku aarku commented Feb 18, 2022

If you export a DiceRoll with roll groups, like with notation {d20} and then import the result, you will get an error TypeError: value must be one of ResultGroup, RollResults, string, or number.

This PR solves it by modifying ResultGroup.addResult to accept a POJO, doing some very rudimentary validation, and instantiate the rich classes.

Full JSON validation on import might be nice, but it would bloat the library. Perhaps it could be separated out into multiple packages, (Core, Import?) but that's quite an undertaking.

I also made a small repo that shows the bug: https://github.com/aarku/rpg-dice-roller-import-bug/blob/main/index.js

For testing, I decided to simply make the notation that gets exported/imported contain {}.

Hope it helps
-Jon

@aarku aarku requested a review from GreenImp as a code owner February 18, 2022 21:24
@@ -753,7 +753,7 @@ describe('DiceRoll', () => {
let diceRoll;

beforeEach(() => {
diceRoll = new DiceRoll('4d6/7+2d10dl1');
diceRoll = new DiceRoll('{4d6/7+2d10dl1}');
Copy link
Collaborator

Choose a reason for hiding this comment

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

Would you mind reverting this, and creating a separate test for the roll group syntax?
Got to make sure that the other syntax still works, and that the group roll syntax works / throws the correct errors 😄

@GreenImp GreenImp force-pushed the develop branch 3 times, most recently from 4ff7fb9 to 03379d6 Compare May 12, 2023 00:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants