From b9dd1c06a8de98414a620658a61e6188385ef147 Mon Sep 17 00:00:00 2001 From: Evan Hahn Date: Mon, 21 Oct 2024 23:48:29 +0000 Subject: [PATCH] Skeleton removal of server peer --- src/member-api.js | 9 +++++++++ test-e2e/server.js | 26 +++++++++++++++++++++++++- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/src/member-api.js b/src/member-api.js index 670ca942..b3c49086 100644 --- a/src/member-api.js +++ b/src/member-api.js @@ -366,6 +366,15 @@ export class MemberApi extends TypedEmitter { } } + /** + * @param {string} serverDeviceId + * @returns {Promise} + */ + async removeServerPeer(serverDeviceId) { + // TODO + console.log({ serverDeviceId }) + } + /** * @param {object} options * @param {string} options.baseUrl diff --git a/test-e2e/server.js b/test-e2e/server.js index 523f50f5..3f09d3d9 100644 --- a/test-e2e/server.js +++ b/test-e2e/server.js @@ -5,7 +5,7 @@ import createFastify from 'fastify' import assert from 'node:assert/strict' import test from 'node:test' import { pEvent } from 'p-event' -import { MEMBER_ROLE_ID } from '../src/roles.js' +import { LEFT_ROLE_ID, MEMBER_ROLE_ID } from '../src/roles.js' import createServer from '../src/server/app.js' import { connectPeers, @@ -221,6 +221,30 @@ test('adding a server peer', async (t) => { ) }) +test.skip('removing a server peer', async (t) => { + const manager = createManager('device0', t) + const projectId = await manager.createProject() + const project = await manager.getProject(projectId) + + const serverBaseUrl = await createTestServer(t) + + await project.$member.addServerPeer(serverBaseUrl, { + dangerouslyAllowInsecureConnections: true, + }) + + const serverPeer = await findServerPeer(project) + assert(serverPeer, 'server peer should be added') + await project.$member.removeServerPeer(serverPeer.deviceId) + + assert.equal( + (await findServerPeer(project))?.role.roleId, + LEFT_ROLE_ID, + 'we should believe the server is gone' + ) + + // TODO: ensure no connections are made +}) + test("can't add a server to two different projects", async (t) => { const [managerA, managerB] = await createManagers(2, t, 'mobile') const projectIdA = await managerA.createProject()