Skip to content

Commit

Permalink
feat: added endpoint setter to agent InitConfig (openwallet-foundatio…
Browse files Browse the repository at this point in the history
…n#1278)

Signed-off-by: Jim Ezesinachi <jim@animo.id>
  • Loading branch information
jimezesinachi authored Feb 10, 2023
1 parent 86cb9d0 commit 1d487b1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
10 changes: 8 additions & 2 deletions packages/core/src/agent/AgentConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ import { DidCommMimeType } from '../types'

export class AgentConfig {
private initConfig: InitConfig
private _endpoints: string[] | undefined
public label: string
public logger: Logger
public readonly agentDependencies: AgentDependencies

public constructor(initConfig: InitConfig, agentDependencies: AgentDependencies) {
this.initConfig = initConfig
this._endpoints = initConfig.endpoints
this.label = initConfig.label
this.logger = initConfig.logger ?? new ConsoleLogger(LogLevel.off)
this.agentDependencies = agentDependencies
Expand Down Expand Up @@ -134,11 +136,15 @@ export class AgentConfig {
public get endpoints(): [string, ...string[]] {
// if endpoints is not set, return queue endpoint
// https://github.com/hyperledger/aries-rfcs/issues/405#issuecomment-582612875
if (!this.initConfig.endpoints || this.initConfig.endpoints.length === 0) {
if (!this._endpoints || this._endpoints.length === 0) {
return [DID_COMM_TRANSPORT_QUEUE]
}

return this.initConfig.endpoints as [string, ...string[]]
return this._endpoints as [string, ...string[]]
}

public set endpoints(endpoints: string[]) {
this._endpoints = endpoints
}

/**
Expand Down
12 changes: 12 additions & 0 deletions packages/core/src/agent/__tests__/AgentConfig.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,18 @@ describe('AgentConfig', () => {

expect(agentConfig.endpoints).toStrictEqual(['didcomm:transport/queue'])
})

it('should return the new config endpoint after setter is called', () => {
const endpoint = 'https://local-url.com'
const newEndpoint = 'https://new-local-url.com'

const agentConfig = getAgentConfig('AgentConfig Test', {
endpoints: [endpoint],
})

agentConfig.endpoints = [newEndpoint]
expect(agentConfig.endpoints).toEqual([newEndpoint])
})
})

describe('label', () => {
Expand Down

0 comments on commit 1d487b1

Please sign in to comment.