Skip to content

Commit

Permalink
feat: add isInitialized agent property (#293)
Browse files Browse the repository at this point in the history
Signed-off-by: Timo Glastra <timo@animo.id>
  • Loading branch information
TimoGlastra authored May 27, 2021
1 parent ec95d83 commit deb5554
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/agent/Agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export class Agent {
protected messageReceiver: MessageReceiver
protected messageSender: MessageSender
public inboundTransporter?: InboundTransporter
private _isInitialized = false

public readonly connections!: ConnectionsModule
public readonly proofs!: ProofsModule
Expand Down Expand Up @@ -114,6 +115,10 @@ export class Agent {
return this.eventEmitter
}

public get isInitialized() {
return this._isInitialized
}

public async init() {
await this.wallet.init()

Expand All @@ -126,6 +131,8 @@ export class Agent {
if (this.inboundTransporter) {
await this.inboundTransporter.start(this)
}

this._isInitialized = true
}

public get publicDid() {
Expand Down
14 changes: 13 additions & 1 deletion src/agent/__tests__/Agent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,21 @@ import { Dispatcher } from '../Dispatcher'
import { EnvelopeService } from '../EnvelopeService'
import { getBaseConfig } from '../../__tests__/helpers'

const config = getBaseConfig('DI Test')
const config = getBaseConfig('Agent Class Test')

describe('Agent', () => {
describe('Initialization', () => {
it('isInitialized should only return true after initialization', async () => {
expect.assertions(2)

const agent = new Agent(config)

expect(agent.isInitialized).toBe(false)
await agent.init()
expect(agent.isInitialized).toBe(true)
})
})

describe('Dependency Injection', () => {
it('should be able to resolve registered instances', () => {
const agent = new Agent(config)
Expand Down

0 comments on commit deb5554

Please sign in to comment.