-
Notifications
You must be signed in to change notification settings - Fork 144
Expand file tree
/
Copy pathcommon-errors-data.test.ts
More file actions
107 lines (90 loc) · 2.88 KB
/
common-errors-data.test.ts
File metadata and controls
107 lines (90 loc) · 2.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import { describe, expect, it } from 'vitest';
import type {
CommonErrorCategory,
CommonErrorSeverity,
} from '$lib/types/common-errors';
import {
COMMON_ERRORS,
getCommonErrorById,
getCommonErrorsByCategory,
} from './common-errors-data';
const VALID_SEVERITIES: CommonErrorSeverity[] = ['error', 'warning', 'info'];
const VALID_CATEGORIES: CommonErrorCategory[] = [
'workflow-timeouts',
'continue-as-new',
'retry-policies',
'activity-timeouts',
'heartbeat',
'delayed-start',
'local-activities',
'event-history',
'multiple-payloads',
'workflow-id-reuse',
'memo-headers',
];
describe('COMMON_ERRORS', () => {
it('contains 35 errors', () => {
expect(COMMON_ERRORS).toHaveLength(35);
});
it('has no duplicate IDs', () => {
const ids = COMMON_ERRORS.map((e) => e.id);
expect(new Set(ids).size).toBe(ids.length);
});
it('has valid severity for every error', () => {
for (const error of COMMON_ERRORS) {
expect(VALID_SEVERITIES).toContain(error.severity);
}
});
it('has valid category for every error', () => {
for (const error of COMMON_ERRORS) {
expect(VALID_CATEGORIES).toContain(error.category);
}
});
it('has required fields for every error', () => {
for (const error of COMMON_ERRORS) {
expect(error.id).toBeTypeOf('number');
expect(error.title).toBeTruthy();
expect(error.description).toBeTruthy();
expect(error.link).toBeTruthy();
expect(error.action).toBeTruthy();
expect(error.category).toBeTruthy();
}
});
it('has valid links for every error', () => {
for (const error of COMMON_ERRORS) {
expect(error.link).toMatch(/^https:\/\/docs\.temporal\.io\//);
}
});
});
describe('getCommonErrorById', () => {
it('returns the correct error for a valid ID', () => {
const error = getCommonErrorById(1);
expect(error).toBeDefined();
expect(error?.id).toBe(1);
expect(error?.title).toBe('Workflow Execution Timeout Set');
});
it('returns undefined for an invalid ID', () => {
expect(getCommonErrorById(999)).toBeUndefined();
});
it('returns undefined for ID 0', () => {
expect(getCommonErrorById(0)).toBeUndefined();
});
});
describe('getCommonErrorsByCategory', () => {
it('returns only errors matching the category', () => {
const errors = getCommonErrorsByCategory('workflow-timeouts');
expect(errors.length).toBeGreaterThan(0);
for (const error of errors) {
expect(error.category).toBe('workflow-timeouts');
}
});
it('returns 6 workflow-timeouts errors', () => {
expect(getCommonErrorsByCategory('workflow-timeouts')).toHaveLength(6);
});
it('returns 3 continue-as-new errors', () => {
expect(getCommonErrorsByCategory('continue-as-new')).toHaveLength(3);
});
it('returns errors for memo-headers category', () => {
expect(getCommonErrorsByCategory('memo-headers')).toHaveLength(1);
});
});