(
noteStoreFactory: (
wsRoot: string,
vaults: DVault[],
engine: DEngineClient
) => Promise<INoteStore<string>>
)
| 147 | } |
| 148 | |
| 149 | function 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 | } |
no test coverage detected