Skip to content

Commit

Permalink
feat: save self-hosted server details on member info
Browse files Browse the repository at this point in the history
We added support for self-hosted servers in
98d9981. This saves the details to
project-level member info.

This is a follow-up to 1913694.
  • Loading branch information
EvanHahn committed Oct 28, 2024
1 parent 1913694 commit 0722b30
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/mapeo-project.js
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@ export class MapeoProject extends TypedEmitter {
}

/**
* @param {Pick<import('@comapeo/schema').DeviceInfoValue, 'name' | 'deviceType'>} value
* @param {Pick<import('@comapeo/schema').DeviceInfoValue, 'name' | 'deviceType' | 'selfHostedServerDetails'>} value
* @returns {Promise<import('@comapeo/schema').DeviceInfo>}
*/
async [kSetOwnDeviceInfo](value) {
Expand All @@ -640,6 +640,7 @@ export class MapeoProject extends TypedEmitter {
const doc = {
name: value.name,
deviceType: value.deviceType,
selfHostedServerDetails: value.selfHostedServerDetails,
schemaName: /** @type {const} */ ('deviceInfo'),
}

Expand Down
4 changes: 4 additions & 0 deletions src/member-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ import { ROLES, isRoleIdForNewInvite } from './roles.js'
* @prop {DeviceInfo['name']} [name]
* @prop {DeviceInfo['deviceType']} [deviceType]
* @prop {DeviceInfo['createdAt']} [joinedAt]
* @prop {object} [selfHostedServerDetails]
* @prop {string} selfHostedServerDetails.baseUrl
*/

export class MemberApi extends TypedEmitter {
Expand Down Expand Up @@ -304,6 +306,8 @@ export class MemberApi extends TypedEmitter {
memberInfo.name = deviceInfo?.name
memberInfo.deviceType = deviceInfo?.deviceType
memberInfo.joinedAt = deviceInfo?.createdAt
memberInfo.selfHostedServerDetails =
deviceInfo?.selfHostedServerDetails
} catch (err) {
// Attempting to get someone else may throw because sync hasn't occurred or completed
// Only throw if attempting to get themself since the relevant information should be available
Expand Down
18 changes: 12 additions & 6 deletions test-e2e/members.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@ import {
MEMBER_ROLE_ID,
NO_ROLE,
} from '../src/roles.js'
import { connectPeers, createManagers, invite, waitForSync } from './utils.js'
import {
connectPeers,
createManagers,
invite,
removeUndefinedFields,
waitForSync,
} from './utils.js'
import { kDataTypes } from '../src/mapeo-project.js'

test('getting yourself after creating project', async (t) => {
Expand All @@ -30,7 +36,7 @@ test('getting yourself after creating project', async (t) => {
'time of joined project is close to now'
)
assert.deepEqual(
me,
removeUndefinedFields(me),
{
deviceId: project.deviceId,
deviceType: 'tablet',
Expand All @@ -45,7 +51,7 @@ test('getting yourself after creating project', async (t) => {

assert.equal(members.length, 1)
assert.deepEqual(
member,
removeUndefinedFields(member),
{
deviceId: project.deviceId,
deviceType: 'tablet',
Expand Down Expand Up @@ -81,7 +87,7 @@ test('getting yourself after adding project (but not yet synced)', async (t) =>
)

assert.deepEqual(
me,
removeUndefinedFields(me),
{
deviceId: project.deviceId,
deviceType: 'tablet',
Expand All @@ -96,7 +102,7 @@ test('getting yourself after adding project (but not yet synced)', async (t) =>

assert.equal(members.length, 1)
assert.deepEqual(
member,
removeUndefinedFields(member),
{
deviceId: project.deviceId,
deviceType: 'tablet',
Expand Down Expand Up @@ -170,7 +176,7 @@ test('getting invited member after invite accepted', async (t) => {
)

assert.deepEqual(
invitedMemberWithoutJoinedAt,
removeUndefinedFields(invitedMemberWithoutJoinedAt),
{
deviceId: invitee.deviceId,
deviceType: 'device_type_unspecified',
Expand Down

0 comments on commit 0722b30

Please sign in to comment.