Skip to content

Commit deb5554

Browse files
authored
feat: add isInitialized agent property (#293)
Signed-off-by: Timo Glastra <timo@animo.id>
1 parent ec95d83 commit deb5554

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

src/agent/Agent.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export class Agent {
3232
protected messageReceiver: MessageReceiver
3333
protected messageSender: MessageSender
3434
public inboundTransporter?: InboundTransporter
35+
private _isInitialized = false
3536

3637
public readonly connections!: ConnectionsModule
3738
public readonly proofs!: ProofsModule
@@ -114,6 +115,10 @@ export class Agent {
114115
return this.eventEmitter
115116
}
116117

118+
public get isInitialized() {
119+
return this._isInitialized
120+
}
121+
117122
public async init() {
118123
await this.wallet.init()
119124

@@ -126,6 +131,8 @@ export class Agent {
126131
if (this.inboundTransporter) {
127132
await this.inboundTransporter.start(this)
128133
}
134+
135+
this._isInitialized = true
129136
}
130137

131138
public get publicDid() {

src/agent/__tests__/Agent.test.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,21 @@ import { Dispatcher } from '../Dispatcher'
2626
import { EnvelopeService } from '../EnvelopeService'
2727
import { getBaseConfig } from '../../__tests__/helpers'
2828

29-
const config = getBaseConfig('DI Test')
29+
const config = getBaseConfig('Agent Class Test')
3030

3131
describe('Agent', () => {
32+
describe('Initialization', () => {
33+
it('isInitialized should only return true after initialization', async () => {
34+
expect.assertions(2)
35+
36+
const agent = new Agent(config)
37+
38+
expect(agent.isInitialized).toBe(false)
39+
await agent.init()
40+
expect(agent.isInitialized).toBe(true)
41+
})
42+
})
43+
3244
describe('Dependency Injection', () => {
3345
it('should be able to resolve registered instances', () => {
3446
const agent = new Agent(config)

0 commit comments

Comments
 (0)