|
| 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