onboardingTasks.spec.tsx 3.1 KB

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