|
1 | | -const Utils = require('../src/Utils'); |
| 1 | +const Utils = require('../lib/Utils'); |
| 2 | +const { createSanitizedError, createSanitizedHttpError } = require("../lib/Error") |
2 | 3 |
|
3 | 4 | describe('Utils', () => { |
4 | 5 | describe('encodeForUrl', () => { |
@@ -173,4 +174,42 @@ describe('Utils', () => { |
173 | 174 | expect(Utils.getNestedProperty(obj, 'database.name')).toBe(''); |
174 | 175 | }); |
175 | 176 | }); |
| 177 | + |
| 178 | + describe('createSanitizedError', () => { |
| 179 | + it('should return "Permission denied" when enableSanitizedErrorResponse is true', () => { |
| 180 | + const config = { enableSanitizedErrorResponse: true }; |
| 181 | + const error = createSanitizedError(Parse.Error.OPERATION_FORBIDDEN, 'Detailed error message', config); |
| 182 | + expect(error.message).toBe('Permission denied'); |
| 183 | + }); |
| 184 | + |
| 185 | + it('should not crash with config undefined', () => { |
| 186 | + const error = createSanitizedError(Parse.Error.OPERATION_FORBIDDEN, 'Detailed error message', undefined); |
| 187 | + expect(error.message).toBe('Permission denied'); |
| 188 | + }); |
| 189 | + |
| 190 | + it('should return the detailed message when enableSanitizedErrorResponse is false', () => { |
| 191 | + const config = { enableSanitizedErrorResponse: false }; |
| 192 | + const error = createSanitizedError(Parse.Error.OPERATION_FORBIDDEN, 'Detailed error message', config); |
| 193 | + expect(error.message).toBe('Detailed error message'); |
| 194 | + }); |
| 195 | + }); |
| 196 | + |
| 197 | + describe('createSanitizedHttpError', () => { |
| 198 | + it('should return "Permission denied" when enableSanitizedErrorResponse is true', () => { |
| 199 | + const config = { enableSanitizedErrorResponse: true }; |
| 200 | + const error = createSanitizedHttpError(403, 'Detailed error message', config); |
| 201 | + expect(error.message).toBe('Permission denied'); |
| 202 | + }); |
| 203 | + |
| 204 | + it('should not crash with config undefined', () => { |
| 205 | + const error = createSanitizedHttpError(403, 'Detailed error message', undefined); |
| 206 | + expect(error.message).toBe('Permission denied'); |
| 207 | + }); |
| 208 | + |
| 209 | + it('should return the detailed message when enableSanitizedErrorResponse is false', () => { |
| 210 | + const config = { enableSanitizedErrorResponse: false }; |
| 211 | + const error = createSanitizedHttpError(403, 'Detailed error message', config); |
| 212 | + expect(error.message).toBe('Detailed error message'); |
| 213 | + }); |
| 214 | + }); |
176 | 215 | }); |
0 commit comments