Added special script to handle parcel and node require. Added new tagging control. Adding new HTML Sanitizer. Packages so I could be sqlite with the right electron version. Some style changes. Interface changes. Changes to the sqlite/client. Interfaces cuased errors. Fixed bugs in electron ipc handling. Fixes to the sqlite libs. Create a new input control that can handle pasting. pasting HTML works with cycle through HTML,Text, Sanatized HTML. New UI controls. Time stamp control has more functionality.
214 lines
6.3 KiB
JavaScript
214 lines
6.3 KiB
JavaScript
const {TimeChainDataSqliteRecord,ConnectToDatabase, TimeChainDataSqliteFile, TimeChainDataSqliteTag, TimeChainDataSqliteTagLink} = require('../src/data/sqlite');
|
|
const { nanoid } = require('nanoid');
|
|
const { unsubscribe } = require('pubsub-js');
|
|
|
|
let db = null;
|
|
|
|
beforeAll(() => {
|
|
db = ConnectToDatabase(__dirname + "/test.db");
|
|
});
|
|
|
|
afterAll(()=>{
|
|
db.close();
|
|
})
|
|
|
|
test("Should create a records table", ()=>{
|
|
const rec = new TimeChainDataSqliteRecord();
|
|
|
|
const st = db.prepare("SELECT name FROM sqlite_master WHERE type='table' AND name=?");
|
|
const res = st.get('records');
|
|
|
|
expect(res).not.toBeNull();
|
|
expect(res.name).toEqual('records');
|
|
});
|
|
|
|
test("Should create a files table", ()=>{
|
|
const file = new TimeChainDataSqliteFile();
|
|
|
|
const st = db.prepare("SELECT name FROM sqlite_master WHERE type='table' AND name=?");
|
|
const res = st.get('files');
|
|
|
|
expect(res).not.toBeNull();
|
|
expect(res.name).toEqual('files');
|
|
|
|
});
|
|
|
|
test("Should create a tags table", ()=>{
|
|
const tags = new TimeChainDataSqliteTag();
|
|
|
|
const st = db.prepare("SELECT name FROM sqlite_master WHERE type='table' AND name=?");
|
|
const res = st.get('tags');
|
|
|
|
expect(res).not.toBeNull();
|
|
expect(res.name).toEqual('tags');
|
|
|
|
|
|
});
|
|
|
|
test("Should create a tags link table", ()=>{
|
|
const links = new TimeChainDataSqliteTagLink();
|
|
|
|
const st = db.prepare("SELECT name FROM sqlite_master WHERE type='table' AND name=?");
|
|
const res = st.get('taglink');
|
|
|
|
expect(res).not.toBeNull();
|
|
expect(res.name).toEqual('taglink');
|
|
});
|
|
|
|
test("Should create a record in the database and then remove it",async ()=>{
|
|
const rec = new TimeChainDataSqliteRecord();
|
|
const id = nanoid();
|
|
const hash = "fakehash";
|
|
const content = "This is a test";
|
|
const mime = "text/plain";
|
|
const ts = Math.floor(Date.now());
|
|
|
|
return rec.add(id,ts,content,mime,hash).then(res=>{
|
|
expect(res).toEqual(1);
|
|
return rec.get(id).then(res=>{
|
|
expect(res.uuid).toEqual(id);
|
|
expect(res.timestamp).toEqual(ts);
|
|
expect(res.mime).toEqual(mime);
|
|
expect(res.content).toEqual(content);
|
|
expect(res.hash).toEqual(hash);
|
|
return rec.delete(id);
|
|
})
|
|
})
|
|
});
|
|
|
|
test("Should create a record, attach a file, and then remove it",async ()=>{
|
|
const rec = new TimeChainDataSqliteRecord();
|
|
const filerec = new TimeChainDataSqliteFile();
|
|
|
|
const record = {
|
|
id: nanoid(),
|
|
hash: "fakehash",
|
|
content: "This is a test",
|
|
mime: "text/plain",
|
|
ts: Math.floor(Date.now())
|
|
};
|
|
|
|
const attached = {
|
|
id: nanoid(),
|
|
hash: "faskhash",
|
|
ts: Math.floor(Date.now()),
|
|
content: "this is fake data that would normally be binary file data",
|
|
mime: "application/octet-stream"
|
|
}
|
|
|
|
return rec.add(record.id,record.ts,record.content,record.mime,record.hash).then(res=>{
|
|
expect(res).toEqual(1);
|
|
return rec.get(record.id).then(res=>{
|
|
expect(res.uuid).toEqual(record.id);
|
|
expect(res.timestamp).toEqual(record.ts);
|
|
expect(res.mime).toEqual(record.mime);
|
|
expect(res.content).toEqual(record.content);
|
|
expect(res.hash).toEqual(record.hash);
|
|
|
|
return filerec.add(record.id,attached.id,attached.ts,attached.content,attached.mime,attached.hash).then(res=>{
|
|
expect(res).toEqual(1);
|
|
|
|
return filerec.get(attached.id).then(afile=>{
|
|
expect(afile.uuid).toEqual(attached.id);
|
|
expect(afile.hash).toEqual(attached.hash);
|
|
expect(afile.timestamp).toEqual(attached.ts);
|
|
expect(afile.content).toEqual(attached.content);
|
|
expect(afile.mime).toEqual(attached.mime);
|
|
});
|
|
|
|
|
|
});
|
|
|
|
|
|
});
|
|
}).then(()=>{
|
|
return rec.delete(record.id).then(res=>{
|
|
expect(res).toEqual(1);
|
|
})
|
|
}).then(()=>{
|
|
return filerec.delete(attached.id).then(res=>{
|
|
expect(res).toEqual(1);
|
|
});
|
|
})
|
|
});
|
|
|
|
test('Should add, check that it exist, remove tags to tag table', async ()=>{
|
|
const tags = new TimeChainDataSqliteTag();
|
|
const tag = "test";
|
|
|
|
return tags.add(tag).then(res=>{
|
|
expect(res).toEqual(1);
|
|
return tags.get(tag).then(res=>{
|
|
expect(res).not.toBeNull();
|
|
expect(res.create_at).not.toBeNull();
|
|
expect(res.tag).toEqual(tag);
|
|
})
|
|
})
|
|
.then(()=>{
|
|
return tags.has(tag).then(res=>{
|
|
expect(res).toBe(true);
|
|
})
|
|
})
|
|
.then(()=>{
|
|
return tags.delete(tag).then(res=>{
|
|
expect(res).toEqual(1);
|
|
})
|
|
});
|
|
});
|
|
|
|
test("Should create a record and tag the record", async ()=>{
|
|
const records = new TimeChainDataSqliteRecord();
|
|
const tags = new TimeChainDataSqliteTag();
|
|
const links = new TimeChainDataSqliteTagLink();
|
|
|
|
const rec = {
|
|
id: nanoid(),
|
|
hash: "fakehash",
|
|
content: "This is a test",
|
|
mime: "text/plain",
|
|
ts: Math.floor(Date.now())
|
|
};
|
|
|
|
const tag = "testing";
|
|
|
|
return records.add(rec.id,rec.ts,rec.content,rec.mime,rec.hash).then(res=>{
|
|
expect(res).toBe(1);
|
|
}).then(()=>{
|
|
return tags.add(tag).then(res=>{
|
|
expect(res).toBe(1);
|
|
});
|
|
}).then(()=>{
|
|
return links.add(rec.id,tag).then(res=>{
|
|
expect(res).toBe(1);
|
|
});
|
|
}).then(()=>{
|
|
return records.get(rec.id).then(res=>{
|
|
expect(res).not.toBeNull();
|
|
expect(res.uuid).toBe(rec.id);
|
|
});
|
|
}).then(()=>{
|
|
return links.getRecords(tag).then(res=>{
|
|
expect(res).not.toBeNull();
|
|
expect(res.length).toBeTruthy();
|
|
expect(res[0].uuid).toBe(rec.id);
|
|
});
|
|
}).then(()=>{
|
|
return links.getTags(rec.id).then(res=>{
|
|
expect(res).not.toBeNull();
|
|
expect(res.length).toBeTruthy();
|
|
expect(res[0].tag).toBe(tag);
|
|
});
|
|
}).then(()=>{
|
|
return links.deleteRecord(rec.id).then(res=>{
|
|
expect(res).toBe(1);
|
|
})
|
|
}).then(()=>{
|
|
return tags.delete(tag).then(res=>{
|
|
expect(res).toBe(1);
|
|
})
|
|
}).then(()=>{
|
|
return records.delete(rec.id).then(res=>{
|
|
expect(res).toBe(1);
|
|
})
|
|
});
|
|
}) |