onboardingTasks.spec.jsx 2.8 KB

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