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

Commit

Permalink
test: add tests for patching and merging protocols (#87)
Browse files Browse the repository at this point in the history
  • Loading branch information
achingbrain authored Jun 3, 2023
1 parent af73e3f commit 3e51962
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 0 deletions.
37 changes: 37 additions & 0 deletions test/merge.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down
36 changes: 36 additions & 0 deletions test/patch.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down

0 comments on commit 3e51962

Please sign in to comment.