require('bare-process/global') const test = require('brittle') const { HyperP2PInvertedIndex, PROTOCOL } = require('../index.js') test('exports', (t) => { t.ok(HyperP2PInvertedIndex) t.is(PROTOCOL, 'inverted-index/v1') }) test('index search removeDoc', async (t) => { const m = new HyperP2PInvertedIndex() m.index('d1', ['Hello', 'World']) t.alike(m.search('hello'), ['d1']) t.ok(m.removeDoc('d1')) t.is(m.search('world').length, 0) await m.close() }) test('validation', async (t) => { const m = new HyperP2PInvertedIndex() try { m.index('', ['x']) } catch (e) { t.ok(e) } await m.close() }) test('remote gossip', async (t) => { const m = new HyperP2PInvertedIndex() m._onGossip({ type: 'term-index-sync', op: 'add', term: 'cat', docId: 'd9' }) t.alike(m.search('cat'), ['d9']) m._onGossip({ type: 'term-index-sync', op: 'remove', term: 'cat', docId: 'd9' }) t.is(m.search('cat').length, 0) await m.close() }) test('getStats', async (t) => { const m = new HyperP2PInvertedIndex() m.index('a', ['z']) t.is(m.getStats().protocol, 'inverted-index/v1') t.is(m.getStats().indexed, 1) await m.close() })