Skip to content

Commit

Permalink
Fix Credentials endpoint (#610)
Browse files Browse the repository at this point in the history
* Fix Credentials endpoint

* Fix lint

---------

Co-authored-by: Subash Pradhan <[email protected]>
  • Loading branch information
SubashPradhan and Subash Pradhan authored Nov 28, 2024
1 parent d779b87 commit ebf4992
Show file tree
Hide file tree
Showing 2 changed files with 160 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/resources/credentials.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { AsyncListResponse, Resource } from './resource.js';
import { Overrides } from '../config.js';
import { Provider } from '../models/auth.js';
import {
Credential,
CreateCredentialRequest,
Credential,
ListCredentialsQueryParams,
UpdateCredentialRequest,
} from '../models/credentials.js';
import { Overrides } from '../config.js';
import {
NylasBaseResponse,
NylasListResponse,
NylasResponse,
} from '../models/response.js';
import { Provider } from '../models/auth.js';
import { AsyncListResponse, Resource } from './resource.js';

/**
* The parameters for the {@link Credentials.find} method
Expand Down Expand Up @@ -80,7 +80,7 @@ export class Credentials extends Resource {
return super._list<NylasListResponse<Credential>>({
queryParams,
overrides,
path: `/v3/credentials/${provider}/creds`,
path: `/v3/connectors/${provider}/creds`,
});
}

Expand All @@ -94,7 +94,7 @@ export class Credentials extends Resource {
overrides,
}: FindCredentialParams & Overrides): Promise<NylasResponse<Credential>> {
return super._find({
path: `/v3/credentials/${provider}/creds/${credentialsId}`,
path: `/v3/connectors/${provider}/creds/${credentialsId}`,
overrides,
});
}
Expand All @@ -109,7 +109,7 @@ export class Credentials extends Resource {
overrides,
}: CreateCredentialParams & Overrides): Promise<NylasResponse<Credential>> {
return super._create({
path: `/v3/credentials/${provider}/creds`,
path: `/v3/connectors/${provider}/creds`,
requestBody,
overrides,
});
Expand All @@ -126,7 +126,7 @@ export class Credentials extends Resource {
overrides,
}: UpdateCredentialParams & Overrides): Promise<NylasResponse<Credential>> {
return super._update({
path: `/v3/credentials/${provider}/creds/${credentialsId}}`,
path: `/v3/connectors/${provider}/creds/${credentialsId}`,
requestBody,
overrides,
});
Expand All @@ -142,7 +142,7 @@ export class Credentials extends Resource {
overrides,
}: DestroyCredentialParams & Overrides): Promise<NylasBaseResponse> {
return super._destroy({
path: `/v3/credentials/${provider}/creds/${credentialsId}}`,
path: `/v3/connectors/${provider}/creds/${credentialsId}`,
overrides,
});
}
Expand Down
151 changes: 151 additions & 0 deletions tests/resources/credentials.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
import APIClient from '../../src/apiClient';
import { CredentialType } from '../../src/models/credentials';
import { Credentials } from '../../src/resources/credentials';
jest.mock('../src/apiClient');

describe('Credentials', () => {
let apiClient: jest.Mocked<APIClient>;
let credentials: Credentials;

beforeAll(() => {
apiClient = new APIClient({
apiKey: 'apiKey',
apiUri: 'https://test.api.nylas.com',
timeout: 30,
headers: {},
}) as jest.Mocked<APIClient>;

credentials = new Credentials(apiClient);
apiClient.request.mockResolvedValue({});
});

describe('list', () => {
it('should call apiClient.request with the correct params', async () => {
await credentials.list({
provider: 'microsoft',
overrides: {
apiUri: 'https://test.api.nylas.com',
headers: { override: 'bar' },
},
});

expect(apiClient.request).toHaveBeenCalledWith({
method: 'GET',
path: '/v3/connectors/microsoft/creds',
overrides: {
apiUri: 'https://test.api.nylas.com',
headers: { override: 'bar' },
},
});
});
});

describe('find', () => {
it('should call apiClient.request with the correct params', async () => {
await credentials.find({
provider: 'microsoft',
credentialsId: 'microsoft-id123',
overrides: {
apiUri: 'https://test.api.nylas.com',
headers: { override: 'bar' },
},
});

expect(apiClient.request).toHaveBeenCalledWith({
method: 'GET',
path: '/v3/connectors/microsoft/creds/microsoft-id123',
overrides: {
apiUri: 'https://test.api.nylas.com',
headers: { override: 'bar' },
},
});
});
});

describe('create', () => {
it('should call apiClient.request with the correct params', async () => {
await credentials.create({
provider: 'microsoft',
requestBody: {
name: 'My Microsoft Connector',
credentialType: CredentialType.CONNECTOR,
credentialData: {
clientID: '<CLIENT_ID>',
clientSecret: '<CLIENT_SECRET>',
},
},
overrides: {
apiUri: 'https://test.api.nylas.com',
headers: { override: 'bar' },
},
});

expect(apiClient.request).toHaveBeenCalledWith({
method: 'POST',
path: '/v3/connectors/microsoft/creds',
body: {
name: 'My Microsoft Connector',
credentialType: CredentialType.CONNECTOR,
credentialData: {
clientID: '<CLIENT_ID>',
clientSecret: '<CLIENT_SECRET>',
},
},
overrides: {
apiUri: 'https://test.api.nylas.com',
headers: { override: 'bar' },
},
});
});
});

describe('update', () => {
it('should call apiClient.request with the correct params', async () => {
await credentials.update({
provider: 'microsoft',
credentialsId: 'microsoft-123',
requestBody: {
name: 'Changed Name',
},
overrides: {
apiUri: 'https://test.api.nylas.com',
headers: { override: 'bar' },
},
});

expect(apiClient.request).toHaveBeenCalledWith({
method: 'PUT',
path: '/v3/connectors/microsoft/creds/microsoft-123',
body: {
name: 'Changed Name',
},
overrides: {
apiUri: 'https://test.api.nylas.com',
headers: { override: 'bar' },
},
});
});
});

describe('destroy', () => {
it('should call apiClient.request with the correct params', async () => {
await credentials.destroy({
provider: 'microsoft',
credentialsId: 'microsoft-1234',
overrides: {
apiUri: 'https://test.api.nylas.com',
headers: { override: 'bar' },
},
});

expect(apiClient.request).toHaveBeenCalledWith({
method: 'DELETE',
path: '/v3/connectors/microsoft/creds/microsoft-1234',
overrides: {
apiUri: 'https://test.api.nylas.com',
headers: { override: 'bar' },
},
});
});
});
});

0 comments on commit ebf4992

Please sign in to comment.