npm package diff

Package: @forge/events

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

File: package/out/__test__/jobProgress.test.js

Index: package/out/__test__/jobProgress.test.js
===================================================================
--- package/out/__test__/jobProgress.test.js
+++ package/out/__test__/jobProgress.test.js
@@ -1,118 +0,0 @@
-"use strict";
-Object.defineProperty(exports, "__esModule", { value: true });
-const utils_1 = require("./utils");
-const errors_1 = require("../errors");
-const jobProgress_1 = require("../jobProgress");
-const api_1 = require("@forge/api");
-jest.mock('@forge/api', () => ({
-    __requestAtlassianAsApp: (0, utils_1.getMockFetchMethod)({ done: true }, 200)
-}));
-const queueParams = { key: 'test-queue-name' };
-const getJobProgress = (jobId, apiClientMock) => new jobProgress_1.JobProgress(queueParams, jobId, apiClientMock);
-describe('JobProgress methods', () => {
-    describe('getStats', () => {
-        it('should call the queue/stats endpoint', async () => {
-            const apiClientMock = (0, utils_1.getMockFetchMethod)({
-                success: 100,
-                inProgress: 50,
-                failed: 1
-            }, 200);
-            const jobProgress = getJobProgress('test-job-id', apiClientMock);
-            const { success, inProgress, failed } = await jobProgress.getStats();
-            (0, utils_1.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 = (0, utils_1.getMockFetchMethod)({
-                message: 'Job Not Found',
-                code: 404
-            }, 404);
-            const jobProgress = getJobProgress('test-job-id', apiClientMock);
-            await expect(jobProgress.getStats()).rejects.toThrow(new errors_1.JobDoesNotExistError(`The job test-job-id was not found for the queue test-queue-name.`));
-            (0, utils_1.verifyApiClientCalledWith)(apiClientMock, '/webhook/queue/stats/{contextAri}/{environmentId}/{appId}/{appVersion}', {
-                queueName: 'test-queue-name',
-                jobId: 'test-job-id'
-            });
-        });
-        it('should throw RateLimitError', async () => {
-            const apiClientMock = (0, utils_1.getMockFetchMethod)({}, 429);
-            const jobProgress = getJobProgress('test-job-id', apiClientMock);
-            await expect(jobProgress.getStats()).rejects.toThrow(new errors_1.RateLimitError(`Too many requests.`));
-            (0, utils_1.verifyApiClientCalledWith)(apiClientMock, '/webhook/queue/stats/{contextAri}/{environmentId}/{appId}/{appVersion}', {
-                queueName: 'test-queue-name',
-                jobId: 'test-job-id'
-            });
-        });
-        it('should throw InternalServerError', async () => {
-            const apiClientMock = (0, utils_1.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 errors_1.InternalServerError(`513 Status Text: Service is not available`, 513));
-            (0, utils_1.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 = (0, utils_1.getMockFetchMethod)({}, 204);
-            const jobProgress = getJobProgress('test-job-id', apiClientMock);
-            await jobProgress.cancel();
-            (0, utils_1.verifyApiClientCalledWith)(apiClientMock, '/webhook/queue/cancel/{contextAri}/{environmentId}/{appId}/{appVersion}', {
-                queueName: 'test-queue-name',
-                jobId: 'test-job-id'
-            });
-        });
-        it('should throw JobDoesNotExistError', async () => {
-            const apiClientMock = (0, utils_1.getMockFetchMethod)({
-                message: 'Job Not Found',
-                code: 404
-            }, 404);
-            const jobProgress = getJobProgress('test-job-id', apiClientMock);
-            await expect(jobProgress.cancel()).rejects.toThrow(new errors_1.JobDoesNotExistError(`The job test-job-id was not found for the queue test-queue-name.`));
-            (0, utils_1.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 = (0, utils_1.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 errors_1.InternalServerError(`422 Status Text: jobId must not be null, queueName must not be null`));
-        (0, utils_1.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 = (0, utils_1.getMockFetchMethod)({
-            success: 100,
-            inProgress: 50,
-            failed: 1
-        }, 200);
-        const jobProgress1 = getJobProgress('', apiClientMock);
-        await expect(jobProgress1.getStats()).rejects.toThrow(new errors_1.JobDoesNotExistError(`jobId cannot be empty.`));
-        const jobProgress2 = new jobProgress_1.JobProgress({ key: '!' }, 'test-job-id', apiClientMock);
-        await expect(jobProgress2.getStats()).rejects.toThrow(new errors_1.InvalidQueueNameError('Queue names can only contain alphanumeric characters, dashes and underscores.'));
-        const jobProgress3 = getJobProgress('', apiClientMock);
-        await expect(jobProgress3.getStats()).rejects.toThrow(new errors_1.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(api_1.__requestAtlassianAsApp).toHaveBeenCalledTimes(1);
-    });
-});