All files / rpc-calls/src/testing TypedCallee.fixtures.ts

90% Statements 9/10
100% Branches 0/0
50% Functions 1/2
88.88% Lines 8/9

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 931x 1x 1x   1x 1x   1x                                                                                                                                                                 1x 11x      
import {TypedCallee} from '../callee/TypedCallee';
import {ObjValue} from '@jsonjoy.com/json-type';
import {procedures, type SampleCtx} from './Callee.fixtures';
 
const base = ObjValue.new();
const t = base.system.t;
 
export const obj = base
  .add('ping', t.fn.inp(t.undef).out(t.con('pong')).ctx<SampleCtx>(), procedures.ping.call.bind(procedures.ping))
  .add(
    'getIp',
    t.fn
      .inp(t.undef)
      .out(t.object({ip: t.str}))
      .ctx<SampleCtx>(),
    procedures.getIp.call.bind(procedures.getIp),
  )
  .add(
    'delay',
    t.fn
      .inp(t.object({timeout: t.num}))
      .out(t.object({done: t.bool, timeout: t.num}))
      .ctx<SampleCtx>()
      .default(({timeout}) => {
        return {
          done: true,
          timeout,
        };
      }),
    procedures.delay.call.bind(procedures.delay),
  )
  .add(
    'notificationSetValue',
    t.fn
      .inp(t.object({value: t.num}))
      .out(t.undef)
      .ctx<SampleCtx>(),
    procedures.notificationSetValue.call.bind(procedures.notificationSetValue),
  )
  .add(
    'notificationSetValueFromCtx',
    t.fn.inp(t.undef).out(t.undef).ctx<SampleCtx>(),
    procedures.notificationSetValueFromCtx.call.bind(procedures.notificationSetValueFromCtx),
  )
  .add(
    'getValue',
    t.fn
      .inp(t.undef)
      .out(t.object({value: t.num}))
      .ctx<SampleCtx>(),
    procedures.getValue.call.bind(procedures.getValue),
  )
  .add(
    'delayStreaming',
    t.fn
      .inp(t.object({timeout: t.num}))
      .out(t.object({done: t.bool, timeout: t.num}))
      .ctx<SampleCtx>(),
    procedures.delayStreaming.call.bind(procedures.delayStreaming),
  )
  .add(
    'double',
    t.fn
      .inp(t.object({num: t.num}))
      .out(t.object({num: t.num}))
      .ctx<SampleCtx>(),
    procedures.double.call.bind(procedures.double),
  )
  .add('error', t.fn.inp(t.undef).out(t.undef).ctx<SampleCtx>(), procedures.error.call.bind(procedures.error))
  .add(
    'streamError',
    t.fn.inp(t.undef).out(t.undef).ctx<SampleCtx>(),
    procedures.streamError.call.bind(procedures.streamError),
  )
  .add(
    'auth.users.get',
    t.fn
      .inp(t.object({id: t.str}))
      .out(t.object({id: t.str, name: t.str, tags: t.array(t.str)}))
      .ctx<SampleCtx>(),
    procedures['auth.users.get'].call.bind(procedures['auth.users.get']),
  )
  .add(
    'utilTimer',
    t.fn.inp(t.undef).out(t.num).ctx<SampleCtx>(),
    procedures.utilTimer.call.bind(procedures.utilTimer),
  );
 
export const createTypedCallee = () =>
  new TypedCallee<SampleCtx | void, typeof obj>({
    router: obj,
  });