npm package diff
Package: @forge/sql
Versions: 2.2.0-next.2 - 2.2.0-next.3
File: package/out/utils/__test__/response-handler.test.js
Index: package/out/utils/__test__/response-handler.test.js
===================================================================
--- package/out/utils/__test__/response-handler.test.js
+++ package/out/utils/__test__/response-handler.test.js
@@ -1,60 +0,0 @@
-"use strict";
-Object.defineProperty(exports, "__esModule", { value: true });
-const response_handler_1 = require("../response-handler");
-describe('getResponseBody', () => {
- it('should return parsed response when response is ok', async () => {
- const mockResponse = {
- text: jest.fn().mockResolvedValue(JSON.stringify({ rows: [] })),
- ok: true,
- status: 200
- };
- const result = await (0, response_handler_1.getResponseBody)(mockResponse);
- expect(result).toEqual({ rows: [] });
- });
- it('should throw ApiError with parsed error when response is not ok and error JSON is valid', async () => {
- const mockResponse = {
- text: jest
- .fn()
- .mockResolvedValue(JSON.stringify({ code: 'ERROR_CODE', message: 'Error Title', debug: { info: 'detail' } })),
- ok: false,
- status: 400
- };
- await expect((0, response_handler_1.getResponseBody)(mockResponse)).rejects.toThrow(response_handler_1.ApiError);
- await expect((0, response_handler_1.getResponseBody)(mockResponse)).rejects.toMatchObject({
- status: 400,
- code: 'ERROR_CODE',
- message: 'Error Title',
- debug: { info: 'detail' }
- });
- });
- it('should throw ApiError with UNKNOWN_ERROR when response is not ok and error JSON is invalid', async () => {
- const mockResponse = {
- text: jest.fn().mockResolvedValue('Invalid JSON'),
- ok: false,
- status: 500
- };
- await expect((0, response_handler_1.getResponseBody)(mockResponse)).rejects.toThrow(response_handler_1.ApiError);
- await expect((0, response_handler_1.getResponseBody)(mockResponse)).rejects.toMatchObject({
- status: 500,
- code: 'UNKNOWN_ERROR',
- message: 'Invalid JSON'
- });
- });
- it('should throw Error when response text is not valid JSON', async () => {
- const mockResponse = {
- text: jest.fn().mockResolvedValue('Invalid JSON'),
- ok: true,
- status: 200
- };
- await expect((0, response_handler_1.getResponseBody)(mockResponse)).rejects.toThrowError(new Error('Unexpected error. Response was not valid JSON: Invalid JSON'));
- });
-});
-describe('ApiError', () => {
- it('should create an ApiError with correct properties', () => {
- const error = new response_handler_1.ApiError(404, 'NOT_FOUND', 'Resource not found');
- expect(error).toBeInstanceOf(Error);
- expect(error.status).toBe(404);
- expect(error.code).toBe('NOT_FOUND');
- expect(error.message).toBe('Resource not found');
- });
-});