-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#3216: add tests; clarify use of helper method
- Loading branch information
1 parent
c53cd0f
commit 1fadfdf
Showing
5 changed files
with
94 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* | ||
* Copyright (C) 2022 PixieBrix, Inc. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
import { JQTransformer } from "@/blocks/transformers/jq"; | ||
import { unsafeAssumeValidArg } from "@/runtime/runtimeTypes"; | ||
import ConsoleLogger from "@/utils/ConsoleLogger"; | ||
import { InputValidationError } from "@/blocks/errors"; | ||
import { BusinessError } from "@/errors"; | ||
|
||
describe("parse compile error", () => { | ||
test("invalid fromdate", async () => { | ||
// https://github.com/pixiebrix/pixiebrix-extension/issues/3216 | ||
const promise = new JQTransformer().transform( | ||
unsafeAssumeValidArg({ filter: '"" | fromdate', input: {} }), | ||
{ | ||
ctxt: {}, | ||
root: null, | ||
logger: new ConsoleLogger(), | ||
} | ||
); | ||
|
||
await expect(promise).rejects.toThrowError(InputValidationError); | ||
await expect(promise).rejects.toThrowError( | ||
'date "" does not match format "%Y-%m-%dT%H:%M:%SZ"' | ||
); | ||
}); | ||
|
||
test("missing brace", async () => { | ||
// https://github.com/pixiebrix/pixiebrix-extension/issues/3216 | ||
const promise = new JQTransformer().transform( | ||
unsafeAssumeValidArg({ filter: "{", input: {} }), | ||
{ | ||
ctxt: {}, | ||
root: null, | ||
logger: new ConsoleLogger(), | ||
} | ||
); | ||
|
||
await expect(promise).rejects.toThrowError(InputValidationError); | ||
await expect(promise).rejects.toThrowError( | ||
"Unexpected end of jq filter, are you missing a parentheses, brace, and/or quote mark?" | ||
); | ||
}); | ||
|
||
test("null iteration", async () => { | ||
// https://github.com/pixiebrix/pixiebrix-extension/issues/3216 | ||
const promise = new JQTransformer().transform( | ||
unsafeAssumeValidArg({ filter: ".foo[]", input: {} }), | ||
{ | ||
ctxt: {}, | ||
root: null, | ||
logger: new ConsoleLogger(), | ||
} | ||
); | ||
|
||
await expect(promise).rejects.toThrowError(BusinessError); | ||
await expect(promise).rejects.toThrowError( | ||
"Cannot iterate over null (null)" | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters