Skip to content

Add unit tests for license-uitilities.js #125

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

Closed
akmadian opened this issue Mar 5, 2020 · 16 comments · Fixed by #136
Closed

Add unit tests for license-uitilities.js #125

akmadian opened this issue Mar 5, 2020 · 16 comments · Fixed by #136
Assignees
Labels
💻 aspect: code Concerns the software code in the repository 🤖 aspect: dx Concerns developers' experience with the codebase good first issue New-contributor friendly help wanted Open to participation from the community

Comments

@akmadian
Copy link
Member

akmadian commented Mar 5, 2020

Unit tests need to be written for license-utilities.js. Unit tests are done with Jest.

Please remember to test the following things:

  • All methods, being sure to test a range of inputs for each method, including edge cases.

Additional Context

@akmadian akmadian added help wanted Open to participation from the community good first issue New-contributor friendly test-coverage labels Mar 5, 2020
@akmadian akmadian mentioned this issue Mar 5, 2020
14 tasks
@acagastya
Copy link
Contributor

Hello. Could I work on the test coverages?

@akmadian
Copy link
Member Author

akmadian commented Mar 5, 2020

Go ahead! @acagastya

@acagastya
Copy link
Contributor

@akmadian Hi. Could you please tell me how to organise the tests? In which directory am I supposed to put it under?

@akmadian
Copy link
Member Author

akmadian commented Mar 5, 2020

It should be organized similarly to how component tests are organized. Just like component unit tests go in ./tests/unit/specs/components/, unit test specs for utils should go in ./tests/unit/specs/utils/

@acagastya
Copy link
Contributor

Okay, thank you. :-)
I have already started, and I will move it to the appropriate folder now.

@acagastya
Copy link
Contributor

@akmadian While writing the tests, I just realised, the function attrToFull, which takes an object as a parameter, and outputs license string gives a wrong answer for this object: { BY: true, ND: true, SA: true }. Non-Deriv is mutually exclusive from ShareAlike. Right now, its result is Attribution-NonDerivatives 4.0 International (CC BY-ND 4.0).

Do we assume the parameters passed to the function will correspond to a valid license? Or should the function return an error?

@akmadian
Copy link
Member Author

akmadian commented Mar 5, 2020

I think it's safe to assume that the ND and SA incompatability won't be an issue, the ability to make a selection for SA is disabled when ND is selected, so it's theoretically impossible for that specific configuration to get passed in.

So, to answer your question directly, it's safe to assume that the parameters passed will correspond to a valid license.

@acagastya
Copy link
Contributor

Thank you for the swift response, @akmadian. I found another oddity.
attrToFull({ BY: undefined}) //? CC0 1.0 Universal
attrToShort({ BY: undefined}) //? undefined

Is that how they are supposed to behave?

@akmadian
Copy link
Member Author

akmadian commented Mar 6, 2020

Thanks for catching this, I would say that for now, yes, this is expected behavior. The person who wrote this code is @obulat, and she's gonna be unavailable for a while, and I'm unsure if this is expected behavior.

Let's assume that this behavior is expected for now, and we can re-examine once @obulat is back :)

@acagastya
Copy link
Contributor

acagastya commented Mar 6, 2020

Okay, point noted. And I have duly updated the tests. Thank you for letting me know. :-)

@acagastya
Copy link
Contributor

@akmadian I had been thinking of edge cases, and unsurprisingly, shortToAttr('AND')'s result is CC BY-ND, because it matches "ND". Should I assume the input to shortToAttr would always be the correct short-hand notation of the CC licenses?

@akmadian
Copy link
Member Author

akmadian commented Mar 7, 2020

Yes, I think that's safe to assume

@obulat
Copy link
Contributor

obulat commented Mar 7, 2020

attrToFull({ BY: undefined}) //? CC0 1.0 Universal
attrToShort({ BY: undefined}) //? undefined

Is that how they are supposed to behave?

Thank you for catching this issue, @acagastya !

At first, we had CC BY license set by default, and all attributes were set to false (except for BY, which was set to true) at the beginning. Then we decided not to have a default license choice, so all attributes became undefined at the start, and the function attrToShort was changed to return undefined if no selection had been made. This undefined value is actually used in the dropdown step to show placeholder value if no license had been selected.
However, I forgot to update the attrToFull.

Could you update attrToFull in accordance with attrToShort?

@acagastya
Copy link
Contributor

@obulat Sure thing, I will do that. And update the tests accordingly. Thank you for letting me know the context.

And I agree with your way of approaching this. Creative Commons licenses (especially version 4.0) are very clear about the requirements and explicitly state what is true, what is defined. If something is not defined (and marked as undefined), it is not to be treated as false. If it was false, it must be set explicitly.

@acagastya
Copy link
Contributor

Hi, I am sorry for the delay. I will be submitting the PR in a few hours.

@acagastya
Copy link
Contributor

acagastya commented Mar 14, 2020

@obulat Just a quick clarification, what should be the output of licenseIconsArr({ BY: undefined }). Should it be empty array. Or should I assume it is not possible to have that? What aboutlicenseUrl({ BY: undefined})?

@dhruvkb dhruvkb added 💻 aspect: code Concerns the software code in the repository 🤖 aspect: dx Concerns developers' experience with the codebase and removed test-coverage labels Oct 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
💻 aspect: code Concerns the software code in the repository 🤖 aspect: dx Concerns developers' experience with the codebase good first issue New-contributor friendly help wanted Open to participation from the community
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants