MCPcopy Create free account
hub / github.com/block/buzz / prependMockHistory

Function prependMockHistory

desktop/src/testing/e2eBridge.ts:3077–3129  ·  view source on GitHub ↗
(input: {
  channelName: string;
  count: number;
  startIndex?: number;
  lineCount?: number;
  createdAtStart?: number;
  emit?: boolean;
})

Source from the content-addressed store, hash-verified

3075}
3076
3077function prependMockHistory(input: {
3078 channelName: string;
3079 count: number;
3080 startIndex?: number;
3081 lineCount?: number;
3082 createdAtStart?: number;
3083 emit?: boolean;
3084}) {
3085 const channel = mockChannels.find(
3086 (candidate) => candidate.name === input.channelName,
3087 );
3088 if (!channel) {
3089 throw new Error(`Unknown mock channel: ${input.channelName}`);
3090 }
3091
3092 const store = getMockMessageStore(channel.id);
3093 const earliestCreatedAt = store.reduce(
3094 (earliest, event) => Math.min(earliest, event.created_at),
3095 Math.floor(Date.now() / 1000),
3096 );
3097 const createdAtStart =
3098 input.createdAtStart ?? earliestCreatedAt - input.count - 1;
3099 const startIndex = input.startIndex ?? 0;
3100 const lineCount = input.lineCount ?? 1;
3101
3102 const events = Array.from({ length: input.count }, (_, offset) => {
3103 const index = startIndex + offset;
3104 const body = Array.from(
3105 { length: lineCount },
3106 (_unused, lineIndex) => `mock older ${index} line ${lineIndex + 1}`,
3107 ).join("\n");
3108
3109 return createMockEvent(
3110 9,
3111 body,
3112 [["h", channel.id]],
3113 ALICE_PUBKEY,
3114 createdAtStart + offset,
3115 `mock-older-${channel.name}-${index}`.replace(/[^a-zA-Z0-9]/g, ""),
3116 );
3117 });
3118
3119 store.unshift(...events);
3120 store.sort((left, right) => left.created_at - right.created_at);
3121
3122 if (input.emit) {
3123 for (const event of events) {
3124 emitMockLiveEvent(channel.id, event);
3125 }
3126 }
3127
3128 return events;
3129}
3130
3131function emitMockHistory(
3132 socket: MockSocket,

Callers

nothing calls this directly

Calls 4

getMockMessageStoreFunction · 0.85
createMockEventFunction · 0.85
emitMockLiveEventFunction · 0.85
fromMethod · 0.45

Tested by

no test coverage detected