0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2025-01-06 20:40:08 -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,
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: {

View file

@ -159,7 +159,7 @@ export default function connectorRoutes<T extends AuthedRouter>(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<T extends AuthedRouter>(router: T) {
}
}
const connector = await getLogtoConnectorById(insertConnectorId);
ctx.body = transpileLogtoConnector(connector);
return next();
}
);