diff --git a/packages/nodes-base/credentials/FreshserviceApi.credentials.ts b/packages/nodes-base/credentials/FreshserviceApi.credentials.ts index 5d028787836..687f30d3920 100644 --- a/packages/nodes-base/credentials/FreshserviceApi.credentials.ts +++ b/packages/nodes-base/credentials/FreshserviceApi.credentials.ts @@ -1,4 +1,9 @@ -import type { ICredentialType, INodeProperties } from 'n8n-workflow'; +import type { + IAuthenticateGeneric, + ICredentialTestRequest, + ICredentialType, + INodeProperties, +} from 'n8n-workflow'; export class FreshserviceApi implements ICredentialType { name = 'freshserviceApi'; @@ -26,4 +31,21 @@ export class FreshserviceApi implements ICredentialType { 'Domain in the Freshservice org URL. For example, in https://n8n.freshservice.com, the domain is n8n', }, ]; + + authenticate: IAuthenticateGeneric = { + type: 'generic', + properties: { + auth: { + username: '={{$credentials.apiKey}}', + password: 'X', + }, + }, + }; + + test: ICredentialTestRequest = { + request: { + baseURL: '=https://{{$credentials.domain}}.freshservice.com/api/v2', + url: '/agents/me', + }, + }; } diff --git a/packages/nodes-base/credentials/test/FreshserviceApi.credentials.test.ts b/packages/nodes-base/credentials/test/FreshserviceApi.credentials.test.ts new file mode 100644 index 00000000000..6745f4af6b2 --- /dev/null +++ b/packages/nodes-base/credentials/test/FreshserviceApi.credentials.test.ts @@ -0,0 +1,35 @@ +import type { IAuthenticateGeneric } from 'n8n-workflow'; + +import { FreshserviceApi } from '../FreshserviceApi.credentials'; + +describe('FreshserviceApi Credential', () => { + const freshserviceApi = new FreshserviceApi(); + + it('should have correct metadata and properties', () => { + expect(freshserviceApi.name).toBe('freshserviceApi'); + expect(freshserviceApi.displayName).toBe('Freshservice API'); + expect(freshserviceApi.documentationUrl).toBe('freshservice'); + expect(freshserviceApi.properties).toHaveLength(2); + expect(freshserviceApi.properties[0].name).toBe('apiKey'); + expect(freshserviceApi.properties[0].typeOptions).toEqual({ password: true }); + expect(freshserviceApi.properties[1].name).toBe('domain'); + }); + + it('should have correct test request configuration', () => { + expect(freshserviceApi.test.request.baseURL).toBe( + '=https://{{$credentials.domain}}.freshservice.com/api/v2', + ); + expect(freshserviceApi.test.request.url).toBe('/agents/me'); + }); + + describe('authenticate', () => { + it('should be configured for basic auth with apiKey as username and X as password', () => { + const auth = freshserviceApi.authenticate as IAuthenticateGeneric; + + expect(auth.type).toBe('generic'); + expect(auth.properties.auth).toBeDefined(); + expect(auth.properties.auth?.username).toBe('={{$credentials.apiKey}}'); + expect(auth.properties.auth?.password).toBe('X'); + }); + }); +});