onboardingTasks.spec.tsx 3.0 KB

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