mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-16 19:21:52 +00:00
add fixtures.TestDummy and transform method
This commit is contained in:
@@ -47,6 +47,7 @@
|
|||||||
"electron-gh-releases": "^2.0.2",
|
"electron-gh-releases": "^2.0.2",
|
||||||
"font-awesome": "^4.3.0",
|
"font-awesome": "^4.3.0",
|
||||||
"highlight.js": "^9.3.0",
|
"highlight.js": "^9.3.0",
|
||||||
|
"immutable": "^3.8.1",
|
||||||
"lodash": "^4.11.1",
|
"lodash": "^4.11.1",
|
||||||
"markdown-it": "^6.0.1",
|
"markdown-it": "^6.0.1",
|
||||||
"markdown-it-checkbox": "^1.1.0",
|
"markdown-it-checkbox": "^1.1.0",
|
||||||
@@ -75,11 +76,13 @@
|
|||||||
"dom-storage": "^2.0.2",
|
"dom-storage": "^2.0.2",
|
||||||
"electron-packager": "^6.0.0",
|
"electron-packager": "^6.0.0",
|
||||||
"electron-prebuilt": "^1.2.8",
|
"electron-prebuilt": "^1.2.8",
|
||||||
|
"faker": "^3.1.0",
|
||||||
"grunt": "^0.4.5",
|
"grunt": "^0.4.5",
|
||||||
"grunt-electron-installer": "^1.2.0",
|
"grunt-electron-installer": "^1.2.0",
|
||||||
"history": "^1.17.0",
|
"history": "^1.17.0",
|
||||||
"jsdom": "^9.4.2",
|
"jsdom": "^9.4.2",
|
||||||
"merge-stream": "^1.0.0",
|
"merge-stream": "^1.0.0",
|
||||||
|
"mock-fs": "^3.11.0",
|
||||||
"nib": "^1.1.0",
|
"nib": "^1.1.0",
|
||||||
"oh-my-cdn": "^0.1.1",
|
"oh-my-cdn": "^0.1.1",
|
||||||
"react": "^15.3.0",
|
"react": "^15.3.0",
|
||||||
|
|||||||
@@ -14,10 +14,11 @@ const CSON = require('season')
|
|||||||
const _ = require('lodash')
|
const _ = require('lodash')
|
||||||
const os = require('os')
|
const os = require('os')
|
||||||
|
|
||||||
const dummyStoragePath = path.join(os.tmpdir(), 'sandbox/transform-test-storage')
|
const dummyStoragePath = path.join(os.tmpdir(), 'test/transform-test-storage')
|
||||||
|
|
||||||
test.beforeEach((t) => {
|
test.beforeEach((t) => {
|
||||||
let dummyData = t.context.dummyData = TestDummy.dummyLegacyStorage(dummyStoragePath)
|
let dummyData = t.context.dummyData = TestDummy.dummyLegacyStorage(dummyStoragePath)
|
||||||
|
console.log('init count', dummyData.notes.length)
|
||||||
localStorage.setItem('storages', JSON.stringify([dummyData.cache]))
|
localStorage.setItem('storages', JSON.stringify([dummyData.cache]))
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -34,6 +35,7 @@ test.serial('Transform legacy storage into v1 storage', (t) => {
|
|||||||
let dummyData = t.context.dummyData
|
let dummyData = t.context.dummyData
|
||||||
let noteDirPath = path.join(dummyStoragePath, 'notes')
|
let noteDirPath = path.join(dummyStoragePath, 'notes')
|
||||||
let fileList = sander.readdirSync(noteDirPath)
|
let fileList = sander.readdirSync(noteDirPath)
|
||||||
|
t.is(dummyData.notes.length, fileList.length)
|
||||||
let noteMap = fileList
|
let noteMap = fileList
|
||||||
.map((filePath) => {
|
.map((filePath) => {
|
||||||
return CSON.readFileSync(path.join(noteDirPath, filePath))
|
return CSON.readFileSync(path.join(noteDirPath, filePath))
|
||||||
|
|||||||
22
tests/fixtures/TestDummy.js
vendored
22
tests/fixtures/TestDummy.js
vendored
@@ -95,12 +95,13 @@ function dummyStorage (storagePath, override = {}) {
|
|||||||
var cacheData = override.cache != null
|
var cacheData = override.cache != null
|
||||||
? override.cache
|
? override.cache
|
||||||
: {}
|
: {}
|
||||||
if (cacheData.key == null) cacheData.key = key
|
if (cacheData.key == null) cacheData.key = keygen()
|
||||||
if (cacheData.name == null) cacheData.name = faker.random.word()
|
if (cacheData.name == null) cacheData.name = faker.random.word()
|
||||||
|
if (cacheData.type == null) cacheData.type = 'FILESYSTEM'
|
||||||
|
cacheData.path = storagePath
|
||||||
|
|
||||||
sander.writeFileSync(path.join(storagePath, 'boostnote.json'), JSON.stringify(jsonData))
|
sander.writeFileSync(path.join(storagePath, 'boostnote.json'), JSON.stringify(jsonData))
|
||||||
var notesData = []
|
var notesData = []
|
||||||
console.log(notesData)
|
|
||||||
var noteCount = Math.floor((Math.random() * 15)) + 1
|
var noteCount = Math.floor((Math.random() * 15)) + 1
|
||||||
for (var i = 0; i < noteCount; i++) {
|
for (var i = 0; i < noteCount; i++) {
|
||||||
var key = keygen()
|
var key = keygen()
|
||||||
@@ -133,17 +134,20 @@ function dummyLegacyStorage (storagePath, override = {}) {
|
|||||||
var cacheData = override.cache != null
|
var cacheData = override.cache != null
|
||||||
? override.cache
|
? override.cache
|
||||||
: {}
|
: {}
|
||||||
if (cacheData.key == null) cacheData.key = key
|
if (cacheData.key == null) cacheData.key = keygen()
|
||||||
if (cacheData.name == null) cacheData.name = faker.random.word()
|
if (cacheData.name == null) cacheData.name = faker.random.word()
|
||||||
|
if (cacheData.type == null) cacheData.type = 'FILESYSTEM'
|
||||||
|
cacheData.path = storagePath
|
||||||
|
|
||||||
sander.writeFileSync(path.join(storagePath, 'boostnote.json'), JSON.stringify(jsonData))
|
sander.writeFileSync(path.join(storagePath, 'boostnote.json'), JSON.stringify(jsonData))
|
||||||
|
|
||||||
for (var j = 0; j < jsonData.folders.length; j++) {
|
|
||||||
var noteCount = Math.floor((Math.random() * 5)) + 1
|
|
||||||
var notesData = []
|
var notesData = []
|
||||||
|
for (var j = 0; j < jsonData.folders.length; j++) {
|
||||||
|
var folderNotes = []
|
||||||
|
var noteCount = Math.floor((Math.random() * 5)) + 1
|
||||||
for (var i = 0; i < noteCount; i++) {
|
for (var i = 0; i < noteCount; i++) {
|
||||||
var key = keygen(6)
|
var key = keygen(6)
|
||||||
while (notesData.some((note) => note.key === key)) {
|
while (folderNotes.some((note) => note.key === key)) {
|
||||||
key = keygen(6)
|
key = keygen(6)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -151,10 +155,10 @@ function dummyLegacyStorage (storagePath, override = {}) {
|
|||||||
key,
|
key,
|
||||||
folder: jsonData.folders[j].key
|
folder: jsonData.folders[j].key
|
||||||
})
|
})
|
||||||
notesData.push(noteData)
|
folderNotes.push(noteData)
|
||||||
}
|
}
|
||||||
|
notesData = notesData.concat(folderNotes)
|
||||||
CSON.writeFileSync(path.join(storagePath, jsonData.folders[j].key, 'data.json'), {notes: notesData.map((note) => _.omit(note, ['folder']))})
|
CSON.writeFileSync(path.join(storagePath, jsonData.folders[j].key, 'data.json'), {notes: folderNotes.map((note) => _.omit(note, ['folder']))})
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
Reference in New Issue
Block a user