Skip to content

Commit

Permalink
feat: return deviceId from getDeviceInfo() (#454)
Browse files Browse the repository at this point in the history
Fixes #453
  • Loading branch information
gmaclennan committed Jan 30, 2024
1 parent 805a45a commit f20c832
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
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

0 comments on commit f20c832

Please sign in to comment.