|
1 | | -import { describe, it, expect } from "vitest"; |
2 | | -import { getErrorDetails } from "../src/helpers"; |
| 1 | +import { describe, expect, it } from 'vitest'; |
| 2 | +import { getErrorDetails } from '../src/helpers'; |
3 | 3 |
|
4 | | -describe("getErrorDetails", () => { |
5 | | - it("returns full error object for valid error codes", () => { |
| 4 | +describe('getErrorDetails', () => { |
| 5 | + it('returns full error object for valid error codes', () => { |
6 | 6 | const result = getErrorDetails(1); |
7 | 7 | expect(result).toEqual({ |
8 | 8 | code: 1, |
9 | | - name: "InternalError", |
10 | | - description: "An unspecified internal error occurred." |
| 9 | + name: 'InternalError', |
| 10 | + description: 'An unspecified internal error occurred.', |
11 | 11 | }); |
12 | 12 |
|
13 | 13 | const duplicateKeyResult = getErrorDetails(11000); |
14 | 14 | expect(duplicateKeyResult).toEqual({ |
15 | 15 | code: 11000, |
16 | | - name: "DuplicateKey" |
| 16 | + name: 'DuplicateKey', |
17 | 17 | }); |
18 | 18 | }); |
19 | 19 |
|
20 | | - it("returns full error object for valid error names", () => { |
21 | | - const result = getErrorDetails("InternalError"); |
| 20 | + it('returns full error object for valid error names', () => { |
| 21 | + const result = getErrorDetails('InternalError'); |
22 | 22 | expect(result).toEqual({ |
23 | 23 | code: 1, |
24 | | - name: "InternalError", |
25 | | - description: "An unspecified internal error occurred." |
| 24 | + name: 'InternalError', |
| 25 | + description: 'An unspecified internal error occurred.', |
26 | 26 | }); |
27 | 27 |
|
28 | | - const duplicateKeyResult = getErrorDetails("DuplicateKey"); |
| 28 | + const duplicateKeyResult = getErrorDetails('DuplicateKey'); |
29 | 29 | expect(duplicateKeyResult).toEqual({ |
30 | 30 | code: 11000, |
31 | | - name: "DuplicateKey" |
| 31 | + name: 'DuplicateKey', |
32 | 32 | }); |
33 | 33 | }); |
34 | 34 |
|
35 | | - it("returns undefined for unknown error codes", () => { |
| 35 | + it('returns undefined for unknown error codes', () => { |
36 | 36 | expect(getErrorDetails(99999)).toBeUndefined(); |
37 | 37 | expect(getErrorDetails(-1)).toBeUndefined(); |
38 | 38 | expect(getErrorDetails(0)).toBeUndefined(); |
39 | 39 | }); |
40 | 40 |
|
41 | | - it("returns undefined for unknown error names", () => { |
42 | | - expect(getErrorDetails("NonExistentError")).toBeUndefined(); |
43 | | - expect(getErrorDetails("")).toBeUndefined(); |
44 | | - expect(getErrorDetails("invalidname")).toBeUndefined(); |
| 41 | + it('returns undefined for unknown error names', () => { |
| 42 | + expect(getErrorDetails('NonExistentError')).toBeUndefined(); |
| 43 | + expect(getErrorDetails('')).toBeUndefined(); |
| 44 | + expect(getErrorDetails('invalidname')).toBeUndefined(); |
45 | 45 | }); |
46 | 46 |
|
47 | | - it("handles NaN, Infinity/-Infinity for numeric input", () => { |
| 47 | + it('handles NaN, Infinity/-Infinity for numeric input', () => { |
48 | 48 | expect(getErrorDetails(NaN)).toBeUndefined(); |
49 | 49 | expect(getErrorDetails(Infinity)).toBeUndefined(); |
50 | 50 | expect(getErrorDetails(-Infinity)).toBeUndefined(); |
51 | 51 | }); |
52 | 52 |
|
53 | | - it("handles case sensitivity for string input", () => { |
54 | | - expect(getErrorDetails("internalerror")).toBeUndefined(); |
55 | | - expect(getErrorDetails("INTERNALERROR")).toBeUndefined(); |
56 | | - expect(getErrorDetails("InternalError")).toBeDefined(); |
| 53 | + it('handles case sensitivity for string input', () => { |
| 54 | + expect(getErrorDetails('internalerror')).toBeUndefined(); |
| 55 | + expect(getErrorDetails('INTERNALERROR')).toBeUndefined(); |
| 56 | + expect(getErrorDetails('InternalError')).toBeDefined(); |
57 | 57 | }); |
58 | 58 | }); |
0 commit comments