mirror of
https://github.com/n8n-io/n8n.git
synced 2025-02-02 07:01:30 -08:00
feat: Add RS client to hooks service (#9834)
This commit is contained in:
parent
8e529219df
commit
b807e6726f
|
@ -18,6 +18,7 @@ import type { Settings } from '@db/entities/Settings';
|
|||
import { UserService } from '@/services/user.service';
|
||||
import type { AuthenticatedRequest } from '@/requests';
|
||||
import type { Invitation } from '@/Interfaces';
|
||||
import RudderStack, { type constructorOptions } from '@rudderstack/rudder-sdk-node';
|
||||
|
||||
/**
|
||||
* Exposes functionality to be used by the cloud BE hooks.
|
||||
|
@ -106,6 +107,10 @@ export class HooksService {
|
|||
return await this.authService.authMiddleware(req, res, next);
|
||||
}
|
||||
|
||||
getRudderStackClient(key: string, options: constructorOptions): RudderStack {
|
||||
return new RudderStack(key, options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return repositories to be used in the hooks
|
||||
* 1. Some self-hosted users rely in the repositories to interact with the DB directly
|
||||
|
|
|
@ -12,6 +12,9 @@ import { HooksService } from '@/services/hooks.service';
|
|||
import type { Invitation } from '@/Interfaces';
|
||||
import type { AuthenticatedRequest } from '@/requests';
|
||||
import type { AuthUserRepository } from '@/databases/repositories/authUser.repository';
|
||||
import RudderStack from '@rudderstack/rudder-sdk-node';
|
||||
|
||||
jest.mock('@rudderstack/rudder-sdk-node');
|
||||
|
||||
describe('HooksService', () => {
|
||||
const mockedUser = mock<AuthUser>();
|
||||
|
@ -148,4 +151,14 @@ describe('HooksService', () => {
|
|||
expect(collections).toHaveProperty('Credentials');
|
||||
expect(collections).toHaveProperty('Workflow');
|
||||
});
|
||||
|
||||
it('hooksService.getRudderStackClient', async () => {
|
||||
// ACT
|
||||
const key = 'TEST';
|
||||
const opts = { dataPlaneUrl: 'test.com' };
|
||||
const client = hooksService.getRudderStackClient(key, opts);
|
||||
|
||||
expect(client instanceof RudderStack).toBeTruthy();
|
||||
expect(RudderStack).toHaveBeenCalledWith(key, opts);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue