|
1 | 1 | import { validateAndCreateFunctions } from "../functions.ts"; |
2 | | -import { assertExists } from "../dev_deps.ts"; |
| 2 | +import { assertEquals, assertExists, assertRejects } from "../dev_deps.ts"; |
| 3 | +import { Options } from "../types.ts"; |
3 | 4 |
|
4 | 5 | Deno.test("validateAndCreateFunctions", () => { |
5 | 6 | assertExists(validateAndCreateFunctions); |
6 | 7 | }); |
| 8 | + |
| 9 | +Deno.test("validateAndCreateFunctions should not throw an exception when fed a function file that has a default export", async () => { |
| 10 | + const captured_log: string[] = []; |
| 11 | + const options: Options = { |
| 12 | + manifestOnly: true, |
| 13 | + workingDirectory: Deno.cwd(), |
| 14 | + log: (x) => { |
| 15 | + captured_log.push(x); |
| 16 | + }, |
| 17 | + }; |
| 18 | + const manifest = { |
| 19 | + "functions": { |
| 20 | + "test_function": { |
| 21 | + "title": "Test function", |
| 22 | + "description": "this is a test", |
| 23 | + "source_file": "src/tests/functions/test_function_file.ts", |
| 24 | + "input_parameters": { |
| 25 | + "required": [], |
| 26 | + "properties": {}, |
| 27 | + }, |
| 28 | + "output_parameters": { |
| 29 | + "required": [], |
| 30 | + "properties": {}, |
| 31 | + }, |
| 32 | + }, |
| 33 | + }, |
| 34 | + }; |
| 35 | + |
| 36 | + await validateAndCreateFunctions( |
| 37 | + options, |
| 38 | + manifest, |
| 39 | + ); |
| 40 | + assertEquals("", captured_log.join("")); |
| 41 | +}); |
| 42 | + |
| 43 | +Deno.test("Function files with no default export should get an error", async () => { |
| 44 | + const captured_log: string[] = []; |
| 45 | + const options: Options = { |
| 46 | + manifestOnly: true, |
| 47 | + workingDirectory: Deno.cwd(), |
| 48 | + log: (x) => { |
| 49 | + captured_log.push(x); |
| 50 | + }, |
| 51 | + }; |
| 52 | + const manifest = { |
| 53 | + "functions": { |
| 54 | + "test_function": { |
| 55 | + "title": "Test function", |
| 56 | + "description": "this is a test", |
| 57 | + "source_file": "src/tests/functions/test_function_no_export_file.ts", |
| 58 | + "input_parameters": { |
| 59 | + "required": [], |
| 60 | + "properties": {}, |
| 61 | + }, |
| 62 | + "output_parameters": { |
| 63 | + "required": [], |
| 64 | + "properties": {}, |
| 65 | + }, |
| 66 | + }, |
| 67 | + }, |
| 68 | + }; |
| 69 | + await assertRejects( |
| 70 | + () => validateAndCreateFunctions(options, manifest), |
| 71 | + Error, |
| 72 | + "default export handler", |
| 73 | + ); |
| 74 | +}); |
| 75 | + |
| 76 | +Deno.test("Function files not exporting a function should get an error", async () => { |
| 77 | + const captured_log: string[] = []; |
| 78 | + const options: Options = { |
| 79 | + manifestOnly: true, |
| 80 | + workingDirectory: Deno.cwd(), |
| 81 | + log: (x) => { |
| 82 | + captured_log.push(x); |
| 83 | + }, |
| 84 | + }; |
| 85 | + const manifest = { |
| 86 | + "functions": { |
| 87 | + "test_function": { |
| 88 | + "title": "Test function", |
| 89 | + "description": "this is a test", |
| 90 | + "source_file": "src/tests/functions/test_function_not_function_file.ts", |
| 91 | + "input_parameters": { |
| 92 | + "required": [], |
| 93 | + "properties": {}, |
| 94 | + }, |
| 95 | + "output_parameters": { |
| 96 | + "required": [], |
| 97 | + "properties": {}, |
| 98 | + }, |
| 99 | + }, |
| 100 | + }, |
| 101 | + }; |
| 102 | + await assertRejects( |
| 103 | + () => validateAndCreateFunctions(options, manifest), |
| 104 | + Error, |
| 105 | + "default export handler", |
| 106 | + ); |
| 107 | +}); |
0 commit comments