-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeployment-errors.test.ts
More file actions
158 lines (143 loc) · 4.53 KB
/
deployment-errors.test.ts
File metadata and controls
158 lines (143 loc) · 4.53 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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
import {
collectLaunchDeploymentErrorCodesFromGraphQLError,
FILE_UPLOAD_SIZE_LIMIT_USER_MESSAGE,
isLaunchDeploymentFileSizeRelatedError,
} from './deployment-errors';
describe('deployment-errors', () => {
it('should expose user message aligned with Launch file upload rules', () => {
expect(FILE_UPLOAD_SIZE_LIMIT_USER_MESSAGE).toBe(
'Please use a file over the size of 1KB and under the size of 100MB.',
);
});
it('should collect codes from messages, uploadUid errorObject, and cause graphQLErrors in one flow', () => {
const error = {
graphQLErrors: [
{
extensions: {
exception: {
messages: ['launch.DEPLOYMENT.INVALID_FILE_SIZE', 'other'],
errorObject: {
uploadUid: [{ code: 'launch.DEPLOYMENT.FILE_UPLOAD_FAILED' }],
},
},
},
},
],
cause: {
graphQLErrors: [
{
extensions: {
exception: {
messages: ['launch.OTHER.CODE'],
},
},
},
],
},
};
const codes = collectLaunchDeploymentErrorCodesFromGraphQLError(error);
expect(codes).toEqual([
'launch.DEPLOYMENT.INVALID_FILE_SIZE',
'other',
'launch.DEPLOYMENT.FILE_UPLOAD_FAILED',
'launch.OTHER.CODE',
]);
expect(isLaunchDeploymentFileSizeRelatedError(error)).toBe(true);
});
it('should return false when graphQL errors have no file size related codes', () => {
const error = {
graphQLErrors: [
{
extensions: {
exception: {
messages: ['launch.PROJECTS.DUPLICATE_NAME'],
},
},
},
],
};
expect(collectLaunchDeploymentErrorCodesFromGraphQLError(error)).toEqual(['launch.PROJECTS.DUPLICATE_NAME']);
expect(isLaunchDeploymentFileSizeRelatedError(error)).toBe(false);
});
it('should return false for empty or malformed error input', () => {
expect(collectLaunchDeploymentErrorCodesFromGraphQLError(undefined)).toEqual([]);
expect(isLaunchDeploymentFileSizeRelatedError(undefined)).toBe(false);
expect(collectLaunchDeploymentErrorCodesFromGraphQLError({})).toEqual([]);
expect(isLaunchDeploymentFileSizeRelatedError({})).toBe(false);
expect(
collectLaunchDeploymentErrorCodesFromGraphQLError({
graphQLErrors: [{ extensions: {} }],
}),
).toEqual([]);
expect(
isLaunchDeploymentFileSizeRelatedError({
graphQLErrors: [{ extensions: {} }],
}),
).toBe(false);
});
it('should skip non-string entries in messages and still collect string codes', () => {
const error = {
graphQLErrors: [
{
extensions: {
exception: {
messages: [
null,
42,
{ nested: 'launch.DEPLOYMENT.INVALID_FILE_SIZE' },
'launch.DEPLOYMENT.INVALID_FILE_SIZE',
'',
' ',
'\t',
],
},
},
},
],
};
const codes = collectLaunchDeploymentErrorCodesFromGraphQLError(error);
expect(codes).toEqual(['launch.DEPLOYMENT.INVALID_FILE_SIZE']);
expect(isLaunchDeploymentFileSizeRelatedError(error)).toBe(true);
});
it('should skip uploadUid entries without a string code and still collect valid codes', () => {
const error = {
graphQLErrors: [
{
extensions: {
exception: {
errorObject: {
uploadUid: [
null,
'not-an-object',
{},
{ code: 123 },
{ notCode: 'launch.DEPLOYMENT.FILE_UPLOAD_FAILED' },
{ code: 'launch.DEPLOYMENT.FILE_UPLOAD_FAILED' },
],
},
},
},
},
],
};
const codes = collectLaunchDeploymentErrorCodesFromGraphQLError(error);
expect(codes).toEqual(['launch.DEPLOYMENT.FILE_UPLOAD_FAILED']);
expect(isLaunchDeploymentFileSizeRelatedError(error)).toBe(true);
});
it('should detect FILE_UPLOAD_FAILED only from uploadUid when messages are absent', () => {
const error = {
graphQLErrors: [
{
extensions: {
exception: {
errorObject: {
uploadUid: [{ code: 'launch.DEPLOYMENT.FILE_UPLOAD_FAILED' }],
},
},
},
},
],
};
expect(isLaunchDeploymentFileSizeRelatedError(error)).toBe(true);
});
});