mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-09-26 06:51:31 +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("#sanitizeFilenameForHeader", () => {
|
||||
// only test our own code, not the sanitize-filename side of things
|
||||
const testCases: TestCase<typeof utils.sanitizeFilenameForHeader>[] = [
|
||||
["when passed filename is empty, it should fallback to default value 'file'", [" "], "file"],
|
||||
["when passed filename '..' would cause sanitized filename to be empty, it should fallback to default value 'file'", [".."], "file"],
|
||||
describe("#getContentDisposition", () => {
|
||||
|
||||
const defaultFallBackDisposition = `file; filename="file"; filename*=UTF-8''file`;
|
||||
const testCases: TestCase<typeof utils.getContentDisposition>[] = [
|
||||
[
|
||||
"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
|
||||
["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 => {
|
||||
const [desc, fnParams, expected] = testCase;
|
||||
it(desc, () => {
|
||||
const result = utils.sanitizeFilenameForHeader(...fnParams);
|
||||
expect(result).toStrictEqual(expected);
|
||||
const result = utils.getContentDisposition(...fnParams);
|
||||
expect(result).toStrictEqual(expected);
|
||||
})
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe.todo("#getContentDisposition", () => {});
|
||||
|
||||
describe("#isStringNote", () => {
|
||||
|
||||
const testCases: TestCase<typeof utils.isStringNote>[] = [
|
||||
|
Loading…
x
Reference in New Issue
Block a user