feat: Add RS client to hooks service (#9834)

This commit is contained in:
Mutasem Aldmour 2024-06-24 10:44:49 +02:00 committed by GitHub
parent 8e529219df
commit b807e6726f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 18 additions and 0 deletions

View file

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

View file

@ -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);
});
});