Skip to content

Commit

Permalink
feat: add setAvatar method
Browse files Browse the repository at this point in the history
  • Loading branch information
dwickr committed Oct 20, 2023
1 parent 5f57cfc commit 89c8e02
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/bot.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const fs = require('fs')
const EventEmitter = require('events')
const mergician = require('mergician')
const WickrBrain = require('./brain')
Expand Down Expand Up @@ -299,6 +300,12 @@ class WickrBot extends EventEmitter {
this.defaultHandler = fn
}

setAvatar(imgPath) {
if (!fs.existsSync(imgPath)) throw new Error(`Unable to set avatar. File ${imgPath} not found.`)

return this.wickr.cmdSetAvatar(imgPath)
}

async waitForState(state, retries=10, interval=1000, exponential=true) {
const curState = this.wickr.getClientState()

Expand Down
1 change: 1 addition & 0 deletions test/fakes/wickr.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class FakeWickr {
cmdStartAsyncRecvMessages() {}
cmdSendRoomMessage() {}
cmdSend1to1Message() {}
cmdSetAvatar() {}
isConnected() {}
}

Expand Down
Binary file added test/fixtures/1x1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 20 additions & 0 deletions test/test-wickr-bot.js
Original file line number Diff line number Diff line change
Expand Up @@ -439,4 +439,24 @@ describe('wickr-bot', function() {
expect(this.wickr.cmdLeaveRoom.calledWith('Sfakevgroupid'))
})
})

describe('#setAvatar', function() {
it('calls cmdSetAvatar', function() {
let bot = new WickrBot(this.wickr, 'foo')
const avatar = __dirname + '/fixtures/1x1.png'
sinon.spy(this.wickr, 'cmdSetAvatar')

bot.setAvatar(avatar)
sinon.assert.calledWith(this.wickr.cmdSetAvatar, avatar)
})

it('throws an error when the avatar path does not exist', function() {
let fn = () => {
const bot = new WickrBot(this.wickr, 'foo')
bot.setAvatar('lol.png')
}

expect(fn).to.throw(/File lol.png not found/)
})
})
})

0 comments on commit 89c8e02

Please sign in to comment.