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

fix: destructured save #272

Merged
merged 2 commits into from
Dec 11, 2022
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
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'))
})
})