import type { CallContext } from '../base/iapi' import * as ut from '../base/util' import { test } from '@edgeros/tapes' test('util test minby', (t) => { t.ok(Buffer.isBuffer(ut.toBuffer(888)), 'util test is buffer.') const p = ut.minBy(['3', '1', '5', '1'], (prop: string): number => Number(prop)) t.ok(p[0] === '1', 'util test is minBy.') t.end() }) test('util test sample', (t) => { const items = ['1', '3', '5', 'abc'] const sample = ut.sample(items) t.ok(items.includes(sample), 'util test sample') t.end() }) test('util test forOwn', (t) => { const obj = { foo: 1, bar: 2, foo1: 3, bar1: 4, } const keys = [] const it = (v: number, k: string) => { keys.push(k) } ut.forOwn(obj, it) t.ok(keys.length === 4, 'util test forOwn') t.end() }) test('util test resolveCallOptions', (t) => { const options = ut.resolveCallOptions( { host: '10.12.0.204:2379' }, () => ({ deadline: 10000 }), // eslint-disable-next-line @stylistic/comma-dangle, @typescript-eslint/consistent-type-assertions -- ignore {} as CallContext ) t.ok(options?.host === '10.12.0.204:2379' && options.deadline === 10000, 'util test resolveCallOptions ') t.end() }) test('util test getDeferred', (t) => { const { res } = ut.getDeferred() res(null) t.pass('util test getDeferred') t.end() })