1
0
mirror of https://github.com/BoostIo/Boostnote synced 2025-12-13 09:46:22 +00:00

refactored snippet dataApi for easy testing and added some test. Fixed old snippet still display when deleted

This commit is contained in:
Nguyễn Việt Hưng
2018-04-27 11:16:45 +07:00
parent 78957cf128
commit 291d76674b
8 changed files with 143 additions and 17 deletions

View File

@@ -0,0 +1,38 @@
const test = require('ava')
const deleteSnippet = require('browser/main/lib/dataApi/deleteSnippet')
const sander = require('sander')
const os = require('os')
const path = require('path')
const crypto = require('crypto')
const snippetFilePath = path.join(os.tmpdir(), `test${path.sep}delete-snippet`)
const snippetFile = path.join(snippetFilePath, 'snippets.json')
const newSnippet = {
id: crypto.randomBytes(16).toString('hex'),
name: 'Unnamed snippet',
prefix: [],
content: ''
}
test.beforeEach((t) => {
sander.writeFileSync(snippetFile, JSON.stringify([newSnippet]))
})
test.serial('Delete a snippet', (t) => {
return Promise.resolve()
.then(function doTest () {
return Promise.all([
deleteSnippet(newSnippet, snippetFile)
])
})
.then(function assert (data) {
data = data[0]
const snippets = JSON.parse(sander.readFileSync(snippetFile))
const snippet = snippets.find(currentSnippet => currentSnippet.id === data.id)
t.is(snippets.length, 0)
})
})
test.after.always(() => {
sander.rimrafSync(snippetFilePath)
})