-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathgenerateOperationId.test.js
134 lines (131 loc) · 4.88 KB
/
generateOperationId.test.js
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
import { describe, expect, it } from '@jest/globals';
import {
generateOperationIdForCustomMethod,
generateOperationIdForStandardMethod,
} from '../../rulesets/functions/utils/generateOperationId.js';
const customMethodCases = [
// Real examples that work well
{
path: '/api/atlas/v2/orgs/{orgId}/resourcePolicies:validate',
expectedOperationId: 'validateOrgResourcePolicies',
},
{
path: '/api/atlas/v2/orgs/{orgId}/invoices/{invoiceId}/lineItems:search',
expectedOperationId: 'searchOrgInvoiceLineItems',
},
{
path: '/api/atlas/v2/groups/{groupId}:migrate',
expectedOperationId: 'migrateGroup',
},
{
path: '/api/atlas/v2/groups/{groupId}/serviceAccounts/{clientId}:invite',
expectedOperationId: 'inviteGroupServiceAccountsClient',
},
{
path: '/api/atlas/v2/groups/{groupId}/streams/{tenantName}/processor/{processorName}:stop',
expectedOperationId: 'stopGroupStreamsTenantProcessor',
},
{
path: '/api/atlas/v2/groups/{groupId}/flexClusters:tenantUpgrade',
expectedOperationId: 'tenantGroupFlexClustersUpgrade',
},
{
path: '/api/atlas/v2/orgs/{orgId}/users/{userId}:addRole',
expectedOperationId: 'addOrgUserRole',
},
// Some examples to show some edge cases
{
path: '/api/atlas/v2/orgs/{orgId}/billing/costExplorer:getUsage',
expectedOperationId: 'getOrgBillingCostExplorerUsage', // Double parent case works well here
},
// Some examples to show some caveats
{
path: '/api/atlas/v2/groups/{groupId}/streams:withSampleConnections',
method: 'get',
expectedOperationId: 'withGroupStreamsSampleConnections', // This one has a weird custom method, ideally it would be /streams:createWithSampleConnections
},
];
const standardMethodCases = [
// Real examples that work well
{
path: '/api/atlas/v2/groups/{groupId}/serviceAccounts',
method: 'list',
expectedOperationId: 'listGroupServiceAccounts',
},
{
path: '/api/atlas/v2/groups/{groupId}/serviceAccounts/{clientId}',
method: 'get',
expectedOperationId: 'getGroupServiceAccountsClient',
},
{
path: '/api/atlas/v2/groups/{groupId}/pushBasedLogExport',
method: 'delete',
expectedOperationId: 'deleteGroupPushBasedLogExport',
},
{
path: '/api/atlas/v2/groups/{groupId}/processes/{processId}/measurements',
method: 'list',
expectedOperationId: 'listGroupProcessMeasurements',
},
// Some examples to show some caveats
{
path: '/api/atlas/v2/groups/{groupId}/serviceAccounts',
method: 'create',
expectedOperationId: 'createGroupServiceAccounts', // Ideally singular instead of plural
},
{
path: '/api/atlas/v2/groups/{groupId}/invites/{invitationId}',
method: 'get',
expectedOperationId: 'getGroupInvitation',
},
{
path: '/api/atlas/v2/federationSettings/{federationSettingsId}/connectedOrgConfigs/{orgId}/roleMappings/{id}',
method: 'delete',
expectedOperationId: 'deleteFederationSettingsConnectedOrgConfigsOrgRoleMappings',
},
{
path: '/api/atlas/v2/groups/{groupId}/clusters/{hostName}/logs/{logName}.gz',
method: 'get',
expectedOperationId: 'getGroupClustersHostLog',
},
{
path: '/api/atlas/v2/groups/{groupId}/serverless/{name}',
method: 'delete',
expectedOperationId: 'deleteGroupServerless', // Ideally it should be something like /{instanceName} -> deleteGroupServerlessInstance
},
{
path: '/api/atlas/v2/groups/{groupId}/cloudProviderAccess/{cloudProvider}/{roleId}',
method: 'get',
expectedOperationId: 'getGroupCloudRole', // Ideally the provider from cloudProvider wouldn't be stripped here
},
{
path: '/api/atlas/v2/orgs',
method: 'list',
expectedOperationId: 'listOrgs',
},
{
path: '/api/atlas/v2/orgs/{orgId}/apiKeys/{apiUserId}',
method: 'get',
expectedOperationId: 'getOrgApiKeysApiUser', // This one is a bit weird, ideally it would be /apiKeys/{apiKeyId} -> getOrgApiKey
},
{
path: '/api/atlas/v2/groups/{groupId}/privateEndpoint/{cloudProvider}/endpointService/{endpointServiceId}/endpoint/{endpointId}',
method: 'delete',
expectedOperationId: 'deleteGroupPrivateEndpointCloudEndpointServiceEndpoint', // This gets complicated, and ideally for this case cloudProvider wouldn't be stripped to only 'cloud'
},
];
describe('tools/spectral/ipa/rulesets/functions/utils/generateOperationId.js', () => {
for (const testCase of customMethodCases) {
it.concurrent(`Custom method ${testCase.path} gets operationId ${testCase.expectedOperationId}`, () => {
expect(generateOperationIdForCustomMethod(testCase.path)).toBe(testCase.expectedOperationId);
});
}
for (const testCase of standardMethodCases) {
it.concurrent(
`Standard method ${testCase.method} ${testCase.path} gets operationId ${testCase.expectedOperationId}`,
() => {
expect(generateOperationIdForStandardMethod(testCase.path, testCase.method)).toBe(testCase.expectedOperationId);
}
);
}
});