useProjectCreationAccess.spec.tsx 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. import {Organization} from 'sentry-fixture/organization';
  2. import {reactHooks} from 'sentry-test/reactTestingLibrary';
  3. import * as useExperiment from 'sentry/utils/useExperiment';
  4. import {useProjectCreationAccess} from './useProjectCreationAccess';
  5. describe('ProjectCreationAccess', function () {
  6. const organization = Organization();
  7. const teams = [TestStubs.Team()];
  8. it('passes project creation eligibility for org-manager', function () {
  9. const {result} = reactHooks.renderHook(useProjectCreationAccess, {
  10. initialProps: {organization, teams},
  11. });
  12. expect(result.current.canCreateProject).toBeTruthy();
  13. });
  14. it('fails project creation eligibility for org-members', function () {
  15. const member_org = Organization({
  16. access: ['org:read', 'team:read', 'project:read'],
  17. });
  18. const {result} = reactHooks.renderHook(useProjectCreationAccess, {
  19. initialProps: {organization: member_org, teams},
  20. });
  21. expect(result.current.canCreateProject).toBeFalsy();
  22. });
  23. it('passes project creation eligibility for team-admin', function () {
  24. const member_org = Organization({
  25. access: ['org:read', 'team:read', 'project:read'],
  26. });
  27. const admin_teams = [
  28. {...TestStubs.Team(), access: ['team:admin', 'team:write', 'team:read']},
  29. ];
  30. const {result} = reactHooks.renderHook(useProjectCreationAccess, {
  31. initialProps: {organization: member_org, teams: admin_teams},
  32. });
  33. expect(result.current.canCreateProject).toBeTruthy();
  34. });
  35. it('passes if org is part of experiment and member has no access', function () {
  36. const experiment_org = Organization({
  37. access: ['org:read', 'team:read', 'project:read'],
  38. features: ['team-project-creation-all'],
  39. experiments: {ProjectCreationForAllExperimentV2: 1},
  40. });
  41. jest.spyOn(useExperiment, 'useExperiment').mockReturnValue({
  42. experimentAssignment: 1,
  43. logExperiment: jest.fn(),
  44. });
  45. const {result} = reactHooks.renderHook(useProjectCreationAccess, {
  46. initialProps: {organization: experiment_org, teams},
  47. });
  48. expect(result.current.canCreateProject).toBeTruthy();
  49. });
  50. it('fails if org is not part of experiment and member has no access', function () {
  51. const no_exp_org = Organization({
  52. access: ['org:read', 'team:read', 'project:read'],
  53. features: ['team-project-creation-all'],
  54. experiments: {ProjectCreationForAllExperimentV2: 0},
  55. });
  56. jest.spyOn(useExperiment, 'useExperiment').mockReturnValue({
  57. experimentAssignment: 0,
  58. logExperiment: jest.fn(),
  59. });
  60. const {result} = reactHooks.renderHook(useProjectCreationAccess, {
  61. initialProps: {organization: no_exp_org, teams},
  62. });
  63. expect(result.current.canCreateProject).toBeFalsy();
  64. });
  65. it('fails if org does not have the feature regardless of experiment value', function () {
  66. const no_flag_org = Organization({
  67. access: ['org:read', 'team:read', 'project:read'],
  68. features: [],
  69. experiments: {ProjectCreationForAllExperimentV2: 1},
  70. });
  71. jest.spyOn(useExperiment, 'useExperiment').mockReturnValue({
  72. experimentAssignment: 1,
  73. logExperiment: jest.fn(),
  74. });
  75. const {result} = reactHooks.renderHook(useProjectCreationAccess, {
  76. initialProps: {organization: no_flag_org, teams},
  77. });
  78. expect(result.current.canCreateProject).toBeFalsy();
  79. });
  80. });