Skip to content

Commit

Permalink
fix(webhook-custom-actions): register webhook actions configured from…
Browse files Browse the repository at this point in the history
… the frontend (#686)
  • Loading branch information
Guillaume Gautreau authored May 3, 2023
1 parent 52adcac commit fd9334a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/agent/src/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,13 @@ export default class Agent<S extends TSchema = TSchema> extends FrameworkMounter
override async start(): Promise<void> {
const { isProduction, logger, skipSchemaUpdate, typingsPath, typingsMaxDepth } = this.options;

const dataSource = await this.nocodeCustomizer.getDataSource(logger);

await this.nocodeCustomizer.use(
this.actionCustomizationService.addWebhookActions,
this.options.experimental?.webhookCustomActions,
);

const dataSource = await this.nocodeCustomizer.getDataSource(logger);

const [router] = await Promise.all([
this.getRouter(dataSource),
!skipSchemaUpdate ? this.sendSchema(dataSource) : Promise.resolve(),
Expand Down
22 changes: 22 additions & 0 deletions packages/agent/test/agent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,28 @@ describe('Agent', () => {
expect(mockCustomizer.use).toHaveBeenCalledTimes(1);
});

test('use should be called before getDatasource in order to be correctly applied', async () => {
const agent = new Agent(options);
let useCalled = false;
let getDataSourceCalledAfterUseCalled = false;

mockNocodeCustomizer.use.mockImplementationOnce(async () => {
useCalled = true;
});

mockNocodeCustomizer.getDataSource.mockImplementationOnce(async () => {
getDataSourceCalledAfterUseCalled = useCalled;

return factories.dataSource.build();
});

await agent.start();

expect(mockNocodeCustomizer.use).toHaveBeenCalledTimes(1);
expect(mockNocodeCustomizer.getDataSource).toHaveBeenCalledTimes(1);
expect(getDataSourceCalledAfterUseCalled).toBe(true);
});

// eslint-disable-next-line max-len
test("should add the customizer's factory as a datasource for the nocode customizer", async () => {
mockCustomizer.getFactory.mockReturnValueOnce('factory');
Expand Down

0 comments on commit fd9334a

Please sign in to comment.