Page MenuHomePhabricator

[Cashtab] New token url validation
AbandonedPublic

Authored by kieran709 on Dec 1 2021, 16:36.

Details

Reviewers
bytesofman
Group Reviewers
Restricted Project
Summary

Altered the isValidTokenDocumentUrl function to check for protocol, top level domain, and the presence of a '.'. Related to task T1998

Test Plan

cd web/cashtab
npm start
navigate to the createToken form
begin inputting url
ensure that if the conditions aren't met, an error message will be displayed
ensure that when the conditions are met, the error message disappears
ensure error message is adequate

Diff Detail

Repository
rABC Bitcoin ABC
Branch
token-url-validation
Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 17545
Build 34916: Build Diffcashtab-tests
Build 34915: arc lint + arc unit

Event Timeline

Failed tests logs:

====== CashTab Unit Tests: Validation utils Accepts a valid eToken token document URL ======
Error: expect(received).toBe(expected) // Object.is equality

Expected: true
Received: false
    at Object.<anonymous> (/work/web/cashtab/src/utils/__tests__/validation.test.js:192:59)
    at Object.asyncJestTest (/work/web/cashtab/node_modules/jest-jasmine2/build/jasmineAsyncInstall.js:106:37)
    at /work/web/cashtab/node_modules/jest-jasmine2/build/queueRunner.js:45:12
    at new Promise (<anonymous>)
    at mapper (/work/web/cashtab/node_modules/jest-jasmine2/build/queueRunner.js:28:19)
    at /work/web/cashtab/node_modules/jest-jasmine2/build/queueRunner.js:75:41
    at processTicksAndRejections (node:internal/process/task_queues:94:5)
====== CashTab Unit Tests: Validation utils Accepts a blank string as a valid eToken token document URL ======
Error: expect(received).toBe(expected) // Object.is equality

Expected: true
Received: false
    at Object.<anonymous> (/work/web/cashtab/src/utils/__tests__/validation.test.js:198:45)
    at Object.asyncJestTest (/work/web/cashtab/node_modules/jest-jasmine2/build/jasmineAsyncInstall.js:106:37)
    at /work/web/cashtab/node_modules/jest-jasmine2/build/queueRunner.js:45:12
    at new Promise (<anonymous>)
    at mapper (/work/web/cashtab/node_modules/jest-jasmine2/build/queueRunner.js:28:19)
    at /work/web/cashtab/node_modules/jest-jasmine2/build/queueRunner.js:75:41
    at processTicksAndRejections (node:internal/process/task_queues:94:5)
====== CashTab Unit Tests: Validation utils Rejects eToken token name if longer than 68 characters ======
Error: expect(received).toBe(expected) // Object.is equality

Expected: false
Received: true
    at Object.<anonymous> (/work/web/cashtab/src/utils/__tests__/validation.test.js:205:11)
    at Object.asyncJestTest (/work/web/cashtab/node_modules/jest-jasmine2/build/jasmineAsyncInstall.js:106:37)
    at /work/web/cashtab/node_modules/jest-jasmine2/build/queueRunner.js:45:12
    at new Promise (<anonymous>)
    at mapper (/work/web/cashtab/node_modules/jest-jasmine2/build/queueRunner.js:28:19)
    at /work/web/cashtab/node_modules/jest-jasmine2/build/queueRunner.js:75:41
    at processTicksAndRejections (node:internal/process/task_queues:94:5)

Each failure log is accessible here:
CashTab Unit Tests: Validation utils Accepts a valid eToken token document URL
CashTab Unit Tests: Validation utils Accepts a blank string as a valid eToken token document URL
CashTab Unit Tests: Validation utils Rejects eToken token name if longer than 68 characters

bytesofman requested changes to this revision.Dec 3 2021, 00:04

Function is in the right place and using the right pattern for a validation function in Cashtab, but I think over-complicated.

Try implementing this RegExp answer:

Don't forget to add some unit tests to validation.test.js (Write enough unit tests so that we know it's doing basically what we want -- try some normal urls, some weird URLs, some stuff that's definitely not a URL...mb like 5 or 6 tests).

This revision now requires changes to proceed.Dec 3 2021, 00:04

Using regex solution instead of JS
Added 6 unit tests to validation.test.js

bytesofman requested changes to this revision.Dec 8 2021, 15:42
bytesofman added inline comments.
web/cashtab/src/utils/validation.js
88

Refactor to match format of other validatioon.js functions; do not define a function within a validation function, should be simpler

This revision now requires changes to proceed.Dec 8 2021, 15:42