From 8ea7746dd505c9645969c3c263896c675d209d18 Mon Sep 17 00:00:00 2001 From: Katalina Okano Date: Sun, 22 Nov 2020 01:31:46 -0500 Subject: [PATCH] fix tests --- package-lock.json | 22 +++++++++++++++++++ package.json | 1 + src/common/utils/hasPermission.spec.ts | 4 ++-- src/common/utils/hasPermission.ts | 10 ++++----- .../PreauthSecretCode.spec.tsx | 2 +- .../organisms/role-picker/RolePicker.spec.tsx | 8 +++---- 6 files changed, 34 insertions(+), 13 deletions(-) diff --git a/package-lock.json b/package-lock.json index f150e96..53e44e5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12516,6 +12516,28 @@ "integrity": "sha512-olV41bKSMm8BdnuMsewT4jqlZ8+3TCARAXjZGT9jcoSnrfUnRCqnMoF9XEeoWjbzObpqF9dRhHQj0Xb9QdF6/w==", "dev": true }, + "jest-react-hooks-shallow": { + "version": "1.4.2", + "resolved": "https://registry.npmjs.org/jest-react-hooks-shallow/-/jest-react-hooks-shallow-1.4.2.tgz", + "integrity": "sha512-Xpn/RjedUEhLpsly1SoNbHYc1RbuG5II1HzrRAXDdRmHmiyOz+28i/VUmDXMRoJooe1ohSKYzkLxhE8E50T6QA==", + "dev": true, + "requires": { + "react": "^16.8.0" + }, + "dependencies": { + "react": { + "version": "16.14.0", + "resolved": "https://registry.npmjs.org/react/-/react-16.14.0.tgz", + "integrity": "sha512-0X2CImDkJGApiAlcf0ODKIneSwBPhqJawOa5wCtKbu7ZECrmS26NvtSILynQ66cgkT/RJ4LidJOc3bUESwmU8g==", + "dev": true, + "requires": { + "loose-envify": "^1.1.0", + "object-assign": "^4.1.1", + "prop-types": "^15.6.2" + } + } + } + }, "jest-regex-util": { "version": "26.0.0", "resolved": "https://registry.npmjs.org/jest-regex-util/-/jest-regex-util-26.0.0.tgz", diff --git a/package.json b/package.json index d49630f..9516b74 100644 --- a/package.json +++ b/package.json @@ -66,6 +66,7 @@ "jest-cli": "^26.6.3", "jest-environment-enzyme": "^7.1.2", "jest-enzyme": "^7.1.2", + "jest-react-hooks-shallow": "^1.4.2", "jest-styled-components": "^7.0.3", "minimist": "^1.2.5", "npm-run-all": "^4.1.5", diff --git a/src/common/utils/hasPermission.spec.ts b/src/common/utils/hasPermission.spec.ts index 487811c..48a208d 100644 --- a/src/common/utils/hasPermission.spec.ts +++ b/src/common/utils/hasPermission.spec.ts @@ -1,8 +1,8 @@ import { hasPermission, permissions, hasPermissionOrAdmin } from './hasPermission'; -import { Role } from 'roleypoly/rpc/shared'; +import { Role } from 'roleypoly/common/types'; import { guildRoles } from 'roleypoly/common/types/storyData'; -const roles: Role.AsObject[] = [ +const roles: Role[] = [ { ...guildRoles.rolesList[0], permissions: permissions.ADMINISTRATOR, diff --git a/src/common/utils/hasPermission.ts b/src/common/utils/hasPermission.ts index 5c4cf8a..b29a8c7 100644 --- a/src/common/utils/hasPermission.ts +++ b/src/common/utils/hasPermission.ts @@ -1,14 +1,12 @@ -import { Role } from 'roleypoly/rpc/shared'; +import { Role } from 'roleypoly/common/types'; -export const hasPermission = (roles: Role.AsObject[], permission: number): boolean => { +export const hasPermission = (roles: Role[], permission: number): boolean => { const aggregateRoles = roles.reduce((acc, role) => acc | role.permissions, 0); return (aggregateRoles & permission) === permission; }; -export const hasPermissionOrAdmin = ( - roles: Role.AsObject[], - permission: number -): boolean => hasPermission(roles, permission | permissions.ADMINISTRATOR); +export const hasPermissionOrAdmin = (roles: Role[], permission: number): boolean => + hasPermission(roles, permission | permissions.ADMINISTRATOR); export const permissions = { CREATE_INSTANT_INVITE: 0x1, diff --git a/src/design-system/molecules/preauth-secret-code/PreauthSecretCode.spec.tsx b/src/design-system/molecules/preauth-secret-code/PreauthSecretCode.spec.tsx index a380d6a..e9098a1 100644 --- a/src/design-system/molecules/preauth-secret-code/PreauthSecretCode.spec.tsx +++ b/src/design-system/molecules/preauth-secret-code/PreauthSecretCode.spec.tsx @@ -1,4 +1,4 @@ -jest.unmock('roleypoly/src/design-system/atoms/text-input'); +jest.unmock('roleypoly/design-system/atoms/text-input'); jest.unmock('./PreauthSecretCode'); import { Button } from 'roleypoly/design-system/atoms/button'; diff --git a/src/design-system/organisms/role-picker/RolePicker.spec.tsx b/src/design-system/organisms/role-picker/RolePicker.spec.tsx index d2ac6ca..f0a3c63 100644 --- a/src/design-system/organisms/role-picker/RolePicker.spec.tsx +++ b/src/design-system/organisms/role-picker/RolePicker.spec.tsx @@ -1,7 +1,7 @@ -jest.unmock('roleypoly/src/design-system/atoms/role') - .unmock('roleypoly/src/design-system/atoms/button') - .unmock('roleypoly/src/design-system/molecules/picker-category') - .unmock('roleypoly/src/design-system/organisms/role-picker'); +jest.unmock('roleypoly/design-system/atoms/role') + .unmock('roleypoly/design-system/atoms/button') + .unmock('roleypoly/design-system/molecules/picker-category') + .unmock('roleypoly/design-system/organisms/role-picker'); import { shallow } from 'enzyme'; import * as React from 'react';