mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-09-25 22:41:36 +08:00
test(server/utils): adapt tests for getContentDisposition
since we merged these functions, adapt the previous tests of sanitizeFilenameForHeader and use them for the newly merged function getContentDisposition
This commit is contained in:
parent
fedaec6c79
commit
b812e67794
@ -116,28 +116,42 @@ describe.todo("#escapeRegExp", () => {});
|
|||||||
|
|
||||||
describe.todo("#crash", () => {});
|
describe.todo("#crash", () => {});
|
||||||
|
|
||||||
describe("#sanitizeFilenameForHeader", () => {
|
describe("#getContentDisposition", () => {
|
||||||
// only test our own code, not the sanitize-filename side of things
|
|
||||||
const testCases: TestCase<typeof utils.sanitizeFilenameForHeader>[] = [
|
const defaultFallBackDisposition = `file; filename="file"; filename*=UTF-8''file`;
|
||||||
["when passed filename is empty, it should fallback to default value 'file'", [" "], "file"],
|
const testCases: TestCase<typeof utils.getContentDisposition>[] = [
|
||||||
["when passed filename '..' would cause sanitized filename to be empty, it should fallback to default value 'file'", [".."], "file"],
|
[
|
||||||
|
"when passed filename is empty, it should fallback to default value 'file'",
|
||||||
|
[" "],
|
||||||
|
defaultFallBackDisposition
|
||||||
|
],
|
||||||
|
[
|
||||||
|
"when passed filename '..' would cause sanitized filename to be empty, it should fallback to default value 'file'",
|
||||||
|
[".."],
|
||||||
|
defaultFallBackDisposition
|
||||||
|
],
|
||||||
// COM1 is a Windows specific "illegal filename" that sanitize filename strips away
|
// COM1 is a Windows specific "illegal filename" that sanitize filename strips away
|
||||||
["when passed filename 'COM1' would cause sanitized filename to be empty, it should fallback to default value 'file'", ["COM1"], "file"],
|
[
|
||||||
["sanitized passed filename should be returned URIEncoded", ["test file.csv"], "test%20file.csv"]
|
"when passed filename 'COM1' would cause sanitized filename to be empty, it should fallback to default value 'file'",
|
||||||
|
["COM1"],
|
||||||
|
defaultFallBackDisposition
|
||||||
|
],
|
||||||
|
[
|
||||||
|
"sanitized passed filename should be returned URIEncoded",
|
||||||
|
["test file.csv"],
|
||||||
|
`file; filename="test%20file.csv"; filename*=UTF-8''test%20file.csv`
|
||||||
|
]
|
||||||
]
|
]
|
||||||
|
|
||||||
testCases.forEach(testCase => {
|
testCases.forEach(testCase => {
|
||||||
const [desc, fnParams, expected] = testCase;
|
const [desc, fnParams, expected] = testCase;
|
||||||
it(desc, () => {
|
it(desc, () => {
|
||||||
const result = utils.sanitizeFilenameForHeader(...fnParams);
|
const result = utils.getContentDisposition(...fnParams);
|
||||||
expect(result).toStrictEqual(expected);
|
expect(result).toStrictEqual(expected);
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe.todo("#getContentDisposition", () => {});
|
|
||||||
|
|
||||||
describe("#isStringNote", () => {
|
describe("#isStringNote", () => {
|
||||||
|
|
||||||
const testCases: TestCase<typeof utils.isStringNote>[] = [
|
const testCases: TestCase<typeof utils.isStringNote>[] = [
|
||||||
|
Loading…
x
Reference in New Issue
Block a user