Skip to content

Commit

Permalink
fix: destructured save (#272)
Browse files Browse the repository at this point in the history
  • Loading branch information
Alan Shaw authored Dec 11, 2022
1 parent 6dc77ca commit a4f20a9
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
3 changes: 2 additions & 1 deletion packages/access-client/src/agent-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ export class AgentData {
this.spaces = data.spaces
this.delegations = data.delegations
this.currentSpace = data.currentSpace
this.#save = options.store ? options.store.save : () => {}
this.#save = (data) =>
options.store ? options.store.save(data) : undefined
}

/**
Expand Down
26 changes: 26 additions & 0 deletions packages/access-client/test/agent-data.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import assert from 'assert'
import { AgentData } from '../src/agent-data.js'

describe('AgentData', () => {
it('should not destructure store methods', async () => {
// eslint-disable-next-line unicorn/no-await-expression-member
const raw = (await AgentData.create()).export()
class Store {
async open() {}
async close() {}
async load() {
return raw
}

async reset() {}
async save() {
if (!(this instanceof Store)) {
throw new TypeError('unexpected this value')
}
}
}
const store = new Store()
const data = await AgentData.create(undefined, { store })
await assert.doesNotReject(data.setCurrentSpace('did:x:y'))
})
})

0 comments on commit a4f20a9

Please sign in to comment.