Skip to content

Commit

Permalink
add test for encode/decode
Browse files Browse the repository at this point in the history
  • Loading branch information
Corbin Robb authored and Corbin Robb committed Feb 3, 2022
1 parent 76ce8b1 commit d88c4fe
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
19 changes: 19 additions & 0 deletions superset-frontend/src/views/CRUD/utils.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
import rison from 'rison';
import {
isNeedsPassword,
isAlreadyExists,
Expand Down Expand Up @@ -171,3 +172,21 @@ test('does not ask for password when the import type is wrong', () => {
};
expect(hasTerminalValidation(error.errors)).toBe(true);
});

test('successfully modified rison to encode correctly', () => {
const problemCharacters = '& # ? ^ { } [ ] | " = + `';

const testObject = problemCharacters.split(' ').reduce((a, c) => {
// eslint-disable-next-line no-param-reassign
a[c] = c;
return a;
}, {});

const actualEncoding = rison.encode(testObject);

const expectedEncoding =
"('\"':'\"','#':'#','&':'&','+':'+','=':'=','?':'?','[':'[',']':']','^':'^','`':'`','{':'{','|':'|','}':'}')";

expect(actualEncoding).toEqual(expectedEncoding);
expect(rison.decode(actualEncoding)).toEqual(testObject);
});
6 changes: 2 additions & 4 deletions superset-frontend/src/views/CRUD/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import { Dashboard, Filters } from './types';

// Modifies the rison encoding slightly to match the backend's
// rison encoding/decoding. Applies globally. Code pulled from rison.js
const fixRisonEncodeDecode = () => {
(() => {
const risonRef: {
not_idchar: string;
not_idstart: string;
Expand All @@ -60,9 +60,7 @@ const fixRisonEncodeDecode = () => {

risonRef.id_ok = new RegExp(`^${idrx}$`);
risonRef.next_id = new RegExp(idrx, 'g');
};

fixRisonEncodeDecode();
})();

const createFetchResourceMethod =
(method: string) =>
Expand Down

0 comments on commit d88c4fe

Please sign in to comment.