MCPcopy
hub / github.com/dendronhq/dendron / queryMetadataTest

Function queryMetadataTest

packages/engine-test-utils/src/noteStore.common.ts:149–209  ·  view source on GitHub ↗
(
  noteStoreFactory: (
    wsRoot: string,
    vaults: DVault[],
    engine: DEngineClient
  ) => Promise<INoteStore<string>>
)

Source from the content-addressed store, hash-verified

147}
148
149function queryMetadataTest(
150 noteStoreFactory: (
151 wsRoot: string,
152 vaults: DVault[],
153 engine: DEngineClient
154 ) => Promise<INoteStore<string>>
155) {
156 test("WHEN workspace contains notes, THEN queryMetadata should return correct notes", async () => {
157 await runEngineTestV5(
158 async ({ wsRoot, vaults, engine }) => {
159 const noteStore = await noteStoreFactory(wsRoot, vaults, engine);
160
161 const engineNotes = await engine.findNotesMeta({ excludeStub: false });
162 await Promise.all(
163 engineNotes.map(async (noteMeta) => {
164 return noteStore.writeMetadata({ key: noteMeta.id, noteMeta });
165 })
166 );
167
168 // Test NoteStore.query
169 let queryResp = await noteStore.queryMetadata({
170 qs: "foo.ch1",
171 originalQS: "foo.ch1",
172 });
173 expect(queryResp.isOk()).toBeTruthy();
174 queryResp.map((results) => {
175 expect(results.length).toEqual(1);
176 expect(results[0].fname).toEqual("foo.ch1");
177 });
178
179 // Test NoteStore.find empty query returns root notes
180 queryResp = await noteStore.queryMetadata({ qs: "", originalQS: "" });
181 expect(queryResp.isOk()).toBeTruthy();
182 queryResp.map((results) => {
183 expect(results.length).toEqual(3);
184 expect(results[0].fname).toEqual("root");
185 expect(results[1].fname).toEqual("root");
186 expect(results[2].fname).toEqual("root");
187 });
188
189 // Test NoteStore.find multiple matches
190 queryResp = await noteStore.queryMetadata({
191 qs: "fo",
192 originalQS: "fo",
193 });
194 expect(queryResp.isOk()).toBeTruthy();
195 queryResp.map((results) => {
196 expect(results.length).toEqual(2);
197
198 const fnames = results.map((result) => result.fname);
199 expect(fnames.includes("foo")).toBeTruthy();
200 expect(fnames.includes("foo.ch1")).toBeTruthy();
201 });
202 },
203 {
204 expect,
205 preSetupHook: ENGINE_HOOKS.setupBasic,
206 }

Callers 1

runAllNoteStoreTestsFunction · 0.85

Calls 6

runEngineTestV5Function · 0.90
expectFunction · 0.85
allMethod · 0.80
writeMetadataMethod · 0.65
queryMetadataMethod · 0.65
findNotesMetaMethod · 0.45

Tested by

no test coverage detected