(
noteStoreFactory: (
wsRoot: string,
vaults: DVault[],
engine: DEngineClient
) => Promise<INoteStore<string>>
)
| 400 | } |
| 401 | |
| 402 | function updateNoteTest( |
| 403 | noteStoreFactory: ( |
| 404 | wsRoot: string, |
| 405 | vaults: DVault[], |
| 406 | engine: DEngineClient |
| 407 | ) => Promise<INoteStore<string>> |
| 408 | ) { |
| 409 | test("WHEN writing a note, THEN subsequent writes should update note", async () => { |
| 410 | await runEngineTestV5( |
| 411 | async ({ vaults, wsRoot, engine }) => { |
| 412 | const vault = vaults[0]; |
| 413 | |
| 414 | const noteStore = await noteStoreFactory(wsRoot, vaults, engine); |
| 415 | const newNote = await NoteTestUtilsV4.createNote({ |
| 416 | fname: "foobar", |
| 417 | body: "note body", |
| 418 | vault, |
| 419 | wsRoot, |
| 420 | }); |
| 421 | |
| 422 | let writeResp = await noteStore.write({ |
| 423 | key: newNote.id, |
| 424 | note: newNote, |
| 425 | }); |
| 426 | expect(writeResp.data).toBeTruthy(); |
| 427 | |
| 428 | const note = await noteStore.get(newNote.id); |
| 429 | expect(note.data!.fname).toEqual(newNote.fname); |
| 430 | expect(note.data!.body.trim()).toEqual(newNote.body.trim()); |
| 431 | |
| 432 | // Write same note |
| 433 | writeResp = await noteStore.write({ key: newNote.id, note: newNote }); |
| 434 | expect(writeResp.data).toBeTruthy(); |
| 435 | const note2 = await noteStore.get(newNote.id); |
| 436 | expect(note2.data!.fname).toEqual(newNote.fname); |
| 437 | expect(note2.data!.body.trim()).toEqual(newNote.body.trim()); |
| 438 | expect(note2.data!.contentHash === note.data!.contentHash).toBeTruthy(); |
| 439 | |
| 440 | // Update note body and write |
| 441 | newNote.body = "new body"; |
| 442 | writeResp = await noteStore.write({ key: newNote.id, note: newNote }); |
| 443 | expect(writeResp.data).toBeTruthy(); |
| 444 | |
| 445 | const note3 = await noteStore.get(newNote.id); |
| 446 | expect(note3.data!.fname).toEqual(newNote.fname); |
| 447 | expect(note3.data!.body.trim()).toEqual(newNote.body.trim()); |
| 448 | expect(note3.data!.contentHash !== note.data!.contentHash).toBeTruthy(); |
| 449 | }, |
| 450 | { |
| 451 | expect, |
| 452 | } |
| 453 | ); |
| 454 | }); |
| 455 | } |
| 456 | |
| 457 | function writeSameFnameTest( |
| 458 | noteStoreFactory: ( |
no test coverage detected