From 3e5196237d3416ca730696bae6ec0797958d90c7 Mon Sep 17 00:00:00 2001 From: Alex Potsides Date: Sat, 3 Jun 2023 10:05:00 +0100 Subject: [PATCH] test: add tests for patching and merging protocols (#87) --- test/merge.spec.ts | 37 +++++++++++++++++++++++++++++++++++++ test/patch.spec.ts | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+) diff --git a/test/merge.spec.ts b/test/merge.spec.ts index 4ecb8bf..b16a56d 100644 --- a/test/merge.spec.ts +++ b/test/merge.spec.ts @@ -174,6 +174,43 @@ describe('merge', () => { expect(updated).to.have.property('peerRecordEnvelope').that.deep.equals(original.peerRecordEnvelope) }) + it('merges protocols', async () => { + const peer: PeerData = { + multiaddrs: [ + addr1, + addr2 + ], + metadata: { + foo: Uint8Array.from([0, 1, 2]) + }, + tags: { + tag1: { value: 10 } + }, + protocols: [ + '/foo/bar' + ], + peerRecordEnvelope: Uint8Array.from([3, 4, 5]) + } + + const original = await peerStore.save(otherPeerId, peer) + const updated = await peerStore.merge(otherPeerId, { + protocols: [ + '/bar/foo' + ] + }) + + expect(updated).to.have.property('protocols').that.deep.equals([ + '/bar/foo', + '/foo/bar' + ]) + + // other fields should be untouched + expect(updated).to.have.property('addresses').that.deep.equals(original.addresses) + expect(updated).to.have.property('metadata').that.deep.equals(original.metadata) + expect(updated).to.have.property('tags').that.deep.equals(original.tags) + expect(updated).to.have.property('peerRecordEnvelope').that.deep.equals(original.peerRecordEnvelope) + }) + it('merges peer record envelope', async () => { const peer: PeerData = { multiaddrs: [ diff --git a/test/patch.spec.ts b/test/patch.spec.ts index 0fea047..3d64bf4 100644 --- a/test/patch.spec.ts +++ b/test/patch.spec.ts @@ -159,6 +159,42 @@ describe('patch', () => { expect(updated).to.have.property('peerRecordEnvelope').that.deep.equals(original.peerRecordEnvelope) }) + it('replaces protocols', async () => { + const peer: PeerData = { + multiaddrs: [ + addr1, + addr2 + ], + metadata: { + foo: Uint8Array.from([0, 1, 2]) + }, + tags: { + tag1: { value: 10 } + }, + protocols: [ + '/foo/bar' + ], + peerRecordEnvelope: Uint8Array.from([3, 4, 5]) + } + + const original = await peerStore.save(otherPeerId, peer) + const updated = await peerStore.patch(otherPeerId, { + protocols: [ + '/bar/foo' + ] + }) + + expect(updated).to.have.property('protocols').that.deep.equals([ + '/bar/foo' + ]) + + // other fields should be untouched + expect(updated).to.have.property('addresses').that.deep.equals(original.addresses) + expect(updated).to.have.property('metadata').that.deep.equals(original.metadata) + expect(updated).to.have.property('tags').that.deep.equals(original.tags) + expect(updated).to.have.property('peerRecordEnvelope').that.deep.equals(original.peerRecordEnvelope) + }) + it('replaces peer record envelope', async () => { const peer: PeerData = { multiaddrs: [