onboardingTasks.spec.tsx 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. import {OrganizationFixture} from 'sentry-fixture/organization';
  2. import {ProjectFixture} from 'sentry-fixture/project';
  3. import {TeamFixture} from 'sentry-fixture/team';
  4. import {updateOnboardingTask} from 'sentry/actionCreators/onboardingTasks';
  5. import {updateOrganization} from 'sentry/actionCreators/organizations';
  6. import ConfigStore from 'sentry/stores/configStore';
  7. import {OnboardingTaskKey} from 'sentry/types';
  8. jest.mock('sentry/actionCreators/organizations', () => ({
  9. updateOrganization: jest.fn(),
  10. }));
  11. describe('actionCreators/onboardingTasks', function () {
  12. const api = new MockApiClient();
  13. const user = ConfigStore.get('user');
  14. describe('updateOnboardingTask', function () {
  15. it('Adds the task to the organization when task does not exists', async function () {
  16. const detailedOrg = OrganizationFixture({
  17. teams: [TeamFixture()],
  18. projects: [ProjectFixture()],
  19. });
  20. // User is not passed into the update request
  21. const testTask = {
  22. task: OnboardingTaskKey.FIRST_PROJECT,
  23. status: 'complete',
  24. } as const;
  25. const mockUpdate = MockApiClient.addMockResponse({
  26. url: `/organizations/${detailedOrg.slug}/onboarding-tasks/`,
  27. method: 'POST',
  28. body: testTask,
  29. });
  30. updateOnboardingTask(api, detailedOrg, testTask);
  31. await tick();
  32. expect(mockUpdate).toHaveBeenCalled();
  33. expect(updateOrganization).toHaveBeenCalledWith({
  34. onboardingTasks: [{...testTask, user}],
  35. });
  36. });
  37. it('Updates existing onboarding task', async function () {
  38. const detailedOrg = OrganizationFixture({
  39. teams: [TeamFixture()],
  40. projects: [ProjectFixture()],
  41. onboardingTasks: [{task: OnboardingTaskKey.FIRST_EVENT, status: 'skipped'}],
  42. });
  43. const testTask = {
  44. task: OnboardingTaskKey.FIRST_EVENT,
  45. status: 'complete',
  46. } as const;
  47. MockApiClient.clearMockResponses();
  48. const mockUpdate = MockApiClient.addMockResponse({
  49. url: `/organizations/${detailedOrg.slug}/onboarding-tasks/`,
  50. method: 'POST',
  51. body: testTask,
  52. });
  53. updateOnboardingTask(api, detailedOrg, testTask);
  54. await tick();
  55. expect(mockUpdate).toHaveBeenCalled();
  56. // NOTE: user is not passed as it is already associated to the existing
  57. // onboarding task.
  58. expect(updateOrganization).toHaveBeenCalledWith({
  59. onboardingTasks: [testTask],
  60. });
  61. });
  62. it('Does not make API request without api object', async function () {
  63. const detailedOrg = OrganizationFixture({
  64. teams: [TeamFixture()],
  65. projects: [ProjectFixture()],
  66. });
  67. const testTask = {
  68. task: OnboardingTaskKey.FIRST_EVENT,
  69. status: 'complete',
  70. } as const;
  71. const mockUpdate = MockApiClient.addMockResponse({
  72. url: `/organizations/${detailedOrg.slug}/onboarding-tasks/`,
  73. method: 'POST',
  74. });
  75. updateOnboardingTask(null, detailedOrg, testTask);
  76. await tick();
  77. expect(mockUpdate).not.toHaveBeenCalled();
  78. expect(updateOrganization).toHaveBeenCalledWith({
  79. onboardingTasks: [{...testTask, user}],
  80. });
  81. });
  82. });
  83. });