From 87ebd057ea7eee7aa654168228dd04414373a6cb Mon Sep 17 00:00:00 2001 From: Darcy Ye Date: Thu, 22 Dec 2022 14:02:15 +0800 Subject: [PATCH] chore: response of connector POST API should be ConnectorResponse (#2699) --- packages/core/src/routes/connector.test.ts | 21 ++++++++------------- packages/core/src/routes/connector.ts | 5 ++++- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/packages/core/src/routes/connector.test.ts b/packages/core/src/routes/connector.test.ts index 08167fd16..e4ef111f5 100644 --- a/packages/core/src/routes/connector.test.ts +++ b/packages/core/src/routes/connector.test.ts @@ -40,6 +40,7 @@ const { countConnectorByConnectorId, deleteConnectorById, deleteConnectorByIds, + insertConnector, } = await mockEsmWithActual('#src/queries/connector.js', () => ({ findConnectorById: jest.fn(), countConnectorByConnectorId: jest.fn(), @@ -165,20 +166,16 @@ describe('connector route', () => { ...mockLogtoConnector, }, ]); - const response = await connectorRequest.post('/connectors').send({ + await connectorRequest.post('/connectors').send({ connectorId: 'connectorId', config: { cliend_id: 'client_id', client_secret: 'client_secret' }, }); - expect(response.body).toMatchObject( + expect(insertConnector).toHaveBeenCalledWith( expect.objectContaining({ connectorId: 'connectorId', - config: { - cliend_id: 'client_id', - client_secret: 'client_secret', - }, + config: { cliend_id: 'client_id', client_secret: 'client_secret' }, }) ); - expect(response).toHaveProperty('statusCode', 200); }); it('throws when connector factory not found', async () => { @@ -216,12 +213,12 @@ describe('connector route', () => { ...mockLogtoConnector, }, ]); - const response = await connectorRequest.post('/connectors').send({ + await connectorRequest.post('/connectors').send({ connectorId: 'id0', config: { cliend_id: 'client_id', client_secret: 'client_secret' }, metadata: { target: 'new_target' }, }); - expect(response.body).toMatchObject( + expect(insertConnector).toHaveBeenCalledWith( expect.objectContaining({ connectorId: 'id0', config: { @@ -231,7 +228,6 @@ describe('connector route', () => { metadata: { target: 'new_target' }, }) ); - expect(response).toHaveProperty('statusCode', 200); }); it('throws when add more than 1 instance with non-connector factory', async () => { @@ -266,12 +262,11 @@ describe('connector route', () => { }, ]); countConnectorByConnectorId.mockResolvedValueOnce({ count: 0 }); - const response = await connectorRequest.post('/connectors').send({ + await connectorRequest.post('/connectors').send({ connectorId: 'id1', config: { cliend_id: 'client_id', client_secret: 'client_secret' }, }); - expect(response).toHaveProperty('statusCode', 200); - expect(response.body).toMatchObject( + expect(insertConnector).toHaveBeenCalledWith( expect.objectContaining({ connectorId: 'id1', config: { diff --git a/packages/core/src/routes/connector.ts b/packages/core/src/routes/connector.ts index d3c9eea09..2da4839ac 100644 --- a/packages/core/src/routes/connector.ts +++ b/packages/core/src/routes/connector.ts @@ -159,7 +159,7 @@ export default function connectorRoutes(router: T) { } const insertConnectorId = generateConnectorId(); - ctx.body = await insertConnector({ + await insertConnector({ id: insertConnectorId, connectorId, ...cleanDeep({ syncProfile, config, metadata }), @@ -186,6 +186,9 @@ export default function connectorRoutes(router: T) { } } + const connector = await getLogtoConnectorById(insertConnectorId); + ctx.body = transpileLogtoConnector(connector); + return next(); } );