Skip to content

Commit ebf4992

Browse files
SubashPradhanSubash Pradhan
andauthored
Fix Credentials endpoint (#610)
* Fix Credentials endpoint * Fix lint --------- Co-authored-by: Subash Pradhan <[email protected]>
1 parent d779b87 commit ebf4992

File tree

2 files changed

+160
-9
lines changed

2 files changed

+160
-9
lines changed

src/resources/credentials.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
import { AsyncListResponse, Resource } from './resource.js';
1+
import { Overrides } from '../config.js';
2+
import { Provider } from '../models/auth.js';
23
import {
3-
Credential,
44
CreateCredentialRequest,
5+
Credential,
56
ListCredentialsQueryParams,
67
UpdateCredentialRequest,
78
} from '../models/credentials.js';
8-
import { Overrides } from '../config.js';
99
import {
1010
NylasBaseResponse,
1111
NylasListResponse,
1212
NylasResponse,
1313
} from '../models/response.js';
14-
import { Provider } from '../models/auth.js';
14+
import { AsyncListResponse, Resource } from './resource.js';
1515

1616
/**
1717
* The parameters for the {@link Credentials.find} method
@@ -80,7 +80,7 @@ export class Credentials extends Resource {
8080
return super._list<NylasListResponse<Credential>>({
8181
queryParams,
8282
overrides,
83-
path: `/v3/credentials/${provider}/creds`,
83+
path: `/v3/connectors/${provider}/creds`,
8484
});
8585
}
8686

@@ -94,7 +94,7 @@ export class Credentials extends Resource {
9494
overrides,
9595
}: FindCredentialParams & Overrides): Promise<NylasResponse<Credential>> {
9696
return super._find({
97-
path: `/v3/credentials/${provider}/creds/${credentialsId}`,
97+
path: `/v3/connectors/${provider}/creds/${credentialsId}`,
9898
overrides,
9999
});
100100
}
@@ -109,7 +109,7 @@ export class Credentials extends Resource {
109109
overrides,
110110
}: CreateCredentialParams & Overrides): Promise<NylasResponse<Credential>> {
111111
return super._create({
112-
path: `/v3/credentials/${provider}/creds`,
112+
path: `/v3/connectors/${provider}/creds`,
113113
requestBody,
114114
overrides,
115115
});
@@ -126,7 +126,7 @@ export class Credentials extends Resource {
126126
overrides,
127127
}: UpdateCredentialParams & Overrides): Promise<NylasResponse<Credential>> {
128128
return super._update({
129-
path: `/v3/credentials/${provider}/creds/${credentialsId}}`,
129+
path: `/v3/connectors/${provider}/creds/${credentialsId}`,
130130
requestBody,
131131
overrides,
132132
});
@@ -142,7 +142,7 @@ export class Credentials extends Resource {
142142
overrides,
143143
}: DestroyCredentialParams & Overrides): Promise<NylasBaseResponse> {
144144
return super._destroy({
145-
path: `/v3/credentials/${provider}/creds/${credentialsId}}`,
145+
path: `/v3/connectors/${provider}/creds/${credentialsId}`,
146146
overrides,
147147
});
148148
}
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
import APIClient from '../../src/apiClient';
2+
import { CredentialType } from '../../src/models/credentials';
3+
import { Credentials } from '../../src/resources/credentials';
4+
jest.mock('../src/apiClient');
5+
6+
describe('Credentials', () => {
7+
let apiClient: jest.Mocked<APIClient>;
8+
let credentials: Credentials;
9+
10+
beforeAll(() => {
11+
apiClient = new APIClient({
12+
apiKey: 'apiKey',
13+
apiUri: 'https://test.api.nylas.com',
14+
timeout: 30,
15+
headers: {},
16+
}) as jest.Mocked<APIClient>;
17+
18+
credentials = new Credentials(apiClient);
19+
apiClient.request.mockResolvedValue({});
20+
});
21+
22+
describe('list', () => {
23+
it('should call apiClient.request with the correct params', async () => {
24+
await credentials.list({
25+
provider: 'microsoft',
26+
overrides: {
27+
apiUri: 'https://test.api.nylas.com',
28+
headers: { override: 'bar' },
29+
},
30+
});
31+
32+
expect(apiClient.request).toHaveBeenCalledWith({
33+
method: 'GET',
34+
path: '/v3/connectors/microsoft/creds',
35+
overrides: {
36+
apiUri: 'https://test.api.nylas.com',
37+
headers: { override: 'bar' },
38+
},
39+
});
40+
});
41+
});
42+
43+
describe('find', () => {
44+
it('should call apiClient.request with the correct params', async () => {
45+
await credentials.find({
46+
provider: 'microsoft',
47+
credentialsId: 'microsoft-id123',
48+
overrides: {
49+
apiUri: 'https://test.api.nylas.com',
50+
headers: { override: 'bar' },
51+
},
52+
});
53+
54+
expect(apiClient.request).toHaveBeenCalledWith({
55+
method: 'GET',
56+
path: '/v3/connectors/microsoft/creds/microsoft-id123',
57+
overrides: {
58+
apiUri: 'https://test.api.nylas.com',
59+
headers: { override: 'bar' },
60+
},
61+
});
62+
});
63+
});
64+
65+
describe('create', () => {
66+
it('should call apiClient.request with the correct params', async () => {
67+
await credentials.create({
68+
provider: 'microsoft',
69+
requestBody: {
70+
name: 'My Microsoft Connector',
71+
credentialType: CredentialType.CONNECTOR,
72+
credentialData: {
73+
clientID: '<CLIENT_ID>',
74+
clientSecret: '<CLIENT_SECRET>',
75+
},
76+
},
77+
overrides: {
78+
apiUri: 'https://test.api.nylas.com',
79+
headers: { override: 'bar' },
80+
},
81+
});
82+
83+
expect(apiClient.request).toHaveBeenCalledWith({
84+
method: 'POST',
85+
path: '/v3/connectors/microsoft/creds',
86+
body: {
87+
name: 'My Microsoft Connector',
88+
credentialType: CredentialType.CONNECTOR,
89+
credentialData: {
90+
clientID: '<CLIENT_ID>',
91+
clientSecret: '<CLIENT_SECRET>',
92+
},
93+
},
94+
overrides: {
95+
apiUri: 'https://test.api.nylas.com',
96+
headers: { override: 'bar' },
97+
},
98+
});
99+
});
100+
});
101+
102+
describe('update', () => {
103+
it('should call apiClient.request with the correct params', async () => {
104+
await credentials.update({
105+
provider: 'microsoft',
106+
credentialsId: 'microsoft-123',
107+
requestBody: {
108+
name: 'Changed Name',
109+
},
110+
overrides: {
111+
apiUri: 'https://test.api.nylas.com',
112+
headers: { override: 'bar' },
113+
},
114+
});
115+
116+
expect(apiClient.request).toHaveBeenCalledWith({
117+
method: 'PUT',
118+
path: '/v3/connectors/microsoft/creds/microsoft-123',
119+
body: {
120+
name: 'Changed Name',
121+
},
122+
overrides: {
123+
apiUri: 'https://test.api.nylas.com',
124+
headers: { override: 'bar' },
125+
},
126+
});
127+
});
128+
});
129+
130+
describe('destroy', () => {
131+
it('should call apiClient.request with the correct params', async () => {
132+
await credentials.destroy({
133+
provider: 'microsoft',
134+
credentialsId: 'microsoft-1234',
135+
overrides: {
136+
apiUri: 'https://test.api.nylas.com',
137+
headers: { override: 'bar' },
138+
},
139+
});
140+
141+
expect(apiClient.request).toHaveBeenCalledWith({
142+
method: 'DELETE',
143+
path: '/v3/connectors/microsoft/creds/microsoft-1234',
144+
overrides: {
145+
apiUri: 'https://test.api.nylas.com',
146+
headers: { override: 'bar' },
147+
},
148+
});
149+
});
150+
});
151+
});

0 commit comments

Comments
 (0)