onboardingTasks.spec.tsx 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. import {OrganizationFixture} 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/onboarding';
  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 = OrganizationFixture();
  13. // User is not passed into the update request
  14. const testTask = {
  15. task: OnboardingTaskKey.FIRST_PROJECT,
  16. status: 'complete',
  17. } as const;
  18. const mockUpdate = MockApiClient.addMockResponse({
  19. url: `/organizations/${detailedOrg.slug}/onboarding-tasks/`,
  20. method: 'POST',
  21. body: testTask,
  22. });
  23. updateOnboardingTask(api, detailedOrg, testTask);
  24. await tick();
  25. expect(mockUpdate).toHaveBeenCalled();
  26. expect(OrganizationStore.onUpdate).toHaveBeenCalledWith({
  27. onboardingTasks: [{...testTask, user}],
  28. });
  29. });
  30. it('Updates existing onboarding task', async function () {
  31. const detailedOrg = OrganizationFixture({
  32. onboardingTasks: [{task: OnboardingTaskKey.FIRST_EVENT, status: 'skipped'}],
  33. });
  34. const testTask = {
  35. task: OnboardingTaskKey.FIRST_EVENT,
  36. status: 'complete',
  37. } as const;
  38. MockApiClient.clearMockResponses();
  39. const mockUpdate = MockApiClient.addMockResponse({
  40. url: `/organizations/${detailedOrg.slug}/onboarding-tasks/`,
  41. method: 'POST',
  42. body: testTask,
  43. });
  44. updateOnboardingTask(api, detailedOrg, testTask);
  45. await tick();
  46. expect(mockUpdate).toHaveBeenCalled();
  47. // NOTE: user is not passed as it is already associated to the existing
  48. // onboarding task.
  49. expect(OrganizationStore.onUpdate).toHaveBeenCalledWith({
  50. onboardingTasks: [testTask],
  51. });
  52. });
  53. it('Does not make API request without api object', async function () {
  54. const detailedOrg = OrganizationFixture();
  55. const testTask = {
  56. task: OnboardingTaskKey.FIRST_EVENT,
  57. status: 'complete',
  58. } as const;
  59. const mockUpdate = MockApiClient.addMockResponse({
  60. url: `/organizations/${detailedOrg.slug}/onboarding-tasks/`,
  61. method: 'POST',
  62. });
  63. updateOnboardingTask(null, detailedOrg, testTask);
  64. await tick();
  65. expect(mockUpdate).not.toHaveBeenCalled();
  66. expect(OrganizationStore.onUpdate).toHaveBeenCalledWith({
  67. onboardingTasks: [{...testTask, user}],
  68. });
  69. });
  70. });
  71. });