npm package diff

Package: @forge/events

Versions: 2.0.1-next.0 - 2.0.1-next.1

File: package/src/__test__/jobProgress.test.ts

Index: package/src/__test__/jobProgress.test.ts
===================================================================
--- package/src/__test__/jobProgress.test.ts
+++ package/src/__test__/jobProgress.test.ts
@@ -1,184 +0,0 @@
-import { getMockFetchMethod, verifyApiClientCalledWith } from './utils';
-import { InternalServerError, InvalidQueueNameError, JobDoesNotExistError, RateLimitError } from '../errors';
-import { JobProgress } from '../jobProgress';
-import { __requestAtlassianAsApp } from '@forge/api';
-import { QueueParams } from '../types';
-
-jest.mock('@forge/api', () => ({
-  __requestAtlassianAsApp: getMockFetchMethod({ done: true }, 200)
-}));
-
-const queueParams: QueueParams = { key: 'test-queue-name' };
-const getJobProgress = (jobId: string, apiClientMock?: any) => new JobProgress(queueParams, jobId, apiClientMock);
-
-describe('JobProgress methods', () => {
-  describe('getStats', () => {
-    it('should call the queue/stats endpoint', async () => {
-      const apiClientMock = getMockFetchMethod(
-        {
-          success: 100,
-          inProgress: 50,
-          failed: 1
-        },
-        200
-      );
-      const jobProgress = getJobProgress('test-job-id', apiClientMock);
-      const { success, inProgress, failed } = await jobProgress.getStats();
-      verifyApiClientCalledWith(
-        apiClientMock,
-        '/webhook/queue/stats/{contextAri}/{environmentId}/{appId}/{appVersion}',
-        {
-          queueName: 'test-queue-name',
-          jobId: 'test-job-id'
-        }
-      );
-      expect(success).toEqual(100);
-      expect(inProgress).toEqual(50);
-      expect(failed).toEqual(1);
-    });
-
-    it('should throw JobDoesNotExistError', async () => {
-      const apiClientMock = getMockFetchMethod(
-        {
-          message: 'Job Not Found',
-          code: 404
-        },
-        404
-      );
-      const jobProgress = getJobProgress('test-job-id', apiClientMock);
-      await expect(jobProgress.getStats()).rejects.toThrow(
-        new JobDoesNotExistError(`The job test-job-id was not found for the queue test-queue-name.`)
-      );
-      verifyApiClientCalledWith(
-        apiClientMock,
-        '/webhook/queue/stats/{contextAri}/{environmentId}/{appId}/{appVersion}',
-        {
-          queueName: 'test-queue-name',
-          jobId: 'test-job-id'
-        }
-      );
-    });
-
-    it('should throw RateLimitError', async () => {
-      const apiClientMock = getMockFetchMethod({}, 429);
-      const jobProgress = getJobProgress('test-job-id', apiClientMock);
-      await expect(jobProgress.getStats()).rejects.toThrow(new RateLimitError(`Too many requests.`));
-      verifyApiClientCalledWith(
-        apiClientMock,
-        '/webhook/queue/stats/{contextAri}/{environmentId}/{appId}/{appVersion}',
-        {
-          queueName: 'test-queue-name',
-          jobId: 'test-job-id'
-        }
-      );
-    });
-
-    it('should throw InternalServerError', async () => {
-      const apiClientMock = getMockFetchMethod(
-        {
-          message: 'Service is not available',
-          code: 513,
-          details: 'The request processing has failed because of an unknown error, exception or failure'
-        },
-        513
-      );
-      const jobProgress = getJobProgress('test-job-id', apiClientMock);
-      await expect(jobProgress.getStats()).rejects.toThrow(
-        new InternalServerError(`513 Status Text: Service is not available`, 513)
-      );
-      verifyApiClientCalledWith(
-        apiClientMock,
-        '/webhook/queue/stats/{contextAri}/{environmentId}/{appId}/{appVersion}',
-        {
-          queueName: 'test-queue-name',
-          jobId: 'test-job-id'
-        }
-      );
-    });
-  });
-
-  describe('cancel', () => {
-    it('should call the queue/cancel endpoint', async () => {
-      const apiClientMock = getMockFetchMethod({}, 204);
-      const jobProgress = getJobProgress('test-job-id', apiClientMock);
-      await jobProgress.cancel();
-      verifyApiClientCalledWith(
-        apiClientMock,
-        '/webhook/queue/cancel/{contextAri}/{environmentId}/{appId}/{appVersion}',
-        {
-          queueName: 'test-queue-name',
-          jobId: 'test-job-id'
-        }
-      );
-    });
-
-    it('should throw JobDoesNotExistError', async () => {
-      const apiClientMock = getMockFetchMethod(
-        {
-          message: 'Job Not Found',
-          code: 404
-        },
-        404
-      );
-      const jobProgress = getJobProgress('test-job-id', apiClientMock);
-      await expect(jobProgress.cancel()).rejects.toThrow(
-        new JobDoesNotExistError(`The job test-job-id was not found for the queue test-queue-name.`)
-      );
-      verifyApiClientCalledWith(
-        apiClientMock,
-        '/webhook/queue/cancel/{contextAri}/{environmentId}/{appId}/{appVersion}',
-        {
-          queueName: 'test-queue-name',
-          jobId: 'test-job-id'
-        }
-      );
-    });
-  });
-
-  it('should throw InternalServerError when WHP returns 422 response', async () => {
-    const apiClientMock = getMockFetchMethod(
-      {
-        errors: ['jobId must not be null', 'queueName must not be null']
-      },
-      422
-    );
-    const jobProgress = getJobProgress('test-job-id', apiClientMock);
-    await expect(jobProgress.getStats()).rejects.toThrow(
-      new InternalServerError(`422 Status Text: jobId must not be null, queueName must not be null`)
-    );
-
-    verifyApiClientCalledWith(apiClientMock, '/webhook/queue/stats/{contextAri}/{environmentId}/{appId}/{appVersion}', {
-      queueName: 'test-queue-name',
-      jobId: 'test-job-id'
-    });
-  });
-
-  it('should throw errors when queueName or jobId is empty', async () => {
-    const apiClientMock = getMockFetchMethod(
-      {
-        success: 100,
-        inProgress: 50,
-        failed: 1
-      },
-      200
-    );
-    const jobProgress1 = getJobProgress('', apiClientMock);
-    await expect(jobProgress1.getStats()).rejects.toThrow(new JobDoesNotExistError(`jobId cannot be empty.`));
-
-    const jobProgress2 = new JobProgress({ key: '!' }, 'test-job-id', apiClientMock);
-    await expect(jobProgress2.getStats()).rejects.toThrow(
-      new InvalidQueueNameError('Queue names can only contain alphanumeric characters, dashes and underscores.')
-    );
-
-    const jobProgress3 = getJobProgress('', apiClientMock);
-    await expect(jobProgress3.getStats()).rejects.toThrow(new JobDoesNotExistError(`jobId cannot be empty.`));
-
-    expect(apiClientMock).toHaveBeenCalledTimes(0);
-  });
-
-  it('requests stargate if no api client is provided', async () => {
-    const jobProgress = getJobProgress('job-id');
-    await jobProgress.getStats();
-    expect(__requestAtlassianAsApp).toHaveBeenCalledTimes(1);
-  });
-});