-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLinearTrigger.node.test.ts
More file actions
98 lines (87 loc) · 2.81 KB
/
Copy pathLinearTrigger.node.test.ts
File metadata and controls
98 lines (87 loc) · 2.81 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
import type { IHookFunctions } from 'n8n-workflow';
import { NodeApiError } from 'n8n-workflow';
import { linearApiRequest } from '../GenericFunctions';
describe('Linear -> LinearTrigger.node', () => {
const mockHttpRequestWithAuthentication = jest.fn();
describe('webhook creation error handling', () => {
let mockHookFunctions: IHookFunctions;
beforeEach(() => {
mockHookFunctions = {
getNodeParameter: jest.fn().mockReturnValue('apiToken'),
helpers: {
httpRequestWithAuthentication: mockHttpRequestWithAuthentication,
},
getNode: jest.fn().mockReturnValue({ name: 'Linear Trigger', type: 'n8n-nodes-base.linearTrigger' }),
} as unknown as IHookFunctions;
jest.clearAllMocks();
});
it('should throw error that clearly mentions Linear when webhook creation fails due to admin permission', async () => {
// Simulate Linear API error response for insufficient permissions
const linearErrorResponse = {
errors: [
{
message: 'Invalid role: admin required',
extensions: {
userPresentableMessage: 'You need to have the "Admin" scope to create webhooks.',
},
},
],
};
mockHttpRequestWithAuthentication.mockResolvedValue(linearErrorResponse);
const webhookCreateBody = {
query: `
mutation webhookCreate($url: String!, $teamId: String!, $resources: [String!]!) {
webhookCreate(
input: {
url: $url
teamId: $teamId
resourceTypes: $resources
}
) {
success
webhook {
id
enabled
}
}
}`,
variables: {
url: 'http://example.com/webhook',
teamId: 'team-123',
resources: ['Issue', 'Comment'],
},
};
try {
await linearApiRequest.call(mockHookFunctions, webhookCreateBody);
fail('Expected error to be thrown');
} catch (error) {
expect(error).toBeInstanceOf(NodeApiError);
// The error message should clearly mention Linear to avoid confusion with n8n permissions
expect(error.message).toMatch(/linear/i);
// Should include information about admin requirement
expect(error.message.toLowerCase()).toContain('admin');
}
});
it('should preserve userPresentableMessage in error description', async () => {
const linearErrorResponse = {
errors: [
{
message: 'Invalid role: admin required',
extensions: {
userPresentableMessage: 'You need to have the "Admin" scope to create webhooks.',
},
},
],
};
mockHttpRequestWithAuthentication.mockResolvedValue(linearErrorResponse);
try {
await linearApiRequest.call(mockHookFunctions, {});
fail('Expected error to be thrown');
} catch (error) {
expect(error).toBeInstanceOf(NodeApiError);
expect(error.description).toContain('Admin');
expect(error.description).toContain('webhooks');
}
});
});
});