mirror of
https://github.com/roleypoly/roleypoly.git
synced 2025-04-25 11:59:11 +00:00
fix tests
This commit is contained in:
parent
1dd910a5f6
commit
8ea7746dd5
6 changed files with 34 additions and 13 deletions
22
package-lock.json
generated
22
package-lock.json
generated
|
@ -12516,6 +12516,28 @@
|
||||||
"integrity": "sha512-olV41bKSMm8BdnuMsewT4jqlZ8+3TCARAXjZGT9jcoSnrfUnRCqnMoF9XEeoWjbzObpqF9dRhHQj0Xb9QdF6/w==",
|
"integrity": "sha512-olV41bKSMm8BdnuMsewT4jqlZ8+3TCARAXjZGT9jcoSnrfUnRCqnMoF9XEeoWjbzObpqF9dRhHQj0Xb9QdF6/w==",
|
||||||
"dev": true
|
"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": {
|
"jest-regex-util": {
|
||||||
"version": "26.0.0",
|
"version": "26.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/jest-regex-util/-/jest-regex-util-26.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/jest-regex-util/-/jest-regex-util-26.0.0.tgz",
|
||||||
|
|
|
@ -66,6 +66,7 @@
|
||||||
"jest-cli": "^26.6.3",
|
"jest-cli": "^26.6.3",
|
||||||
"jest-environment-enzyme": "^7.1.2",
|
"jest-environment-enzyme": "^7.1.2",
|
||||||
"jest-enzyme": "^7.1.2",
|
"jest-enzyme": "^7.1.2",
|
||||||
|
"jest-react-hooks-shallow": "^1.4.2",
|
||||||
"jest-styled-components": "^7.0.3",
|
"jest-styled-components": "^7.0.3",
|
||||||
"minimist": "^1.2.5",
|
"minimist": "^1.2.5",
|
||||||
"npm-run-all": "^4.1.5",
|
"npm-run-all": "^4.1.5",
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
import { hasPermission, permissions, hasPermissionOrAdmin } from './hasPermission';
|
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';
|
import { guildRoles } from 'roleypoly/common/types/storyData';
|
||||||
|
|
||||||
const roles: Role.AsObject[] = [
|
const roles: Role[] = [
|
||||||
{
|
{
|
||||||
...guildRoles.rolesList[0],
|
...guildRoles.rolesList[0],
|
||||||
permissions: permissions.ADMINISTRATOR,
|
permissions: permissions.ADMINISTRATOR,
|
||||||
|
|
|
@ -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);
|
const aggregateRoles = roles.reduce((acc, role) => acc | role.permissions, 0);
|
||||||
return (aggregateRoles & permission) === permission;
|
return (aggregateRoles & permission) === permission;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const hasPermissionOrAdmin = (
|
export const hasPermissionOrAdmin = (roles: Role[], permission: number): boolean =>
|
||||||
roles: Role.AsObject[],
|
hasPermission(roles, permission | permissions.ADMINISTRATOR);
|
||||||
permission: number
|
|
||||||
): boolean => hasPermission(roles, permission | permissions.ADMINISTRATOR);
|
|
||||||
|
|
||||||
export const permissions = {
|
export const permissions = {
|
||||||
CREATE_INSTANT_INVITE: 0x1,
|
CREATE_INSTANT_INVITE: 0x1,
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
jest.unmock('roleypoly/src/design-system/atoms/text-input');
|
jest.unmock('roleypoly/design-system/atoms/text-input');
|
||||||
jest.unmock('./PreauthSecretCode');
|
jest.unmock('./PreauthSecretCode');
|
||||||
|
|
||||||
import { Button } from 'roleypoly/design-system/atoms/button';
|
import { Button } from 'roleypoly/design-system/atoms/button';
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
jest.unmock('roleypoly/src/design-system/atoms/role')
|
jest.unmock('roleypoly/design-system/atoms/role')
|
||||||
.unmock('roleypoly/src/design-system/atoms/button')
|
.unmock('roleypoly/design-system/atoms/button')
|
||||||
.unmock('roleypoly/src/design-system/molecules/picker-category')
|
.unmock('roleypoly/design-system/molecules/picker-category')
|
||||||
.unmock('roleypoly/src/design-system/organisms/role-picker');
|
.unmock('roleypoly/design-system/organisms/role-picker');
|
||||||
|
|
||||||
import { shallow } from 'enzyme';
|
import { shallow } from 'enzyme';
|
||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
|
|
Loading…
Add table
Reference in a new issue