diff options
Diffstat (limited to 'desktop/modules/notes/test_notes.js')
| -rw-r--r-- | desktop/modules/notes/test_notes.js | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/desktop/modules/notes/test_notes.js b/desktop/modules/notes/test_notes.js index 6a316ce..3f91a5e 100644 --- a/desktop/modules/notes/test_notes.js +++ b/desktop/modules/notes/test_notes.js @@ -18,7 +18,7 @@ const assert = require("assert"); const src = fs.readFileSync(__dirname + "/Notes.js", "utf8") .replace(/^\.pragma library$/m, ""); -const N = new Function(src + "\nreturn { parse, valid, stringify, sorted, formatDate, nextId," +const N = new Function(src + "\nreturn { parse, valid, validFile, stringify, sorted, formatDate, nextId," + " filter, addNote, updateNote, removeNote, setLastpull };")(); const db = { @@ -63,6 +63,17 @@ assert.strictEqual(N.valid('{"a":1}'), null); assert.strictEqual(N.valid("<<<<<<< HEAD\n{}\n=======\n{}\n>>>>>>> other\n"), null); assert.deepStrictEqual(N.parse("not json"), { notes: [] }); // display stays tolerant +// validFile(): the epoch-second name, or "" for anything else. The page builds +// a read path, a write path and an rm path from a note's file, and a db.json +// that came off a git remote is not entirely under this user's control. +assert.strictEqual(N.validFile("1750000000"), "1750000000"); +assert.strictEqual(N.validFile(""), ""); +assert.strictEqual(N.validFile(undefined), ""); +assert.strictEqual(N.validFile("../../.bashrc"), ""); +assert.strictEqual(N.validFile("1750000000\n"), ""); +assert.strictEqual(N.validFile("1e9"), ""); +assert.strictEqual(N.validFile("notes/1750000000"), ""); + // pure transforms preserve everything else and do not mutate const added = N.addNote(db, "T", "1750"); assert.strictEqual(added.notes.length, 4); |
