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

feat: return deviceId from getDeviceInfo() #454

Merged
merged 1 commit into from
Jan 30, 2024
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
4 changes: 2 additions & 2 deletions src/mapeo-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -678,15 +678,15 @@ export class MapeoManager extends TypedEmitter {
}

/**
* @returns {Promise<Partial<import('./schema/client.js').DeviceInfoParam>>}
* @returns {Promise<{ deviceId: string } & Partial<import('./schema/client.js').DeviceInfoParam>>}
*/
async getDeviceInfo() {
const row = this.#db
.select()
.from(localDeviceInfoTable)
.where(eq(localDeviceInfoTable.deviceId, this.#deviceId))
.get()
return row ? row.deviceInfo : {}
return { deviceId: this.#deviceId, ...row?.deviceInfo }
}

/**
Expand Down
6 changes: 4 additions & 2 deletions test-e2e/device-info.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@ test('write and read deviceInfo', async (t) => {
const info1 = { name: 'my device' }
await manager.setDeviceInfo(info1)
const readInfo1 = await manager.getDeviceInfo()
t.alike(readInfo1, info1)
const expected1 = { ...info1, deviceId: manager.deviceId }
t.alike(readInfo1, expected1)
const info2 = { name: 'new name' }
await manager.setDeviceInfo(info2)
const readInfo2 = await manager.getDeviceInfo()
t.alike(readInfo2, info2)
const expected2 = { ...info2, deviceId: manager.deviceId }
t.alike(readInfo2, expected2)
})

test('device info written to projects', (t) => {
Expand Down
Loading