onboardingTasks.spec.tsx 3.0 KB

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