0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2025-01-20 21:32:31 -05:00

chore: response of connector POST API should be ConnectorResponse (#2699)

This commit is contained in:
Darcy Ye 2022-12-22 14:02:15 +08:00 committed by GitHub
parent f50509dfab
commit 87ebd057ea
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 14 deletions

View file

@ -40,6 +40,7 @@ const {
countConnectorByConnectorId, countConnectorByConnectorId,
deleteConnectorById, deleteConnectorById,
deleteConnectorByIds, deleteConnectorByIds,
insertConnector,
} = await mockEsmWithActual('#src/queries/connector.js', () => ({ } = await mockEsmWithActual('#src/queries/connector.js', () => ({
findConnectorById: jest.fn(), findConnectorById: jest.fn(),
countConnectorByConnectorId: jest.fn(), countConnectorByConnectorId: jest.fn(),
@ -165,20 +166,16 @@ describe('connector route', () => {
...mockLogtoConnector, ...mockLogtoConnector,
}, },
]); ]);
const response = await connectorRequest.post('/connectors').send({ await connectorRequest.post('/connectors').send({
connectorId: 'connectorId', connectorId: 'connectorId',
config: { cliend_id: 'client_id', client_secret: 'client_secret' }, config: { cliend_id: 'client_id', client_secret: 'client_secret' },
}); });
expect(response.body).toMatchObject( expect(insertConnector).toHaveBeenCalledWith(
expect.objectContaining({ expect.objectContaining({
connectorId: 'connectorId', connectorId: 'connectorId',
config: { config: { cliend_id: 'client_id', client_secret: 'client_secret' },
cliend_id: 'client_id',
client_secret: 'client_secret',
},
}) })
); );
expect(response).toHaveProperty('statusCode', 200);
}); });
it('throws when connector factory not found', async () => { it('throws when connector factory not found', async () => {
@ -216,12 +213,12 @@ describe('connector route', () => {
...mockLogtoConnector, ...mockLogtoConnector,
}, },
]); ]);
const response = await connectorRequest.post('/connectors').send({ await connectorRequest.post('/connectors').send({
connectorId: 'id0', connectorId: 'id0',
config: { cliend_id: 'client_id', client_secret: 'client_secret' }, config: { cliend_id: 'client_id', client_secret: 'client_secret' },
metadata: { target: 'new_target' }, metadata: { target: 'new_target' },
}); });
expect(response.body).toMatchObject( expect(insertConnector).toHaveBeenCalledWith(
expect.objectContaining({ expect.objectContaining({
connectorId: 'id0', connectorId: 'id0',
config: { config: {
@ -231,7 +228,6 @@ describe('connector route', () => {
metadata: { target: 'new_target' }, metadata: { target: 'new_target' },
}) })
); );
expect(response).toHaveProperty('statusCode', 200);
}); });
it('throws when add more than 1 instance with non-connector factory', async () => { it('throws when add more than 1 instance with non-connector factory', async () => {
@ -266,12 +262,11 @@ describe('connector route', () => {
}, },
]); ]);
countConnectorByConnectorId.mockResolvedValueOnce({ count: 0 }); countConnectorByConnectorId.mockResolvedValueOnce({ count: 0 });
const response = await connectorRequest.post('/connectors').send({ await connectorRequest.post('/connectors').send({
connectorId: 'id1', connectorId: 'id1',
config: { cliend_id: 'client_id', client_secret: 'client_secret' }, config: { cliend_id: 'client_id', client_secret: 'client_secret' },
}); });
expect(response).toHaveProperty('statusCode', 200); expect(insertConnector).toHaveBeenCalledWith(
expect(response.body).toMatchObject(
expect.objectContaining({ expect.objectContaining({
connectorId: 'id1', connectorId: 'id1',
config: { config: {

View file

@ -159,7 +159,7 @@ export default function connectorRoutes<T extends AuthedRouter>(router: T) {
} }
const insertConnectorId = generateConnectorId(); const insertConnectorId = generateConnectorId();
ctx.body = await insertConnector({ await insertConnector({
id: insertConnectorId, id: insertConnectorId,
connectorId, connectorId,
...cleanDeep({ syncProfile, config, metadata }), ...cleanDeep({ syncProfile, config, metadata }),
@ -186,6 +186,9 @@ export default function connectorRoutes<T extends AuthedRouter>(router: T) {
} }
} }
const connector = await getLogtoConnectorById(insertConnectorId);
ctx.body = transpileLogtoConnector(connector);
return next(); return next();
} }
); );