Skip to content

Commit

Permalink
fix: [unibroker] add identifier field in connection
Browse files Browse the repository at this point in the history
  • Loading branch information
aarlaud committed Jun 25, 2024
1 parent f2f20ae commit 64f0cad
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 2 deletions.
5 changes: 4 additions & 1 deletion lib/client/config/remoteConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ export const retrieveConnectionsForDeployment = async (
].type = connections[i].attributes.type;
connectionsObjectForFile.CONNECTIONS[
`${connections[i].attributes.name}`
].identifier = connections[i].id;
].identifier = connections[i].identifier;
connectionsObjectForFile.CONNECTIONS[
`${connections[i].attributes.name}`
].id = connections[i].id;
}
const universalConfigFileBuffer = readFileSync(universalFilePath);
const universalConfigFile = JSON.parse(
Expand Down
1 change: 1 addition & 0 deletions lib/client/types/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { ConnectionValidation } from './config';

export interface BrokerConnectionApiResponse {
id: string;
identifier: string;
type: string;
attributes: BrokerConnectionAttributes;
}
Expand Down
71 changes: 70 additions & 1 deletion test/unit/remoteConfig.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,35 @@ describe('Remote config helpers', () => {
{
data: [
{
id: 'BROKER_TOKEN_1',
id: 'CONNECTION_ID_1',
identifier: 'BROKER_TOKEN_1',
type: 'broker_connection',
attributes: {
name: 'my github connection',
type: 'github',
configuration: {
default: {},
required: {
GITHUB_TOKEN: 'GITHUB_TOKEN_XYZ',
},
},
},
deployment_id: '67890',
},
],
},
];
})
.get(
`/rest/tenants/12345/brokers/installs/12345/deployments/67891/connections?version=2024-04-02~experimental`,
)
.reply(() => {
return [
200,
{
data: [
{
id: 'CONNECTION_ID_1',
type: 'broker_connection',
attributes: {
name: 'my github connection',
Expand Down Expand Up @@ -82,6 +110,47 @@ describe('Remote config helpers', () => {
'my github connection': {
GITHUB_TOKEN: 'GITHUB_TOKEN_XYZ',
identifier: 'BROKER_TOKEN_1',
id: 'CONNECTION_ID_1',
type: 'github',
},
});
});

it('Retrieve identifier less connection from install ID and deployment ID', async () => {
await loadBrokerConfig();
let config = getConfig();

const installId = '12345';
const tenantId = '12345';
const deploymentId = '67891';
const apiVersion = '2024-04-02~experimental';
const apiBaseUrl = 'http://restapihostname';
config.tenantId = tenantId;
config.installId = installId;
config.deploymentId = deploymentId;
config.apiVersion = apiVersion;
config.API_BASE_URL = apiBaseUrl;
process.env.SERVICE_ENV = 'universal';
process.env.CLIENT_ID = '123';
process.env.CLIENT_SECRET = '123';

const clientOps: ClientOpts = {
port: 0,
config,
filters: { public: [], private: [] },
};

await retrieveConnectionsForDeployment(
clientOps,
universalFilePathLocationForTests,
);
await loadBrokerConfig();
config = getConfig();

expect(config.connections).toEqual({
'my github connection': {
GITHUB_TOKEN: 'GITHUB_TOKEN_XYZ',
id: 'CONNECTION_ID_1',
type: 'github',
},
});
Expand Down

0 comments on commit 64f0cad

Please sign in to comment.