MCPcopy
hub / github.com/callumalpass/tasknotes / createPluginContext

Function createPluginContext

tests/unit/api/tasknotes-api-v1.test.ts:122–528  ·  view source on GitHub ↗
(initialTasks: TaskInfo[] = [createTask()])

Source from the content-addressed store, hash-verified

120}
121
122function createPluginContext(initialTasks: TaskInfo[] = [createTask()]): TestPluginContext {
123 const tasks = new Map(initialTasks.map((task) => [task.path, task]));
124 const files = new Map(initialTasks.map((task) => [task.path, new TFile(task.path)]));
125 const folders = new Set(["", "Tasks"]);
126 const emitter = createEmitter();
127
128 const cacheManager: TestPluginContext["cacheManager"] = {
129 getTaskInfo: jest.fn(async (path: string) => tasks.get(path) ?? null),
130 getAllTasks: jest.fn(async () => Array.from(tasks.values())),
131 clearCacheEntry: jest.fn((path: string) => {
132 tasks.delete(path);
133 }),
134 updateTaskInfoInCache: jest.fn((path: string, task: TaskInfo) => {
135 tasks.set(path, task);
136 }),
137 };
138
139 const emitTaskUpdate = (originalTask: TaskInfo | undefined, updatedTask: TaskInfo): void => {
140 emitter.trigger(EVENT_TASK_UPDATED, {
141 path: updatedTask.path,
142 originalTask,
143 updatedTask,
144 });
145 };
146
147 const taskService: TestPluginContext["taskService"] = {
148 createTask: jest.fn(
149 async (
150 taskData: TaskCreationData,
151 _options?: { applyDefaults?: boolean }
152 ): Promise<{ file: TFile; taskInfo: TaskInfo }> => {
153 const path = taskData.path ?? `Tasks/${taskData.title ?? "new-task"}.md`;
154 const task = createTask({
155 ...taskData,
156 title: taskData.title ?? "New task",
157 status: taskData.status ?? "open",
158 priority: taskData.priority ?? "normal",
159 path,
160 archived: taskData.archived ?? false,
161 });
162 const file = new TFile(path);
163 tasks.set(path, task);
164 files.set(path, file);
165 emitTaskUpdate(undefined, task);
166 return { file, taskInfo: task };
167 }
168 ),
169 updateTask: jest.fn(async (task: TaskInfo, patch: TaskNotesTaskPatch) => {
170 const updatedTask = { ...task, ...patch };
171 tasks.set(updatedTask.path, updatedTask);
172 emitTaskUpdate(task, updatedTask);
173 return updatedTask;
174 }),
175 updateProperty: jest.fn(
176 async (task: TaskInfo, property: keyof TaskInfo, value: unknown) => {
177 const updatedTask = { ...task, [property]: value } as TaskInfo;
178 tasks.set(updatedTask.path, updatedTask);
179 emitTaskUpdate(task, updatedTask);

Callers 1

Calls 12

emitTaskUpdateFunction · 0.85
hasMethod · 0.80
updatePropertyMethod · 0.80
createTaskFunction · 0.70
createEmitterFunction · 0.70
getMethod · 0.65
deleteMethod · 0.65
setMethod · 0.65
triggerMethod · 0.65
toggleArchiveMethod · 0.45
startTimeTrackingMethod · 0.45
stopTimeTrackingMethod · 0.45

Tested by

no test coverage detected