Skip to content
This repository was archived by the owner on Jul 21, 2023. It is now read-only.

Commit 3e51962

Browse files
authored
test: add tests for patching and merging protocols (#87)
1 parent af73e3f commit 3e51962

File tree

2 files changed

+73
-0
lines changed

2 files changed

+73
-0
lines changed

test/merge.spec.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,43 @@ describe('merge', () => {
174174
expect(updated).to.have.property('peerRecordEnvelope').that.deep.equals(original.peerRecordEnvelope)
175175
})
176176

177+
it('merges protocols', async () => {
178+
const peer: PeerData = {
179+
multiaddrs: [
180+
addr1,
181+
addr2
182+
],
183+
metadata: {
184+
foo: Uint8Array.from([0, 1, 2])
185+
},
186+
tags: {
187+
tag1: { value: 10 }
188+
},
189+
protocols: [
190+
'/foo/bar'
191+
],
192+
peerRecordEnvelope: Uint8Array.from([3, 4, 5])
193+
}
194+
195+
const original = await peerStore.save(otherPeerId, peer)
196+
const updated = await peerStore.merge(otherPeerId, {
197+
protocols: [
198+
'/bar/foo'
199+
]
200+
})
201+
202+
expect(updated).to.have.property('protocols').that.deep.equals([
203+
'/bar/foo',
204+
'/foo/bar'
205+
])
206+
207+
// other fields should be untouched
208+
expect(updated).to.have.property('addresses').that.deep.equals(original.addresses)
209+
expect(updated).to.have.property('metadata').that.deep.equals(original.metadata)
210+
expect(updated).to.have.property('tags').that.deep.equals(original.tags)
211+
expect(updated).to.have.property('peerRecordEnvelope').that.deep.equals(original.peerRecordEnvelope)
212+
})
213+
177214
it('merges peer record envelope', async () => {
178215
const peer: PeerData = {
179216
multiaddrs: [

test/patch.spec.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,42 @@ describe('patch', () => {
159159
expect(updated).to.have.property('peerRecordEnvelope').that.deep.equals(original.peerRecordEnvelope)
160160
})
161161

162+
it('replaces protocols', async () => {
163+
const peer: PeerData = {
164+
multiaddrs: [
165+
addr1,
166+
addr2
167+
],
168+
metadata: {
169+
foo: Uint8Array.from([0, 1, 2])
170+
},
171+
tags: {
172+
tag1: { value: 10 }
173+
},
174+
protocols: [
175+
'/foo/bar'
176+
],
177+
peerRecordEnvelope: Uint8Array.from([3, 4, 5])
178+
}
179+
180+
const original = await peerStore.save(otherPeerId, peer)
181+
const updated = await peerStore.patch(otherPeerId, {
182+
protocols: [
183+
'/bar/foo'
184+
]
185+
})
186+
187+
expect(updated).to.have.property('protocols').that.deep.equals([
188+
'/bar/foo'
189+
])
190+
191+
// other fields should be untouched
192+
expect(updated).to.have.property('addresses').that.deep.equals(original.addresses)
193+
expect(updated).to.have.property('metadata').that.deep.equals(original.metadata)
194+
expect(updated).to.have.property('tags').that.deep.equals(original.tags)
195+
expect(updated).to.have.property('peerRecordEnvelope').that.deep.equals(original.peerRecordEnvelope)
196+
})
197+
162198
it('replaces peer record envelope', async () => {
163199
const peer: PeerData = {
164200
multiaddrs: [

0 commit comments

Comments
 (0)