mirror of
https://github.com/thelounge/thelounge.git
synced 2024-05-05 07:53:27 +02:00
Update tests
This commit is contained in:
parent
ef651e3e46
commit
1fd1df29da
|
@ -54,96 +54,68 @@ describe("SQLite Message Storage", function () {
|
|||
});
|
||||
|
||||
it("should create tables", function (done) {
|
||||
store.database.serialize(() =>
|
||||
store.database.all(
|
||||
"SELECT name, tbl_name, sql FROM sqlite_master WHERE type = 'table'",
|
||||
(err, row) => {
|
||||
expect(err).to.be.null;
|
||||
expect(row).to.deep.equal([
|
||||
{
|
||||
name: "options",
|
||||
tbl_name: "options",
|
||||
sql:
|
||||
"CREATE TABLE options (name TEXT, value TEXT, CONSTRAINT name_unique UNIQUE (name))",
|
||||
},
|
||||
{
|
||||
name: "messages",
|
||||
tbl_name: "messages",
|
||||
sql:
|
||||
"CREATE TABLE messages (network TEXT, channel TEXT, time INTEGER, type TEXT, msg TEXT)",
|
||||
},
|
||||
]);
|
||||
const rows = store.database
|
||||
.prepare("SELECT name, tbl_name, sql FROM sqlite_master WHERE type = 'table'")
|
||||
.all();
|
||||
|
||||
done();
|
||||
}
|
||||
)
|
||||
);
|
||||
expect(rows).to.deep.equal([
|
||||
{
|
||||
name: "options",
|
||||
tbl_name: "options",
|
||||
sql:
|
||||
"CREATE TABLE options (name TEXT, value TEXT, CONSTRAINT name_unique UNIQUE (name))",
|
||||
},
|
||||
{
|
||||
name: "messages",
|
||||
tbl_name: "messages",
|
||||
sql:
|
||||
"CREATE TABLE messages (network TEXT, channel TEXT, time INTEGER, type TEXT, msg TEXT)",
|
||||
},
|
||||
]);
|
||||
|
||||
done();
|
||||
});
|
||||
|
||||
it("should insert schema version to options table", function (done) {
|
||||
store.database.serialize(() =>
|
||||
store.database.get(
|
||||
"SELECT value FROM options WHERE name = 'schema_version'",
|
||||
(err, row) => {
|
||||
expect(err).to.be.null;
|
||||
|
||||
// Should be sqlite.currentSchemaVersion,
|
||||
// compared as string because it's returned as such from the database
|
||||
expect(row.value).to.equal("1520239200");
|
||||
|
||||
done();
|
||||
}
|
||||
)
|
||||
);
|
||||
const row = store.database
|
||||
.prepare("SELECT value FROM options WHERE name = 'schema_version'")
|
||||
.get();
|
||||
expect(row.value).to.equal("1520239200");
|
||||
done();
|
||||
});
|
||||
|
||||
it("should store a message", function (done) {
|
||||
store.database.serialize(() => {
|
||||
store.index(
|
||||
{
|
||||
uuid: "this-is-a-network-guid",
|
||||
},
|
||||
{
|
||||
name: "#thisISaCHANNEL",
|
||||
},
|
||||
new Msg({
|
||||
time: 123456789,
|
||||
text: "Hello from sqlite world!",
|
||||
})
|
||||
);
|
||||
store.index(
|
||||
{uuid: "this-is-a-network-guid"},
|
||||
{name: "#thisISaCHANNEL"},
|
||||
new Msg({
|
||||
time: 123456789,
|
||||
text: "Hello from sqlite world!",
|
||||
})
|
||||
);
|
||||
|
||||
done();
|
||||
});
|
||||
done();
|
||||
});
|
||||
|
||||
it("should retrieve previously stored message", function (done) {
|
||||
store.database.serialize(() =>
|
||||
store
|
||||
.getMessages(
|
||||
{
|
||||
uuid: "this-is-a-network-guid",
|
||||
},
|
||||
{
|
||||
name: "#thisisaCHANNEL",
|
||||
}
|
||||
)
|
||||
.then((messages) => {
|
||||
expect(messages).to.have.lengthOf(1);
|
||||
store
|
||||
.getMessages({uuid: "this-is-a-network-guid"}, {name: "#thisisaCHANNEL"})
|
||||
.then((messages) => {
|
||||
expect(messages).to.have.lengthOf(1);
|
||||
|
||||
const msg = messages[0];
|
||||
const msg = messages[0];
|
||||
|
||||
expect(msg.text).to.equal("Hello from sqlite world!");
|
||||
expect(msg.type).to.equal(Msg.Type.MESSAGE);
|
||||
expect(msg.time.getTime()).to.equal(123456789);
|
||||
expect(msg.text).to.equal("Hello from sqlite world!");
|
||||
expect(msg.type).to.equal(Msg.Type.MESSAGE);
|
||||
expect(msg.time.getTime()).to.equal(123456789);
|
||||
|
||||
done();
|
||||
})
|
||||
);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it("should close database", function (done) {
|
||||
store.close((err) => {
|
||||
expect(err).to.be.null;
|
||||
expect(err).to.be.undefined;
|
||||
expect(fs.existsSync(expectedPath)).to.be.true;
|
||||
done();
|
||||
});
|
||||
|
|
|
@ -4,9 +4,11 @@ const expect = require("chai").expect;
|
|||
const TextFileMessageStorage = require("../../src/plugins/messageStorage/text");
|
||||
|
||||
describe("TextFileMessageStorage", function () {
|
||||
const store = new TextFileMessageStorage();
|
||||
|
||||
it("should combine network name and uuid into a safe name", function () {
|
||||
expect(
|
||||
TextFileMessageStorage.getNetworkFolderName({
|
||||
store._getNetworkFolderName({
|
||||
name: "Freenode",
|
||||
uuid: "f9042ec9-4016-45e0-a8a8-d378fb252628",
|
||||
})
|
||||
|
@ -15,7 +17,7 @@ describe("TextFileMessageStorage", function () {
|
|||
|
||||
it("network name should be cleaned up and lowercased", function () {
|
||||
expect(
|
||||
TextFileMessageStorage.getNetworkFolderName({
|
||||
store._getNetworkFolderName({
|
||||
name: '@ TeSt ../..\\<>:"/\\|?*',
|
||||
uuid: "f9042ec9-4016-45e0-a8a8-d378fb252628",
|
||||
})
|
||||
|
@ -24,7 +26,7 @@ describe("TextFileMessageStorage", function () {
|
|||
|
||||
it("folder name may contain two dashes if on boundary", function () {
|
||||
expect(
|
||||
TextFileMessageStorage.getNetworkFolderName({
|
||||
store._getNetworkFolderName({
|
||||
name: "Freenod",
|
||||
uuid: "f9042ec9-4016-45e0-a8a8-d378fb252628",
|
||||
})
|
||||
|
@ -33,7 +35,7 @@ describe("TextFileMessageStorage", function () {
|
|||
|
||||
it("should limit network name length", function () {
|
||||
expect(
|
||||
TextFileMessageStorage.getNetworkFolderName({
|
||||
store._getNetworkFolderName({
|
||||
name: "This network name is longer than the uuid itself but it should be limited",
|
||||
uuid: "f9042ec9-4016-45e0-a8a8-d378fb252628",
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue