Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added endpoint setter to agent InitConfig #1278

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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