onboardingTasks.spec.tsx 3.0 KB

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