2022-06-19 00:25:21 +00:00
|
|
|
import {expect} from "chai";
|
|
|
|
import Network from "../../server/models/network";
|
|
|
|
import TextFileMessageStorage from "../../server/plugins/messageStorage/text";
|
2018-09-09 10:09:30 +00:00
|
|
|
|
2020-03-21 20:55:36 +00:00
|
|
|
describe("TextFileMessageStorage", function () {
|
|
|
|
it("should combine network name and uuid into a safe name", function () {
|
2019-07-17 09:33:59 +00:00
|
|
|
expect(
|
|
|
|
TextFileMessageStorage.getNetworkFolderName({
|
|
|
|
name: "Freenode",
|
|
|
|
uuid: "f9042ec9-4016-45e0-a8a8-d378fb252628",
|
2022-06-19 00:25:21 +00:00
|
|
|
} as Network)
|
2019-07-17 09:33:59 +00:00
|
|
|
).to.equal("freenode-4016-45e0-a8a8-d378fb252628");
|
2018-09-09 10:09:30 +00:00
|
|
|
});
|
|
|
|
|
2020-03-21 20:55:36 +00:00
|
|
|
it("network name should be cleaned up and lowercased", function () {
|
2019-07-17 09:33:59 +00:00
|
|
|
expect(
|
|
|
|
TextFileMessageStorage.getNetworkFolderName({
|
|
|
|
name: '@ TeSt ../..\\<>:"/\\|?*',
|
|
|
|
uuid: "f9042ec9-4016-45e0-a8a8-d378fb252628",
|
2022-06-19 00:25:21 +00:00
|
|
|
} as Network)
|
2019-07-17 09:33:59 +00:00
|
|
|
).to.equal("@-test-.._..--45e0-a8a8-d378fb252628");
|
2018-09-09 10:09:30 +00:00
|
|
|
});
|
|
|
|
|
2020-03-21 20:55:36 +00:00
|
|
|
it("folder name may contain two dashes if on boundary", function () {
|
2019-07-17 09:33:59 +00:00
|
|
|
expect(
|
|
|
|
TextFileMessageStorage.getNetworkFolderName({
|
|
|
|
name: "Freenod",
|
|
|
|
uuid: "f9042ec9-4016-45e0-a8a8-d378fb252628",
|
2022-06-19 00:25:21 +00:00
|
|
|
} as Network)
|
2019-07-17 09:33:59 +00:00
|
|
|
).to.equal("freenod--4016-45e0-a8a8-d378fb252628");
|
2018-09-09 10:09:30 +00:00
|
|
|
});
|
|
|
|
|
2020-03-21 20:55:36 +00:00
|
|
|
it("should limit network name length", function () {
|
2019-07-17 09:33:59 +00:00
|
|
|
expect(
|
|
|
|
TextFileMessageStorage.getNetworkFolderName({
|
|
|
|
name: "This network name is longer than the uuid itself but it should be limited",
|
|
|
|
uuid: "f9042ec9-4016-45e0-a8a8-d378fb252628",
|
2022-06-19 00:25:21 +00:00
|
|
|
} as Network)
|
2019-07-17 09:33:59 +00:00
|
|
|
).to.equal("this-network-name-is-lo-d378fb252628");
|
2018-09-09 10:09:30 +00:00
|
|
|
});
|
|
|
|
});
|